Unverified Commit 6351dc33 authored by Armando Lüscher's avatar Armando Lüscher

Merge branch 'develop' into add_missing_db_fields

parents 24ce6b71 488f68d7
......@@ -6,14 +6,40 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
## [Unreleased]
:exclamation: After updating to this version, you will need to execute the [SQL migration script][unreleased-sql-migration] on your database.
### Added
- Bot API 4.2 (Polls).
- `getIsMember()` method to `ChatMember` entity.
- `getForwardSenderName()` method to `Message` entity.
- `forward_sender_name` (and forgotten `forward_signature`) DB fields.
- Added missing API fields to Entities and DB.
- Created database tables for `shipping_query` and `pre_checkout_query`.
### Changed
### Deprecated
### Removed
### Fixed
- Missing DB table name specifier in `/cleanup` command. (#947)
### Security
## [0.56.0] - 2019-04-15
### Added
- Helper for sending `InputMedia` objects using `Request::sendMediaGroup()` and `Request::editMediaMessage()` methods. (#934)
- Allow passing absolute file path for InputFile fields, instead of `Request::encodeFile($path)`. (#934)
### Changed
- All Message field types dynamically search for an existing Command class that can handle them. (#940)
- Upgrade dependencies. (#945)
### Deprecated
- Botan.io service has been discontinued. (#925)
- Most built-in System Commands will be handled by GenericmessageCommand by default in a future release and will require a custom implementation. (#940)
### Fixed
- Constraint errors in `/cleanup` command. (#930)
- Return correct objects for requests. (#934)
- PHPCS: static before visibility declaration. (#945)
## [0.55.1] - 2019-01-06
### Added
- Add missing `Request::editMessageMedia()` and `CallbackQuery::getChatInstance()` methods.
### Fixed
- Return correct message type.
## [0.55.0] - 2018-12-20
:exclamation: After updating to this version, you will need to execute the [SQL migration script][0.55.0-sql-migration] on your database.
### Added
......@@ -230,7 +256,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Deprecated
- Move `hideKeyboard` to `removeKeyboard`.
[unreleased-sql-migration]: https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.55.0-unreleased.sql
[unreleased-sql-migration]: https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/unreleased.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.54.0-sql-migration]: https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.53.0-0.54.0.sql
......@@ -250,6 +276,8 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
[example-bot]: https://github.com/php-telegram-bot/example-bot
[Unreleased]: https://github.com/php-telegram-bot/core/compare/master...develop
[0.56.0]: https://github.com/php-telegram-bot/core/compare/0.55.1...0.56.0
[0.55.1]: https://github.com/php-telegram-bot/core/compare/0.55.0...0.55.1
[0.55.0]: https://github.com/php-telegram-bot/core/compare/0.54.1...0.55.0
[0.54.1]: https://github.com/php-telegram-bot/core/compare/0.54.0...0.54.1
[0.54.0]: https://github.com/php-telegram-bot/core/compare/0.53.0...0.54.0
......
......@@ -28,12 +28,12 @@
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"monolog/monolog": "^1.23",
"monolog/monolog": "^1.24",
"guzzlehttp/guzzle": "^6.3"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.7|^6.5|^7.4",
"squizlabs/php_codesniffer": "^3.3"
"phpunit/phpunit": "^4.8|^5.7|^6.5|^7.4|^8.1",
"squizlabs/php_codesniffer": "^3.4"
},
"autoload": {
"psr-4": {
......
This diff is collapsed.
......@@ -18,6 +18,8 @@ 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
......@@ -64,6 +66,8 @@ class Botan
*/
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!');
}
......
......@@ -15,6 +15,8 @@ use Longman\TelegramBot\Exception\TelegramException;
/**
* Class BotanDB
*
* @deprecated Botan.io service is no longer working
*/
class BotanDB extends DB
{
......
......@@ -164,6 +164,7 @@ class CleanupCommand extends AdminCommand
SELECT `id`
FROM `%4$s`
WHERE `chat_id` = `%4$s`.`id`
AND `updated_at` < \'%1$s\'
)
AND (
`message_id` IS NOT NULL
......@@ -301,20 +302,38 @@ class CleanupCommand extends AdminCommand
if (in_array('message', $tables_to_clean, true)) {
$queries[] = sprintf(
'DELETE FROM `%1$s`
WHERE `date` < \'%2$s\'
AND `id` NOT IN (
SELECT `message_id`
FROM `%3$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT `message_id`
FROM `%4$s`
WHERE `message_id` = `%1$s`.`id`
)
WHERE id IN (
SELECT id
FROM (
SELECT id
FROM `%1$s`
WHERE `date` < \'%2$s\'
AND `id` NOT IN (
SELECT `message_id`
FROM `%3$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT `message_id`
FROM `%4$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT `message_id`
FROM `%5$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT a.`reply_to_message` FROM `%1$s` a
INNER JOIN `%1$s` b ON b.`id` = a.`reply_to_message` AND b.`chat_id` = a.`reply_to_chat`
)
ORDER BY `id` DESC
) a
)
',
TB_MESSAGE,
$clean_older_than['message'],
TB_EDITED_MESSAGE,
TB_TELEGRAM_UPDATE,
TB_CALLBACK_QUERY
);
......
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Channel chat created command
*
* @todo Remove due to deprecation!
*/
class ChannelchatcreatedCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class ChannelchatcreatedCommand extends SystemCommand
//$message = $this->getMessage();
//$channel_chat_created = $message->getChannelChatCreated();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Channel post command
*
* @todo Remove due to deprecation!
*/
class ChannelpostCommand extends SystemCommand
{
......@@ -42,6 +44,8 @@ class ChannelpostCommand extends SystemCommand
{
//$channel_post = $this->getUpdate()->getChannelPost();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Chosen inline result command
*
* @todo Remove due to deprecation!
*/
class ChoseninlineresultCommand extends SystemCommand
{
......@@ -45,6 +47,8 @@ class ChoseninlineresultCommand extends SystemCommand
//$inline_query = $update->getChosenInlineResult();
//$query = $inline_query->getQuery();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Delete chat photo command
*
* @todo Remove due to deprecation!
*/
class DeletechatphotoCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class DeletechatphotoCommand extends SystemCommand
//$message = $this->getMessage();
//$delete_chat_photo = $message->getDeleteChatPhoto();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Edited channel post command
*
* @todo Remove due to deprecation!
*/
class EditedchannelpostCommand extends SystemCommand
{
......@@ -42,6 +44,8 @@ class EditedchannelpostCommand extends SystemCommand
{
//$edited_channel_post = $this->getUpdate()->getEditedChannelPost();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Edited message command
*
* @todo Remove due to deprecation!
*/
class EditedmessageCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class EditedmessageCommand extends SystemCommand
//$update = $this->getUpdate();
//$edited_message = $update->getEditedMessage();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Group chat created command
*
* @todo Remove due to deprecation!
*/
class GroupchatcreatedCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class GroupchatcreatedCommand extends SystemCommand
//$message = $this->getMessage();
//$group_chat_created = $message->getGroupChatCreated();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Left chat member command
*
* @todo Remove due to deprecation!
*/
class LeftchatmemberCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class LeftchatmemberCommand extends SystemCommand
//$message = $this->getMessage();
//$member = $message->getLeftChatMember();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Migrate from chat id command
*
* @todo Remove due to deprecation!
*/
class MigratefromchatidCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class MigratefromchatidCommand extends SystemCommand
//$message = $this->getMessage();
//$migrate_from_chat_id = $message->getMigrateFromChatId();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Migrate to chat id command
*
* @todo Remove due to deprecation!
*/
class MigratetochatidCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class MigratetochatidCommand extends SystemCommand
//$message = $this->getMessage();
//$migrate_to_chat_id = $message->getMigrateToChatId();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* New chat members command
*
* @todo Remove due to deprecation!
*/
class NewchatmembersCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class NewchatmembersCommand extends SystemCommand
//$message = $this->getMessage();
//$members = $message->getNewChatMembers();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* New chat photo command
*
* @todo Remove due to deprecation!
*/
class NewchatphotoCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class NewchatphotoCommand extends SystemCommand
//$message = $this->getMessage();
//$new_chat_photo = $message->getNewChatPhoto();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* New chat title command
*
* @todo Remove due to deprecation!
*/
class NewchattitleCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class NewchattitleCommand extends SystemCommand
//$message = $this->getMessage();
//$new_chat_title = $message->getNewChatTitle();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Pinned message command
*
* @todo Remove due to deprecation!
*/
class PinnedmessageCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class PinnedmessageCommand extends SystemCommand
//$message = $this->getMessage();
//$pinned_message = $message->getPinnedMessage();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -15,6 +15,8 @@ use Longman\TelegramBot\Request;
/**
* Start command
*
* @todo Remove due to deprecation!
*/
class StartCommand extends SystemCommand
{
......@@ -50,6 +52,8 @@ class StartCommand extends SystemCommand
//$chat_id = $message->getChat()->getId();
//$user_id = $message->getFrom()->getId();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Super group chat created command
*
* @todo Remove due to deprecation!
*/
class SupergroupchatcreatedCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class SupergroupchatcreatedCommand extends SystemCommand
//$message = $this->getMessage();
//$supergroup_chat_created = $message->getSuperGroupChatCreated();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute();
}
}
This diff is collapsed.
......@@ -27,6 +27,7 @@ namespace Longman\TelegramBot\Entities;
* @method bool getCanRestrictMembers() Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members
* @method bool getCanPinMessages() Optional. Administrators only. True, if the administrator can pin messages, supergroups only
* @method bool getCanPromoteMembers() Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user)
* @method bool getIsMember() Optional. Restricted only. True, if the user is a member of the chat at the moment of the request
* @method bool getCanSendMessages() Optional. Restricted only. True, if the user can send text messages, contacts, locations and venues
* @method bool getCanSendMediaMessages() Optional. Restricted only. True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages
* @method bool getCanSendOtherMessages() Optional. Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages
......
......@@ -12,7 +12,7 @@ namespace Longman\TelegramBot\Entities;
use Exception;
use Longman\TelegramBot\Entities\InlineQuery\InlineEntity;
use Longman\TelegramBot\TelegramLog;
use Longman\TelegramBot\Entities\InputMedia\InputMedia;
/**
* Class Entity
......@@ -149,7 +149,7 @@ abstract class Entity
}
} elseif ($action === 'set') {
// Limit setters to specific classes.
if ($this instanceof InlineEntity || $this instanceof Keyboard || $this instanceof KeyboardButton) {
if ($this instanceof InlineEntity || $this instanceof InputMedia || $this instanceof Keyboard || $this instanceof KeyboardButton) {
$this->$property_name = $args[0];
return $this;
......
......@@ -28,6 +28,7 @@ use Longman\TelegramBot\Entities\TelegramPassport\PassportData;
* @method Chat getForwardFromChat() Optional. For messages forwarded from a channel, information about the original channel
* @method int getForwardFromMessageId() Optional. For forwarded channel posts, identifier of the original message in the channel
* @method string getForwardSignature() Optional. For messages forwarded from channels, signature of the post author if present
* @method string getForwardSenderName() Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages
* @method int getForwardDate() Optional. For forwarded messages, date the original message was sent in Unix time
* @method Message getReplyToMessage() Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
* @method int getEditDate() Optional. Date the message was last edited in Unix time
......@@ -45,6 +46,7 @@ use Longman\TelegramBot\Entities\TelegramPassport\PassportData;
* @method Contact getContact() Optional. Message is a shared contact, information about the contact
* @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 Poll getPoll() Optional. Message is a native poll, information about the poll
* @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 bool getDeleteChatPhoto() Optional. Service message: the chat photo was deleted
......@@ -86,6 +88,7 @@ class Message extends Entity
'contact' => Contact::class,
'location' => Location::class,
'venue' => Venue::class,
'poll' => Poll::class,
'new_chat_members' => User::class,
'left_chat_member' => User::class,
'new_chat_photo' => PhotoSize::class,
......@@ -295,6 +298,7 @@ class Message extends Entity
'contact',
'location',
'venue',
'poll',
'new_chat_members',
'left_chat_member',
'new_chat_title',
......@@ -313,7 +317,7 @@ class Message extends Entity
$is_command = strlen($this->getCommand()) > 0;
foreach ($types as $type) {
if ($this->getProperty($type)) {
if ($this->getProperty($type) !== null) {
if ($is_command && $type === 'text') {
return 'command';
}
......
<?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\Entities;
/**
* Class Poll
*
* This entity contains information about a poll.
*
* @link https://core.telegram.org/bots/api#poll
*
* @method string getId() Unique poll identifier
* @method string getQuestion() Poll question, 1-255 characters
* @method bool getIsClosed() True, if the poll is closed
*/
class Poll extends Entity
{
/**
* {@inheritdoc}
*/
protected function subEntities()
{
return [
'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;
}
}
<?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\Entities;
/**
* Class PollOption
*
* This entity contains information about one answer option in a poll.
*
* @link https://core.telegram.org/bots/api#polloption
*
* @method string getText() Option text, 1-100 characters
* @method int getVoterCount() Number of users that voted for this option
*/
class PollOption extends Entity
{
}
......@@ -8,6 +8,9 @@
namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Entities\Games\GameHighScore;
use Longman\TelegramBot\Request;
/**
* Class ServerResponse
*
......@@ -103,32 +106,27 @@ class ServerResponse extends Entity
* @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
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
private function createResultObject($result, $bot_username)
private function createResultObject(array $result, $bot_username)
{
$action = Request::getCurrentAction();
// We don't need to save the raw_data of the response object!
$result['raw_data'] = null;
$result_object_types = [
'total_count' => 'UserProfilePhotos', //Response from getUserProfilePhotos
'stickers' => 'StickerSet', //Response from getStickerSet
'file_id' => 'File', //Response from getFile
'title' => 'Chat', //Response from getChat
'username' => 'User', //Response from getMe
'user' => 'ChatMember', //Response from getChatMember
'url' => 'WebhookInfo', //Response from getWebhookInfo
'getChat' => Chat::class,
'getChatMember' => ChatMember::class,
'getFile' => File::class,
'getMe' => User::class,
'getStickerSet' => StickerSet::class,
'getUserProfilePhotos' => UserProfilePhotos::class,
'getWebhookInfo' => WebhookInfo::class,
];
foreach ($result_object_types as $type => $object_class) {
if (isset($result[$type])) {
$object_class = __NAMESPACE__ . '\\' . $object_class;
return new $object_class($result);
}
}
$object_class = array_key_exists($action, $result_object_types) ? $result_object_types[$action] : Message::class;
//Response from sendMessage
return new Message($result, $bot_username);
return new $object_class($result, $bot_username);
}
/**
......@@ -137,28 +135,26 @@ class ServerResponse extends Entity
* @param array $result
* @param string $bot_username
*
* @return null|\Longman\TelegramBot\Entities\ChatMember[]|\Longman\TelegramBot\Entities\Update[]
* @throws \Longman\TelegramBot\Exception\TelegramException
* @return \Longman\TelegramBot\Entities\ChatMember[]|\Longman\TelegramBot\Entities\Games\GameHighScore[]|\Longman\TelegramBot\Entities\Message[]|\Longman\TelegramBot\Entities\Update[]
*/
private function createResultObjects($result, $bot_username)
private function createResultObjects(array $result, $bot_username)
{
$results = [];
if (isset($result[0]['user'])) {
//Response from getChatAdministrators
foreach ($result as $user) {
// We don't need to save the raw_data of the response object!
$user['raw_data'] = null;
$action = Request::getCurrentAction();
$results[] = new ChatMember($user);
}
} else {
//Get Update
foreach ($result as $update) {
// We don't need to save the raw_data of the response object!
$update['raw_data'] = null;
$result_object_types = [
'getChatAdministrators' => ChatMember::class,
'getGameHighScores' => GameHighScore::class,
'sendMediaGroup' => Message::class,
];
$results[] = new Update($update, $bot_username);
}
$object_class = array_key_exists($action, $result_object_types) ? $result_object_types[$action] : Update::class;
foreach ($result as $data) {
// We don't need to save the raw_data of the response object!
$data['raw_data'] = null;
$results[] = new $object_class($data, $bot_username);
}
return $results;
......
......@@ -28,6 +28,7 @@ use Longman\TelegramBot\Entities\Payments\ShippingQuery;
* @method CallbackQuery getCallbackQuery() Optional. New incoming callback query
* @method ShippingQuery getShippingQuery() Optional. New incoming shipping query. Only for invoices with flexible price
* @method PreCheckoutQuery getPreCheckoutQuery() Optional. New incoming pre-checkout query. Contains full information about checkout
* @method Poll getPoll() Optional. New poll state. Bots receive only updates about polls, which are sent or stopped by the bot
*/
class Update extends Entity
{
......@@ -46,6 +47,7 @@ class Update extends Entity
'callback_query' => CallbackQuery::class,
'shipping_query' => ShippingQuery::class,
'pre_checkout_query' => PreCheckoutQuery::class,
'poll' => Poll::class,
];
}
......@@ -66,6 +68,7 @@ class Update extends Entity
'callback_query',
'shipping_query',
'pre_checkout_query',
'poll',
];
foreach ($types as $type) {
if ($this->getProperty($type)) {
......
This diff is collapsed.
......@@ -30,7 +30,7 @@ class Telegram
*
* @var string
*/
protected $version = '0.55.0';
protected $version = '0.56.0';
/**
* Telegram API key
......@@ -123,13 +123,6 @@ class Telegram
*/
protected $last_command_response;
/**
* Botan.io integration
*
* @var boolean
*/
protected $botan_enabled = false;
/**
* Check if runCommands() is running in this session
*
......@@ -452,47 +445,36 @@ class Telegram
$this->update = $update;
$this->last_update_id = $update->getUpdateId();
//Load admin commands
if ($this->isAdmin()) {
$this->addCommandsPath(TB_BASE_COMMANDS_PATH . '/AdminCommands', false);
}
//Make sure we have an up-to-date command list
//This is necessary to "require" all the necessary command files!
$this->getCommandsList();
//If all else fails, it's a generic message.
$command = 'genericmessage';
$update_type = $this->update->getUpdateType();
if ($update_type === 'message') {
$message = $this->update->getMessage();
//Load admin commands
if ($this->isAdmin()) {
$this->addCommandsPath(TB_BASE_COMMANDS_PATH . '/AdminCommands', false);
}
$type = $message->getType();
$type = $message->getType();
if ($type === 'command') {
$command = $message->getCommand();
} elseif (in_array($type, [
'new_chat_members',
'left_chat_member',
'new_chat_title',
'new_chat_photo',
'delete_chat_photo',
'group_chat_created',
'supergroup_chat_created',
'channel_chat_created',
'migrate_to_chat_id',
'migrate_from_chat_id',
'pinned_message',
'invoice',
'successful_payment',
], true)
) {
$command = $this->getCommandFromType($type);
} else {
// Let's check if the message object has the type field we're looking for
// and if a fitting command class is available.
$command_tmp = $this->getCommandFromType($type);
if ($this->getCommandObject($command_tmp) !== null) {
$command = $command_tmp;
}
}
} else {
$command = $this->getCommandFromType($update_type);
}
//Make sure we have an up-to-date command list
//This is necessary to "require" all the necessary command files!
$this->getCommandsList();
//Make sure we don't try to process update that was already processed
$last_id = DB::selectTelegramUpdate(1, $this->update->getUpdateId());
if ($last_id && count($last_id) === 1) {
......@@ -527,19 +509,9 @@ class Telegram
//Handle a generic command or non existing one
$this->last_command_response = $this->executeCommand('generic');
} else {
//Botan.io integration, make sure only the actual command user executed is reported
if ($this->botan_enabled) {
Botan::lock($command);
}
//execute() method is executed after preExecute()
//This is to prevent executing a DB query without a valid connection
$this->last_command_response = $command_obj->preExecute();
//Botan.io integration, send report after executing the command
if ($this->botan_enabled) {
Botan::track($this->update, $command);
}
}
return $this->last_command_response;
......@@ -905,16 +877,16 @@ class Telegram
/**
* Enable Botan.io integration
*
* @deprecated Botan.io service is no longer working
*
* @param string $token
* @param array $options
*
* @return \Longman\TelegramBot\Telegram
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function enableBotan($token, array $options = [])
{
Botan::initializeBotan($token, $options);
$this->botan_enabled = true;
trigger_error('Longman\TelegramBot\Telegram::enableBotan is deprecated and will be removed in future release.', E_USER_DEPRECATED);
return $this;
}
......@@ -947,7 +919,6 @@ class Telegram
}
$this->run_commands = true;
$this->botan_enabled = false; // Force disable Botan.io integration, we don't want to track self-executed commands!
$result = Request::getMe();
......
......@@ -22,42 +22,42 @@ class TelegramLog
*
* @var \Monolog\Logger
*/
static protected $monolog;
protected static $monolog;
/**
* Monolog instance for update
*
* @var \Monolog\Logger
*/
static protected $monolog_update;
protected static $monolog_update;
/**
* Path for error log
*
* @var string
*/
static protected $error_log_path;
protected static $error_log_path;
/**
* Path for debug log
*
* @var string
*/
static protected $debug_log_path;
protected static $debug_log_path;
/**
* Path for update log
*
* @var string
*/
static protected $update_log_path;
protected static $update_log_path;
/**
* Temporary stream handle for debug log
*
* @var resource|null
*/
static protected $debug_log_temp_stream_handle;
protected static $debug_log_temp_stream_handle;
/**
* Initialize Monolog Logger instance, optionally passing an existing one
......
......@@ -67,6 +67,16 @@ CREATE TABLE IF NOT EXISTS `chosen_inline_result` (
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `poll` (
`id` bigint UNSIGNED COMMENT 'Unique poll identifier',
`question` char(255) NOT NULL COMMENT 'Poll question',
`options` text NOT NULL COMMENT 'List of poll options',
`is_closed` tinyint(1) DEFAULT 0 COMMENT 'True, if the poll is closed',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `message` (
`chat_id` bigint COMMENT 'Unique chat identifier',
`id` bigint UNSIGNED COMMENT 'Unique message identifier',
......@@ -75,7 +85,8 @@ CREATE TABLE IF NOT EXISTS `message` (
`forward_from` bigint NULL DEFAULT NULL COMMENT 'Unique user identifier, sender of the original message',
`forward_from_chat` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier, chat the original message belongs to',
`forward_from_message_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier of the original message in the channel',
`forward_signature` TEXT COMMENT 'For messages forwarded from channels, signature of the post author if present',
`forward_signature` TEXT NULL DEFAULT NULL COMMENT 'For messages forwarded from channels, signature of the post author if present',
`forward_sender_name` TEXT NULL DEFAULT NULL COMMENT 'Sender''s name for messages forwarded from users who disallow adding a link to their account in forwarded messages',
`forward_date` timestamp NULL DEFAULT NULL COMMENT 'date the original message was sent in timestamp format',
`reply_to_chat` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',
`reply_to_message` bigint UNSIGNED DEFAULT NULL COMMENT 'Message that this message is reply to',
......@@ -98,6 +109,8 @@ CREATE TABLE IF NOT EXISTS `message` (
`contact` TEXT COMMENT 'Contact object. Message is a shared contact, information about the contact',
`location` TEXT COMMENT 'Location object. Message is a shared location, information about the location',
`venue` TEXT COMMENT 'Venue object. Message is a Venue, information about the Venue',
`poll` TEXT COMMENT 'Poll object. Message is a native poll, information about the poll',
`caption` TEXT COMMENT 'For message with caption, the actual UTF-8 text of the caption',
`new_chat_members` TEXT COMMENT 'List of unique user identifiers, new member(s) were added to the group, information about them (one of these members may be the bot itself)',
`left_chat_member` bigint NULL DEFAULT NULL COMMENT 'Unique user identifier, a member was removed from the group, information about them (this member may be the bot itself)',
`new_chat_title` CHAR(255) DEFAULT NULL COMMENT 'A chat title was changed to this value',
......@@ -202,6 +215,16 @@ CREATE TABLE IF NOT EXISTS `pre_checkout_query` (
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `poll` (
`id` bigint UNSIGNED COMMENT 'Unique poll identifier',
`question` char(255) NOT NULL COMMENT 'Poll question',
`options` text NOT NULL COMMENT 'List of poll options',
`is_closed` tinyint(1) DEFAULT 0 COMMENT 'True, if the poll is closed',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `telegram_update` (
`id` bigint UNSIGNED COMMENT 'Update''s unique identifier',
`chat_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',
......@@ -214,6 +237,7 @@ CREATE TABLE IF NOT EXISTS `telegram_update` (
`callback_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming callback query',
`shipping_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming shipping query. Only for invoices with flexible price',
`pre_checkout_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming pre-checkout query. Contains full information about checkout',
`poll_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New poll state. Bots receive only updates about polls, which are sent or stopped by the bot',
PRIMARY KEY (`id`),
KEY `message_id` (`chat_id`, `message_id`),
......@@ -225,6 +249,7 @@ CREATE TABLE IF NOT EXISTS `telegram_update` (
KEY `callback_query_id` (`callback_query_id`),
KEY `shipping_query_id` (`shipping_query_id`),
KEY `pre_checkout_query_id` (`pre_checkout_query_id`),
KEY `poll_id` (`poll_id`),
FOREIGN KEY (`chat_id`, `message_id`) REFERENCES `message` (`chat_id`, `id`),
FOREIGN KEY (`edited_message_id`) REFERENCES `edited_message` (`id`),
......@@ -234,7 +259,8 @@ CREATE TABLE IF NOT EXISTS `telegram_update` (
FOREIGN KEY (`chosen_inline_result_id`) REFERENCES `chosen_inline_result` (`id`),
FOREIGN KEY (`callback_query_id`) REFERENCES `callback_query` (`id`),
FOREIGN KEY (`shipping_query_id`) REFERENCES `shipping_query` (`id`),
FOREIGN KEY (`pre_checkout_query_id`) REFERENCES `pre_checkout_query` (`id`)
FOREIGN KEY (`pre_checkout_query_id`) REFERENCES `pre_checkout_query` (`id`),
FOREIGN KEY (`poll_id`) REFERENCES `poll` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `conversation` (
......
......@@ -25,6 +25,12 @@ use Longman\TelegramBot\Request;
*/
class ServerResponseTest extends TestCase
{
protected function setUp()
{
// Make sure the current action in the Request class is unset.
TestHelpers::setStaticProperty(Request::class, 'current_action', null);
}
public function sendMessageOk()
{
return '{
......@@ -193,6 +199,7 @@ class ServerResponseTest extends TestCase
public function getUserProfilePhotos()
{
TestHelpers::setStaticProperty(Request::class, 'current_action', 'getUserProfilePhotos');
return '{
"ok":true,
"result":{
......@@ -238,6 +245,7 @@ class ServerResponseTest extends TestCase
public function getFile()
{
TestHelpers::setStaticProperty(Request::class, 'current_action', 'getFile');
return '{
"ok":true,
"result":{
......@@ -301,6 +309,7 @@ class ServerResponseTest extends TestCase
public function getStickerSet()
{
TestHelpers::setStaticProperty(Request::class, 'current_action', 'getStickerSet');
return '{
"ok":true,
"result":{
......
ALTER TABLE `chat` ADD COLUMN `first_name` CHAR(255) DEFAULT NULL COMMENT 'First name of the other party in a private chat' AFTER `username`;
ALTER TABLE `chat` ADD COLUMN `last_name` CHAR(255) DEFAULT NULL COMMENT 'Last name of the other party in a private chat' AFTER `first_name`;
ALTER TABLE `message` ADD COLUMN `animation` TEXT NULL COMMENT 'Message is an animation, information about the animation' AFTER `document`;
ALTER TABLE `message` ADD COLUMN `forward_signature` TEXT COMMENT 'For messages forwarded from channels, signature of the post author if present' AFTER `forward_from_message_id`;
ALTER TABLE `message` ADD COLUMN `forward_signature` TEXT NULL DEFAULT NULL COMMENT 'For messages forwarded from channels, signature of the post author if present' AFTER `forward_from_message_id`;
ALTER TABLE `message` ADD COLUMN `forward_sender_name` TEXT NULL DEFAULT NULL COMMENT 'Sender''s name for messages forwarded from users who disallow adding a link to their account in forwarded messages' AFTER `forward_signature`;
ALTER TABLE `message` ADD COLUMN `edit_date` bigint UNSIGNED DEFAULT NULL COMMENT 'Date the message was last edited in Unix time' AFTER `reply_to_message`;
ALTER TABLE `message` ADD COLUMN `author_signature` TEXT COMMENT 'Signature of the post author for messages in channels' AFTER `media_group_id`;
ALTER TABLE `message` ADD COLUMN `caption_entities` TEXT COMMENT 'For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption';
ALTER TABLE `message` ADD COLUMN `animation` TEXT NULL COMMENT 'Message is an animation, information about the animation' AFTER `document`;
ALTER TABLE `message` ADD COLUMN `poll` TEXT COMMENT 'Poll object. Message is a native poll, information about the poll' AFTER `venue`;
ALTER TABLE `message` ADD COLUMN `invoice` TEXT NULL COMMENT 'Message is an invoice for a payment, information about the invoice' AFTER `pinned_message`;
ALTER TABLE `message` ADD COLUMN `successful_payment` TEXT NULL COMMENT 'Message is a service message about a successful payment, information about the payment' AFTER `invoice`;
ALTER TABLE `callback_query` ADD COLUMN `chat_instance` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent' AFTER `inline_message_id`;
......@@ -39,17 +41,30 @@ CREATE TABLE IF NOT EXISTS `pre_checkout_query` (
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `poll` (
`id` bigint UNSIGNED COMMENT 'Unique poll identifier',
`question` char(255) NOT NULL COMMENT 'Poll question',
`options` text NOT NULL COMMENT 'List of poll options',
`is_closed` tinyint(1) DEFAULT 0 COMMENT 'True, if the poll is closed',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
ALTER TABLE `telegram_update` ADD COLUMN `channel_post_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming channel post of any kind - text, photo, sticker, etc.';
ALTER TABLE `telegram_update` ADD COLUMN `edited_channel_post_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New version of a channel post that is known to the bot and was edited';
ALTER TABLE `telegram_update` ADD COLUMN `shipping_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming shipping query. Only for invoices with flexible price';
ALTER TABLE `telegram_update` ADD COLUMN `pre_checkout_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming pre-checkout query. Contains full information about checkout';
ALTER TABLE `telegram_update` ADD COLUMN `poll_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New poll state. Bots receive only updates about polls, which are sent or stopped by the bot';
ALTER TABLE `telegram_update` ADD KEY `channel_post_id` (`channel_post_id`);
ALTER TABLE `telegram_update` ADD KEY `edited_channel_post_id` (`edited_channel_post_id`);
ALTER TABLE `telegram_update` ADD KEY `shipping_query_id` (`shipping_query_id`);
ALTER TABLE `telegram_update` ADD KEY `pre_checkout_query_id` (`pre_checkout_query_id`);
ALTER TABLE `telegram_update` ADD KEY `poll_id` (`poll_id`);
ALTER TABLE `telegram_update` ADD FOREIGN KEY (`chat_id`, `channel_post_id`) REFERENCES `message` (`chat_id`, `id`);
ALTER TABLE `telegram_update` ADD FOREIGN KEY (`edited_channel_post_id`) REFERENCES `edited_message` (`id`);
ALTER TABLE `telegram_update` ADD FOREIGN KEY (`shipping_query_id`) REFERENCES `shipping_query` (`id`);
ALTER TABLE `telegram_update` ADD FOREIGN KEY (`pre_checkout_query_id`) REFERENCES `pre_checkout_query` (`id`);
ALTER TABLE `telegram_update` ADD FOREIGN KEY (`poll_id`) REFERENCES `poll` (`id`);
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