Unverified Commit 377173e8 authored by Armando Lüscher's avatar Armando Lüscher

Merge branch 'develop' into psr3-logger

parents a933b64d c8329d63
...@@ -7,3 +7,6 @@ charset = utf-8 ...@@ -7,3 +7,6 @@ charset = utf-8
indent_style = space indent_style = space
indent_size = 4 indent_size = 4
trim_trailing_whitespace = true trim_trailing_whitespace = true
[*.{yml, yaml}]
indent_size = 2
/.* export-ignore
/composer.lock export-ignore
/phpcs.xml.dist export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
tidelift: packagist/longman%2Ftelegram-bot
patreon: phptelegrambot
liberapay: PHP-Telegram-Bot
open_collective: php-telegram-bot
ko_fi: phptelegrambot
custom: https://github.com/php-telegram-bot/core#donate
<!-- If this is a feature request or idea, please remove all the text below this line before writing. -->
<!-- If this is a bug report or support request, please fill in the info below as accurately as you can. -->
### Required Information
<!-- Please enter exact version numbers, not just "latest" etc.! -->
- Operating system:
- PHP version:
- PHP Telegram Bot version:
- Using MySQL database: yes / no
- MySQL version:
- Update Method: Webhook / getUpdates
- Self-signed certificate: yes / no
- RAW update (if available):
### Expected behaviour
<!-- What SHOULD be happening? -->
### Actual behaviour
<!-- What IS happening? -->
### Steps to reproduce
<!-- Explain how to reproduce the issue -->
### Extra details
<!-- Please post any extra details that might help solve the issue (e.g. logs) -->
---
name: 💥 BC Break
about: Have you encountered an issue during an upgrade? 💣
---
<!--
Before reporting a BC break, please consult the changelog and wiki entry for the particular version to make sure it's not an expected change:
- https://github.com/php-telegram-bot/core/blob/master/CHANGELOG.md
- https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility
-->
### BC Break Report
<--
❗ NEVER put your Telegram API key or any other private details here. (like passwords, user IDs, etc.)
Substitute them like <API_KEY> or <USER_ID> etc.
-->
#### Required Information
<!-- Fill in the relevant information below to help triage your pull request. -->
<!-- Please enter exact version numbers, not just "latest" etc.! -->
| ? | !
| --- | ---
| Operating system | Name and version
| PHP Telegram Bot version | x.y.z
| PHP version | x.y.z
| MySQL version | x.y.z / none
| Update Method | Webhook / getUpdates
| Self-signed certificate | yes / no
| RAW update (if available) | `{...}`
#### Summary
<!-- Provide a summary describing the problem you are experiencing. -->
#### Previous behaviour
<!-- What was the previous (working) behaviour? -->
#### Current behaviour
<!-- What is the current (broken) behaviour? -->
#### How to reproduce
<!--
Provide steps to reproduce the bug.
If possible, also add any relevant code snippet.
-->
#### Expected behaviour
<!-- What was the expected (correct) behaviour? -->
---
name: 🐞 Bug Report
about: Something is broken? 🔨
---
### Bug Report
<--
❗ NEVER put your Telegram API key or any other private details here. (like passwords, user IDs, etc.)
Substitute them like <API_KEY> or <USER_ID> etc.
-->
#### Required Information
<!-- Fill in the relevant information below to help triage your pull request. -->
<!-- Please enter exact version numbers, not just "latest" etc.! -->
| ? | !
| --- | ---
| Operating system | Name and version
| PHP Telegram Bot version | x.y.z
| PHP version | x.y.z
| MySQL version | x.y.z / none
| Update Method | Webhook / getUpdates
| Self-signed certificate | yes / no
| RAW update (if available) | `{...}`
#### Summary
<!-- Provide a summary describing the problem you are experiencing. -->
### Current behaviour
<!-- What is the current (buggy) behaviour? -->
#### How to reproduce
<!--
Provide steps to reproduce the bug.
If possible, also add any relevant code snippet.
-->
#### Expected behaviour
<!-- What was the expected (correct) behaviour? -->
---
name: 🎉 Feature Request
about: You have a neat idea that should be implemented? 🎩
---
### Feature Request
#### Summary
<!-- Provide a summary of the feature you would like to see implemented. -->
---
name: ❓ Support Question
about: Have a problem that you can't figure out? 🤔
---
### Support Question
<!--
Before asking a question here, please try asking in the support group first.
https://telegram.me/PHP_Telegram_Bot_Support
Keep in mind that GitHub is primarily an issue tracker.
-->
<--
❗ NEVER put your Telegram API key or any other private details here. (like passwords, user IDs, etc.)
Substitute them like <API_KEY> or <USER_ID> etc.
-->
#### Required Information
<!-- Fill in the relevant information below to help triage your pull request. -->
<!-- Please enter exact version numbers, not just "latest" etc.! -->
| ? | !
| --- | ---
| Operating system | Name and version
| PHP Telegram Bot version | x.y.z
| PHP version | x.y.z
| MySQL version | x.y.z / none
| Update Method | Webhook / getUpdates
| Self-signed certificate | yes / no
| RAW update (if available) | `{...}`
#### Summary
<!-- Describe the issue you are facing here. -->
<!-- Important: If this pull request is not related to any issue and contains a new feature, please create an issue first for discussion. --> <!--
Important:
If this pull request is not related to any issue and contains a new feature, please create an issue first for discussion.
https://github.com/php-telegram-bot/core/issues/new?template=Feature_Request.md
<!-- Make sure this pull request is pointed towards the "develop" branch and refers to any issue that it's related to! --> Make sure this pull request is pointed towards the "develop" branch and refers to any issue that it's related to!
-->
<!-- Explain in detail what this pull request contains. --> <!-- Fill in the relevant information below to help triage your pull request. -->
| ? | !
|--- | ---
| Type | bug / feature / improvement
| BC Break | yes / no
| Fixed issues | <!-- use #NUM format to reference an issue -->
#### Summary
<!-- Provide a summary of your change. -->
...@@ -5,28 +5,20 @@ ...@@ -5,28 +5,20 @@
.DS_Store .DS_Store
.idea .idea
.phpintel .phpintel
composer.phar
# Local System Files (i.e. cache, logs, etc.) #
/cache
/build/logs
/build/coverage
/tmp
# Test Related Files #
/phpunit.xml
#Exception output
TelegramException.log
# Composer # Composer
vendor/ /composer.phar
/vendor
# Test-Related Files
/clover.xml
/phpcs.xml
/phpunit.xml
# phpDocumentor Logs # # phpDocumentor Logs
phpdoc-* phpdoc-*
# OSX # # OSX
._* ._*
.Spotlight-V100 .Spotlight-V100
.Trashes .Trashes
build:
nodes:
analysis:
tests:
override:
- php-scrutinizer-run
filter: filter:
paths: [src/*] paths:
- src/
dependency_paths:
- lib/
checks: checks:
php: php:
remove_extra_empty_lines: true check_method_contracts:
remove_php_closing_tag: true verify_interface_like_constraints: true
remove_trailing_whitespace: true verify_documented_constraints: true
verify_parent_constraints: true
fix_doc_comments: true
fix_identation_4spaces: true
fix_line_ending: true
fix_linefeed: true
fix_php_opening_tag: true
fix_use_statements: fix_use_statements:
remove_unused: true remove_unused: true
preserve_multiple: false preserve_multiple: false
preserve_blanklines: true preserve_blanklines: true
order_alphabetically: true order_alphabetically: true
fix_php_opening_tag: true more_specific_types_in_doc_comments: true
fix_linefeed: true no_goto: true
fix_line_ending: true param_doc_comment_if_not_inferrable: true
fix_identation_4spaces: true parameter_doc_comments: true
fix_doc_comments: true remove_extra_empty_lines: true
return_doc_comment_if_not_inferrable: true
return_doc_comments: true
simplify_boolean_return: true
tools: tools:
external_code_coverage: external_code_coverage:
timeout: 120 timeout: 300
dist: trusty
sudo: required
language: php language: php
sudo: required
dist: trusty
addons: addons:
mariadb: 10.1 mariadb: 10.1
cache: cache:
directories: directories:
- "$HOME/.composer/cache" - vendor
- $HOME/.composer/cache
php: php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3 - 7.3
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- nightly - nightly
- hhvm - hhvm
...@@ -44,7 +45,7 @@ before_script: ...@@ -44,7 +45,7 @@ before_script:
script: script:
- composer check-code - composer check-code
- if [ "$TRAVIS_PHP_VERSION" == "7.2" ] ; then composer test-cov; else composer test; fi - if [ "$TRAVIS_PHP_VERSION" == "7.3" ]; then composer test-cov; else composer test; fi
after_script: after_script:
- if [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then composer test-cov-upload; fi - if [ "$TRAVIS_PHP_VERSION" == "7.3" ]; then composer test-cov-upload; fi
...@@ -5,13 +5,22 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -5,13 +5,22 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
## [Unreleased] ## [Unreleased]
### Added ### Added
- New funding and support details.
- Custom issue templates. (#972)
### Changed ### Changed
- Use PSR-12 for code style.
- Some general housekeeping. (#972)
- [:exclamation:][unreleased-bc] Return an empty array for Entity properties with no items, instead of `null`. (#969)
- `TelegramLog` now adheres to [PSR-3] `LoggerInterface` and allows custom logger implementations. - `TelegramLog` now adheres to [PSR-3] `LoggerInterface` and allows custom logger implementations.
### Deprecated ### Deprecated
- Old logging that uses Monolog still works but will be removed in the near future. Use `TelegramLog::initialize($logger, $update_logger);` from now on. - Old logging that uses Monolog still works but will be removed in the near future. Use `TelegramLog::initialize($logger, $update_logger);` from now on.
### Removed ### Removed
- Botan.io integration completely removed.
### Fixed ### Fixed
- `forward_date` is now correctly saved to the DB.
- Broken `StickerSet::getStickers()` method.
### Security ### Security
- Security disclosure managed by Tidelift.
## [0.57.0] - 2019-06-01 ## [0.57.0] - 2019-06-01
:exclamation: After updating to this version, you will need to execute the [SQL migration script][0.57.0-sql-migration] on your database. :exclamation: After updating to this version, you will need to execute the [SQL migration script][0.57.0-sql-migration] on your database.
...@@ -264,6 +273,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -264,6 +273,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- Move `hideKeyboard` to `removeKeyboard`. - Move `hideKeyboard` to `removeKeyboard`.
[unreleased-sql-migration]: https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/unreleased.sql [unreleased-sql-migration]: https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/unreleased.sql
[unreleased-bc]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#unreleased
[0.57.0-sql-migration]: https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.56.0-0.57.0.sql [0.57.0-sql-migration]: https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.56.0-0.57.0.sql
[0.55.0-sql-migration]: https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.54.1-0.55.0.sql [0.55.0-sql-migration]: https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.54.1-0.55.0.sql
[0.55.0-bc-move-animation-out-of-games-namespace]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#move-animation-out-of-games-namespace [0.55.0-bc-move-animation-out-of-games-namespace]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#move-animation-out-of-games-namespace
......
Contributing # Contributing
-------------
The easiest way to contribute is to work on a checkout of your own fork. The easiest way to contribute is to work on a checkout of your own fork.
When working on the `core` repository, it makes sense to rename your fork to `php-telegram-bot`. When working on the `core` repository, it makes sense to rename your fork to `php-telegram-bot`.
Before you contribute code, please make sure it conforms to the PSR-2 coding standard and that the unit tests still pass. Before you contribute code, please make sure it conforms to the PSR-12 coding standard and that the unit tests still pass.
You can run the following commands to check if everything is ready to submit: You can run the following commands to check if everything is ready to submit:
cd php-telegram-bot ```bash
composer install cd php-telegram-bot
composer check-code composer install
composer check-code
```
Which should give you no output, indicating that there are no coding standard errors. Which should give you no output, indicating that there are no coding standard errors.
And then (remember to set up your test database!): And then (remember to set up your test database!):
composer test ```bash
composer test
```
Which should give you no failures or errors. You can ignore any skipped tests as these are for external tools. Which should give you no failures or errors. You can ignore any skipped tests as these are for external tools.
Pushing ## Pushing
-------
Development is based on the git flow branching model (see http://nvie.com/posts/a-successful-git-branching-model/) Development is based on the git flow branching model (see http://nvie.com/posts/a-successful-git-branching-model/)
If you fix a bug please push in hotfix branch. If you fix a bug please push in hotfix branch.
If you develop a new feature please create a new branch. If you develop a new feature please create a new branch.
Version ## Version
-------
Version number: 0.#version.#hotfix Version number: 0.#version.#hotfix
Further code convention adopted ## Further code convention adopted
-------------------------------
- Each method and class is documented with a docblock - Each method and class is documented with a docblock
......
<img src="assets/logo/512px/logo_plain.png" title="PHP Telegram Bot" alt="PHP Telegram Bot logo">
# PHP Telegram Bot # PHP Telegram Bot
A Telegram Bot based on the official [Telegram Bot API][Telegram-Bot-API]
[![Join the bot support group on Telegram](https://img.shields.io/badge/telegram-@PHP__Telegram__Bot__Support-32a2da.svg)](https://telegram.me/PHP_Telegram_Bot_Support) [![Join the bot support group on Telegram](https://img.shields.io/badge/telegram-@PHP__Telegram__Bot__Support-32a2da.svg)](https://telegram.me/PHP_Telegram_Bot_Support)
[![Donate](https://img.shields.io/badge/%F0%9F%92%99-Donate-blue.svg)](#donate) [![Donate](https://img.shields.io/badge/%F0%9F%92%99-Donate-blue.svg)](#donate)
[![Build Status](https://travis-ci.org/php-telegram-bot/core.svg?branch=master)](https://travis-ci.org/php-telegram-bot/core) [![Build Status](https://travis-ci.org/php-telegram-bot/core.svg?branch=master)](https://travis-ci.org/php-telegram-bot/core)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-telegram-bot/core/develop.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-telegram-bot/core/?b=develop) [![Dependencies](https://tidelift.com/badges/github/php-telegram-bot/core)][Tidelift]
[![Code Quality](https://img.shields.io/scrutinizer/g/php-telegram-bot/core/develop.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-telegram-bot/core/?b=develop) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-telegram-bot/core/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-telegram-bot/core/?b=master)
[![Latest Stable Version](https://img.shields.io/packagist/v/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot) [![Code Quality](https://img.shields.io/scrutinizer/g/php-telegram-bot/core/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-telegram-bot/core/?b=master)
[![Total Downloads](https://img.shields.io/packagist/dt/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot) [![Latest Stable Version](https://img.shields.io/packagist/v/longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot)
[![Downloads Month](https://img.shields.io/packagist/dm/Longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot) [![Total Downloads](https://img.shields.io/packagist/dt/longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot)
[![Downloads Month](https://img.shields.io/packagist/dm/longman/telegram-bot.svg)](https://packagist.org/packages/longman/telegram-bot)
[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D5.6-8892BF.svg)](https://php.net/) [![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D5.6-8892BF.svg)](https://php.net/)
[![License](https://img.shields.io/packagist/l/Longman/telegram-bot.svg)](https://github.com/php-telegram-bot/core/LICENSE.md) [![License](https://img.shields.io/packagist/l/longman/telegram-bot.svg)](https://github.com/php-telegram-bot/core/LICENSE)
![Telegram Bot API Logo](assets/logo/512px/logo_plain.png) ![Telegram Bot API Logo](assets/logo/512px/logo_plain.png)
...@@ -22,10 +27,11 @@ A Telegram Bot based on the official [Telegram Bot API][Telegram-Bot-API] ...@@ -22,10 +27,11 @@ A Telegram Bot based on the official [Telegram Bot API][Telegram-Bot-API]
- [Create your first bot](#create-your-first-bot) - [Create your first bot](#create-your-first-bot)
- [Require this package with Composer](#require-this-package-with-composer) - [Require this package with Composer](#require-this-package-with-composer)
- [Choose how to retrieve Telegram updates](#choose-how-to-retrieve-telegram-updates) - [Choose how to retrieve Telegram updates](#choose-how-to-retrieve-telegram-updates)
- [Webhook installation](#webhook-installation) - [Webhook installation](#webhook-installation)
- [Self Signed Certificate](#self-signed-certificate) - [Self Signed Certificate](#self-signed-certificate)
- [Unset Webhook](#unset-webhook) - [Unset Webhook](#unset-webhook)
- [getUpdates installation](#getupdates-installation) - [getUpdates installation](#getupdates-installation)
- [getUpdates without database](#getupdates-without-database)
- [Support](#support) - [Support](#support)
- [Types](#types) - [Types](#types)
- [Inline Query](#inline-query) - [Inline Query](#inline-query)
...@@ -38,13 +44,13 @@ A Telegram Bot based on the official [Telegram Bot API][Telegram-Bot-API] ...@@ -38,13 +44,13 @@ A Telegram Bot based on the official [Telegram Bot API][Telegram-Bot-API]
- [Send message to all active chats](#send-message-to-all-active-chats) - [Send message to all active chats](#send-message-to-all-active-chats)
- [Utils](#utils) - [Utils](#utils)
- [MySQL storage (Recommended)](#mysql-storage-recommended) - [MySQL storage (Recommended)](#mysql-storage-recommended)
- [External Database connection](#external-database-connection)
- [Channels Support](#channels-support) - [Channels Support](#channels-support)
- [Botan.io integration (Optional)](#botanio-integration-optional)
- [Commands](#commands) - [Commands](#commands)
- [Predefined Commands](#predefined-commands) - [Predefined Commands](#predefined-commands)
- [Custom Commands](#custom-commands) - [Custom Commands](#custom-commands)
- [Commands Configuration](#commands-configuration) - [Commands Configuration](#commands-configuration)
- [Admin Commands](#admin-commands) - [Admin Commands](#admin-commands)
- [Set Admins](#set-admins) - [Set Admins](#set-admins)
- [Channel Administration](#channel-administration) - [Channel Administration](#channel-administration)
- [Upload and Download directory path](#upload-and-download-directory-path) - [Upload and Download directory path](#upload-and-download-directory-path)
...@@ -54,6 +60,7 @@ A Telegram Bot based on the official [Telegram Bot API][Telegram-Bot-API] ...@@ -54,6 +60,7 @@ A Telegram Bot based on the official [Telegram Bot API][Telegram-Bot-API]
- [Projects with this library](#projects-with-this-library) - [Projects with this library](#projects-with-this-library)
- [Troubleshooting](#troubleshooting) - [Troubleshooting](#troubleshooting)
- [Contributing](#contributing) - [Contributing](#contributing)
- [Security](#security)
- [Donate](#donate) - [Donate](#donate)
- [License](#license) - [License](#license)
- [Credits](#credits) - [Credits](#credits)
...@@ -81,7 +88,6 @@ The Bot can: ...@@ -81,7 +88,6 @@ The Bot can:
- full support for **inline bots**. - full support for **inline bots**.
- inline keyboard. - inline keyboard.
- Messages, InlineQuery and ChosenInlineQuery are stored in the Database. - Messages, InlineQuery and ChosenInlineQuery are stored in the Database.
- *Botan.io* integration and database cache system. (**new!**)
- Conversation feature - Conversation feature
----- -----
...@@ -180,7 +186,7 @@ composer require longman/telegram-bot ...@@ -180,7 +186,7 @@ composer require longman/telegram-bot
### Choose how to retrieve Telegram updates ### Choose how to retrieve Telegram updates
The bot can handle updates with **Webhook** or **getUpdates** method: The bot can handle updates with [**Webhook**](#webhook-installation) or [**getUpdates**](#getupdates-installation) method:
| | Webhook | getUpdates | | | Webhook | getUpdates |
| ---- | :----: | :----: | | ---- | :----: | :----: |
...@@ -188,7 +194,6 @@ The bot can handle updates with **Webhook** or **getUpdates** method: ...@@ -188,7 +194,6 @@ The bot can handle updates with **Webhook** or **getUpdates** method:
| Host with https | Required | Not required | | Host with https | Required | Not required |
| MySQL | Not required | ([Not](#getupdates-without-database)) Required | | MySQL | Not required | ([Not](#getupdates-without-database)) Required |
## Webhook installation ## Webhook installation
Note: For a more detailed explanation, head over to the [example-bot repository][example-bot-repository] and follow the instructions there. Note: For a more detailed explanation, head over to the [example-bot repository][example-bot-repository] and follow the instructions there.
...@@ -444,32 +449,9 @@ $telegram->enableExternalMySql($external_pdo_connection) ...@@ -444,32 +449,9 @@ $telegram->enableExternalMySql($external_pdo_connection)
All methods implemented can be used to manage channels. All methods implemented can be used to manage channels.
With [admin commands](#admin-commands) you can manage your channels directly with your bot private chat. With [admin commands](#admin-commands) you can manage your channels directly with your bot private chat.
### Botan.io integration (Optional) ## Commands
You can enable the integration using this line in you `hook.php`:
```php
$telegram->enableBotan('your_token');
```
Replace `your_token` with your Botan.io token, check [this page](https://github.com/botanio/sdk#creating-an-account) to see how to obtain one.
The following actions will be tracked:
- Commands (shown as `Command (/command_name)` in the stats
- Inline Queries, Chosen Inline Results and Callback Queries
- Messages sent to the bot (or replies in groups)
In order to use the URL shortener you must include the class `use Longman\TelegramBot\Botan;` and call it like this:
```php ### Predefined Commands
Botan::shortenUrl('https://github.com/php-telegram-bot/core', $user_id);
```
Shortened URLs are cached in the database (if MySQL storage is enabled).
### Commands
#### Predefined Commands
The bot is able to recognise commands in a chat with multiple bots (/command@mybot). The bot is able to recognise commands in a chat with multiple bots (/command@mybot).
...@@ -495,14 +477,14 @@ Here's the list: ...@@ -495,14 +477,14 @@ Here's the list:
- Favourite colour? */black, /red* - Favourite colour? */black, /red*
- Favourite number? */1, /134* - Favourite number? */1, /134*
#### Custom Commands ### Custom Commands
Maybe you would like to develop your own commands. Maybe you would like to develop your own commands.
There is a guide to help you [create your own commands][wiki-create-your-own-commands]. There is a guide to help you [create your own commands][wiki-create-your-own-commands].
Also, be sure to have a look at the [example commands][ExampleCommands-folder] to learn more about custom commands and how they work. Also, be sure to have a look at the [example commands][ExampleCommands-folder] to learn more about custom commands and how they work.
#### Commands Configuration ### Commands Configuration
With this method you can set some command specific parameters, for example: With this method you can set some command specific parameters, for example:
...@@ -571,7 +553,7 @@ $telegram->setCommandConfig('sendtochannel', [ ...@@ -571,7 +553,7 @@ $telegram->setCommandConfig('sendtochannel', [
``` ```
- Enjoy! - Enjoy!
### Upload and Download directory path ## Upload and Download directory path
To use the Upload and Download functionality, you need to set the paths with: To use the Upload and Download functionality, you need to set the paths with:
```php ```php
...@@ -603,7 +585,15 @@ If you like living on the edge, please report any bugs you find on the ...@@ -603,7 +585,15 @@ If you like living on the edge, please report any bugs you find on the
## Contributing ## Contributing
See [CONTRIBUTING](.github/CONTRIBUTING.md) for more information. See [CONTRIBUTING](CONTRIBUTING.md) for more information.
## Security
See [SECURITY](SECURITY.md) for more information.
## Security
See [SECURITY](SECURITY.md) for more information.
## Donate ## Donate
...@@ -612,15 +602,20 @@ If you enjoy using this library and would like to say thank you, donations are a ...@@ -612,15 +602,20 @@ If you enjoy using this library and would like to say thank you, donations are a
Donations are invested back into the project :+1: Donations are invested back into the project :+1:
- Gratipay: [Gratipay/PHP-Telegram-Bot] Thank you for keeping this project alive :pray:
- Liberapay: [Liberapay/PHP-Telegram-Bot]
- PayPal: [PayPal/noplanman] (account of @noplanman) - [![Patreon](https://user-images.githubusercontent.com/9423417/59235980-a5fa6b80-8be3-11e9-8ae7-020bc4ae9baa.png) Patreon.com/phptelegrambot][Patreon]
- Bitcoin: [166NcyE7nDxkRPWidWtG1rqrNJoD5oYNiV][bitcoin] - [![OpenCollective](https://user-images.githubusercontent.com/9423417/59235978-a561d500-8be3-11e9-89be-82ec54be1546.png) OpenCollective.com/php-telegram-bot][OpenCollective]
- Ethereum: [0x485855634fa212b0745375e593fAaf8321A81055][ethereum] - [![Ko-fi](https://user-images.githubusercontent.com/9423417/59235976-a561d500-8be3-11e9-911d-b1908c3e6a33.png) Ko-fi.com/phptelegrambot][Ko-fi]
- [![Tidelift](https://user-images.githubusercontent.com/9423417/59235982-a6930200-8be3-11e9-8ac2-bfb6991d80c5.png) Tidelift.com/longman/telegram-bot][Tidelift]
- [![Liberapay](https://user-images.githubusercontent.com/9423417/59235977-a561d500-8be3-11e9-9d16-bc3b13d3ceba.png) Liberapay.com/PHP-Telegram-Bot][Liberapay]
- [![PayPal](https://user-images.githubusercontent.com/9423417/59235981-a5fa6b80-8be3-11e9-9761-15eb7a524cb0.png) PayPal.me/noplanman][PayPal-noplanman] (account of @noplanman)
- [![Bitcoin](https://user-images.githubusercontent.com/9423417/59235974-a4c93e80-8be3-11e9-9fde-260c821b6eae.png) 166NcyE7nDxkRPWidWtG1rqrNJoD5oYNiV][Bitcoin]
- [![Ethereum](https://user-images.githubusercontent.com/9423417/59235975-a4c93e80-8be3-11e9-8762-7a47c62c968d.png) 0x485855634fa212b0745375e593fAaf8321A81055][Ethereum]
## License ## License
Please see the [LICENSE](LICENSE.md) included in this repository for a full copy of the MIT license, Please see the [LICENSE](LICENSE) included in this repository for a full copy of the MIT license,
which this project is licensed under. which this project is licensed under.
## Credits ## Credits
...@@ -645,8 +640,12 @@ Credit list in [CREDITS](CREDITS) ...@@ -645,8 +640,12 @@ Credit list in [CREDITS](CREDITS)
[wiki]: https://github.com/php-telegram-bot/core/wiki "PHP Telegram Bot Wiki" [wiki]: https://github.com/php-telegram-bot/core/wiki "PHP Telegram Bot Wiki"
[wiki-create-your-own-commands]: https://github.com/php-telegram-bot/core/wiki/Create-your-own-commands "Create your own commands" [wiki-create-your-own-commands]: https://github.com/php-telegram-bot/core/wiki/Create-your-own-commands "Create your own commands"
[issues]: https://github.com/php-telegram-bot/core/issues "PHP Telegram Bot Issues" [issues]: https://github.com/php-telegram-bot/core/issues "PHP Telegram Bot Issues"
[Gratipay/PHP-Telegram-Bot]: https://gratipay.com/PHP-Telegram-Bot "Donate with Gratipay"
[Liberapay/PHP-Telegram-Bot]: https://liberapay.com/PHP-Telegram-Bot "Donate with Liberapay" [Patreon]: https://www.patreon.com/phptelegrambot "Support us on Patreon"
[PayPal/noplanman]: https://paypal.me/noplanman "Donate with PayPal" [OpenCollective]: https://opencollective.com/php-telegram-bot "Support us on Open Collective"
[bitcoin]: bitcoin:166NcyE7nDxkRPWidWtG1rqrNJoD5oYNiV "Donate with Bitcoin" [Ko-fi]: https://ko-fi.com/phptelegrambot "Support us on Ko-fi"
[ethereum]: https://www.myetherwallet.com/?to=0x485855634fa212b0745375e593fAaf8321A81055 "Donate with Ethereum" [Tidelift]: https://tidelift.com/subscription/pkg/packagist-longman-telegram-bot?utm_source=packagist-longman-telegram-bot&utm_medium=referral&utm_campaign=readme "Support us on Tidelift"
[Liberapay]: https://liberapay.com/PHP-Telegram-Bot "Donate with Liberapay"
[PayPal-noplanman]: https://paypal.me/noplanman "Donate with PayPal"
[Bitcoin]: https://www.blockchain.com/btc/address/166NcyE7nDxkRPWidWtG1rqrNJoD5oYNiV "Donate with Bitcoin"
[Ethereum]: https://etherscan.io/address/0x485855634fa212b0745375e593fAaf8321A81055 "Donate with Ethereum"
# Security
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
Tidelift will then coordinate the fix and disclosure.
...@@ -48,16 +48,16 @@ ...@@ -48,16 +48,16 @@
}, },
"scripts": { "scripts": {
"check-code": [ "check-code": [
"\"vendor/bin/phpcs\" --standard=phpcs.xml -snp --encoding=utf-8 src/ tests/ --report-width=150" "\"vendor/bin/phpcs\" -snp src/ tests/"
], ],
"test": [ "test": [
"\"vendor/bin/phpunit\"" "\"vendor/bin/phpunit\""
], ],
"test-cov": [ "test-cov": [
"\"vendor/bin/phpunit\" --coverage-clover build/logs/clover.xml" "\"vendor/bin/phpunit\" --coverage-clover clover.xml"
], ],
"test-cov-upload": [ "test-cov-upload": [
"wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml" "wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover clover.xml"
] ]
} }
} }
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
<description>PHP Code Sniffer</description> <description>PHP Code Sniffer</description>
<arg name="colors"/> <arg name="colors"/>
<arg name="parallel" value="8"/>
<arg name="encoding" value="utf-8"/>
<arg name="report-width" value="150"/>
<rule ref="PSR2"/> <rule ref="PSR12"/>
<rule ref="Generic.CodeAnalysis.EmptyStatement"/> <rule ref="Generic.CodeAnalysis.EmptyStatement"/>
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/> <rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
......
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
timeoutForMediumTests="10" timeoutForMediumTests="10"
timeoutForSmallTests="1" timeoutForSmallTests="1"
verbose="false" verbose="false"
> >
<php> <php>
<ini name="error_reporting" value="-1" /> <ini name="error_reporting" value="-1"/>
<const name="PHPUNIT_TESTSUITE" value="true"/> <const name="PHPUNIT_TESTSUITE" value="true"/>
<const name="PHPUNIT_DB_HOST" value="127.0.0.1"/> <const name="PHPUNIT_DB_HOST" value="127.0.0.1"/>
<const name="PHPUNIT_DB_NAME" value="telegrambot"/> <const name="PHPUNIT_DB_NAME" value="telegrambot"/>
......
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class Botan
*
* @deprecated Botan.io service is no longer working
*
* Integration with http://botan.io statistics service for Telegram bots
*/
class Botan
{
/**
* Botan.io API URL
*
* @var string
*/
protected static $api_base_uri = 'https://api.botan.io';
/**
* Yandex AppMetrica application key
*
* @var string
*/
protected static $token = '';
/**
* Guzzle Client object
*
* @var \GuzzleHttp\Client
*/
private static $client;
/**
* The actual command that is going to be reported
*
* Set as public to let the developers either:
* - block tracking from inside commands by setting the value to non-existent command
* - override which command is tracked when commands call other commands with executeCommand()
*
* @var string
*/
public static $command = '';
/**
* Initialize Botan
*
* @param string $token
* @param array $options
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function initializeBotan($token, array $options = [])
{
trigger_error('Longman\TelegramBot\Botan::initializeBotan is deprecated and will be removed in future release.', E_USER_DEPRECATED);
if (empty($token)) {
throw new TelegramException('Botan token is empty!');
}
$options_default = [
'timeout' => 3,
];
$options = array_merge($options_default, $options);
if (!is_numeric($options['timeout'])) {
throw new TelegramException('Timeout must be a number!');
}
self::$token = $token;
self::$client = new Client(['base_uri' => self::$api_base_uri, 'timeout' => $options['timeout']]);
BotanDB::initializeBotanDb();
}
/**
* Lock function to make sure only the first command is reported (the one user requested)
*
* This is in case commands are calling other commands with executeCommand()
*
* @param string $command
*/
public static function lock($command = '')
{
if (empty(self::$command)) {
self::$command = strtolower($command);
}
}
/**
* Track function
*
* @param \Longman\TelegramBot\Entities\Update $update
* @param string $command
*
* @return bool|string
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function track(Update $update, $command = '')
{
$command = strtolower($command);
if (empty(self::$token) || $command !== self::$command) {
return false;
}
if ($update === null) {
throw new TelegramException('Update object is empty!');
}
// Release the lock in case this is getUpdates instance in foreach loop
self::$command = '';
$data = [];
$update_data = (array) $update; // For now, this is the only way
$update_type = $update->getUpdateType();
$update_object_names = [
'message' => 'Message',
'edited_message' => 'Edited Message',
'channel_post' => 'Channel Post',
'edited_channel_post' => 'Edited Channel Post',
'inline_query' => 'Inline Query',
'chosen_inline_result' => 'Chosen Inline Result',
'callback_query' => 'Callback Query',
];
if (array_key_exists($update_type, $update_object_names)) {
$data = $update_data[$update_type];
$event_name = $update_object_names[$update_type];
if ($update_type === 'message' && $entities = $update->getMessage()->getEntities()) {
foreach ($entities as $entity) {
if ($entity->getType() === 'bot_command' && $entity->getOffset() === 0) {
if ($command === 'generic') {
$command = 'Generic';
} elseif ($command === 'genericmessage') { // This should not happen as it equals normal message but leaving it as a fail-safe
$command = 'Generic Message';
} else {
$command = '/' . $command;
}
$event_name = 'Command (' . $command . ')';
break;
}
}
}
}
if (empty($event_name)) {
TelegramLog::error('Botan.io stats report failed, no suitable update object found!');
return false;
}
// In case there is no from field assign id = 0
$uid = isset($data['from']['id']) ? $data['from']['id'] : 0;
try {
$response = self::$client->post(
sprintf(
'/track?token=%1$s&uid=%2$s&name=%3$s',
self::$token,
$uid,
urlencode($event_name)
),
[
'headers' => [
'Content-Type' => 'application/json',
],
'json' => $data,
]
);
$result = (string) $response->getBody();
} catch (RequestException $e) {
$result = $e->getMessage();
}
$responseData = json_decode($result, true);
if (!$responseData || $responseData['status'] !== 'accepted') {
TelegramLog::debug('Botan.io stats report failed: %s', $result ?: 'empty response');
return false;
}
return $responseData;
}
/**
* Url Shortener function
*
* @param string $url
* @param integer $user_id
*
* @return string
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function shortenUrl($url, $user_id)
{
if (empty(self::$token)) {
return $url;
}
if (empty($user_id)) {
throw new TelegramException('User id is empty!');
}
if ($cached = BotanDB::selectShortUrl($url, $user_id)) {
return $cached;
}
try {
$response = self::$client->post(
sprintf(
'/s?token=%1$s&user_ids=%2$s&url=%3$s',
self::$token,
$user_id,
urlencode($url)
)
);
$result = (string) $response->getBody();
} catch (RequestException $e) {
$result = $e->getMessage();
}
if (filter_var($result, FILTER_VALIDATE_URL) === false) {
TelegramLog::debug('Botan.io URL shortening failed for "%s": %s', $url, $result ?: 'empty response');
return $url;
}
BotanDB::insertShortUrl($url, $user_id, $result);
return $result;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot;
use Exception;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class BotanDB
*
* @deprecated Botan.io service is no longer working
*/
class BotanDB extends DB
{
/**
* Initialize botan shortener table
*/
public static function initializeBotanDb()
{
if (!defined('TB_BOTAN_SHORTENER')) {
define('TB_BOTAN_SHORTENER', self::$table_prefix . 'botan_shortener');
}
}
/**
* Select cached shortened URL from the database
*
* @param string $url
* @param string $user_id
*
* @return array|bool
* @throws TelegramException
*/
public static function selectShortUrl($url, $user_id)
{
if (!self::isDbConnected()) {
return false;
}
try {
$sth = self::$pdo->prepare('
SELECT `short_url`
FROM `' . TB_BOTAN_SHORTENER . '`
WHERE `user_id` = :user_id
AND `url` = :url
ORDER BY `created_at` DESC
LIMIT 1
');
$sth->bindValue(':user_id', $user_id);
$sth->bindValue(':url', $url);
$sth->execute();
return $sth->fetchColumn();
} catch (Exception $e) {
throw new TelegramException($e->getMessage());
}
}
/**
* Insert shortened URL into the database
*
* @param string $url
* @param string $user_id
* @param string $short_url
*
* @return bool
* @throws TelegramException
*/
public static function insertShortUrl($url, $user_id, $short_url)
{
if (!self::isDbConnected()) {
return false;
}
try {
$sth = self::$pdo->prepare('
INSERT INTO `' . TB_BOTAN_SHORTENER . '`
(`user_id`, `url`, `short_url`, `created_at`)
VALUES
(:user_id, :url, :short_url, :created_at)
');
$sth->bindValue(':user_id', $user_id);
$sth->bindValue(':url', $url);
$sth->bindValue(':short_url', $short_url);
$sth->bindValue(':created_at', self::getTimestamp());
return $sth->execute();
} catch (Exception $e) {
throw new TelegramException($e->getMessage());
}
}
}
...@@ -13,6 +13,8 @@ namespace Longman\TelegramBot\Commands\AdminCommands; ...@@ -13,6 +13,8 @@ namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand; use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\DB; use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Chat; use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
class ChatsCommand extends AdminCommand class ChatsCommand extends AdminCommand
...@@ -45,8 +47,8 @@ class ChatsCommand extends AdminCommand ...@@ -45,8 +47,8 @@ class ChatsCommand extends AdminCommand
/** /**
* Command execute method * Command execute method
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -12,6 +12,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands; ...@@ -12,6 +12,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand; use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\DB; use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
use Longman\TelegramBot\TelegramLog; use Longman\TelegramBot\TelegramLog;
...@@ -68,7 +69,6 @@ class CleanupCommand extends AdminCommand ...@@ -68,7 +69,6 @@ class CleanupCommand extends AdminCommand
* @var array * @var array
*/ */
protected static $default_tables_to_clean = [ protected static $default_tables_to_clean = [
'botan_shortener',
'callback_query', 'callback_query',
'chosen_inline_result', 'chosen_inline_result',
'conversation', 'conversation',
...@@ -85,7 +85,6 @@ class CleanupCommand extends AdminCommand ...@@ -85,7 +85,6 @@ class CleanupCommand extends AdminCommand
* @var array * @var array
*/ */
protected static $default_clean_older_than = [ protected static $default_clean_older_than = [
'botan_shortener' => '30 days',
'chat' => '365 days', 'chat' => '365 days',
'callback_query' => '30 days', 'callback_query' => '30 days',
'chosen_inline_result' => '30 days', 'chosen_inline_result' => '30 days',
...@@ -242,11 +241,6 @@ class CleanupCommand extends AdminCommand ...@@ -242,11 +241,6 @@ class CleanupCommand extends AdminCommand
'request_limiter' => ['table' => TB_REQUEST_LIMITER, 'field' => 'created_at'], 'request_limiter' => ['table' => TB_REQUEST_LIMITER, 'field' => 'created_at'],
]; ];
// Botan table is only available if enabled.
if (defined('TB_BOTAN_SHORTENER')) {
$simple_tables['botan_shortener'] = ['table' => TB_BOTAN_SHORTENER, 'field' => 'created_at'];
}
foreach (array_intersect(array_keys($simple_tables), $tables_to_clean) as $table_to_clean) { foreach (array_intersect(array_keys($simple_tables), $tables_to_clean) as $table_to_clean) {
$queries[] = sprintf( $queries[] = sprintf(
'DELETE FROM `%1$s` 'DELETE FROM `%1$s`
...@@ -345,7 +339,8 @@ class CleanupCommand extends AdminCommand ...@@ -345,7 +339,8 @@ class CleanupCommand extends AdminCommand
/** /**
* Execution if MySQL is required but not available * Execution if MySQL is required but not available
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws TelegramException
*/ */
public function executeNoDb() public function executeNoDb()
{ {
...@@ -364,8 +359,8 @@ class CleanupCommand extends AdminCommand ...@@ -364,8 +359,8 @@ class CleanupCommand extends AdminCommand
/** /**
* Command execute method * Command execute method
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -12,6 +12,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands; ...@@ -12,6 +12,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand; use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\DB; use Longman\TelegramBot\DB;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -43,7 +44,7 @@ class DebugCommand extends AdminCommand ...@@ -43,7 +44,7 @@ class DebugCommand extends AdminCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -13,6 +13,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands; ...@@ -13,6 +13,7 @@ namespace Longman\TelegramBot\Commands\AdminCommands;
use Longman\TelegramBot\Commands\AdminCommand; use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\Entities\Message; use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\ServerResponse; use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -48,8 +49,8 @@ class SendtoallCommand extends AdminCommand ...@@ -48,8 +49,8 @@ class SendtoallCommand extends AdminCommand
/** /**
* Execute command * Execute command
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -15,6 +15,8 @@ use Longman\TelegramBot\Conversation; ...@@ -15,6 +15,8 @@ use Longman\TelegramBot\Conversation;
use Longman\TelegramBot\Entities\Chat; use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\Keyboard; use Longman\TelegramBot\Entities\Keyboard;
use Longman\TelegramBot\Entities\Message; use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
class SendtochannelCommand extends AdminCommand class SendtochannelCommand extends AdminCommand
...@@ -47,15 +49,15 @@ class SendtochannelCommand extends AdminCommand ...@@ -47,15 +49,15 @@ class SendtochannelCommand extends AdminCommand
/** /**
* Conversation Object * Conversation Object
* *
* @var \Longman\TelegramBot\Conversation * @var Conversation
*/ */
protected $conversation; protected $conversation;
/** /**
* Command execute method * Command execute method
* *
* @return \Longman\TelegramBot\Entities\ServerResponse|mixed * @return ServerResponse|mixed
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function execute() public function execute()
{ {
...@@ -272,11 +274,11 @@ class SendtochannelCommand extends AdminCommand ...@@ -272,11 +274,11 @@ class SendtochannelCommand extends AdminCommand
* @todo This method will be moved to a higher level maybe in AdminCommand or Command * @todo This method will be moved to a higher level maybe in AdminCommand or Command
* @todo Looking for a more significant name * @todo Looking for a more significant name
* *
* @param \Longman\TelegramBot\Entities\Message $message * @param Message $message
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
protected function sendBack(Message $message, array $data) protected function sendBack(Message $message, array $data)
{ {
...@@ -311,12 +313,12 @@ class SendtochannelCommand extends AdminCommand ...@@ -311,12 +313,12 @@ class SendtochannelCommand extends AdminCommand
/** /**
* Publish a message to a channel and return success or failure message in markdown format * Publish a message to a channel and return success or failure message in markdown format
* *
* @param \Longman\TelegramBot\Entities\Message $message * @param Message $message
* @param string|int $channel_id * @param string|int $channel_id
* @param string|null $caption * @param string|null $caption
* *
* @return string * @return string
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
protected function publish(Message $message, $channel_id, $caption = null) protected function publish(Message $message, $channel_id, $caption = null)
{ {
...@@ -351,7 +353,7 @@ class SendtochannelCommand extends AdminCommand ...@@ -351,7 +353,7 @@ class SendtochannelCommand extends AdminCommand
* @todo Why send just to the first found channel? * @todo Why send just to the first found channel?
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function executeNoDb() public function executeNoDb()
{ {
......
...@@ -16,7 +16,9 @@ use Longman\TelegramBot\Commands\AdminCommand; ...@@ -16,7 +16,9 @@ use Longman\TelegramBot\Commands\AdminCommand;
use Longman\TelegramBot\DB; use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Chat; use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\PhotoSize; use Longman\TelegramBot\Entities\PhotoSize;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Entities\UserProfilePhotos; use Longman\TelegramBot\Entities\UserProfilePhotos;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -52,8 +54,8 @@ class WhoisCommand extends AdminCommand ...@@ -52,8 +54,8 @@ class WhoisCommand extends AdminCommand
/** /**
* Command execute method * Command execute method
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -18,7 +18,9 @@ use Longman\TelegramBot\Entities\Message; ...@@ -18,7 +18,9 @@ use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\Payments\PreCheckoutQuery; use Longman\TelegramBot\Entities\Payments\PreCheckoutQuery;
use Longman\TelegramBot\Entities\Payments\ShippingQuery; use Longman\TelegramBot\Entities\Payments\ShippingQuery;
use Longman\TelegramBot\Entities\Poll; use Longman\TelegramBot\Entities\Poll;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Entities\Update; use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
use Longman\TelegramBot\Telegram; use Longman\TelegramBot\Telegram;
...@@ -43,14 +45,14 @@ abstract class Command ...@@ -43,14 +45,14 @@ abstract class Command
/** /**
* Telegram object * Telegram object
* *
* @var \Longman\TelegramBot\Telegram * @var Telegram
*/ */
protected $telegram; protected $telegram;
/** /**
* Update object * Update object
* *
* @var \Longman\TelegramBot\Entities\Update * @var Update
*/ */
protected $update; protected $update;
...@@ -120,8 +122,8 @@ abstract class Command ...@@ -120,8 +122,8 @@ abstract class Command
/** /**
* Constructor * Constructor
* *
* @param \Longman\TelegramBot\Telegram $telegram * @param Telegram $telegram
* @param \Longman\TelegramBot\Entities\Update $update * @param Update $update
*/ */
public function __construct(Telegram $telegram, Update $update = null) public function __construct(Telegram $telegram, Update $update = null)
{ {
...@@ -133,9 +135,9 @@ abstract class Command ...@@ -133,9 +135,9 @@ abstract class Command
/** /**
* Set update object * Set update object
* *
* @param \Longman\TelegramBot\Entities\Update $update * @param Update $update
* *
* @return \Longman\TelegramBot\Commands\Command * @return Command
*/ */
public function setUpdate(Update $update = null) public function setUpdate(Update $update = null)
{ {
...@@ -149,8 +151,8 @@ abstract class Command ...@@ -149,8 +151,8 @@ abstract class Command
/** /**
* Pre-execute command * Pre-execute command
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function preExecute() public function preExecute()
{ {
...@@ -182,16 +184,16 @@ abstract class Command ...@@ -182,16 +184,16 @@ abstract class Command
/** /**
* Execute command * Execute command
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
abstract public function execute(); abstract public function execute();
/** /**
* Execution if MySQL is required but not available * Execution if MySQL is required but not available
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function executeNoDb() public function executeNoDb()
{ {
...@@ -210,7 +212,7 @@ abstract class Command ...@@ -210,7 +212,7 @@ abstract class Command
/** /**
* Get update object * Get update object
* *
* @return \Longman\TelegramBot\Entities\Update * @return Update
*/ */
public function getUpdate() public function getUpdate()
{ {
...@@ -260,7 +262,7 @@ abstract class Command ...@@ -260,7 +262,7 @@ abstract class Command
/** /**
* Get telegram object * Get telegram object
* *
* @return \Longman\TelegramBot\Telegram * @return Telegram
*/ */
public function getTelegram() public function getTelegram()
{ {
...@@ -399,7 +401,8 @@ abstract class Command ...@@ -399,7 +401,8 @@ abstract class Command
* @param string $text * @param string $text
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws TelegramException
*/ */
public function replyToChat($text, array $data = []) public function replyToChat($text, array $data = [])
{ {
...@@ -419,7 +422,8 @@ abstract class Command ...@@ -419,7 +422,8 @@ abstract class Command
* @param string $text * @param string $text
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws TelegramException
*/ */
public function replyToUser($text, array $data = []) public function replyToUser($text, array $data = [])
{ {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
abstract class SystemCommand extends Command abstract class SystemCommand extends Command
...@@ -20,7 +21,7 @@ abstract class SystemCommand extends Command ...@@ -20,7 +21,7 @@ abstract class SystemCommand extends Command
* Although system commands should just work and return a successful ServerResponse, * Although system commands should just work and return a successful ServerResponse,
* each system command can override this method to add custom functionality. * each system command can override this method to add custom functionality.
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
*/ */
public function execute() public function execute()
{ {
......
...@@ -42,7 +42,6 @@ class CallbackqueryCommand extends SystemCommand ...@@ -42,7 +42,6 @@ class CallbackqueryCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class ChannelchatcreatedCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class ChannelchatcreatedCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class ChannelpostCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class ChannelpostCommand extends SystemCommand
* Execute command * Execute command
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class ChoseninlineresultCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class ChoseninlineresultCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class DeletechatphotoCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class DeletechatphotoCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class EditedchannelpostCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class EditedchannelpostCommand extends SystemCommand
* Execute command * Execute command
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class EditedmessageCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class EditedmessageCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace Longman\TelegramBot\Commands\SystemCommands; namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand; use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Entities\ServerResponse;
/** /**
* Generic command * Generic command
...@@ -36,8 +36,7 @@ class GenericCommand extends SystemCommand ...@@ -36,8 +36,7 @@ class GenericCommand extends SystemCommand
/** /**
* Command execute method * Command execute method
* *
* @return mixed * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
namespace Longman\TelegramBot\Commands\SystemCommands; namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Conversation; use Longman\TelegramBot\Conversation;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* Generic message command * Generic message command
...@@ -42,7 +44,7 @@ class GenericmessageCommand extends SystemCommand ...@@ -42,7 +44,7 @@ class GenericmessageCommand extends SystemCommand
/** /**
* Execution if MySQL is required but not available * Execution if MySQL is required but not available
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
*/ */
public function executeNoDb() public function executeNoDb()
{ {
...@@ -53,8 +55,8 @@ class GenericmessageCommand extends SystemCommand ...@@ -53,8 +55,8 @@ class GenericmessageCommand extends SystemCommand
/** /**
* Execute command * Execute command
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class GroupchatcreatedCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class GroupchatcreatedCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
namespace Longman\TelegramBot\Commands\SystemCommands; namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand; use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Entities\InlineQuery\InlineQueryResultArticle;
use Longman\TelegramBot\Entities\InputMessageContent\InputTextMessageContent;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -39,7 +37,6 @@ class InlinequeryCommand extends SystemCommand ...@@ -39,7 +37,6 @@ class InlinequeryCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class LeftchatmemberCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class LeftchatmemberCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class MigratefromchatidCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class MigratefromchatidCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class MigratetochatidCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class MigratetochatidCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class NewchatmembersCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class NewchatmembersCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class NewchatphotoCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class NewchatphotoCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class NewchattitleCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class NewchattitleCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class PinnedmessageCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class PinnedmessageCommand extends SystemCommand
* Execute command * Execute command
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace Longman\TelegramBot\Commands\SystemCommands; namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand; use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;
/** /**
* Start command * Start command
...@@ -44,7 +43,6 @@ class StartCommand extends SystemCommand ...@@ -44,7 +43,6 @@ class StartCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -38,7 +38,6 @@ class SupergroupchatcreatedCommand extends SystemCommand ...@@ -38,7 +38,6 @@ class SupergroupchatcreatedCommand extends SystemCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
namespace Longman\TelegramBot; namespace Longman\TelegramBot;
use Longman\TelegramBot\Exception\TelegramException;
/** /**
* Class Conversation * Class Conversation
* *
...@@ -67,7 +69,7 @@ class Conversation ...@@ -67,7 +69,7 @@ class Conversation
* @param int $chat_id * @param int $chat_id
* @param string $command * @param string $command
* *
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function __construct($user_id, $chat_id, $command = null) public function __construct($user_id, $chat_id, $command = null)
{ {
...@@ -100,7 +102,7 @@ class Conversation ...@@ -100,7 +102,7 @@ class Conversation
* Load the conversation from the database * Load the conversation from the database
* *
* @return bool * @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
protected function load() protected function load()
{ {
...@@ -140,7 +142,7 @@ class Conversation ...@@ -140,7 +142,7 @@ class Conversation
* Start a new conversation if the current command doesn't have one yet * Start a new conversation if the current command doesn't have one yet
* *
* @return bool * @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
protected function start() protected function start()
{ {
...@@ -164,6 +166,7 @@ class Conversation ...@@ -164,6 +166,7 @@ class Conversation
* Currently the Conversation is not deleted but just set to 'stopped' * Currently the Conversation is not deleted but just set to 'stopped'
* *
* @return bool * @return bool
* @throws TelegramException
*/ */
public function stop() public function stop()
{ {
...@@ -174,6 +177,7 @@ class Conversation ...@@ -174,6 +177,7 @@ class Conversation
* Cancel the current conversation * Cancel the current conversation
* *
* @return bool * @return bool
* @throws TelegramException
*/ */
public function cancel() public function cancel()
{ {
...@@ -186,6 +190,7 @@ class Conversation ...@@ -186,6 +190,7 @@ class Conversation
* @param string $status * @param string $status
* *
* @return bool * @return bool
* @throws TelegramException
*/ */
protected function updateStatus($status) protected function updateStatus($status)
{ {
...@@ -209,6 +214,7 @@ class Conversation ...@@ -209,6 +214,7 @@ class Conversation
* Store the array/variable in the database with json_encode() function * Store the array/variable in the database with json_encode() function
* *
* @return bool * @return bool
* @throws TelegramException
*/ */
public function update() public function update()
{ {
......
...@@ -844,7 +844,7 @@ class DB ...@@ -844,7 +844,7 @@ class DB
$sth->bindValue(':id', $poll->getId()); $sth->bindValue(':id', $poll->getId());
$sth->bindValue(':question', $poll->getQuestion()); $sth->bindValue(':question', $poll->getQuestion());
$sth->bindValue(':options', self::entitiesArrayToJson($poll->getOptions())); $sth->bindValue(':options', self::entitiesArrayToJson($poll->getOptions() ?: null));
$sth->bindValue(':is_closed', $poll->getIsClosed()); $sth->bindValue(':is_closed', $poll->getIsClosed());
$sth->bindValue(':created_at', self::getTimestamp()); $sth->bindValue(':created_at', self::getTimestamp());
...@@ -881,18 +881,17 @@ class DB ...@@ -881,18 +881,17 @@ class DB
} }
// Insert the forwarded message user in users table // Insert the forwarded message user in users table
$forward_date = null; $forward_date = $message->getForwardDate() ? self::getTimestamp($message->getForwardDate()) : null;
$forward_from = $message->getForwardFrom(); $forward_from = $message->getForwardFrom();
if ($forward_from instanceof User) { if ($forward_from instanceof User) {
self::insertUser($forward_from, $forward_date); self::insertUser($forward_from);
$forward_from = $forward_from->getId(); $forward_from = $forward_from->getId();
$forward_date = self::getTimestamp($message->getForwardDate());
} }
$forward_from_chat = $message->getForwardFromChat(); $forward_from_chat = $message->getForwardFromChat();
if ($forward_from_chat instanceof Chat) { if ($forward_from_chat instanceof Chat) {
self::insertChat($forward_from_chat, $forward_date); self::insertChat($forward_from_chat);
$forward_from_chat = $forward_from_chat->getId(); $forward_from_chat = $forward_from_chat->getId();
$forward_date = self::getTimestamp($message->getForwardDate());
} }
// New and left chat member // New and left chat member
...@@ -977,13 +976,13 @@ class DB ...@@ -977,13 +976,13 @@ class DB
$sth->bindValue(':media_group_id', $message->getMediaGroupId()); $sth->bindValue(':media_group_id', $message->getMediaGroupId());
$sth->bindValue(':author_signature', $message->getAuthorSignature()); $sth->bindValue(':author_signature', $message->getAuthorSignature());
$sth->bindValue(':text', $message->getText()); $sth->bindValue(':text', $message->getText());
$sth->bindValue(':entities', self::entitiesArrayToJson($message->getEntities())); $sth->bindValue(':entities', self::entitiesArrayToJson($message->getEntities() ?: null));
$sth->bindValue(':caption_entities', self::entitiesArrayToJson($message->getCaptionEntities())); $sth->bindValue(':caption_entities', self::entitiesArrayToJson($message->getCaptionEntities() ?: null));
$sth->bindValue(':audio', $message->getAudio()); $sth->bindValue(':audio', $message->getAudio());
$sth->bindValue(':document', $message->getDocument()); $sth->bindValue(':document', $message->getDocument());
$sth->bindValue(':animation', $message->getAnimation()); $sth->bindValue(':animation', $message->getAnimation());
$sth->bindValue(':game', $message->getGame()); $sth->bindValue(':game', $message->getGame());
$sth->bindValue(':photo', self::entitiesArrayToJson($message->getPhoto())); $sth->bindValue(':photo', self::entitiesArrayToJson($message->getPhoto() ?: null));
$sth->bindValue(':sticker', $message->getSticker()); $sth->bindValue(':sticker', $message->getSticker());
$sth->bindValue(':video', $message->getVideo()); $sth->bindValue(':video', $message->getVideo());
$sth->bindValue(':voice', $message->getVoice()); $sth->bindValue(':voice', $message->getVoice());
...@@ -996,7 +995,7 @@ class DB ...@@ -996,7 +995,7 @@ class DB
$sth->bindValue(':new_chat_members', $new_chat_members_ids); $sth->bindValue(':new_chat_members', $new_chat_members_ids);
$sth->bindValue(':left_chat_member', $left_chat_member_id); $sth->bindValue(':left_chat_member', $left_chat_member_id);
$sth->bindValue(':new_chat_title', $message->getNewChatTitle()); $sth->bindValue(':new_chat_title', $message->getNewChatTitle());
$sth->bindValue(':new_chat_photo', self::entitiesArrayToJson($message->getNewChatPhoto())); $sth->bindValue(':new_chat_photo', self::entitiesArrayToJson($message->getNewChatPhoto() ?: null));
$sth->bindValue(':delete_chat_photo', $message->getDeleteChatPhoto()); $sth->bindValue(':delete_chat_photo', $message->getDeleteChatPhoto());
$sth->bindValue(':group_chat_created', $message->getGroupChatCreated()); $sth->bindValue(':group_chat_created', $message->getGroupChatCreated());
$sth->bindValue(':supergroup_chat_created', $message->getSupergroupChatCreated()); $sth->bindValue(':supergroup_chat_created', $message->getSupergroupChatCreated());
...@@ -1059,7 +1058,7 @@ class DB ...@@ -1059,7 +1058,7 @@ class DB
$sth->bindValue(':user_id', $user_id); $sth->bindValue(':user_id', $user_id);
$sth->bindValue(':edit_date', $edit_date); $sth->bindValue(':edit_date', $edit_date);
$sth->bindValue(':text', $edited_message->getText()); $sth->bindValue(':text', $edited_message->getText());
$sth->bindValue(':entities', self::entitiesArrayToJson($edited_message->getEntities())); $sth->bindValue(':entities', self::entitiesArrayToJson($edited_message->getEntities() ?: null));
$sth->bindValue(':caption', $edited_message->getCaption()); $sth->bindValue(':caption', $edited_message->getCaption());
return $sth->execute(); return $sth->execute();
...@@ -1187,13 +1186,13 @@ class DB ...@@ -1187,13 +1186,13 @@ class DB
* @param integer $chat_id * @param integer $chat_id
* @param string $inline_message_id * @param string $inline_message_id
* *
* @return array|bool Array containing TOTAL and CURRENT fields or false on invalid arguments * @return array Array containing TOTAL and CURRENT fields or false on invalid arguments
* @throws TelegramException * @throws TelegramException
*/ */
public static function getTelegramRequestCount($chat_id = null, $inline_message_id = null) public static function getTelegramRequestCount($chat_id = null, $inline_message_id = null)
{ {
if (!self::isDbConnected()) { if (!self::isDbConnected()) {
return false; return [];
} }
try { try {
......
...@@ -30,7 +30,7 @@ class CallbackQuery extends Entity ...@@ -30,7 +30,7 @@ class CallbackQuery extends Entity
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function subEntities() protected function subEntities()
{ {
return [ return [
'from' => User::class, 'from' => User::class,
......
...@@ -46,7 +46,7 @@ class Chat extends Entity ...@@ -46,7 +46,7 @@ class Chat extends Entity
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function subEntities() protected function subEntities()
{ {
return [ return [
'photo' => ChatPhoto::class, 'photo' => ChatPhoto::class,
......
...@@ -38,7 +38,7 @@ class ChatMember extends Entity ...@@ -38,7 +38,7 @@ class ChatMember extends Entity
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function subEntities() protected function subEntities()
{ {
return [ return [
'user' => User::class, 'user' => User::class,
......
...@@ -33,8 +33,6 @@ abstract class Entity ...@@ -33,8 +33,6 @@ abstract class Entity
* *
* @param array $data * @param array $data
* @param string $bot_username * @param string $bot_username
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct($data, $bot_username = '') public function __construct($data, $bot_username = '')
{ {
...@@ -96,8 +94,6 @@ abstract class Entity ...@@ -96,8 +94,6 @@ abstract class Entity
/** /**
* Perform any special entity validation * Perform any special entity validation
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
protected function validate() protected function validate()
{ {
...@@ -142,7 +138,13 @@ abstract class Entity ...@@ -142,7 +138,13 @@ abstract class Entity
$sub_entities = $this->subEntities(); $sub_entities = $this->subEntities();
if (isset($sub_entities[$property_name])) { if (isset($sub_entities[$property_name])) {
return new $sub_entities[$property_name]($property, $this->getProperty('bot_username')); $class = $sub_entities[$property_name];
if (is_array($class)) {
return $this->makePrettyObjectArray(reset($class), $property_name);
}
return new $class($property, $this->getProperty('bot_username'));
} }
return $property; return $property;
......
...@@ -24,7 +24,9 @@ use Longman\TelegramBot\Entities\PhotoSize; ...@@ -24,7 +24,9 @@ use Longman\TelegramBot\Entities\PhotoSize;
* *
* @method string getTitle() Title of the game * @method string getTitle() Title of the game
* @method string getDescription() Description of the game * @method string getDescription() Description of the game
* @method PhotoSize[] getPhoto() Photo that will be displayed in the game message in chats.
* @method string getText() Optional. Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters. * @method string getText() Optional. Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters.
* @method MessageEntity[] getTextEntities() Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc.
* @method Animation getAnimation() Optional. Animation that will be displayed in the game message in chats. Upload via BotFather * @method Animation getAnimation() Optional. Animation that will be displayed in the game message in chats. Upload via BotFather
**/ **/
class Game extends Entity class Game extends Entity
...@@ -35,39 +37,9 @@ class Game extends Entity ...@@ -35,39 +37,9 @@ class Game extends Entity
protected function subEntities() protected function subEntities()
{ {
return [ return [
'photo' => PhotoSize::class, 'photo' => [PhotoSize::class],
'text_entities' => MessageEntity::class, 'text_entities' => [MessageEntity::class],
'animation' => Animation::class, 'animation' => Animation::class,
]; ];
} }
/**
* Photo that will be displayed in the game message in chats.
*
* This method overrides the default getPhoto method
* and returns a nice array of PhotoSize objects.
*
* @return null|\Longman\TelegramBot\Entities\PhotoSize[]
*/
public function getPhoto()
{
$pretty_array = $this->makePrettyObjectArray(PhotoSize::class, 'photo');
return empty($pretty_array) ? null : $pretty_array;
}
/**
* Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc.
*
* This method overrides the default getTextEntities method
* and returns a nice array of MessageEntity objects.
*
* @return null|\Longman\TelegramBot\Entities\MessageEntity[]
*/
public function getTextEntities()
{
$pretty_array = $this->makePrettyObjectArray(MessageEntity::class, 'text_entities');
return empty($pretty_array) ? null : $pretty_array;
}
} }
...@@ -62,8 +62,6 @@ class InlineQueryResultArticle extends InlineEntity implements InlineQueryResult ...@@ -62,8 +62,6 @@ class InlineQueryResultArticle extends InlineEntity implements InlineQueryResult
* InlineQueryResultArticle constructor * InlineQueryResultArticle constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -56,8 +56,6 @@ class InlineQueryResultAudio extends InlineEntity implements InlineQueryResult ...@@ -56,8 +56,6 @@ class InlineQueryResultAudio extends InlineEntity implements InlineQueryResult
* InlineQueryResultAudio constructor * InlineQueryResultAudio constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -47,8 +47,6 @@ class InlineQueryResultCachedAudio extends InlineEntity implements InlineQueryRe ...@@ -47,8 +47,6 @@ class InlineQueryResultCachedAudio extends InlineEntity implements InlineQueryRe
* InlineQueryResultCachedAudio constructor * InlineQueryResultCachedAudio constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -53,8 +53,6 @@ class InlineQueryResultCachedDocument extends InlineEntity implements InlineQuer ...@@ -53,8 +53,6 @@ class InlineQueryResultCachedDocument extends InlineEntity implements InlineQuer
* InlineQueryResultCachedDocument constructor * InlineQueryResultCachedDocument constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -50,8 +50,6 @@ class InlineQueryResultCachedGif extends InlineEntity implements InlineQueryResu ...@@ -50,8 +50,6 @@ class InlineQueryResultCachedGif extends InlineEntity implements InlineQueryResu
* InlineQueryResultCachedGif constructor * InlineQueryResultCachedGif constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -50,8 +50,6 @@ class InlineQueryResultCachedMpeg4Gif extends InlineEntity implements InlineQuer ...@@ -50,8 +50,6 @@ class InlineQueryResultCachedMpeg4Gif extends InlineEntity implements InlineQuer
* InlineQueryResultCachedMpeg4Gif constructor * InlineQueryResultCachedMpeg4Gif constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -53,8 +53,6 @@ class InlineQueryResultCachedPhoto extends InlineEntity implements InlineQueryRe ...@@ -53,8 +53,6 @@ class InlineQueryResultCachedPhoto extends InlineEntity implements InlineQueryRe
* InlineQueryResultCachedPhoto constructor * InlineQueryResultCachedPhoto constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -44,8 +44,6 @@ class InlineQueryResultCachedSticker extends InlineEntity implements InlineQuery ...@@ -44,8 +44,6 @@ class InlineQueryResultCachedSticker extends InlineEntity implements InlineQuery
* InlineQueryResultCachedSticker constructor * InlineQueryResultCachedSticker constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -53,8 +53,6 @@ class InlineQueryResultCachedVideo extends InlineEntity implements InlineQueryRe ...@@ -53,8 +53,6 @@ class InlineQueryResultCachedVideo extends InlineEntity implements InlineQueryRe
* InlineQueryResultCachedVideo constructor * InlineQueryResultCachedVideo constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -50,8 +50,6 @@ class InlineQueryResultCachedVoice extends InlineEntity implements InlineQueryRe ...@@ -50,8 +50,6 @@ class InlineQueryResultCachedVoice extends InlineEntity implements InlineQueryRe
* InlineQueryResultCachedVoice constructor * InlineQueryResultCachedVoice constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -61,8 +61,6 @@ class InlineQueryResultContact extends InlineEntity implements InlineQueryResult ...@@ -61,8 +61,6 @@ class InlineQueryResultContact extends InlineEntity implements InlineQueryResult
* InlineQueryResultContact constructor * InlineQueryResultContact constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -65,8 +65,6 @@ class InlineQueryResultDocument extends InlineEntity implements InlineQueryResul ...@@ -65,8 +65,6 @@ class InlineQueryResultDocument extends InlineEntity implements InlineQueryResul
* InlineQueryResultDocument constructor * InlineQueryResultDocument constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -40,8 +40,6 @@ class InlineQueryResultGame extends InlineEntity implements InlineQueryResult ...@@ -40,8 +40,6 @@ class InlineQueryResultGame extends InlineEntity implements InlineQueryResult
* InlineQueryResultGame constructor * InlineQueryResultGame constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -61,8 +61,6 @@ class InlineQueryResultGif extends InlineEntity implements InlineQueryResult ...@@ -61,8 +61,6 @@ class InlineQueryResultGif extends InlineEntity implements InlineQueryResult
* InlineQueryResultGif constructor * InlineQueryResultGif constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -62,8 +62,6 @@ class InlineQueryResultLocation extends InlineEntity implements InlineQueryResul ...@@ -62,8 +62,6 @@ class InlineQueryResultLocation extends InlineEntity implements InlineQueryResul
* InlineQueryResultLocation constructor * InlineQueryResultLocation constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -61,8 +61,6 @@ class InlineQueryResultMpeg4Gif extends InlineEntity implements InlineQueryResul ...@@ -61,8 +61,6 @@ class InlineQueryResultMpeg4Gif extends InlineEntity implements InlineQueryResul
* InlineQueryResultMpeg4Gif constructor * InlineQueryResultMpeg4Gif constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -62,8 +62,6 @@ class InlineQueryResultPhoto extends InlineEntity implements InlineQueryResult ...@@ -62,8 +62,6 @@ class InlineQueryResultPhoto extends InlineEntity implements InlineQueryResult
* InlineQueryResultPhoto constructor * InlineQueryResultPhoto constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -67,8 +67,6 @@ class InlineQueryResultVenue extends InlineEntity implements InlineQueryResult ...@@ -67,8 +67,6 @@ class InlineQueryResultVenue extends InlineEntity implements InlineQueryResult
* InlineQueryResultVenue constructor * InlineQueryResultVenue constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -68,8 +68,6 @@ class InlineQueryResultVideo extends InlineEntity implements InlineQueryResult ...@@ -68,8 +68,6 @@ class InlineQueryResultVideo extends InlineEntity implements InlineQueryResult
* InlineQueryResultVideo constructor * InlineQueryResultVideo constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -53,8 +53,6 @@ class InlineQueryResultVoice extends InlineEntity implements InlineQueryResult ...@@ -53,8 +53,6 @@ class InlineQueryResultVoice extends InlineEntity implements InlineQueryResult
* InlineQueryResultVoice constructor * InlineQueryResultVoice constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -4,5 +4,20 @@ namespace Longman\TelegramBot\Entities\InputMedia; ...@@ -4,5 +4,20 @@ namespace Longman\TelegramBot\Entities\InputMedia;
interface InputMedia interface InputMedia
{ {
/**
* @return string Type of the result.
*/
public function getType();
/**
* @return string File to send.
*/
public function getMedia();
/**
* @param string $media File to send.
*
* @return string
*/
public function setMedia($media);
} }
...@@ -52,8 +52,6 @@ class InputMediaAnimation extends Entity implements InputMedia ...@@ -52,8 +52,6 @@ class InputMediaAnimation extends Entity implements InputMedia
* InputMediaAnimation constructor * InputMediaAnimation constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -52,8 +52,6 @@ class InputMediaAudio extends Entity implements InputMedia ...@@ -52,8 +52,6 @@ class InputMediaAudio extends Entity implements InputMedia
* InputMediaAudio constructor * InputMediaAudio constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -43,8 +43,6 @@ class InputMediaDocument extends Entity implements InputMedia ...@@ -43,8 +43,6 @@ class InputMediaDocument extends Entity implements InputMedia
* InputMediaDocument constructor * InputMediaDocument constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -40,8 +40,6 @@ class InputMediaPhoto extends Entity implements InputMedia ...@@ -40,8 +40,6 @@ class InputMediaPhoto extends Entity implements InputMedia
* InputMediaPhoto constructor * InputMediaPhoto constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -55,8 +55,6 @@ class InputMediaVideo extends Entity implements InputMedia ...@@ -55,8 +55,6 @@ class InputMediaVideo extends Entity implements InputMedia
* InputMediaVideo constructor * InputMediaVideo constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -54,7 +54,7 @@ class Keyboard extends Entity ...@@ -54,7 +54,7 @@ class Keyboard extends Entity
/** /**
* Get the proper keyboard button class for this keyboard. * Get the proper keyboard button class for this keyboard.
* *
* @return KeyboardButton|InlineKeyboardButton * @return string
*/ */
public function getKeyboardButtonClass() public function getKeyboardButtonClass()
{ {
...@@ -154,9 +154,9 @@ class Keyboard extends Entity ...@@ -154,9 +154,9 @@ class Keyboard extends Entity
/** /**
* Parse a given button to the correct KeyboardButton object type. * Parse a given button to the correct KeyboardButton object type.
* *
* @param array|string|\Longman\TelegramBot\Entities\KeyboardButton $button * @param array|string|KeyboardButton $button
* *
* @return \Longman\TelegramBot\Entities\KeyboardButton|null * @return KeyboardButton|null
*/ */
protected function parseButton($button) protected function parseButton($button)
{ {
...@@ -166,7 +166,7 @@ class Keyboard extends Entity ...@@ -166,7 +166,7 @@ class Keyboard extends Entity
return $button; return $button;
} }
if (!$this->isInlineKeyboard() || $button_class::couldBe($button)) { if (!$this->isInlineKeyboard() || call_user_func([$button_class, 'couldBe'], $button)) {
return new $button_class($button); return new $button_class($button);
} }
...@@ -201,8 +201,7 @@ class Keyboard extends Entity ...@@ -201,8 +201,7 @@ class Keyboard extends Entity
* *
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\Keyboard * @return Keyboard
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function remove(array $data = []) public static function remove(array $data = [])
{ {
...@@ -216,8 +215,7 @@ class Keyboard extends Entity ...@@ -216,8 +215,7 @@ class Keyboard extends Entity
* *
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\Keyboard * @return Keyboard
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function forceReply(array $data = []) public static function forceReply(array $data = [])
{ {
......
...@@ -34,10 +34,13 @@ use Longman\TelegramBot\Entities\TelegramPassport\PassportData; ...@@ -34,10 +34,13 @@ use Longman\TelegramBot\Entities\TelegramPassport\PassportData;
* @method int getEditDate() Optional. Date the message was last edited in Unix time * @method int getEditDate() Optional. Date the message was last edited in Unix time
* @method string getMediaGroupId() Optional. The unique identifier of a media message group this message belongs to * @method string getMediaGroupId() Optional. The unique identifier of a media message group this message belongs to
* @method string getAuthorSignature() Optional. Signature of the post author for messages in channels * @method string getAuthorSignature() Optional. Signature of the post author for messages in channels
* @method MessageEntity[] getEntities() Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
* @method MessageEntity[] getCaptionEntities() Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption
* @method Audio getAudio() Optional. Message is an audio file, information about the file * @method Audio getAudio() Optional. Message is an audio file, information about the file
* @method Document getDocument() Optional. Message is a general file, information about the file * @method Document getDocument() Optional. Message is a general file, information about the file
* @method Animation getAnimation() Optional. Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set * @method Animation getAnimation() Optional. Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set
* @method Game getGame() Optional. Message is a game, information about the game. * @method Game getGame() Optional. Message is a game, information about the game.
* @method PhotoSize[] getPhoto() Optional. Message is a photo, available sizes of the photo
* @method Sticker getSticker() Optional. Message is a sticker, information about the sticker * @method Sticker getSticker() Optional. Message is a sticker, information about the sticker
* @method Video getVideo() Optional. Message is a video, information about the video * @method Video getVideo() Optional. Message is a video, information about the video
* @method Voice getVoice() Optional. Message is a voice message, information about the file * @method Voice getVoice() Optional. Message is a voice message, information about the file
...@@ -47,8 +50,10 @@ use Longman\TelegramBot\Entities\TelegramPassport\PassportData; ...@@ -47,8 +50,10 @@ use Longman\TelegramBot\Entities\TelegramPassport\PassportData;
* @method Location getLocation() Optional. Message is a shared location, information about the location * @method Location getLocation() Optional. Message is a shared location, information about the location
* @method Venue getVenue() Optional. Message is a venue, information about the venue * @method Venue getVenue() Optional. Message is a venue, information about the venue
* @method Poll getPoll() Optional. Message is a native poll, information about the poll * @method Poll getPoll() Optional. Message is a native poll, information about the poll
* @method User[] getNewChatMembers() Optional. A new member(s) was added to the group, information about them (one of this members may be the bot itself)
* @method User getLeftChatMember() Optional. A member was removed from the group, information about them (this member may be the bot itself) * @method User getLeftChatMember() Optional. A member was removed from the group, information about them (this member may be the bot itself)
* @method string getNewChatTitle() Optional. A chat title was changed to this value * @method string getNewChatTitle() Optional. A chat title was changed to this value
* @method PhotoSize[] getNewChatPhoto() Optional. A chat photo was changed to this value
* @method bool getDeleteChatPhoto() Optional. Service message: the chat photo was deleted * @method bool getDeleteChatPhoto() Optional. Service message: the chat photo was deleted
* @method bool getGroupChatCreated() Optional. Service message: the group has been created * @method bool getGroupChatCreated() Optional. Service message: the group has been created
* @method bool getSupergroupChatCreated() Optional. Service message: the supergroup has been created. This field can't be received in a message coming through updates, because bot can’t be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup. * @method bool getSupergroupChatCreated() Optional. Service message: the supergroup has been created. This field can't be received in a message coming through updates, because bot can’t be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup.
...@@ -74,13 +79,13 @@ class Message extends Entity ...@@ -74,13 +79,13 @@ class Message extends Entity
'forward_from' => User::class, 'forward_from' => User::class,
'forward_from_chat' => Chat::class, 'forward_from_chat' => Chat::class,
'reply_to_message' => ReplyToMessage::class, 'reply_to_message' => ReplyToMessage::class,
'entities' => MessageEntity::class, 'entities' => [MessageEntity::class],
'caption_entities' => MessageEntity::class, 'caption_entities' => [MessageEntity::class],
'audio' => Audio::class, 'audio' => Audio::class,
'document' => Document::class, 'document' => Document::class,
'animation' => Animation::class, 'animation' => Animation::class,
'game' => Game::class, 'game' => Game::class,
'photo' => PhotoSize::class, 'photo' => [PhotoSize::class],
'sticker' => Sticker::class, 'sticker' => Sticker::class,
'video' => Video::class, 'video' => Video::class,
'voice' => Voice::class, 'voice' => Voice::class,
...@@ -89,9 +94,9 @@ class Message extends Entity ...@@ -89,9 +94,9 @@ class Message extends Entity
'location' => Location::class, 'location' => Location::class,
'venue' => Venue::class, 'venue' => Venue::class,
'poll' => Poll::class, 'poll' => Poll::class,
'new_chat_members' => User::class, 'new_chat_members' => [User::class],
'left_chat_member' => User::class, 'left_chat_member' => User::class,
'new_chat_photo' => PhotoSize::class, 'new_chat_photo' => [PhotoSize::class],
'pinned_message' => Message::class, 'pinned_message' => Message::class,
'invoice' => Invoice::class, 'invoice' => Invoice::class,
'successful_payment' => SuccessfulPayment::class, 'successful_payment' => SuccessfulPayment::class,
...@@ -99,94 +104,6 @@ class Message extends Entity ...@@ -99,94 +104,6 @@ class Message extends Entity
]; ];
} }
/**
* Message constructor
*
* @param array $data
* @param string $bot_username
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct(array $data, $bot_username = '')
{
parent::__construct($data, $bot_username);
}
/**
* Optional. Message is a photo, available sizes of the photo
*
* This method overrides the default getPhoto method
* and returns a nice array of PhotoSize objects.
*
* @return null|PhotoSize[]
*/
public function getPhoto()
{
$pretty_array = $this->makePrettyObjectArray(PhotoSize::class, 'photo');
return empty($pretty_array) ? null : $pretty_array;
}
/**
* Optional. A chat photo was changed to this value
*
* This method overrides the default getNewChatPhoto method
* and returns a nice array of PhotoSize objects.
*
* @return null|PhotoSize[]
*/
public function getNewChatPhoto()
{
$pretty_array = $this->makePrettyObjectArray(PhotoSize::class, 'new_chat_photo');
return empty($pretty_array) ? null : $pretty_array;
}
/**
* Optional. A new member(s) was added to the group, information about them (one of this members may be the bot itself)
*
* This method overrides the default getNewChatMembers method
* and returns a nice array of User objects.
*
* @return null|User[]
*/
public function getNewChatMembers()
{
$pretty_array = $this->makePrettyObjectArray(User::class, 'new_chat_members');
return empty($pretty_array) ? null : $pretty_array;
}
/**
* Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
*
* This method overrides the default getEntities method
* and returns a nice array of MessageEntity objects.
*
* @return null|MessageEntity[]
*/
public function getEntities()
{
$pretty_array = $this->makePrettyObjectArray(MessageEntity::class, 'entities');
return empty($pretty_array) ? null : $pretty_array;
}
/**
* Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption
*
* This method overrides the default getCaptionEntities method
* and returns a nice array of MessageEntity objects.
*
* @return null|MessageEntity[]
*/
public function getCaptionEntities()
{
$pretty_array = $this->makePrettyObjectArray(MessageEntity::class, 'caption_entities');
return empty($pretty_array) ? null : $pretty_array;
}
/** /**
* return the entire command like /echo or /echo@bot1 if specified * return the entire command like /echo or /echo@bot1 if specified
* *
...@@ -264,7 +181,6 @@ class Message extends Entity ...@@ -264,7 +181,6 @@ class Message extends Entity
* Bot added in chat * Bot added in chat
* *
* @return bool * @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function botAddedInChat() public function botAddedInChat()
{ {
......
...@@ -29,7 +29,7 @@ class OrderInfo extends Entity ...@@ -29,7 +29,7 @@ class OrderInfo extends Entity
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function subEntities() protected function subEntities()
{ {
return [ return [
'shipping_address' => ShippingAddress::class, 'shipping_address' => ShippingAddress::class,
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
namespace Longman\TelegramBot\Entities\Payments; namespace Longman\TelegramBot\Entities\Payments;
use Longman\TelegramBot\Entities\Entity; use Longman\TelegramBot\Entities\Entity;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Entities\User; use Longman\TelegramBot\Entities\User;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
...@@ -34,7 +35,7 @@ class PreCheckoutQuery extends Entity ...@@ -34,7 +35,7 @@ class PreCheckoutQuery extends Entity
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function subEntities() protected function subEntities()
{ {
return [ return [
'from' => User::class, 'from' => User::class,
...@@ -48,7 +49,7 @@ class PreCheckoutQuery extends Entity ...@@ -48,7 +49,7 @@ class PreCheckoutQuery extends Entity
* @param bool $ok * @param bool $ok
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
*/ */
public function answer($ok, array $data = []) public function answer($ok, array $data = [])
{ {
......
...@@ -21,6 +21,7 @@ use Longman\TelegramBot\Entities\Entity; ...@@ -21,6 +21,7 @@ use Longman\TelegramBot\Entities\Entity;
* *
* @method string getId() Shipping option identifier * @method string getId() Shipping option identifier
* @method string getTitle() Option title * @method string getTitle() Option title
* @method LabeledPrice[] getPrices() List of price portions
**/ **/
class ShippingOption extends Entity class ShippingOption extends Entity
{ {
...@@ -30,19 +31,7 @@ class ShippingOption extends Entity ...@@ -30,19 +31,7 @@ class ShippingOption extends Entity
protected function subEntities() protected function subEntities()
{ {
return [ return [
'prices' => LabeledPrice::class, 'prices' => [LabeledPrice::class],
]; ];
} }
/**
* List of price portions
*
* This method overrides the default getPrices method and returns a nice array
*
* @return LabeledPrice[]
*/
public function getPrices()
{
return $this->makePrettyObjectArray(LabeledPrice::class, 'prices');
}
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
namespace Longman\TelegramBot\Entities\Payments; namespace Longman\TelegramBot\Entities\Payments;
use Longman\TelegramBot\Entities\Entity; use Longman\TelegramBot\Entities\Entity;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Entities\User; use Longman\TelegramBot\Entities\User;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
...@@ -31,7 +32,7 @@ class ShippingQuery extends Entity ...@@ -31,7 +32,7 @@ class ShippingQuery extends Entity
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function subEntities() protected function subEntities()
{ {
return [ return [
'from' => User::class, 'from' => User::class,
...@@ -45,7 +46,7 @@ class ShippingQuery extends Entity ...@@ -45,7 +46,7 @@ class ShippingQuery extends Entity
* @param bool $ok * @param bool $ok
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
*/ */
public function answer($ok, array $data = []) public function answer($ok, array $data = [])
{ {
......
...@@ -32,7 +32,7 @@ class SuccessfulPayment extends Entity ...@@ -32,7 +32,7 @@ class SuccessfulPayment extends Entity
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function subEntities() protected function subEntities()
{ {
return [ return [
'order_info' => OrderInfo::class, 'order_info' => OrderInfo::class,
......
...@@ -19,6 +19,7 @@ namespace Longman\TelegramBot\Entities; ...@@ -19,6 +19,7 @@ namespace Longman\TelegramBot\Entities;
* *
* @method string getId() Unique poll identifier * @method string getId() Unique poll identifier
* @method string getQuestion() Poll question, 1-255 characters * @method string getQuestion() Poll question, 1-255 characters
* @method PollOption[] getOptions() List of poll options
* @method bool getIsClosed() True, if the poll is closed * @method bool getIsClosed() True, if the poll is closed
*/ */
class Poll extends Entity class Poll extends Entity
...@@ -29,22 +30,7 @@ class Poll extends Entity ...@@ -29,22 +30,7 @@ class Poll extends Entity
protected function subEntities() protected function subEntities()
{ {
return [ return [
'options' => PollOption::class, 'options' => [PollOption::class],
]; ];
} }
/**
* List of poll options
*
* This method overrides the default getOptions method
* and returns a nice array of PollOption objects.
*
* @return null|PollOption[]
*/
public function getOptions()
{
$pretty_array = $this->makePrettyObjectArray(PollOption::class, 'options');
return empty($pretty_array) ? null : $pretty_array;
}
} }
...@@ -22,8 +22,6 @@ class ReplyToMessage extends Message ...@@ -22,8 +22,6 @@ class ReplyToMessage extends Message
* *
* @param array $data * @param array $data
* @param string $bot_username * @param string $bot_username
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data, $bot_username = '') public function __construct(array $data, $bot_username = '')
{ {
......
...@@ -30,8 +30,6 @@ class ServerResponse extends Entity ...@@ -30,8 +30,6 @@ class ServerResponse extends Entity
* *
* @param array $data * @param array $data
* @param string $bot_username * @param string $bot_username
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data, $bot_username) public function __construct(array $data, $bot_username)
{ {
...@@ -105,7 +103,7 @@ class ServerResponse extends Entity ...@@ -105,7 +103,7 @@ class ServerResponse extends Entity
* @param array $result * @param array $result
* @param string $bot_username * @param string $bot_username
* *
* @return \Longman\TelegramBot\Entities\Chat|\Longman\TelegramBot\Entities\ChatMember|\Longman\TelegramBot\Entities\File|\Longman\TelegramBot\Entities\Message|\Longman\TelegramBot\Entities\User|\Longman\TelegramBot\Entities\UserProfilePhotos|\Longman\TelegramBot\Entities\WebhookInfo * @return Chat|ChatMember|File|Message|User|UserProfilePhotos|WebhookInfo
*/ */
private function createResultObject(array $result, $bot_username) private function createResultObject(array $result, $bot_username)
{ {
...@@ -135,7 +133,7 @@ class ServerResponse extends Entity ...@@ -135,7 +133,7 @@ class ServerResponse extends Entity
* @param array $result * @param array $result
* @param string $bot_username * @param string $bot_username
* *
* @return \Longman\TelegramBot\Entities\ChatMember[]|\Longman\TelegramBot\Entities\Games\GameHighScore[]|\Longman\TelegramBot\Entities\Message[]|\Longman\TelegramBot\Entities\Update[] * @return ChatMember[]|GameHighScore[]|Message[]|Update[]
*/ */
private function createResultObjects(array $result, $bot_username) private function createResultObjects(array $result, $bot_username)
{ {
......
...@@ -18,21 +18,17 @@ namespace Longman\TelegramBot\Entities; ...@@ -18,21 +18,17 @@ namespace Longman\TelegramBot\Entities;
* @method string getName() Sticker set name * @method string getName() Sticker set name
* @method string getTitle() Sticker set title * @method string getTitle() Sticker set title
* @method bool getContainsMasks() True, if the sticker set contains masks * @method bool getContainsMasks() True, if the sticker set contains masks
* @method Sticker[] getStickers() List of all set stickers
*/ */
class StickerSet extends Entity class StickerSet extends Entity
{ {
/** /**
* List of all set stickers * {@inheritdoc}
*
* This method overrides the default getStickers method
* and returns a nice array of Sticker objects.
*
* @return null|Sticker[]
*/ */
public function getStickers() protected function subEntities()
{ {
$pretty_array = $this->makePrettyObjectArray(Sticker::class, 'stickers'); return [
'stickers' => [Sticker::class],
return empty($pretty_array) ? null : $pretty_array; ];
} }
} }
...@@ -23,9 +23,11 @@ use Longman\TelegramBot\Entities\Entity; ...@@ -23,9 +23,11 @@ use Longman\TelegramBot\Entities\Entity;
* @method string getData() Optional. Base64-encoded encrypted Telegram Passport element data provided by the user, available for “personal_details”, “passport”, “driver_license”, “identity_card”, “identity_passport” and “address” types. Can be decrypted and verified using the accompanying EncryptedCredentials. * @method string getData() Optional. Base64-encoded encrypted Telegram Passport element data provided by the user, available for “personal_details”, “passport”, “driver_license”, “identity_card”, “identity_passport” and “address” types. Can be decrypted and verified using the accompanying EncryptedCredentials.
* @method string getPhoneNumber() Optional. User's verified phone number, available only for “phone_number” type * @method string getPhoneNumber() Optional. User's verified phone number, available only for “phone_number” type
* @method string getEmail() Optional. User's verified email address, available only for “email” type * @method string getEmail() Optional. User's verified email address, available only for “email” type
* @method PassportFile[] getFiles() Optional. Array of encrypted files with documents provided by the user, available for “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can be decrypted and verified using the accompanying EncryptedCredentials.
* @method PassportFile getFrontSide() Optional. Encrypted file with the front side of the document, provided by the user. Available for “passport”, “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified using the accompanying EncryptedCredentials. * @method PassportFile getFrontSide() Optional. Encrypted file with the front side of the document, provided by the user. Available for “passport”, “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified using the accompanying EncryptedCredentials.
* @method PassportFile getReverseSide() Optional. Encrypted file with the reverse side of the document, provided by the user. Available for “driver_license” and “identity_card”. The file can be decrypted and verified using the accompanying EncryptedCredentials. * @method PassportFile getReverseSide() Optional. Encrypted file with the reverse side of the document, provided by the user. Available for “driver_license” and “identity_card”. The file can be decrypted and verified using the accompanying EncryptedCredentials.
* @method PassportFile getSelfie() Optional. Encrypted file with the selfie of the user holding a document, provided by the user; available for “passport”, “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified using the accompanying EncryptedCredentials. * @method PassportFile getSelfie() Optional. Encrypted file with the selfie of the user holding a document, provided by the user; available for “passport”, “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified using the accompanying EncryptedCredentials.
* @method PassportFile[] getTranslation() Optional. Array of encrypted files with translated versions of documents provided by the user. Available if requested for “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can be decrypted and verified using the accompanying EncryptedCredentials.
* @method string getHash() Base64-encoded element hash for using in PassportElementErrorUnspecified * @method string getHash() Base64-encoded element hash for using in PassportElementErrorUnspecified
**/ **/
class EncryptedPassportElement extends Entity class EncryptedPassportElement extends Entity
...@@ -36,41 +38,11 @@ class EncryptedPassportElement extends Entity ...@@ -36,41 +38,11 @@ class EncryptedPassportElement extends Entity
protected function subEntities() protected function subEntities()
{ {
return [ return [
'files' => PassportFile::class, 'files' => [PassportFile::class],
'front_side' => PassportFile::class, 'front_side' => PassportFile::class,
'reverse_side' => PassportFile::class, 'reverse_side' => PassportFile::class,
'selfie' => PassportFile::class, 'selfie' => PassportFile::class,
'translation' => PassportFile::class, 'translation' => [PassportFile::class],
]; ];
} }
/**
* Optional. Array of encrypted files with documents provided by the user, available for “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can be decrypted and verified using the accompanying EncryptedCredentials.
*
* This method overrides the default getFiles method
* and returns a nice array of PassportFile objects.
*
* @return null|PassportFile[]
*/
public function getFiles()
{
$pretty_array = $this->makePrettyObjectArray(PassportFile::class, 'files');
return empty($pretty_array) ? null : $pretty_array;
}
/**
* Optional. Array of encrypted files with translated versions of documents provided by the user. Available if requested for “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can be decrypted and verified using the accompanying EncryptedCredentials.
*
* This method overrides the default getTranslation method
* and returns a nice array of PassportFile objects.
*
* @return null|PassportFile[]
*/
public function getTranslation()
{
$pretty_array = $this->makePrettyObjectArray(PassportFile::class, 'translation');
return empty($pretty_array) ? null : $pretty_array;
}
} }
...@@ -19,6 +19,7 @@ use Longman\TelegramBot\Entities\Entity; ...@@ -19,6 +19,7 @@ use Longman\TelegramBot\Entities\Entity;
* *
* @link https://core.telegram.org/bots/api#passportdata * @link https://core.telegram.org/bots/api#passportdata
* *
* @method EncryptedPassportElement[] getData() Array with information about documents and other Telegram Passport elements that was shared with the bot
* @method EncryptedCredentials getCredentials() Encrypted credentials required to decrypt the data * @method EncryptedCredentials getCredentials() Encrypted credentials required to decrypt the data
**/ **/
class PassportData extends Entity class PassportData extends Entity
...@@ -29,23 +30,8 @@ class PassportData extends Entity ...@@ -29,23 +30,8 @@ class PassportData extends Entity
protected function subEntities() protected function subEntities()
{ {
return [ return [
'data' => EncryptedPassportElement::class, 'data' => [EncryptedPassportElement::class],
'credentials' => EncryptedCredentials::class, 'credentials' => EncryptedCredentials::class,
]; ];
} }
/**
* Array with information about documents and other Telegram Passport elements that was shared with the bot
*
* This method overrides the default getData method
* and returns a nice array of EncryptedPassportElement objects.
*
* @return null|EncryptedPassportElement[]
*/
public function getData()
{
$pretty_array = $this->makePrettyObjectArray(EncryptedPassportElement::class, 'data');
return empty($pretty_array) ? null : $pretty_array;
}
} }
...@@ -31,8 +31,6 @@ class PassportElementErrorDataField extends Entity implements PassportElementErr ...@@ -31,8 +31,6 @@ class PassportElementErrorDataField extends Entity implements PassportElementErr
* PassportElementErrorDataField constructor * PassportElementErrorDataField constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -30,8 +30,6 @@ class PassportElementErrorFile extends Entity implements PassportElementError ...@@ -30,8 +30,6 @@ class PassportElementErrorFile extends Entity implements PassportElementError
* PassportElementErrorFile constructor * PassportElementErrorFile constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -30,8 +30,6 @@ class PassportElementErrorFiles extends Entity implements PassportElementError ...@@ -30,8 +30,6 @@ class PassportElementErrorFiles extends Entity implements PassportElementError
* PassportElementErrorFiles constructor * PassportElementErrorFiles constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -30,8 +30,6 @@ class PassportElementErrorFrontSide extends Entity implements PassportElementErr ...@@ -30,8 +30,6 @@ class PassportElementErrorFrontSide extends Entity implements PassportElementErr
* PassportElementErrorFrontSide constructor * PassportElementErrorFrontSide constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -30,8 +30,6 @@ class PassportElementErrorReverseSide extends Entity implements PassportElementE ...@@ -30,8 +30,6 @@ class PassportElementErrorReverseSide extends Entity implements PassportElementE
* PassportElementErrorReverseSide constructor * PassportElementErrorReverseSide constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -30,8 +30,6 @@ class PassportElementErrorSelfie extends Entity implements PassportElementError ...@@ -30,8 +30,6 @@ class PassportElementErrorSelfie extends Entity implements PassportElementError
* PassportElementErrorSelfie constructor * PassportElementErrorSelfie constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -30,8 +30,6 @@ class PassportElementErrorTranslationFile extends Entity implements PassportElem ...@@ -30,8 +30,6 @@ class PassportElementErrorTranslationFile extends Entity implements PassportElem
* PassportElementErrorTranslationFile constructor * PassportElementErrorTranslationFile constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -30,8 +30,6 @@ class PassportElementErrorTranslationFiles extends Entity implements PassportEle ...@@ -30,8 +30,6 @@ class PassportElementErrorTranslationFiles extends Entity implements PassportEle
* PassportElementErrorTranslationFiles constructor * PassportElementErrorTranslationFiles constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -30,8 +30,6 @@ class PassportElementErrorUnspecified extends Entity implements PassportElementE ...@@ -30,8 +30,6 @@ class PassportElementErrorUnspecified extends Entity implements PassportElementE
* PassportElementErrorUnspecified constructor * PassportElementErrorUnspecified constructor
* *
* @param array $data * @param array $data
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
......
...@@ -82,10 +82,7 @@ class Update extends Entity ...@@ -82,10 +82,7 @@ class Update extends Entity
/** /**
* Get update content * Get update content
* *
* @return \Longman\TelegramBot\Entities\CallbackQuery * @return CallbackQuery|ChosenInlineResult|InlineQuery|Message
* |\Longman\TelegramBot\Entities\ChosenInlineResult
* |\Longman\TelegramBot\Entities\InlineQuery
* |\Longman\TelegramBot\Entities\Message
*/ */
public function getUpdateContent() public function getUpdateContent()
{ {
......
...@@ -34,7 +34,7 @@ class UserProfilePhotos extends Entity ...@@ -34,7 +34,7 @@ class UserProfilePhotos extends Entity
* *
* This method overrides the default getPhotos method and returns a nice array * This method overrides the default getPhotos method and returns a nice array
* *
* @return PhotoSize[] * @return PhotoSize[][]
*/ */
public function getPhotos() public function getPhotos()
{ {
...@@ -42,11 +42,9 @@ class UserProfilePhotos extends Entity ...@@ -42,11 +42,9 @@ class UserProfilePhotos extends Entity
if ($these_photos = $this->getProperty('photos')) { if ($these_photos = $this->getProperty('photos')) {
foreach ($these_photos as $photos) { foreach ($these_photos as $photos) {
$new_photos = []; $all_photos[] = array_map(function ($photo) {
foreach ($photos as $photo) { return new PhotoSize($photo);
$new_photos[] = new PhotoSize($photo); }, $photos);
}
$all_photos[] = $new_photos;
} }
} }
......
...@@ -91,7 +91,7 @@ class Request ...@@ -91,7 +91,7 @@ class Request
/** /**
* Telegram object * Telegram object
* *
* @var \Longman\TelegramBot\Telegram * @var Telegram
*/ */
private static $telegram; private static $telegram;
...@@ -105,7 +105,7 @@ class Request ...@@ -105,7 +105,7 @@ class Request
/** /**
* Guzzle Client object * Guzzle Client object
* *
* @var \GuzzleHttp\Client * @var Client
*/ */
private static $client; private static $client;
...@@ -253,7 +253,7 @@ class Request ...@@ -253,7 +253,7 @@ class Request
/** /**
* Initialize * Initialize
* *
* @param \Longman\TelegramBot\Telegram $telegram * @param Telegram $telegram
* *
* @throws TelegramException * @throws TelegramException
*/ */
...@@ -287,7 +287,7 @@ class Request ...@@ -287,7 +287,7 @@ class Request
* Set input from custom input or stdin and return it * Set input from custom input or stdin and return it
* *
* @return string * @return string
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public static function getInput() public static function getInput()
{ {
...@@ -377,7 +377,7 @@ class Request ...@@ -377,7 +377,7 @@ class Request
} }
// Reformat data array in multipart way if it contains a resource // Reformat data array in multipart way if it contains a resource
$has_resource |= (is_resource($item) || $item instanceof Stream); $has_resource = $has_resource || is_resource($item) || $item instanceof Stream;
$multipart[] = ['name' => $key, 'contents' => $item]; $multipart[] = ['name' => $key, 'contents' => $item];
} }
...@@ -421,6 +421,7 @@ class Request ...@@ -421,6 +421,7 @@ class Request
* @param array $multipart * @param array $multipart
* *
* @return mixed * @return mixed
* @throws TelegramException
*/ */
private static function mediaInputHelper($item, &$has_resource, array &$multipart) private static function mediaInputHelper($item, &$has_resource, array &$multipart)
{ {
...@@ -472,7 +473,7 @@ class Request ...@@ -472,7 +473,7 @@ class Request
* @param array $data Data to attach to the execution * @param array $data Data to attach to the execution
* *
* @return string Result of the HTTP Request * @return string Result of the HTTP Request
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public static function execute($action, array $data = []) public static function execute($action, array $data = [])
{ {
...@@ -509,10 +510,10 @@ class Request ...@@ -509,10 +510,10 @@ class Request
/** /**
* Download file * Download file
* *
* @param \Longman\TelegramBot\Entities\File $file * @param File $file
* *
* @return boolean * @return boolean
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public static function downloadFile(File $file) public static function downloadFile(File $file)
{ {
...@@ -540,7 +541,7 @@ class Request ...@@ -540,7 +541,7 @@ class Request
return filesize($file_path) > 0; return filesize($file_path) > 0;
} catch (RequestException $e) { } catch (RequestException $e) {
return ($e->getResponse()) ? (string) $e->getResponse()->getBody() : ''; return false;
} finally { } finally {
//Logging verbose debug output //Logging verbose debug output
TelegramLog::endDebugLogTempStream('Verbose HTTP File Download Request output:' . PHP_EOL . '%s' . PHP_EOL); TelegramLog::endDebugLogTempStream('Verbose HTTP File Download Request output:' . PHP_EOL . '%s' . PHP_EOL);
...@@ -553,7 +554,7 @@ class Request ...@@ -553,7 +554,7 @@ class Request
* @param string $file * @param string $file
* *
* @return resource * @return resource
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public static function encodeFile($file) public static function encodeFile($file)
{ {
...@@ -574,8 +575,8 @@ class Request ...@@ -574,8 +575,8 @@ class Request
* @param string $action * @param string $action
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public static function send($action, array $data = []) public static function send($action, array $data = [])
{ {
...@@ -643,7 +644,7 @@ class Request ...@@ -643,7 +644,7 @@ class Request
* *
* @param array $data * @param array $data
* *
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
private static function ensureNonEmptyData(array $data) private static function ensureNonEmptyData(array $data)
{ {
...@@ -657,7 +658,7 @@ class Request ...@@ -657,7 +658,7 @@ class Request
* *
* @param string $action * @param string $action
* *
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
private static function ensureValidAction($action) private static function ensureValidAction($action)
{ {
...@@ -673,8 +674,8 @@ class Request ...@@ -673,8 +674,8 @@ class Request
* *
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public static function sendMessage(array $data) public static function sendMessage(array $data)
{ {
...@@ -698,8 +699,7 @@ class Request ...@@ -698,8 +699,7 @@ class Request
* @param string $action * @param string $action
* @param array $data * @param array $data
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function __callStatic($action, array $data) public static function __callStatic($action, array $data)
{ {
...@@ -716,8 +716,7 @@ class Request ...@@ -716,8 +716,7 @@ class Request
* No request to telegram are sent, this function is used in commands that * No request to telegram are sent, this function is used in commands that
* don't need to fire a message after execution * don't need to fire a message after execution
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public static function emptyResponse() public static function emptyResponse()
{ {
...@@ -760,7 +759,7 @@ class Request ...@@ -760,7 +759,7 @@ class Request
* @param boolean $enable * @param boolean $enable
* @param array $options * @param array $options
* *
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public static function setLimiter($enable = true, array $options = []) public static function setLimiter($enable = true, array $options = [])
{ {
...@@ -789,7 +788,7 @@ class Request ...@@ -789,7 +788,7 @@ class Request
* @param string $action * @param string $action
* @param array $data * @param array $data
* *
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
private static function limitTelegramRequests($action, array $data = []) private static function limitTelegramRequests($action, array $data = [])
{ {
...@@ -830,7 +829,7 @@ class Request ...@@ -830,7 +829,7 @@ class Request
$chat_id = isset($data['chat_id']) ? $data['chat_id'] : null; $chat_id = isset($data['chat_id']) ? $data['chat_id'] : null;
$inline_message_id = isset($data['inline_message_id']) ? $data['inline_message_id'] : null; $inline_message_id = isset($data['inline_message_id']) ? $data['inline_message_id'] : null;
if (($chat_id || $inline_message_id) && in_array($action, $limited_methods)) { if (($chat_id || $inline_message_id) && in_array($action, $limited_methods, true)) {
$timeout = 60; $timeout = 60;
while (true) { while (true) {
...@@ -838,18 +837,23 @@ class Request ...@@ -838,18 +837,23 @@ class Request
throw new TelegramException('Timed out while waiting for a request spot!'); throw new TelegramException('Timed out while waiting for a request spot!');
} }
$requests = DB::getTelegramRequestCount($chat_id, $inline_message_id); if (!($requests = DB::getTelegramRequestCount($chat_id, $inline_message_id))) {
break;
}
// Make sure we're handling integers here.
$requests = array_map('intval', $requests);
$chat_per_second = ($requests['LIMIT_PER_SEC'] == 0); // No more than one message per second inside a particular chat $chat_per_second = ($requests['LIMIT_PER_SEC'] === 0); // No more than one message per second inside a particular chat
$global_per_second = ($requests['LIMIT_PER_SEC_ALL'] < 30); // No more than 30 messages per second to different chats $global_per_second = ($requests['LIMIT_PER_SEC_ALL'] < 30); // No more than 30 messages per second to different chats
$groups_per_minute = (((is_numeric($chat_id) && $chat_id > 0) || !is_null($inline_message_id)) || ((!is_numeric($chat_id) || $chat_id < 0) && $requests['LIMIT_PER_MINUTE'] < 20)); // No more than 20 messages per minute in groups and channels $groups_per_minute = (((is_numeric($chat_id) && $chat_id > 0) || $inline_message_id !== null) || ((!is_numeric($chat_id) || $chat_id < 0) && $requests['LIMIT_PER_MINUTE'] < 20)); // No more than 20 messages per minute in groups and channels
if ($chat_per_second && $global_per_second && $groups_per_minute) { if ($chat_per_second && $global_per_second && $groups_per_minute) {
break; break;
} }
$timeout--; $timeout--;
usleep(self::$limiter_interval * 1000000); usleep((int) (self::$limiter_interval * 1000000));
} }
DB::insertTelegramRequest($action, $data); DB::insertTelegramRequest($action, $data);
......
...@@ -70,7 +70,7 @@ class Telegram ...@@ -70,7 +70,7 @@ class Telegram
/** /**
* Current Update object * Current Update object
* *
* @var \Longman\TelegramBot\Entities\Update * @var Update
*/ */
protected $update; protected $update;
...@@ -98,7 +98,7 @@ class Telegram ...@@ -98,7 +98,7 @@ class Telegram
/** /**
* PDO object * PDO object
* *
* @var \PDO * @var PDO
*/ */
protected $pdo; protected $pdo;
...@@ -119,7 +119,7 @@ class Telegram ...@@ -119,7 +119,7 @@ class Telegram
/** /**
* ServerResponse of the last Command execution * ServerResponse of the last Command execution
* *
* @var \Longman\TelegramBot\Entities\ServerResponse * @var ServerResponse
*/ */
protected $last_command_response; protected $last_command_response;
...@@ -151,7 +151,7 @@ class Telegram ...@@ -151,7 +151,7 @@ class Telegram
* @param string $api_key * @param string $api_key
* @param string $bot_username * @param string $bot_username
* *
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function __construct($api_key, $bot_username = '') public function __construct($api_key, $bot_username = '')
{ {
...@@ -182,8 +182,8 @@ class Telegram ...@@ -182,8 +182,8 @@ class Telegram
* @param string $table_prefix * @param string $table_prefix
* @param string $encoding * @param string $encoding
* *
* @return \Longman\TelegramBot\Telegram * @return Telegram
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function enableMySql(array $credential, $table_prefix = null, $encoding = 'utf8mb4') public function enableMySql(array $credential, $table_prefix = null, $encoding = 'utf8mb4')
{ {
...@@ -200,8 +200,8 @@ class Telegram ...@@ -200,8 +200,8 @@ class Telegram
* @param PDO $external_pdo_connection PDO database object * @param PDO $external_pdo_connection PDO database object
* @param string $table_prefix * @param string $table_prefix
* *
* @return \Longman\TelegramBot\Telegram * @return Telegram
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function enableExternalMySql($external_pdo_connection, $table_prefix = null) public function enableExternalMySql($external_pdo_connection, $table_prefix = null)
{ {
...@@ -216,7 +216,7 @@ class Telegram ...@@ -216,7 +216,7 @@ class Telegram
* Get commands list * Get commands list
* *
* @return array $commands * @return array $commands
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function getCommandsList() public function getCommandsList()
{ {
...@@ -261,7 +261,7 @@ class Telegram ...@@ -261,7 +261,7 @@ class Telegram
* *
* @param string $command * @param string $command
* *
* @return \Longman\TelegramBot\Commands\Command|null * @return Command|null
*/ */
public function getCommandObject($command) public function getCommandObject($command)
{ {
...@@ -284,7 +284,7 @@ class Telegram ...@@ -284,7 +284,7 @@ class Telegram
* *
* @param string $input (json format) * @param string $input (json format)
* *
* @return \Longman\TelegramBot\Telegram * @return Telegram
*/ */
public function setCustomInput($input) public function setCustomInput($input)
{ {
...@@ -306,7 +306,7 @@ class Telegram ...@@ -306,7 +306,7 @@ class Telegram
/** /**
* Get the ServerResponse of the last Command execution * Get the ServerResponse of the last Command execution
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
*/ */
public function getLastCommandResponse() public function getLastCommandResponse()
{ {
...@@ -319,8 +319,8 @@ class Telegram ...@@ -319,8 +319,8 @@ class Telegram
* @param int|null $limit * @param int|null $limit
* @param int|null $timeout * @param int|null $timeout
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function handleGetUpdates($limit = null, $timeout = null) public function handleGetUpdates($limit = null, $timeout = null)
{ {
...@@ -344,9 +344,8 @@ class Telegram ...@@ -344,9 +344,8 @@ class Telegram
if ($custom_input = $this->getCustomInput()) { if ($custom_input = $this->getCustomInput()) {
$response = new ServerResponse(json_decode($custom_input, true), $this->bot_username); $response = new ServerResponse(json_decode($custom_input, true), $this->bot_username);
} else { } else {
if (DB::isDbConnected()) { if (DB::isDbConnected() && $last_update = DB::selectTelegramUpdate(1)) {
//Get last update id from the database //Get last update id from the database
$last_update = DB::selectTelegramUpdate(1);
$last_update = reset($last_update); $last_update = reset($last_update);
$this->last_update_id = isset($last_update['id']) ? $last_update['id'] : null; $this->last_update_id = isset($last_update['id']) ? $last_update['id'] : null;
...@@ -394,7 +393,7 @@ class Telegram ...@@ -394,7 +393,7 @@ class Telegram
* *
* @return bool * @return bool
* *
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function handle() public function handle()
{ {
...@@ -435,10 +434,10 @@ class Telegram ...@@ -435,10 +434,10 @@ class Telegram
/** /**
* Process bot Update request * Process bot Update request
* *
* @param \Longman\TelegramBot\Entities\Update $update * @param Update $update
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function processUpdate(Update $update) public function processUpdate(Update $update)
{ {
...@@ -493,7 +492,7 @@ class Telegram ...@@ -493,7 +492,7 @@ class Telegram
* @param string $command * @param string $command
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function executeCommand($command) public function executeCommand($command)
{ {
...@@ -534,7 +533,7 @@ class Telegram ...@@ -534,7 +533,7 @@ class Telegram
* *
* @param integer $admin_id Single admin id * @param integer $admin_id Single admin id
* *
* @return \Longman\TelegramBot\Telegram * @return Telegram
*/ */
public function enableAdmin($admin_id) public function enableAdmin($admin_id)
{ {
...@@ -552,7 +551,7 @@ class Telegram ...@@ -552,7 +551,7 @@ class Telegram
* *
* @param array $admin_ids List of admin ids * @param array $admin_ids List of admin ids
* *
* @return \Longman\TelegramBot\Telegram * @return Telegram
*/ */
public function enableAdmins(array $admin_ids) public function enableAdmins(array $admin_ids)
{ {
...@@ -627,7 +626,7 @@ class Telegram ...@@ -627,7 +626,7 @@ class Telegram
* @param string $path Custom commands path to add * @param string $path Custom commands path to add
* @param bool $before If the path should be prepended or appended to the list * @param bool $before If the path should be prepended or appended to the list
* *
* @return \Longman\TelegramBot\Telegram * @return Telegram
*/ */
public function addCommandsPath($path, $before = true) public function addCommandsPath($path, $before = true)
{ {
...@@ -650,7 +649,7 @@ class Telegram ...@@ -650,7 +649,7 @@ class Telegram
* @param array $paths Custom commands paths to add * @param array $paths Custom commands paths to add
* @param bool $before If the paths should be prepended or appended to the list * @param bool $before If the paths should be prepended or appended to the list
* *
* @return \Longman\TelegramBot\Telegram * @return Telegram
*/ */
public function addCommandsPaths(array $paths, $before = true) public function addCommandsPaths(array $paths, $before = true)
{ {
...@@ -676,7 +675,7 @@ class Telegram ...@@ -676,7 +675,7 @@ class Telegram
* *
* @param string $path Custom upload path * @param string $path Custom upload path
* *
* @return \Longman\TelegramBot\Telegram * @return Telegram
*/ */
public function setUploadPath($path) public function setUploadPath($path)
{ {
...@@ -700,7 +699,7 @@ class Telegram ...@@ -700,7 +699,7 @@ class Telegram
* *
* @param string $path Custom download path * @param string $path Custom download path
* *
* @return \Longman\TelegramBot\Telegram * @return Telegram
*/ */
public function setDownloadPath($path) public function setDownloadPath($path)
{ {
...@@ -729,7 +728,7 @@ class Telegram ...@@ -729,7 +728,7 @@ class Telegram
* @param string $command * @param string $command
* @param array $config * @param array $config
* *
* @return \Longman\TelegramBot\Telegram * @return Telegram
*/ */
public function setCommandConfig($command, array $config) public function setCommandConfig($command, array $config)
{ {
...@@ -796,8 +795,8 @@ class Telegram ...@@ -796,8 +795,8 @@ class Telegram
* @param string $url * @param string $url
* @param array $data Optional parameters. * @param array $data Optional parameters.
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function setWebhook($url, array $data = []) public function setWebhook($url, array $data = [])
{ {
...@@ -832,7 +831,7 @@ class Telegram ...@@ -832,7 +831,7 @@ class Telegram
* Delete any assigned webhook * Delete any assigned webhook
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public function deleteWebhook() public function deleteWebhook()
{ {
...@@ -874,29 +873,13 @@ class Telegram ...@@ -874,29 +873,13 @@ class Telegram
. mb_strtolower(mb_substr($str, 1, mb_strlen($str), $encoding), $encoding); . mb_strtolower(mb_substr($str, 1, mb_strlen($str), $encoding), $encoding);
} }
/**
* Enable Botan.io integration
*
* @deprecated Botan.io service is no longer working
*
* @param string $token
* @param array $options
*
* @return \Longman\TelegramBot\Telegram
*/
public function enableBotan($token, array $options = [])
{
trigger_error('Longman\TelegramBot\Telegram::enableBotan is deprecated and will be removed in future release.', E_USER_DEPRECATED);
return $this;
}
/** /**
* Enable requests limiter * Enable requests limiter
* *
* @param array $options * @param array $options
* *
* @return \Longman\TelegramBot\Telegram * @return Telegram
* @throws TelegramException
*/ */
public function enableLimiter(array $options = []) public function enableLimiter(array $options = [])
{ {
......
...@@ -210,8 +210,8 @@ class TelegramLog ...@@ -210,8 +210,8 @@ class TelegramLog
*/ */
public static function getDebugLogTempStream() public static function getDebugLogTempStream()
{ {
if (self::$debug_log_temp_stream_handle === null) { if ((self::$debug_log_temp_stream_handle === null) && $temp_stream_handle = fopen('php://temp', 'wb+')) {
self::$debug_log_temp_stream_handle = fopen('php://temp', 'w+b'); self::$debug_log_temp_stream_handle = $temp_stream_handle;
} }
return self::$debug_log_temp_stream_handle; return self::$debug_log_temp_stream_handle;
......
...@@ -271,18 +271,6 @@ CREATE TABLE IF NOT EXISTS `conversation` ( ...@@ -271,18 +271,6 @@ CREATE TABLE IF NOT EXISTS `conversation` (
FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`) FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `botan_shortener` (
`id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',
`user_id` bigint NULL DEFAULT NULL COMMENT 'Unique user identifier',
`url` text NOT NULL COMMENT 'Original URL',
`short_url` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Shortened URL',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `request_limiter` ( CREATE TABLE IF NOT EXISTS `request_limiter` (
`id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry', `id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',
`chat_id` char(255) NULL DEFAULT NULL COMMENT 'Unique chat identifier', `chat_id` char(255) NULL DEFAULT NULL COMMENT 'Unique chat identifier',
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace Longman\TelegramBot\Tests\Unit\Commands; namespace Longman\TelegramBot\Tests\Unit\Commands;
use Longman\TelegramBot\Commands\Command;
use Longman\TelegramBot\Telegram; use Longman\TelegramBot\Telegram;
use Longman\TelegramBot\Tests\Unit\TestCase; use Longman\TelegramBot\Tests\Unit\TestCase;
use Longman\TelegramBot\Tests\Unit\TestHelpers; use Longman\TelegramBot\Tests\Unit\TestHelpers;
...@@ -26,25 +27,25 @@ class CommandTest extends TestCase ...@@ -26,25 +27,25 @@ class CommandTest extends TestCase
/** /**
* @var string * @var string
*/ */
private $command_namespace = 'Longman\TelegramBot\Commands\Command'; private $command_namespace = Command::class;
/** /**
* @var \Longman\TelegramBot\Telegram * @var Telegram
*/ */
private $telegram; private $telegram;
/** /**
* @var \Longman\TelegramBot\Commands\Command * @var Command
*/ */
private $command_stub; private $command_stub;
/** /**
* @var \Longman\TelegramBot\Telegram * @var Telegram
*/ */
private $telegram_with_config; private $telegram_with_config;
/** /**
* @var \Longman\TelegramBot\Commands\Command * @var Command
*/ */
private $command_stub_with_config; private $command_stub_with_config;
...@@ -74,7 +75,7 @@ class CommandTest extends TestCase ...@@ -74,7 +75,7 @@ class CommandTest extends TestCase
[null], [null],
[12345], [12345],
['something'], ['something'],
[new \stdClass], [new \stdClass()],
[$this->telegram], // only this one is valid [$this->telegram], // only this one is valid
]; ];
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace Longman\TelegramBot\Tests\Unit\Commands; namespace Longman\TelegramBot\Tests\Unit\Commands;
use Longman\TelegramBot\Commands\Command;
use Longman\TelegramBot\Telegram; use Longman\TelegramBot\Telegram;
use Longman\TelegramBot\Tests\Unit\TestCase; use Longman\TelegramBot\Tests\Unit\TestCase;
...@@ -23,12 +24,12 @@ use Longman\TelegramBot\Tests\Unit\TestCase; ...@@ -23,12 +24,12 @@ use Longman\TelegramBot\Tests\Unit\TestCase;
class CommandTestCase extends TestCase class CommandTestCase extends TestCase
{ {
/** /**
* @var \Longman\TelegramBot\Telegram * @var Telegram
*/ */
protected $telegram; protected $telegram;
/** /**
* @var \Longman\TelegramBot\Commands\Command * @var Command
*/ */
protected $command; protected $command;
......
...@@ -47,7 +47,6 @@ class HiddenCommand extends UserCommand ...@@ -47,7 +47,6 @@ class HiddenCommand extends UserCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -47,7 +47,6 @@ class VisibleCommand extends UserCommand ...@@ -47,7 +47,6 @@ class VisibleCommand extends UserCommand
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
......
...@@ -23,7 +23,7 @@ use Longman\TelegramBot\Telegram; ...@@ -23,7 +23,7 @@ use Longman\TelegramBot\Telegram;
class ConversationTest extends TestCase class ConversationTest extends TestCase
{ {
/** /**
* @var \Longman\TelegramBot\Telegram * @var Telegram
*/ */
private $telegram; private $telegram;
......
...@@ -34,7 +34,7 @@ class AudioTest extends TestCase ...@@ -34,7 +34,7 @@ class AudioTest extends TestCase
public function testInstance() public function testInstance()
{ {
$audio = new Audio($this->record); $audio = new Audio($this->record);
self::assertInstanceOf('Longman\TelegramBot\Entities\Audio', $audio); self::assertInstanceOf(Audio::class, $audio);
} }
public function testGetProperties() public function testGetProperties()
......
...@@ -38,7 +38,7 @@ class FileTest extends TestCase ...@@ -38,7 +38,7 @@ class FileTest extends TestCase
public function testBaseStageLocation() public function testBaseStageLocation()
{ {
$file = new File($this->data); $file = new File($this->data);
$this->assertInstanceOf('Longman\TelegramBot\Entities\File', $file); $this->assertInstanceOf(File::class, $file);
} }
public function testGetFileId() public function testGetFileId()
......
...@@ -34,7 +34,7 @@ class LocationTest extends TestCase ...@@ -34,7 +34,7 @@ class LocationTest extends TestCase
public function testBaseStageLocation() public function testBaseStageLocation()
{ {
$location = new Location($this->coordinates); $location = new Location($this->coordinates);
$this->assertInstanceOf('Longman\TelegramBot\Entities\Location', $location); $this->assertInstanceOf(Location::class, $location);
} }
public function testGetLongitude() public function testGetLongitude()
......
...@@ -12,8 +12,14 @@ ...@@ -12,8 +12,14 @@
namespace Longman\TelegramBot\Tests\Unit; namespace Longman\TelegramBot\Tests\Unit;
use Longman\TelegramBot\Entities\File;
use Longman\TelegramBot\Entities\Message; use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\PhotoSize;
use Longman\TelegramBot\Entities\ServerResponse; use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Entities\Sticker;
use Longman\TelegramBot\Entities\StickerSet;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Entities\UserProfilePhotos;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -54,7 +60,7 @@ class ServerResponseTest extends TestCase ...@@ -54,7 +60,7 @@ class ServerResponseTest extends TestCase
self::assertTrue($server->isOk()); self::assertTrue($server->isOk());
self::assertNull($server->getErrorCode()); self::assertNull($server->getErrorCode());
self::assertNull($server->getDescription()); self::assertNull($server->getDescription());
self::assertInstanceOf('\Longman\TelegramBot\Entities\Message', $server_result); self::assertInstanceOf(Message::class, $server_result);
//Message //Message
self::assertEquals('1234', $server_result->getMessageId()); self::assertEquals('1234', $server_result->getMessageId());
...@@ -181,7 +187,7 @@ class ServerResponseTest extends TestCase ...@@ -181,7 +187,7 @@ class ServerResponseTest extends TestCase
$server = new ServerResponse(json_decode($result, true), 'testbot'); $server = new ServerResponse(json_decode($result, true), 'testbot');
self::assertCount(4, $server->getResult()); self::assertCount(4, $server->getResult());
self::assertInstanceOf('\Longman\TelegramBot\Entities\Update', $server->getResult()[0]); self::assertInstanceOf(Update::class, $server->getResult()[0]);
} }
public function getUpdatesEmpty() public function getUpdatesEmpty()
...@@ -239,8 +245,8 @@ class ServerResponseTest extends TestCase ...@@ -239,8 +245,8 @@ class ServerResponseTest extends TestCase
//Photo size count //Photo size count
self::assertCount(3, $photos[0]); self::assertCount(3, $photos[0]);
self::assertInstanceOf('\Longman\TelegramBot\Entities\UserProfilePhotos', $server_result); self::assertInstanceOf(UserProfilePhotos::class, $server_result);
self::assertInstanceOf('\Longman\TelegramBot\Entities\PhotoSize', $photos[0][0]); self::assertInstanceOf(PhotoSize::class, $photos[0][0]);
} }
public function getFile() public function getFile()
...@@ -261,7 +267,7 @@ class ServerResponseTest extends TestCase ...@@ -261,7 +267,7 @@ class ServerResponseTest extends TestCase
$result = $this->getFile(); $result = $this->getFile();
$server = new ServerResponse(json_decode($result, true), 'testbot'); $server = new ServerResponse(json_decode($result, true), 'testbot');
self::assertInstanceOf('\Longman\TelegramBot\Entities\File', $server->getResult()); self::assertInstanceOf(File::class, $server->getResult());
} }
public function testSetGeneralTestFakeResponse() public function testSetGeneralTestFakeResponse()
...@@ -287,7 +293,7 @@ class ServerResponseTest extends TestCase ...@@ -287,7 +293,7 @@ class ServerResponseTest extends TestCase
self::assertTrue($server->isOk()); self::assertTrue($server->isOk());
self::assertNull($server->getErrorCode()); self::assertNull($server->getErrorCode());
self::assertNull($server->getDescription()); self::assertNull($server->getDescription());
self::assertInstanceOf('\Longman\TelegramBot\Entities\Message', $server_result); self::assertInstanceOf(Message::class, $server_result);
//Message //Message
self::assertEquals('1234', $server_result->getMessageId()); self::assertEquals('1234', $server_result->getMessageId());
...@@ -365,13 +371,13 @@ class ServerResponseTest extends TestCase ...@@ -365,13 +371,13 @@ class ServerResponseTest extends TestCase
$server_result = $server->getResult(); $server_result = $server->getResult();
self::assertInstanceOf('\Longman\TelegramBot\Entities\StickerSet', $server_result); self::assertInstanceOf(StickerSet::class, $server_result);
self::assertEquals('stickerset_name', $server_result->getName()); self::assertEquals('stickerset_name', $server_result->getName());
self::assertEquals('Some name', $server_result->getTitle()); self::assertEquals('Some name', $server_result->getTitle());
self::assertFalse($server_result->getContainsMasks()); self::assertFalse($server_result->getContainsMasks());
$stickers = $server_result->getStickers(); $stickers = $server_result->getStickers();
self::assertCount(4, $stickers); self::assertCount(4, $stickers);
self::assertInstanceOf('\Longman\TelegramBot\Entities\Sticker', $stickers[0]); self::assertInstanceOf(Sticker::class, $stickers[0]);
} }
} }
...@@ -24,7 +24,7 @@ class UserTest extends TestCase ...@@ -24,7 +24,7 @@ class UserTest extends TestCase
public function testInstance() public function testInstance()
{ {
$user = new User(['id' => 1]); $user = new User(['id' => 1]);
self::assertInstanceOf('Longman\TelegramBot\Entities\User', $user); self::assertInstanceOf(User::class, $user);
} }
public function testGetId() public function testGetId()
......
...@@ -42,7 +42,7 @@ class WebhookInfoTest extends TestCase ...@@ -42,7 +42,7 @@ class WebhookInfoTest extends TestCase
public function testBaseStageWebhookInfo() public function testBaseStageWebhookInfo()
{ {
$webhook = new WebhookInfo($this->data); $webhook = new WebhookInfo($this->data);
$this->assertInstanceOf('Longman\TelegramBot\Entities\WebhookInfo', $webhook); $this->assertInstanceOf(WebhookInfo::class, $webhook);
} }
public function testGetUrl() public function testGetUrl()
......
...@@ -22,7 +22,7 @@ use Longman\TelegramBot\Telegram; ...@@ -22,7 +22,7 @@ use Longman\TelegramBot\Telegram;
class TelegramTest extends TestCase class TelegramTest extends TestCase
{ {
/** /**
* @var \Longman\TelegramBot\Telegram * @var Telegram
*/ */
private $telegram; private $telegram;
......
...@@ -85,7 +85,7 @@ class TestHelpers ...@@ -85,7 +85,7 @@ class TestHelpers
* *
* @param array $data Pass custom data array if needed * @param array $data Pass custom data array if needed
* *
* @return \Longman\TelegramBot\Entities\Update * @return Update
*/ */
public static function getFakeUpdateObject($data = null) public static function getFakeUpdateObject($data = null)
{ {
...@@ -107,7 +107,7 @@ class TestHelpers ...@@ -107,7 +107,7 @@ class TestHelpers
* *
* @param string $command_text * @param string $command_text
* *
* @return \Longman\TelegramBot\Entities\Update * @return Update
*/ */
public static function getFakeUpdateCommandObject($command_text) public static function getFakeUpdateCommandObject($command_text)
{ {
...@@ -129,7 +129,7 @@ class TestHelpers ...@@ -129,7 +129,7 @@ class TestHelpers
* *
* @param array $data Pass custom data array if needed * @param array $data Pass custom data array if needed
* *
* @return \Longman\TelegramBot\Entities\User * @return User
*/ */
public static function getFakeUserObject(array $data = []) public static function getFakeUserObject(array $data = [])
{ {
...@@ -143,7 +143,7 @@ class TestHelpers ...@@ -143,7 +143,7 @@ class TestHelpers
* *
* @param array $data Pass custom data array if needed * @param array $data Pass custom data array if needed
* *
* @return \Longman\TelegramBot\Entities\Chat * @return Chat
*/ */
public static function getFakeChatObject(array $data = []) public static function getFakeChatObject(array $data = [])
{ {
...@@ -179,7 +179,7 @@ class TestHelpers ...@@ -179,7 +179,7 @@ class TestHelpers
* @param array $user_data Pass custom user data array if needed * @param array $user_data Pass custom user data array if needed
* @param array $chat_data Pass custom chat data array if needed * @param array $chat_data Pass custom chat data array if needed
* *
* @return \Longman\TelegramBot\Entities\Message * @return Message
*/ */
public static function getFakeMessageObject(array $message_data = [], array $user_data = [], array $chat_data = []) public static function getFakeMessageObject(array $message_data = [], array $user_data = [], array $chat_data = [])
{ {
......
<?php <?php
require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../vendor/autoload.php';
$filename='logfile.log'; $filename = 'logfile.log';
$API_KEY = 'random'; $API_KEY = 'random';
$BOT_NAME = 'bot_name'; $BOT_NAME = 'bot_name';
define('PHPUNIT_TESTSUITE', 'some value'); define('PHPUNIT_TESTSUITE', 'some value');
$CREDENTIALS = array('host'=>'localhost', 'user'=>'', 'password'=>'', 'database'=>''); $CREDENTIALS = ['host' => 'localhost', 'user' => '', 'password' => '', 'database' => ''];
$update = null; $update = null;
try { try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment