Commit 188b3ed8 authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge branch 'develop' into custom_input_for_getUpdates

parents 27b7a8c0 408cbd42
...@@ -6,10 +6,17 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -6,10 +6,17 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
## [Unreleased] ## [Unreleased]
### Added ### Added
- Documents can be sent by providing its contents via Psr7 stream (as opposed to passing a file path). - Documents can be sent by providing its contents via Psr7 stream (as opposed to passing a file path).
- Allow setting a custom Guzzle HTTP Client for requests (#511).
- First implementations towards Bots API 3.0.
### Changed ### Changed
- [:exclamation:][unreleased-bc-chats-params-array] `Request::sendToActiveChats` and `DB::selectChats` now accept parameters as an options array.
### Deprecated ### Deprecated
### Removed ### Removed
- [:exclamation:][unreleased-bc-up-download-directory] Upload and download directories are not set any more by default and must be set manually.
### Fixed ### Fixed
- ID fields are now typed with `PARAM_STR` PDO data type, to allow huge numbers.
- Message type data type for PDO corrected.
- Indexed table columns now have a fitting length.
- Take `custom_input` into account when using getUpdates method (mainly for testing). - Take `custom_input` into account when using getUpdates method (mainly for testing).
### Security ### Security
...@@ -26,7 +33,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -26,7 +33,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Removed ### Removed
- All examples have been moved to a [dedicated repository](https://github.com/php-telegram-bot/example-bot). - All examples have been moved to a [dedicated repository](https://github.com/php-telegram-bot/example-bot).
### Fixed ### Fixed
- [:exclamation:](https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#0440) Format of Update content type using `$update->getUpdateContent()`. - [:exclamation:][0.44.0-bc-update-content-type] Format of Update content type using `$update->getUpdateContent()`.
## [0.43.0] - 2017-04-17 ## [0.43.0] - 2017-04-17
### Added ### Added
...@@ -101,3 +108,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -101,3 +108,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- Logging improvements to Botan integration. - Logging improvements to Botan integration.
### Deprecated ### Deprecated
- Move `hideKeyboard` to `removeKeyboard`. - Move `hideKeyboard` to `removeKeyboard`.
[unreleased-bc-chats-params-array]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#unreleased
[unreleased-bc-up-download-directory]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#unreleased
[0.44.0-bc-update-content-type]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#update-getupdatecontent
...@@ -35,7 +35,7 @@ class ChatsCommand extends AdminCommand ...@@ -35,7 +35,7 @@ class ChatsCommand extends AdminCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.1.0'; protected $version = '1.2.0';
/** /**
* @var bool * @var bool
...@@ -45,7 +45,7 @@ class ChatsCommand extends AdminCommand ...@@ -45,7 +45,7 @@ class ChatsCommand extends AdminCommand
/** /**
* Command execute method * Command execute method
* *
* @return mixed * @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
...@@ -55,19 +55,18 @@ class ChatsCommand extends AdminCommand ...@@ -55,19 +55,18 @@ class ChatsCommand extends AdminCommand
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$text = trim($message->getText(true)); $text = trim($message->getText(true));
$results = DB::selectChats( $results = DB::selectChats([
true, //Select groups (group chat) 'groups' => true,
true, //Select supergroups (super group chat) 'supergroups' => true,
true, //Select users (single chat) 'channels' => true,
null, //'yyyy-mm-dd hh:mm:ss' date range from 'users' => true,
null, //'yyyy-mm-dd hh:mm:ss' date range to 'text' => ($text === '' || $text === '*') ? null : $text //Text to search in user/group name
null, //Specific chat_id to select ]);
($text === '' || $text === '*') ? null : $text //Text to search in user/group name
);
$user_chats = 0; $user_chats = 0;
$group_chats = 0; $group_chats = 0;
$super_group_chats = 0; $supergroup_chats = 0;
$channel_chats = 0;
if ($text === '') { if ($text === '') {
$text_back = ''; $text_back = '';
...@@ -100,24 +99,31 @@ class ChatsCommand extends AdminCommand ...@@ -100,24 +99,31 @@ class ChatsCommand extends AdminCommand
$text_back .= '- S ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL; $text_back .= '- S ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL;
} }
++$super_group_chats; ++$supergroup_chats;
} elseif ($chat->isGroupChat()) { } elseif ($chat->isGroupChat()) {
if ($text !== '') { if ($text !== '') {
$text_back .= '- G ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL; $text_back .= '- G ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL;
} }
++$group_chats; ++$group_chats;
} elseif ($chat->isChannel()) {
if ($text !== '') {
$text_back .= '- C ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL;
}
++$channel_chats;
} }
} }
} }
if (($user_chats + $group_chats + $super_group_chats) === 0) { if (($user_chats + $group_chats + $supergroup_chats) === 0) {
$text_back = 'No chats found..'; $text_back = 'No chats found..';
} else { } else {
$text_back .= PHP_EOL . 'Private Chats: ' . $user_chats; $text_back .= PHP_EOL . 'Private Chats: ' . $user_chats;
$text_back .= PHP_EOL . 'Groups: ' . $group_chats; $text_back .= PHP_EOL . 'Groups: ' . $group_chats;
$text_back .= PHP_EOL . 'Super Groups: ' . $super_group_chats; $text_back .= PHP_EOL . 'Super Groups: ' . $supergroup_chats;
$text_back .= PHP_EOL . 'Total: ' . ($user_chats + $group_chats + $super_group_chats); $text_back .= PHP_EOL . 'Channels: ' . $channel_chats;
$text_back .= PHP_EOL . 'Total: ' . ($user_chats + $group_chats + $supergroup_chats);
if ($text === '') { if ($text === '') {
$text_back .= PHP_EOL . PHP_EOL . 'List all chats: /' . $this->name . ' *' . PHP_EOL . 'Search for chats: /' . $this->name . ' <search string>'; $text_back .= PHP_EOL . PHP_EOL . 'List all chats: /' . $this->name . ' *' . PHP_EOL . 'Search for chats: /' . $this->name . ' <search string>';
......
...@@ -63,8 +63,8 @@ class DebugCommand extends AdminCommand ...@@ -63,8 +63,8 @@ class DebugCommand extends AdminCommand
$debug_info = []; $debug_info = [];
$debug_info[] = sprintf('*TelegramBot version:* `%s`', $this->telegram->getVersion()); $debug_info[] = sprintf('*TelegramBot version:* `%s`', $this->telegram->getVersion());
$debug_info[] = sprintf('*Download path:* `%s`', $this->telegram->getDownloadPath()); $debug_info[] = sprintf('*Download path:* `%s`', $this->telegram->getDownloadPath() ?: '`_Not set_`');
$debug_info[] = sprintf('*Upload path:* `%s`', $this->telegram->getUploadPath()); $debug_info[] = sprintf('*Upload path:* `%s`', $this->telegram->getUploadPath() ?: '`_Not set_`');
// Commands paths. // Commands paths.
$debug_info[] = '*Commands paths:*'; $debug_info[] = '*Commands paths:*';
......
...@@ -38,7 +38,7 @@ class SendtoallCommand extends AdminCommand ...@@ -38,7 +38,7 @@ class SendtoallCommand extends AdminCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.3.0'; protected $version = '1.4.0';
/** /**
* @var bool * @var bool
...@@ -48,7 +48,7 @@ class SendtoallCommand extends AdminCommand ...@@ -48,7 +48,7 @@ class SendtoallCommand extends AdminCommand
/** /**
* Execute command * Execute command
* *
* @return boolean * @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
...@@ -64,11 +64,12 @@ class SendtoallCommand extends AdminCommand ...@@ -64,11 +64,12 @@ class SendtoallCommand extends AdminCommand
$results = Request::sendToActiveChats( $results = Request::sendToActiveChats(
'sendMessage', //callback function to execute (see Request.php methods) 'sendMessage', //callback function to execute (see Request.php methods)
['text' => $text], //Param to evaluate the request ['text' => $text], //Param to evaluate the request
true, //Send to groups (group chat) [
true, //Send to super groups chats (super group chat) 'groups' => true,
true, //Send to users (single chat) 'supergroups' => true,
null, //'yyyy-mm-dd hh:mm:ss' date range from 'channels' => false,
null //'yyyy-mm-dd hh:mm:ss' date range to 'users' => true,
]
); );
$total = 0; $total = 0;
......
...@@ -42,7 +42,7 @@ class WhoisCommand extends AdminCommand ...@@ -42,7 +42,7 @@ class WhoisCommand extends AdminCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.2.0'; protected $version = '1.3.0';
/** /**
* @var bool * @var bool
...@@ -52,7 +52,7 @@ class WhoisCommand extends AdminCommand ...@@ -52,7 +52,7 @@ class WhoisCommand extends AdminCommand
/** /**
* Command execute method * Command execute method
* *
* @return mixed * @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
...@@ -89,28 +89,25 @@ class WhoisCommand extends AdminCommand ...@@ -89,28 +89,25 @@ class WhoisCommand extends AdminCommand
$result = null; $result = null;
if (is_numeric($text)) { if (is_numeric($text)) {
$results = DB::selectChats( $results = DB::selectChats([
true, //Select groups (group chat) 'groups' => true,
true, //Select supergroups (super group chat) 'supergroups' => true,
true, //Select users (single chat) 'channels' => true,
null, //'yyyy-mm-dd hh:mm:ss' date range from 'users' => true,
null, //'yyyy-mm-dd hh:mm:ss' date range to 'chat_id' => $user_id, //Specific chat_id to select
$user_id //Specific chat_id to select ]);
);
if (!empty($results)) { if (!empty($results)) {
$result = reset($results); $result = reset($results);
} }
} else { } else {
$results = DB::selectChats( $results = DB::selectChats([
true, //Select groups (group chat) 'groups' => true,
true, //Select supergroups (super group chat) 'supergroups' => true,
true, //Select users (single chat) 'channels' => true,
null, //'yyyy-mm-dd hh:mm:ss' date range from 'users' => true,
null, //'yyyy-mm-dd hh:mm:ss' date range to 'text' => $text //Text to search in user/group name
null, //Specific chat_id to select ]);
$text //Text to search in user/group name
);
if (is_array($results) && count($results) === 1) { if (is_array($results) && count($results) === 1) {
$result = reset($results); $result = reset($results);
...@@ -118,8 +115,9 @@ class WhoisCommand extends AdminCommand ...@@ -118,8 +115,9 @@ class WhoisCommand extends AdminCommand
} }
if (is_array($result)) { if (is_array($result)) {
$result['id'] = $result['chat_id']; $result['id'] = $result['chat_id'];
$chat = new Chat($result); $result['username'] = $result['chat_username'];
$chat = new Chat($result);
$user_id = $result['id']; $user_id = $result['id'];
$created_at = $result['chat_created_at']; $created_at = $result['chat_created_at'];
......
...@@ -11,22 +11,21 @@ ...@@ -11,22 +11,21 @@
namespace Longman\TelegramBot\Commands\SystemCommands; namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand; use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;
/** /**
* New chat member command * New chat members command
*/ */
class NewchatmemberCommand extends SystemCommand class NewchatmembersCommand extends SystemCommand
{ {
/** /**
* @var string * @var string
*/ */
protected $name = 'Newchatmember'; protected $name = 'Newchatmembers';
/** /**
* @var string * @var string
*/ */
protected $description = 'New Chat Member'; protected $description = 'New Chat Member(s)';
/** /**
* @var string * @var string
...@@ -41,21 +40,9 @@ class NewchatmemberCommand extends SystemCommand ...@@ -41,21 +40,9 @@ class NewchatmemberCommand extends SystemCommand
*/ */
public function execute() public function execute()
{ {
$message = $this->getMessage(); //$message = $this->getMessage();
//$members = $message->getNewChatMembers();
$chat_id = $message->getChat()->getId(); return parent::execute();
$member = $message->getNewChatMember();
$text = 'Hi there!';
if (!$message->botAddedInChat()) {
$text = 'Hi ' . $member->tryMention() . '!';
}
$data = [
'chat_id' => $chat_id,
'text' => $text,
];
return Request::sendMessage($data);
} }
} }
...@@ -201,7 +201,7 @@ class DB ...@@ -201,7 +201,7 @@ class DB
$sth->bindParam(':limit', $limit, PDO::PARAM_INT); $sth->bindParam(':limit', $limit, PDO::PARAM_INT);
if ($id !== null) { if ($id !== null) {
$sth->bindParam(':id', $id, PDO::PARAM_INT); $sth->bindParam(':id', $id, PDO::PARAM_STR);
} }
$sth->execute(); $sth->execute();
...@@ -327,13 +327,13 @@ class DB ...@@ -327,13 +327,13 @@ class DB
(:id, :chat_id, :message_id, :inline_query_id, :chosen_inline_result_id, :callback_query_id, :edited_message_id) (:id, :chat_id, :message_id, :inline_query_id, :chosen_inline_result_id, :callback_query_id, :edited_message_id)
'); ');
$sth->bindParam(':id', $id, PDO::PARAM_INT); $sth->bindParam(':id', $id, PDO::PARAM_STR);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT); $sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_STR);
$sth->bindParam(':chosen_inline_result_id', $chosen_inline_result_id, PDO::PARAM_INT); $sth->bindParam(':chosen_inline_result_id', $chosen_inline_result_id, PDO::PARAM_STR);
$sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT); $sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_STR);
$sth->bindParam(':edited_message_id', $edited_message_id, PDO::PARAM_INT); $sth->bindParam(':edited_message_id', $edited_message_id, PDO::PARAM_STR);
return $sth->execute(); return $sth->execute();
} catch (PDOException $e) { } catch (PDOException $e) {
...@@ -357,28 +357,31 @@ class DB ...@@ -357,28 +357,31 @@ class DB
return false; return false;
} }
$user_id = $user->getId(); $user_id = $user->getId();
$username = $user->getUsername(); $username = $user->getUsername();
$first_name = $user->getFirstName(); $first_name = $user->getFirstName();
$last_name = $user->getLastName(); $last_name = $user->getLastName();
$language_code = $user->getLanguageCode();
try { try {
$sth = self::$pdo->prepare(' $sth = self::$pdo->prepare('
INSERT INTO `' . TB_USER . '` INSERT INTO `' . TB_USER . '`
(`id`, `username`, `first_name`, `last_name`, `created_at`, `updated_at`) (`id`, `username`, `first_name`, `last_name`, `language_code`, `created_at`, `updated_at`)
VALUES VALUES
(:id, :username, :first_name, :last_name, :created_at, :updated_at) (:id, :username, :first_name, :last_name, :language_code, :created_at, :updated_at)
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
`username` = VALUES(`username`), `username` = VALUES(`username`),
`first_name` = VALUES(`first_name`), `first_name` = VALUES(`first_name`),
`last_name` = VALUES(`last_name`), `last_name` = VALUES(`last_name`),
`updated_at` = VALUES(`updated_at`) `language_code` = VALUES(`language_code`),
`updated_at` = VALUES(`updated_at`)
'); ');
$sth->bindParam(':id', $user_id, PDO::PARAM_INT); $sth->bindParam(':id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':username', $username, PDO::PARAM_STR, 255); $sth->bindParam(':username', $username, PDO::PARAM_STR, 255);
$sth->bindParam(':first_name', $first_name, PDO::PARAM_STR, 255); $sth->bindParam(':first_name', $first_name, PDO::PARAM_STR, 255);
$sth->bindParam(':last_name', $last_name, PDO::PARAM_STR, 255); $sth->bindParam(':last_name', $last_name, PDO::PARAM_STR, 255);
$sth->bindParam(':language_code', $language_code, PDO::PARAM_STR, 10);
$sth->bindParam(':created_at', $date, PDO::PARAM_STR); $sth->bindParam(':created_at', $date, PDO::PARAM_STR);
$sth->bindParam(':updated_at', $date, PDO::PARAM_STR); $sth->bindParam(':updated_at', $date, PDO::PARAM_STR);
...@@ -398,8 +401,8 @@ class DB ...@@ -398,8 +401,8 @@ class DB
(:user_id, :chat_id) (:user_id, :chat_id)
'); ');
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$status = $sth->execute(); $status = $sth->execute();
} catch (PDOException $e) { } catch (PDOException $e) {
...@@ -449,14 +452,14 @@ class DB ...@@ -449,14 +452,14 @@ class DB
if ($migrate_to_chat_id) { if ($migrate_to_chat_id) {
$chat_type = 'supergroup'; $chat_type = 'supergroup';
$sth->bindParam(':id', $migrate_to_chat_id, PDO::PARAM_INT); $sth->bindParam(':id', $migrate_to_chat_id, PDO::PARAM_STR);
$sth->bindParam(':oldid', $chat_id, PDO::PARAM_INT); $sth->bindParam(':oldid', $chat_id, PDO::PARAM_STR);
} else { } else {
$sth->bindParam(':id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':oldid', $migrate_to_chat_id, PDO::PARAM_INT); $sth->bindParam(':oldid', $migrate_to_chat_id, PDO::PARAM_STR);
} }
$sth->bindParam(':type', $chat_type, PDO::PARAM_INT); $sth->bindParam(':type', $chat_type, PDO::PARAM_STR);
$sth->bindParam(':title', $chat_title, PDO::PARAM_STR, 255); $sth->bindParam(':title', $chat_title, PDO::PARAM_STR, 255);
$sth->bindParam(':username', $chat_username, PDO::PARAM_STR, 255); $sth->bindParam(':username', $chat_username, PDO::PARAM_STR, 255);
$sth->bindParam(':all_members_are_administrators', $chat_all_members_are_administrators, PDO::PARAM_INT); $sth->bindParam(':all_members_are_administrators', $chat_all_members_are_administrators, PDO::PARAM_INT);
...@@ -616,8 +619,8 @@ class DB ...@@ -616,8 +619,8 @@ class DB
$query = $inline_query->getQuery(); $query = $inline_query->getQuery();
$offset = $inline_query->getOffset(); $offset = $inline_query->getOffset();
$sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT); $sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':location', $location, PDO::PARAM_STR); $sth->bindParam(':location', $location, PDO::PARAM_STR);
$sth->bindParam(':query', $query, PDO::PARAM_STR); $sth->bindParam(':query', $query, PDO::PARAM_STR);
$sth->bindParam(':param_offset', $offset, PDO::PARAM_STR); $sth->bindParam(':param_offset', $offset, PDO::PARAM_STR);
...@@ -665,7 +668,7 @@ class DB ...@@ -665,7 +668,7 @@ class DB
$query = $chosen_inline_result->getQuery(); $query = $chosen_inline_result->getQuery();
$sth->bindParam(':result_id', $result_id, PDO::PARAM_STR); $sth->bindParam(':result_id', $result_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':location', $location, PDO::PARAM_STR); $sth->bindParam(':location', $location, PDO::PARAM_STR);
$sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR); $sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
$sth->bindParam(':query', $query, PDO::PARAM_STR); $sth->bindParam(':query', $query, PDO::PARAM_STR);
...@@ -733,10 +736,10 @@ class DB ...@@ -733,10 +736,10 @@ class DB
$inline_message_id = $callback_query->getInlineMessageId(); $inline_message_id = $callback_query->getInlineMessageId();
$data = $callback_query->getData(); $data = $callback_query->getData();
$sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT); $sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR); $sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
$sth->bindParam(':data', $data, PDO::PARAM_STR); $sth->bindParam(':data', $data, PDO::PARAM_STR);
$sth->bindParam(':created_at', $date, PDO::PARAM_STR); $sth->bindParam(':created_at', $date, PDO::PARAM_STR);
...@@ -773,9 +776,9 @@ class DB ...@@ -773,9 +776,9 @@ class DB
$forward_from_message_id = $message->getForwardFromMessageId(); $forward_from_message_id = $message->getForwardFromMessageId();
$photo = self::entitiesArrayToJson($message->getPhoto(), ''); $photo = self::entitiesArrayToJson($message->getPhoto(), '');
$entities = self::entitiesArrayToJson($message->getEntities(), null); $entities = self::entitiesArrayToJson($message->getEntities(), null);
$new_chat_member = $message->getNewChatMember(); $new_chat_members = $message->getNewChatMembers();
$new_chat_photo = self::entitiesArrayToJson($message->getNewChatPhoto(), '');
$left_chat_member = $message->getLeftChatMember(); $left_chat_member = $message->getLeftChatMember();
$new_chat_photo = self::entitiesArrayToJson($message->getNewChatPhoto(), '');
$migrate_to_chat_id = $message->getMigrateToChatId(); $migrate_to_chat_id = $message->getMigrateToChatId();
//Insert chat, update chat id in case it migrated //Insert chat, update chat id in case it migrated
...@@ -800,10 +803,16 @@ class DB ...@@ -800,10 +803,16 @@ class DB
} }
//New and left chat member //New and left chat member
if ($new_chat_member instanceof User) { if (!empty($new_chat_members)) {
//Insert the new chat user $new_chat_members_ids = [];
self::insertUser($new_chat_member, $date, $chat); foreach ($new_chat_members as $new_chat_member) {
$new_chat_member = $new_chat_member->getId(); if ($new_chat_member instanceof User) {
//Insert the new chat user
self::insertUser($new_chat_member, $date, $chat);
$new_chat_members_ids[] = $new_chat_member->getId();
}
}
$new_chat_members_ids = implode(',', $new_chat_members_ids);
} elseif ($left_chat_member instanceof User) { } elseif ($left_chat_member instanceof User) {
//Insert the left chat user //Insert the left chat user
self::insertUser($left_chat_member, $date, $chat); self::insertUser($left_chat_member, $date, $chat);
...@@ -816,16 +825,16 @@ class DB ...@@ -816,16 +825,16 @@ class DB
( (
`id`, `user_id`, `chat_id`, `date`, `forward_from`, `forward_from_chat`, `forward_from_message_id`, `id`, `user_id`, `chat_id`, `date`, `forward_from`, `forward_from_chat`, `forward_from_message_id`,
`forward_date`, `reply_to_chat`, `reply_to_message`, `text`, `entities`, `audio`, `document`, `forward_date`, `reply_to_chat`, `reply_to_message`, `text`, `entities`, `audio`, `document`,
`photo`, `sticker`, `video`, `voice`, `caption`, `contact`, `photo`, `sticker`, `video`, `voice`, `video_note`, `caption`, `contact`,
`location`, `venue`, `new_chat_member`, `left_chat_member`, `location`, `venue`, `new_chat_members`, `left_chat_member`,
`new_chat_title`,`new_chat_photo`, `delete_chat_photo`, `group_chat_created`, `new_chat_title`,`new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
`supergroup_chat_created`, `channel_chat_created`, `supergroup_chat_created`, `channel_chat_created`,
`migrate_from_chat_id`, `migrate_to_chat_id`, `pinned_message` `migrate_from_chat_id`, `migrate_to_chat_id`, `pinned_message`
) VALUES ( ) VALUES (
:message_id, :user_id, :chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id, :message_id, :user_id, :chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
:forward_date, :reply_to_chat, :reply_to_message, :text, :entities, :audio, :document, :forward_date, :reply_to_chat, :reply_to_message, :text, :entities, :audio, :document,
:photo, :sticker, :video, :voice, :caption, :contact, :photo, :sticker, :video, :voice, :video_note, :caption, :contact,
:location, :venue, :new_chat_member, :left_chat_member, :location, :venue, :new_chat_members, :left_chat_member,
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created, :new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
:supergroup_chat_created, :channel_chat_created, :supergroup_chat_created, :channel_chat_created,
:migrate_from_chat_id, :migrate_to_chat_id, :pinned_message :migrate_from_chat_id, :migrate_to_chat_id, :pinned_message
...@@ -855,6 +864,7 @@ class DB ...@@ -855,6 +864,7 @@ class DB
$sticker = $message->getSticker(); $sticker = $message->getSticker();
$video = $message->getVideo(); $video = $message->getVideo();
$voice = $message->getVoice(); $voice = $message->getVoice();
$video_note = $message->getVideoNote();
$caption = $message->getCaption(); $caption = $message->getCaption();
$contact = $message->getContact(); $contact = $message->getContact();
$location = $message->getLocation(); $location = $message->getLocation();
...@@ -868,13 +878,13 @@ class DB ...@@ -868,13 +878,13 @@ class DB
$migrate_to_chat_id = $message->getMigrateToChatId(); $migrate_to_chat_id = $message->getMigrateToChatId();
$pinned_message = $message->getPinnedMessage(); $pinned_message = $message->getPinnedMessage();
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $from_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $from_id, PDO::PARAM_STR);
$sth->bindParam(':date', $date, PDO::PARAM_STR); $sth->bindParam(':date', $date, PDO::PARAM_STR);
$sth->bindParam(':forward_from', $forward_from, PDO::PARAM_INT); $sth->bindParam(':forward_from', $forward_from, PDO::PARAM_STR);
$sth->bindParam(':forward_from_chat', $forward_from_chat, PDO::PARAM_INT); $sth->bindParam(':forward_from_chat', $forward_from_chat, PDO::PARAM_STR);
$sth->bindParam(':forward_from_message_id', $forward_from_message_id, PDO::PARAM_INT); $sth->bindParam(':forward_from_message_id', $forward_from_message_id, PDO::PARAM_STR);
$sth->bindParam(':forward_date', $forward_date, PDO::PARAM_STR); $sth->bindParam(':forward_date', $forward_date, PDO::PARAM_STR);
$reply_to_chat_id = null; $reply_to_chat_id = null;
...@@ -882,8 +892,8 @@ class DB ...@@ -882,8 +892,8 @@ class DB
$reply_to_chat_id = $chat_id; $reply_to_chat_id = $chat_id;
} }
$sth->bindParam(':reply_to_chat', $reply_to_chat_id, PDO::PARAM_INT); $sth->bindParam(':reply_to_chat', $reply_to_chat_id, PDO::PARAM_STR);
$sth->bindParam(':reply_to_message', $reply_to_message_id, PDO::PARAM_INT); $sth->bindParam(':reply_to_message', $reply_to_message_id, PDO::PARAM_STR);
$sth->bindParam(':text', $text, PDO::PARAM_STR); $sth->bindParam(':text', $text, PDO::PARAM_STR);
$sth->bindParam(':entities', $entities, PDO::PARAM_STR); $sth->bindParam(':entities', $entities, PDO::PARAM_STR);
$sth->bindParam(':audio', $audio, PDO::PARAM_STR); $sth->bindParam(':audio', $audio, PDO::PARAM_STR);
...@@ -892,20 +902,21 @@ class DB ...@@ -892,20 +902,21 @@ class DB
$sth->bindParam(':sticker', $sticker, PDO::PARAM_STR); $sth->bindParam(':sticker', $sticker, PDO::PARAM_STR);
$sth->bindParam(':video', $video, PDO::PARAM_STR); $sth->bindParam(':video', $video, PDO::PARAM_STR);
$sth->bindParam(':voice', $voice, PDO::PARAM_STR); $sth->bindParam(':voice', $voice, PDO::PARAM_STR);
$sth->bindParam(':video_note', $video_note, PDO::PARAM_STR);
$sth->bindParam(':caption', $caption, PDO::PARAM_STR); $sth->bindParam(':caption', $caption, PDO::PARAM_STR);
$sth->bindParam(':contact', $contact, PDO::PARAM_STR); $sth->bindParam(':contact', $contact, PDO::PARAM_STR);
$sth->bindParam(':location', $location, PDO::PARAM_STR); $sth->bindParam(':location', $location, PDO::PARAM_STR);
$sth->bindParam(':venue', $venue, PDO::PARAM_STR); $sth->bindParam(':venue', $venue, PDO::PARAM_STR);
$sth->bindParam(':new_chat_member', $new_chat_member, PDO::PARAM_INT); $sth->bindParam(':new_chat_members', $new_chat_members_ids, PDO::PARAM_STR);
$sth->bindParam(':left_chat_member', $left_chat_member, PDO::PARAM_INT); $sth->bindParam(':left_chat_member', $left_chat_member, PDO::PARAM_STR);
$sth->bindParam(':new_chat_title', $new_chat_title, PDO::PARAM_STR); $sth->bindParam(':new_chat_title', $new_chat_title, PDO::PARAM_STR);
$sth->bindParam(':new_chat_photo', $new_chat_photo, PDO::PARAM_STR); $sth->bindParam(':new_chat_photo', $new_chat_photo, PDO::PARAM_STR);
$sth->bindParam(':delete_chat_photo', $delete_chat_photo, PDO::PARAM_INT); $sth->bindParam(':delete_chat_photo', $delete_chat_photo, PDO::PARAM_INT);
$sth->bindParam(':group_chat_created', $group_chat_created, PDO::PARAM_INT); $sth->bindParam(':group_chat_created', $group_chat_created, PDO::PARAM_INT);
$sth->bindParam(':supergroup_chat_created', $supergroup_chat_created, PDO::PARAM_INT); $sth->bindParam(':supergroup_chat_created', $supergroup_chat_created, PDO::PARAM_INT);
$sth->bindParam(':channel_chat_created', $channel_chat_created, PDO::PARAM_INT); $sth->bindParam(':channel_chat_created', $channel_chat_created, PDO::PARAM_INT);
$sth->bindParam(':migrate_from_chat_id', $migrate_from_chat_id, PDO::PARAM_INT); $sth->bindParam(':migrate_from_chat_id', $migrate_from_chat_id, PDO::PARAM_STR);
$sth->bindParam(':migrate_to_chat_id', $migrate_to_chat_id, PDO::PARAM_INT); $sth->bindParam(':migrate_to_chat_id', $migrate_to_chat_id, PDO::PARAM_STR);
$sth->bindParam(':pinned_message', $pinned_message, PDO::PARAM_STR); $sth->bindParam(':pinned_message', $pinned_message, PDO::PARAM_STR);
return $sth->execute(); return $sth->execute();
...@@ -964,9 +975,9 @@ class DB ...@@ -964,9 +975,9 @@ class DB
$text = $edited_message->getText(); $text = $edited_message->getText();
$caption = $edited_message->getCaption(); $caption = $edited_message->getCaption();
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $from_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $from_id, PDO::PARAM_STR);
$sth->bindParam(':edit_date', $edit_date, PDO::PARAM_STR); $sth->bindParam(':edit_date', $edit_date, PDO::PARAM_STR);
$sth->bindParam(':text', $text, PDO::PARAM_STR); $sth->bindParam(':text', $text, PDO::PARAM_STR);
$sth->bindParam(':entities', $entities, PDO::PARAM_STR); $sth->bindParam(':entities', $entities, PDO::PARAM_STR);
...@@ -979,33 +990,32 @@ class DB ...@@ -979,33 +990,32 @@ class DB
} }
/** /**
* Select Group and/or single Chats * Select Groups, Supergroups, Channels and/or single user Chats (also by ID or text)
* *
* @param bool $select_groups * @param $select_chats_params
* @param bool $select_super_groups
* @param bool $select_users
* @param string $date_from
* @param string $date_to
* @param int $chat_id
* @param string $text
* *
* @return array|bool (Selected chats or false if invalid arguments) * @return array|bool
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public static function selectChats( public static function selectChats($select_chats_params)
$select_groups = true, {
$select_super_groups = true,
$select_users = true,
$date_from = null,
$date_to = null,
$chat_id = null,
$text = null
) {
if (!self::isDbConnected()) { if (!self::isDbConnected()) {
return false; return false;
} }
if (!$select_groups && !$select_users && !$select_super_groups) { // Set defaults for omitted values.
$select = array_merge([
'groups' => true,
'supergroups' => true,
'channels' => true,
'users' => true,
'date_from' => null,
'date_to' => null,
'chat_id' => null,
'text' => null,
], $select_chats_params);
if (!$select['groups'] && !$select['users'] && !$select['supergroups']) {
return false; return false;
} }
...@@ -1013,10 +1023,11 @@ class DB ...@@ -1013,10 +1023,11 @@ class DB
$query = ' $query = '
SELECT * , SELECT * ,
' . TB_CHAT . '.`id` AS `chat_id`, ' . TB_CHAT . '.`id` AS `chat_id`,
' . TB_CHAT . '.`username` AS `chat_username`,
' . TB_CHAT . '.`created_at` AS `chat_created_at`, ' . TB_CHAT . '.`created_at` AS `chat_created_at`,
' . TB_CHAT . '.`updated_at` AS `chat_updated_at` ' . TB_CHAT . '.`updated_at` AS `chat_updated_at`
'; ';
if ($select_users) { if ($select['users']) {
$query .= ' $query .= '
, ' . TB_USER . '.`id` AS `user_id` , ' . TB_USER . '.`id` AS `user_id`
FROM `' . TB_CHAT . '` FROM `' . TB_CHAT . '`
...@@ -1031,33 +1042,34 @@ class DB ...@@ -1031,33 +1042,34 @@ class DB
$where = []; $where = [];
$tokens = []; $tokens = [];
if (!$select_groups || !$select_users || !$select_super_groups) { if (!$select['groups'] || !$select['users'] || !$select['supergroups']) {
$chat_or_user = []; $chat_or_user = [];
$select_groups && $chat_or_user[] = TB_CHAT . '.`type` = "group"'; $select['groups'] && $chat_or_user[] = TB_CHAT . '.`type` = "group"';
$select_super_groups && $chat_or_user[] = TB_CHAT . '.`type` = "supergroup"'; $select['supergroups'] && $chat_or_user[] = TB_CHAT . '.`type` = "supergroup"';
$select_users && $chat_or_user[] = TB_CHAT . '.`type` = "private"'; $select['channels'] && $chat_or_user[] = TB_CHAT . '.`type` = "channel"';
$select['users'] && $chat_or_user[] = TB_CHAT . '.`type` = "private"';
$where[] = '(' . implode(' OR ', $chat_or_user) . ')'; $where[] = '(' . implode(' OR ', $chat_or_user) . ')';
} }
if (null !== $date_from) { if (null !== $select['date_from']) {
$where[] = TB_CHAT . '.`updated_at` >= :date_from'; $where[] = TB_CHAT . '.`updated_at` >= :date_from';
$tokens[':date_from'] = $date_from; $tokens[':date_from'] = $select['date_from'];
} }
if (null !== $date_to) { if (null !== $select['date_to']) {
$where[] = TB_CHAT . '.`updated_at` <= :date_to'; $where[] = TB_CHAT . '.`updated_at` <= :date_to';
$tokens[':date_to'] = $date_to; $tokens[':date_to'] = $select['date_to'];
} }
if (null !== $chat_id) { if (null !== $select['chat_id']) {
$where[] = TB_CHAT . '.`id` = :chat_id'; $where[] = TB_CHAT . '.`id` = :chat_id';
$tokens[':chat_id'] = $chat_id; $tokens[':chat_id'] = $select['chat_id'];
} }
if (null !== $text) { if (null !== $select['text']) {
if ($select_users) { if ($select['users']) {
$where[] = '( $where[] = '(
LOWER(' . TB_CHAT . '.`title`) LIKE :text LOWER(' . TB_CHAT . '.`title`) LIKE :text
OR LOWER(' . TB_USER . '.`first_name`) LIKE :text OR LOWER(' . TB_USER . '.`first_name`) LIKE :text
...@@ -1067,7 +1079,7 @@ class DB ...@@ -1067,7 +1079,7 @@ class DB
} else { } else {
$where[] = 'LOWER(' . TB_CHAT . '.`title`) LIKE :text'; $where[] = 'LOWER(' . TB_CHAT . '.`title`) LIKE :text';
} }
$tokens[':text'] = '%' . strtolower($text) . '%'; $tokens[':text'] = '%' . strtolower($select['text']) . '%';
} }
if (!empty($where)) { if (!empty($where)) {
......
...@@ -37,6 +37,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent; ...@@ -37,6 +37,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
* @method string getGifUrl() A valid URL for the GIF file. File size must not exceed 1MB * @method string getGifUrl() A valid URL for the GIF file. File size must not exceed 1MB
* @method int getGifWidth() Optional. Width of the GIF * @method int getGifWidth() Optional. Width of the GIF
* @method int getGifHeight() Optional. Height of the GIF * @method int getGifHeight() Optional. Height of the GIF
* @method int getGifDuration() Optional. Duration of the GIF
* @method string getThumbUrl() URL of the static thumbnail for the result (jpeg or gif) * @method string getThumbUrl() URL of the static thumbnail for the result (jpeg or gif)
* @method string getTitle() Optional. Title for the result * @method string getTitle() Optional. Title for the result
* @method string getCaption() Optional. Caption of the GIF file to be sent, 0-200 characters * @method string getCaption() Optional. Caption of the GIF file to be sent, 0-200 characters
...@@ -47,6 +48,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent; ...@@ -47,6 +48,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
* @method $this setGifUrl(string $gif_url) A valid URL for the GIF file. File size must not exceed 1MB * @method $this setGifUrl(string $gif_url) A valid URL for the GIF file. File size must not exceed 1MB
* @method $this setGifWidth(int $gif_width) Optional. Width of the GIF * @method $this setGifWidth(int $gif_width) Optional. Width of the GIF
* @method $this setGifHeight(int $gif_height) Optional. Height of the GIF * @method $this setGifHeight(int $gif_height) Optional. Height of the GIF
* @method $this setGifDuration(int $gif_duration) Optional. Duration of the GIF
* @method $this setThumbUrl(string $thumb_url) URL of the static thumbnail for the result (jpeg or gif) * @method $this setThumbUrl(string $thumb_url) URL of the static thumbnail for the result (jpeg or gif)
* @method $this setTitle(string $title) Optional. Title for the result * @method $this setTitle(string $title) Optional. Title for the result
* @method $this setCaption(string $caption) Optional. Caption of the GIF file to be sent, 0-200 characters * @method $this setCaption(string $caption) Optional. Caption of the GIF file to be sent, 0-200 characters
......
...@@ -37,6 +37,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent; ...@@ -37,6 +37,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
* @method string getMpeg4Url() A valid URL for the MP4 file. File size must not exceed 1MB * @method string getMpeg4Url() A valid URL for the MP4 file. File size must not exceed 1MB
* @method int getMpeg4Width() Optional. Video width * @method int getMpeg4Width() Optional. Video width
* @method int getMpeg4Height() Optional. Video height * @method int getMpeg4Height() Optional. Video height
* @method int getMpeg4Duration() Optional. Video duration
* @method string getThumbUrl() URL of the static thumbnail (jpeg or gif) for the result * @method string getThumbUrl() URL of the static thumbnail (jpeg or gif) for the result
* @method string getTitle() Optional. Title for the result * @method string getTitle() Optional. Title for the result
* @method string getCaption() Optional. Caption of the MPEG-4 file to be sent, 0-200 characters * @method string getCaption() Optional. Caption of the MPEG-4 file to be sent, 0-200 characters
...@@ -47,6 +48,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent; ...@@ -47,6 +48,7 @@ use Longman\TelegramBot\Entities\InputMessageContent\InputMessageContent;
* @method $this setMpeg4Url(string $mpeg4_url) A valid URL for the MP4 file. File size must not exceed 1MB * @method $this setMpeg4Url(string $mpeg4_url) A valid URL for the MP4 file. File size must not exceed 1MB
* @method $this setMpeg4Width(int $mpeg4_width) Optional. Video width * @method $this setMpeg4Width(int $mpeg4_width) Optional. Video width
* @method $this setMpeg4Height(int $mpeg4_height) Optional. Video height * @method $this setMpeg4Height(int $mpeg4_height) Optional. Video height
* @method $this setMpeg4Duration(int $mpeg4_duration) Optional. Video duration
* @method $this setThumbUrl(string $thumb_url) URL of the static thumbnail (jpeg or gif) for the result * @method $this setThumbUrl(string $thumb_url) URL of the static thumbnail (jpeg or gif) for the result
* @method $this setTitle(string $title) Optional. Title for the result * @method $this setTitle(string $title) Optional. Title for the result
* @method $this setCaption(string $caption) Optional. Caption of the MPEG-4 file to be sent, 0-200 characters * @method $this setCaption(string $caption) Optional. Caption of the MPEG-4 file to be sent, 0-200 characters
......
...@@ -15,35 +15,35 @@ namespace Longman\TelegramBot\Entities; ...@@ -15,35 +15,35 @@ namespace Longman\TelegramBot\Entities;
* *
* @link https://core.telegram.org/bots/api#message * @link https://core.telegram.org/bots/api#message
* *
* @method int getMessageId() Unique message identifier * @method int getMessageId() Unique message identifier
* @method User getFrom() Optional. Sender, can be empty for messages sent to channels * @method User getFrom() Optional. Sender, can be empty for messages sent to channels
* @method int getDate() Date the message was sent in Unix time * @method int getDate() Date the message was sent in Unix time
* @method Chat getChat() Conversation the message belongs to * @method Chat getChat() Conversation the message belongs to
* @method User getForwardFrom() Optional. For forwarded messages, sender of the original message * @method User getForwardFrom() Optional. For forwarded messages, sender of the original message
* @method Chat getForwardFromChat() Optional. For messages forwarded from a channel, information about the original channel * @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 int getForwardFromMessageId() Optional. For forwarded channel posts, identifier of the original message in the channel
* @method int getForwardDate() Optional. For forwarded messages, date the original message was sent in Unix time * @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 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 * @method int getEditDate() Optional. Date the message was last edited in Unix time
* @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 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
* @method string getCaption() Optional. Caption for the document, photo or video, 0-200 characters * @method Video Note getVideoNote() Optional. Message is a video note message, information about the video
* @method Contact getContact() Optional. Message is a shared contact, information about the contact * @method string getCaption() Optional. Caption for the document, photo or video, 0-200 characters
* @method Location getLocation() Optional. Message is a shared location, information about the location * @method Contact getContact() Optional. Message is a shared contact, information about the contact
* @method Venue getVenue() Optional. Message is a venue, information about the venue * @method Location getLocation() Optional. Message is a shared location, information about the location
* @method User getNewChatMember() Optional. A new member was added to the group, information about them (this member may be the bot itself) * @method Venue getVenue() Optional. Message is a venue, information about the venue
* @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 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.
* @method bool getChannelChatCreated() Optional. Service message: the channel has been created. This field can't be received in a message coming through updates, because bot can’t be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel. * @method bool getChannelChatCreated() Optional. Service message: the channel has been created. This field can't be received in a message coming through updates, because bot can’t be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel.
* @method int getMigrateToChatId() Optional. The group has been migrated to a supergroup with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. * @method int getMigrateToChatId() Optional. The group has been migrated to a supergroup with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
* @method int getMigrateFromChatId() Optional. The supergroup has been migrated from a group with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. * @method int getMigrateFromChatId() Optional. The supergroup has been migrated from a group with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
* @method Message getPinnedMessage() Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply. * @method Message getPinnedMessage() Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.
*/ */
class Message extends Entity class Message extends Entity
{ {
...@@ -65,10 +65,11 @@ class Message extends Entity ...@@ -65,10 +65,11 @@ class Message extends Entity
'sticker' => Sticker::class, 'sticker' => Sticker::class,
'video' => Video::class, 'video' => Video::class,
'voice' => Voice::class, 'voice' => Voice::class,
'video_note' => VideoNote::class,
'contact' => Contact::class, 'contact' => Contact::class,
'location' => Location::class, 'location' => Location::class,
'venue' => Venue::class, 'venue' => Venue::class,
'new_chat_member' => 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,
...@@ -85,16 +86,6 @@ class Message extends Entity ...@@ -85,16 +86,6 @@ class Message extends Entity
*/ */
public function __construct(array $data, $bot_username = '') public function __construct(array $data, $bot_username = '')
{ {
//Retro-compatibility
if (isset($data['new_chat_participant'])) {
$data['new_chat_member'] = $data['new_chat_participant'];
unset($data['new_chat_participant']);
}
if (isset($data['left_chat_participant'])) {
$data['left_chat_member'] = $data['left_chat_participant'];
unset($data['left_chat_participant']);
}
parent::__construct($data, $bot_username); parent::__construct($data, $bot_username);
} }
...@@ -128,6 +119,21 @@ class Message extends Entity ...@@ -128,6 +119,21 @@ class Message extends Entity
return empty($pretty_array) ? null : $pretty_array; 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 * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
* *
...@@ -221,12 +227,17 @@ class Message extends Entity ...@@ -221,12 +227,17 @@ 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()
{ {
$member = $this->getNewChatMember(); foreach ($this->getNewChatMembers() as $member) {
if ($member instanceof User && $member->getUsername() === $this->getBotUsername()) {
return true;
}
}
return $member !== null && $member->getUsername() === $this->getBotUsername(); return false;
} }
/** /**
...@@ -247,7 +258,7 @@ class Message extends Entity ...@@ -247,7 +258,7 @@ class Message extends Entity
'contact', 'contact',
'location', 'location',
'venue', 'venue',
'new_chat_member', 'new_chat_members',
'left_chat_member', 'left_chat_member',
'new_chat_title', 'new_chat_title',
'new_chat_photo', 'new_chat_photo',
......
...@@ -15,15 +15,11 @@ namespace Longman\TelegramBot\Entities; ...@@ -15,15 +15,11 @@ namespace Longman\TelegramBot\Entities;
* *
* @link https://core.telegram.org/bots/api#user * @link https://core.telegram.org/bots/api#user
* *
* @property int $id Unique identifier for this user or bot * @method int getId() Unique identifier for this user or bot
* @property string $first_name User's or bot’s first name * @method string getFirstName() User's or bot’s first name
* @property string $last_name Optional. User's or bot’s last name * @method string getLastName() Optional. User's or bot’s last name
* @property string $username Optional. User's or bot’s username * @method string getUsername() Optional. User's or bot’s username
* * @method string getLanguageCode() Optional. User's system language
* @method int getId() Unique identifier for this user or bot
* @method string getFirstName() User's or bot’s first name
* @method string getLastName() Optional. User's or bot’s last name
* @method string getUsername() Optional. User's or bot’s username
*/ */
class User extends Entity class User extends Entity
{ {
......
<?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 VideoNote
*
* @link https://core.telegram.org/bots/api#videonote
*
* @method string getFileId() Unique identifier for this file
* @method int getLength() Video width and height as defined by sender
* @method int getDuration() Duration of the audio in seconds as defined by sender
* @method PhotoSize getThumb() Optional. Video thumbnail as defined by sender
* @method int getFileSize() Optional. File size
*/
class VideoNote extends Entity
{
/**
* {@inheritdoc}
*/
protected function subEntities()
{
return [
'thumb' => PhotoSize::class,
];
}
}
...@@ -97,6 +97,7 @@ class Request ...@@ -97,6 +97,7 @@ class Request
'editMessageCaption', 'editMessageCaption',
'editMessageReplyMarkup', 'editMessageReplyMarkup',
'getWebhookInfo', 'getWebhookInfo',
'deleteMessage',
]; ];
/** /**
...@@ -104,16 +105,32 @@ class Request ...@@ -104,16 +105,32 @@ class Request
* *
* @param \Longman\TelegramBot\Telegram $telegram * @param \Longman\TelegramBot\Telegram $telegram
* *
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public static function initialize(Telegram $telegram) public static function initialize(Telegram $telegram)
{ {
if (is_object($telegram)) { if (!($telegram instanceof Telegram)) {
self::$telegram = $telegram; throw new TelegramException('Invalid Telegram pointer!');
self::$client = new Client(['base_uri' => self::$api_base_uri]);
} else {
throw new TelegramException('Telegram pointer is empty!');
} }
self::$telegram = $telegram;
self::setClient(new Client(['base_uri' => self::$api_base_uri]));
}
/**
* Set a custom Guzzle HTTP Client object
*
* @param Client $client
*
* @throws TelegramException
*/
public static function setClient(Client $client)
{
if (!($client instanceof Client)) {
throw new TelegramException('Invalid GuzzleHttp\Client pointer!');
}
self::$client = $client;
} }
/** /**
...@@ -262,8 +279,12 @@ class Request ...@@ -262,8 +279,12 @@ class Request
*/ */
public static function downloadFile(File $file) public static function downloadFile(File $file)
{ {
if (empty($download_path = self::$telegram->getDownloadPath())) {
throw new TelegramException('Download path not set!');
}
$tg_file_path = $file->getFilePath(); $tg_file_path = $file->getFilePath();
$file_path = self::$telegram->getDownloadPath() . '/' . $tg_file_path; $file_path = $download_path . '/' . $tg_file_path;
$file_dir = dirname($file_path); $file_dir = dirname($file_path);
//For safety reasons, first try to create the directory, then check that it exists. //For safety reasons, first try to create the directory, then check that it exists.
...@@ -941,38 +962,30 @@ class Request ...@@ -941,38 +962,30 @@ class Request
/** /**
* Send message to all active chats * Send message to all active chats
* *
* @param string $callback_function * @param string $callback_function
* @param array $data * @param array $data
* @param boolean $send_groups * @param array $select_chats_params
* @param boolean $send_super_groups
* @param boolean $send_users
* @param string $date_from
* @param string $date_to
* *
* @return array * @return array
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws TelegramException
*/ */
public static function sendToActiveChats( public static function sendToActiveChats(
$callback_function, $callback_function,
array $data, array $data,
$send_groups = true, array $select_chats_params
$send_super_groups = true,
$send_users = true,
$date_from = null,
$date_to = null
) { ) {
$callback_path = __NAMESPACE__ . '\Request'; $callback_path = __NAMESPACE__ . '\Request';
if (!method_exists($callback_path, $callback_function)) { if (!method_exists($callback_path, $callback_function)) {
throw new TelegramException('Method "' . $callback_function . '" not found in class Request.'); throw new TelegramException('Method "' . $callback_function . '" not found in class Request.');
} }
$chats = DB::selectChats($send_groups, $send_super_groups, $send_users, $date_from, $date_to); $chats = DB::selectChats($select_chats_params);
$results = []; $results = [];
if (is_array($chats)) { if (is_array($chats)) {
foreach ($chats as $row) { foreach ($chats as $row) {
$data['chat_id'] = $row['chat_id']; $data['chat_id'] = $row['chat_id'];
$results[] = call_user_func_array($callback_path . '::' . $callback_function, [$data]); $results[] = call_user_func($callback_path . '::' . $callback_function, $data);
} }
} }
...@@ -1078,4 +1091,39 @@ class Request ...@@ -1078,4 +1091,39 @@ class Request
} }
} }
} }
/**
* Use this method to delete either bot's messages or messages of other users if the bot is admin of the group.
*
* On success, true is returned.
*
* @link https://core.telegram.org/bots/api#deletemessage
*
* @param array $data
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function deleteMessage(array $data)
{
return self::send('deleteMessage', $data);
}
/**
* Use this method to send video notes. On success, the sent Message is returned.
*
* @link https://core.telegram.org/bots/api#sendvideonote
*
* @param array $data
* @param string $file
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function sendVideoNote(array $data, $file = null)
{
self::assignEncodedFile($data, 'video_note', $file);
return self::send('sendVideoNote', $data);
}
} }
...@@ -161,10 +161,6 @@ class Telegram ...@@ -161,10 +161,6 @@ class Telegram
$this->bot_username = $bot_username; $this->bot_username = $bot_username;
} }
//Set default download and upload path
$this->setDownloadPath(BASE_PATH . '/../Download');
$this->setUploadPath(BASE_PATH . '/../Upload');
//Add default system commands path //Add default system commands path
$this->addCommandsPath(BASE_COMMANDS_PATH . '/SystemCommands'); $this->addCommandsPath(BASE_COMMANDS_PATH . '/SystemCommands');
......
CREATE TABLE IF NOT EXISTS `user` ( CREATE TABLE IF NOT EXISTS `user` (
`id` bigint COMMENT 'Unique user identifier', `id` bigint COMMENT 'Unique user identifier',
`first_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User\'s first name', `first_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User''s first name',
`last_name` CHAR(255) DEFAULT NULL COMMENT 'User\'s last name', `last_name` CHAR(255) DEFAULT NULL COMMENT 'User''s last name',
`username` CHAR(255) DEFAULT NULL COMMENT 'User\'s username', `username` CHAR(191) DEFAULT NULL COMMENT 'User''s username',
`language_code` CHAR(10) DEFAULT NULL COMMENT 'User''s system language',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation', `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
`updated_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date update', `updated_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date update',
...@@ -30,10 +31,8 @@ CREATE TABLE IF NOT EXISTS `user_chat` ( ...@@ -30,10 +31,8 @@ CREATE TABLE IF NOT EXISTS `user_chat` (
PRIMARY KEY (`user_id`, `chat_id`), PRIMARY KEY (`user_id`, `chat_id`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`)
ON DELETE CASCADE ON UPDATE CASCADE
) 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 `inline_query` ( CREATE TABLE IF NOT EXISTS `inline_query` (
...@@ -54,7 +53,7 @@ CREATE TABLE IF NOT EXISTS `chosen_inline_result` ( ...@@ -54,7 +53,7 @@ CREATE TABLE IF NOT EXISTS `chosen_inline_result` (
`id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry', `id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',
`result_id` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Identifier for this result', `result_id` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Identifier for this result',
`user_id` bigint NULL COMMENT 'Unique user identifier', `user_id` bigint NULL COMMENT 'Unique user identifier',
`location` CHAR(255) NULL DEFAULT NULL COMMENT 'Location object, user\'s location', `location` CHAR(255) NULL DEFAULT NULL COMMENT 'Location object, user''s location',
`inline_message_id` CHAR(255) NULL DEFAULT NULL COMMENT 'Identifier of the sent inline message', `inline_message_id` CHAR(255) NULL DEFAULT NULL COMMENT 'Identifier of the sent inline message',
`query` TEXT NOT NULL COMMENT 'The query that was used to obtain the result', `query` TEXT NOT NULL COMMENT 'The query that was used to obtain the result',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation', `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
...@@ -84,19 +83,20 @@ CREATE TABLE IF NOT EXISTS `message` ( ...@@ -84,19 +83,20 @@ CREATE TABLE IF NOT EXISTS `message` (
`sticker` TEXT COMMENT 'Sticker object. Message is a sticker, information about the sticker', `sticker` TEXT COMMENT 'Sticker object. Message is a sticker, information about the sticker',
`video` TEXT COMMENT 'Video object. Message is a video, information about the video', `video` TEXT COMMENT 'Video object. Message is a video, information about the video',
`voice` TEXT COMMENT 'Voice Object. Message is a Voice, information about the Voice', `voice` TEXT COMMENT 'Voice Object. Message is a Voice, information about the Voice',
`video_note` TEXT COMMENT 'VoiceNote Object. Message is a Video Note, information about the Video Note',
`contact` TEXT COMMENT 'Contact object. Message is a shared contact, information about the contact', `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', `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', `venue` TEXT COMMENT 'Venue object. Message is a Venue, information about the Venue',
`caption` TEXT COMMENT 'For message with caption, the actual UTF-8 text of the caption', `caption` TEXT COMMENT 'For message with caption, the actual UTF-8 text of the caption',
`new_chat_member` bigint NULL DEFAULT NULL COMMENT 'Unique user identifier, a new member was added to the group, information about them (this member may be bot itself)', `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 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', `new_chat_title` CHAR(255) DEFAULT NULL COMMENT 'A chat title was changed to this value',
`new_chat_photo` TEXT COMMENT 'Array of PhotoSize objects. A chat photo was change to this value', `new_chat_photo` TEXT COMMENT 'Array of PhotoSize objects. A chat photo was change to this value',
`delete_chat_photo` tinyint(1) DEFAULT 0 COMMENT 'Informs that the chat photo was deleted', `delete_chat_photo` tinyint(1) DEFAULT 0 COMMENT 'Informs that the chat photo was deleted',
`group_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the group has been created', `group_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the group has been created',
`supergroup_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the supergroup has been created', `supergroup_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the supergroup has been created',
`channel_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the channel chat has been created', `channel_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the channel chat has been created',
`migrate_to_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate to chat identifier. The group has been migrated to a supergroup with the specified identifie', `migrate_to_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate to chat identifier. The group has been migrated to a supergroup with the specified identifier',
`migrate_from_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate from chat identifier. The supergroup has been migrated from a group with the specified identifier', `migrate_from_chat_id` bigint NULL DEFAULT NULL COMMENT 'Migrate from chat identifier. The supergroup has been migrated from a group with the specified identifier',
`pinned_message` TEXT NULL COMMENT 'Message object. Specified message was pinned', `pinned_message` TEXT NULL COMMENT 'Message object. Specified message was pinned',
...@@ -106,7 +106,6 @@ CREATE TABLE IF NOT EXISTS `message` ( ...@@ -106,7 +106,6 @@ CREATE TABLE IF NOT EXISTS `message` (
KEY `forward_from_chat` (`forward_from_chat`), KEY `forward_from_chat` (`forward_from_chat`),
KEY `reply_to_chat` (`reply_to_chat`), KEY `reply_to_chat` (`reply_to_chat`),
KEY `reply_to_message` (`reply_to_message`), KEY `reply_to_message` (`reply_to_message`),
KEY `new_chat_member` (`new_chat_member`),
KEY `left_chat_member` (`left_chat_member`), KEY `left_chat_member` (`left_chat_member`),
KEY `migrate_from_chat_id` (`migrate_from_chat_id`), KEY `migrate_from_chat_id` (`migrate_from_chat_id`),
KEY `migrate_to_chat_id` (`migrate_to_chat_id`), KEY `migrate_to_chat_id` (`migrate_to_chat_id`),
...@@ -117,7 +116,6 @@ CREATE TABLE IF NOT EXISTS `message` ( ...@@ -117,7 +116,6 @@ CREATE TABLE IF NOT EXISTS `message` (
FOREIGN KEY (`forward_from_chat`) REFERENCES `chat` (`id`), FOREIGN KEY (`forward_from_chat`) REFERENCES `chat` (`id`),
FOREIGN KEY (`reply_to_chat`, `reply_to_message`) REFERENCES `message` (`chat_id`, `id`), FOREIGN KEY (`reply_to_chat`, `reply_to_message`) REFERENCES `message` (`chat_id`, `id`),
FOREIGN KEY (`forward_from`) REFERENCES `user` (`id`), FOREIGN KEY (`forward_from`) REFERENCES `user` (`id`),
FOREIGN KEY (`new_chat_member`) REFERENCES `user` (`id`),
FOREIGN KEY (`left_chat_member`) REFERENCES `user` (`id`) FOREIGN KEY (`left_chat_member`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
...@@ -160,7 +158,7 @@ CREATE TABLE IF NOT EXISTS `edited_message` ( ...@@ -160,7 +158,7 @@ CREATE TABLE IF NOT EXISTS `edited_message` (
) 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 `telegram_update` ( CREATE TABLE IF NOT EXISTS `telegram_update` (
`id` bigint UNSIGNED COMMENT 'Update\'s unique identifier', `id` bigint UNSIGNED COMMENT 'Update''s unique identifier',
`chat_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier', `chat_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',
`message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique message identifier', `message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique message identifier',
`inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique inline query identifier', `inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique inline query identifier',
...@@ -221,4 +219,4 @@ CREATE TABLE IF NOT EXISTS `request_limiter` ( ...@@ -221,4 +219,4 @@ CREATE TABLE IF NOT EXISTS `request_limiter` (
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation', `created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT charSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
ALTER TABLE `message` ADD COLUMN `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)' AFTER `new_chat_member`;
UPDATE `message` SET `new_chat_members` = `new_chat_member`;
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