Commit 1c6fdac0 authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge branch 'develop' into fix_limiter_in_channels

parents 0a67dc90 79444db3
......@@ -6,10 +6,18 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
## [Unreleased]
### Added
- 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
- [:exclamation:][unreleased-bc-chats-params-array] `Request::sendToActiveChats` and `DB::selectChats` now accept parameters as an options array.
### Deprecated
### Removed
- [:exclamation:][unreleased-bc-up-download-directory] Upload and download directories are not set any more by default and must be set manually.
### 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).
### Security
## [0.44.1] - 2017-04-25
......@@ -25,7 +33,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Removed
- All examples have been moved to a [dedicated repository](https://github.com/php-telegram-bot/example-bot).
### 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
### Added
......@@ -100,3 +108,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- Logging improvements to Botan integration.
### Deprecated
- 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
/**
* @var string
*/
protected $version = '1.1.0';
protected $version = '1.2.0';
/**
* @var bool
......@@ -45,7 +45,7 @@ class ChatsCommand extends AdminCommand
/**
* Command execute method
*
* @return mixed
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
......@@ -55,19 +55,18 @@ class ChatsCommand extends AdminCommand
$chat_id = $message->getChat()->getId();
$text = trim($message->getText(true));
$results = DB::selectChats(
true, //Select groups (group chat)
true, //Select supergroups (super group chat)
true, //Select users (single chat)
null, //'yyyy-mm-dd hh:mm:ss' date range from
null, //'yyyy-mm-dd hh:mm:ss' date range to
null, //Specific chat_id to select
($text === '' || $text === '*') ? null : $text //Text to search in user/group name
);
$results = DB::selectChats([
'groups' => true,
'supergroups' => true,
'channels' => true,
'users' => true,
'text' => ($text === '' || $text === '*') ? null : $text //Text to search in user/group name
]);
$user_chats = 0;
$group_chats = 0;
$super_group_chats = 0;
$user_chats = 0;
$group_chats = 0;
$supergroup_chats = 0;
$channel_chats = 0;
if ($text === '') {
$text_back = '';
......@@ -100,24 +99,31 @@ class ChatsCommand extends AdminCommand
$text_back .= '- S ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL;
}
++$super_group_chats;
++$supergroup_chats;
} elseif ($chat->isGroupChat()) {
if ($text !== '') {
$text_back .= '- G ' . $chat->getTitle() . ' [' . $whois . ']' . PHP_EOL;
}
++$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..';
} else {
$text_back .= PHP_EOL . 'Private Chats: ' . $user_chats;
$text_back .= PHP_EOL . 'Groups: ' . $group_chats;
$text_back .= PHP_EOL . 'Super Groups: ' . $super_group_chats;
$text_back .= PHP_EOL . 'Total: ' . ($user_chats + $group_chats + $super_group_chats);
$text_back .= PHP_EOL . 'Super Groups: ' . $supergroup_chats;
$text_back .= PHP_EOL . 'Channels: ' . $channel_chats;
$text_back .= PHP_EOL . 'Total: ' . ($user_chats + $group_chats + $supergroup_chats);
if ($text === '') {
$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
$debug_info = [];
$debug_info[] = sprintf('*TelegramBot version:* `%s`', $this->telegram->getVersion());
$debug_info[] = sprintf('*Download path:* `%s`', $this->telegram->getDownloadPath());
$debug_info[] = sprintf('*Upload path:* `%s`', $this->telegram->getUploadPath());
$debug_info[] = sprintf('*Download path:* `%s`', $this->telegram->getDownloadPath() ?: '`_Not set_`');
$debug_info[] = sprintf('*Upload path:* `%s`', $this->telegram->getUploadPath() ?: '`_Not set_`');
// Commands paths.
$debug_info[] = '*Commands paths:*';
......
......@@ -38,7 +38,7 @@ class SendtoallCommand extends AdminCommand
/**
* @var string
*/
protected $version = '1.3.0';
protected $version = '1.4.0';
/**
* @var bool
......@@ -48,7 +48,7 @@ class SendtoallCommand extends AdminCommand
/**
* Execute command
*
* @return boolean
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
......@@ -64,11 +64,12 @@ class SendtoallCommand extends AdminCommand
$results = Request::sendToActiveChats(
'sendMessage', //callback function to execute (see Request.php methods)
['text' => $text], //Param to evaluate the request
true, //Send to groups (group chat)
true, //Send to super groups chats (super group chat)
true, //Send to users (single chat)
null, //'yyyy-mm-dd hh:mm:ss' date range from
null //'yyyy-mm-dd hh:mm:ss' date range to
[
'groups' => true,
'supergroups' => true,
'channels' => false,
'users' => true,
]
);
$total = 0;
......
......@@ -42,7 +42,7 @@ class WhoisCommand extends AdminCommand
/**
* @var string
*/
protected $version = '1.2.0';
protected $version = '1.3.0';
/**
* @var bool
......@@ -52,7 +52,7 @@ class WhoisCommand extends AdminCommand
/**
* Command execute method
*
* @return mixed
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
......@@ -89,28 +89,25 @@ class WhoisCommand extends AdminCommand
$result = null;
if (is_numeric($text)) {
$results = DB::selectChats(
true, //Select groups (group chat)
true, //Select supergroups (super group chat)
true, //Select users (single chat)
null, //'yyyy-mm-dd hh:mm:ss' date range from
null, //'yyyy-mm-dd hh:mm:ss' date range to
$user_id //Specific chat_id to select
);
$results = DB::selectChats([
'groups' => true,
'supergroups' => true,
'channels' => true,
'users' => true,
'chat_id' => $user_id, //Specific chat_id to select
]);
if (!empty($results)) {
$result = reset($results);
}
} else {
$results = DB::selectChats(
true, //Select groups (group chat)
true, //Select supergroups (super group chat)
true, //Select users (single chat)
null, //'yyyy-mm-dd hh:mm:ss' date range from
null, //'yyyy-mm-dd hh:mm:ss' date range to
null, //Specific chat_id to select
$text //Text to search in user/group name
);
$results = DB::selectChats([
'groups' => true,
'supergroups' => true,
'channels' => true,
'users' => true,
'text' => $text //Text to search in user/group name
]);
if (is_array($results) && count($results) === 1) {
$result = reset($results);
......@@ -118,8 +115,9 @@ class WhoisCommand extends AdminCommand
}
if (is_array($result)) {
$result['id'] = $result['chat_id'];
$chat = new Chat($result);
$result['id'] = $result['chat_id'];
$result['username'] = $result['chat_username'];
$chat = new Chat($result);
$user_id = $result['id'];
$created_at = $result['chat_created_at'];
......
......@@ -11,22 +11,21 @@
namespace Longman\TelegramBot\Commands\SystemCommands;
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
*/
protected $name = 'Newchatmember';
protected $name = 'Newchatmembers';
/**
* @var string
*/
protected $description = 'New Chat Member';
protected $description = 'New Chat Member(s)';
/**
* @var string
......@@ -41,21 +40,9 @@ class NewchatmemberCommand extends SystemCommand
*/
public function execute()
{
$message = $this->getMessage();
//$message = $this->getMessage();
//$members = $message->getNewChatMembers();
$chat_id = $message->getChat()->getId();
$member = $message->getNewChatMember();
$text = 'Hi there!';
if (!$message->botAddedInChat()) {
$text = 'Hi ' . $member->tryMention() . '!';
}
$data = [
'chat_id' => $chat_id,
'text' => $text,
];
return Request::sendMessage($data);
return parent::execute();
}
}
......@@ -201,7 +201,7 @@ class DB
$sth->bindParam(':limit', $limit, PDO::PARAM_INT);
if ($id !== null) {
$sth->bindParam(':id', $id, PDO::PARAM_INT);
$sth->bindParam(':id', $id, PDO::PARAM_STR);
}
$sth->execute();
......@@ -327,13 +327,13 @@ class DB
(: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(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT);
$sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT);
$sth->bindParam(':chosen_inline_result_id', $chosen_inline_result_id, PDO::PARAM_INT);
$sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT);
$sth->bindParam(':edited_message_id', $edited_message_id, PDO::PARAM_INT);
$sth->bindParam(':id', $id, PDO::PARAM_STR);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_STR);
$sth->bindParam(':chosen_inline_result_id', $chosen_inline_result_id, PDO::PARAM_STR);
$sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_STR);
$sth->bindParam(':edited_message_id', $edited_message_id, PDO::PARAM_STR);
return $sth->execute();
} catch (PDOException $e) {
......@@ -357,28 +357,31 @@ class DB
return false;
}
$user_id = $user->getId();
$username = $user->getUsername();
$first_name = $user->getFirstName();
$last_name = $user->getLastName();
$user_id = $user->getId();
$username = $user->getUsername();
$first_name = $user->getFirstName();
$last_name = $user->getLastName();
$language_code = $user->getLanguageCode();
try {
$sth = self::$pdo->prepare('
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
(: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
`username` = VALUES(`username`),
`first_name` = VALUES(`first_name`),
`last_name` = VALUES(`last_name`),
`updated_at` = VALUES(`updated_at`)
`username` = VALUES(`username`),
`first_name` = VALUES(`first_name`),
`last_name` = VALUES(`last_name`),
`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(':first_name', $first_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(':updated_at', $date, PDO::PARAM_STR);
......@@ -398,8 +401,8 @@ class DB
(:user_id, :chat_id)
');
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$status = $sth->execute();
} catch (PDOException $e) {
......@@ -449,14 +452,14 @@ class DB
if ($migrate_to_chat_id) {
$chat_type = 'supergroup';
$sth->bindParam(':id', $migrate_to_chat_id, PDO::PARAM_INT);
$sth->bindParam(':oldid', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':id', $migrate_to_chat_id, PDO::PARAM_STR);
$sth->bindParam(':oldid', $chat_id, PDO::PARAM_STR);
} else {
$sth->bindParam(':id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':oldid', $migrate_to_chat_id, PDO::PARAM_INT);
$sth->bindParam(':id', $chat_id, PDO::PARAM_STR);
$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(':username', $chat_username, PDO::PARAM_STR, 255);
$sth->bindParam(':all_members_are_administrators', $chat_all_members_are_administrators, PDO::PARAM_INT);
......@@ -616,8 +619,8 @@ class DB
$query = $inline_query->getQuery();
$offset = $inline_query->getOffset();
$sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':location', $location, PDO::PARAM_STR);
$sth->bindParam(':query', $query, PDO::PARAM_STR);
$sth->bindParam(':param_offset', $offset, PDO::PARAM_STR);
......@@ -665,7 +668,7 @@ class DB
$query = $chosen_inline_result->getQuery();
$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(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
$sth->bindParam(':query', $query, PDO::PARAM_STR);
......@@ -733,10 +736,10 @@ class DB
$inline_message_id = $callback_query->getInlineMessageId();
$data = $callback_query->getData();
$sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT);
$sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $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(':created_at', $date, PDO::PARAM_STR);
......@@ -773,9 +776,9 @@ class DB
$forward_from_message_id = $message->getForwardFromMessageId();
$photo = self::entitiesArrayToJson($message->getPhoto(), '');
$entities = self::entitiesArrayToJson($message->getEntities(), null);
$new_chat_member = $message->getNewChatMember();
$new_chat_photo = self::entitiesArrayToJson($message->getNewChatPhoto(), '');
$new_chat_members = $message->getNewChatMembers();
$left_chat_member = $message->getLeftChatMember();
$new_chat_photo = self::entitiesArrayToJson($message->getNewChatPhoto(), '');
$migrate_to_chat_id = $message->getMigrateToChatId();
//Insert chat, update chat id in case it migrated
......@@ -800,10 +803,16 @@ class DB
}
//New and left chat member
if ($new_chat_member instanceof User) {
//Insert the new chat user
self::insertUser($new_chat_member, $date, $chat);
$new_chat_member = $new_chat_member->getId();
if (!empty($new_chat_members)) {
$new_chat_members_ids = [];
foreach ($new_chat_members as $new_chat_member) {
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) {
//Insert the left chat user
self::insertUser($left_chat_member, $date, $chat);
......@@ -816,16 +825,16 @@ class DB
(
`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`,
`photo`, `sticker`, `video`, `voice`, `caption`, `contact`,
`location`, `venue`, `new_chat_member`, `left_chat_member`,
`photo`, `sticker`, `video`, `voice`, `video_note`, `caption`, `contact`,
`location`, `venue`, `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_from_chat_id`, `migrate_to_chat_id`, `pinned_message`
) VALUES (
: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,
:photo, :sticker, :video, :voice, :caption, :contact,
:location, :venue, :new_chat_member, :left_chat_member,
:photo, :sticker, :video, :voice, :video_note, :caption, :contact,
:location, :venue, :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_from_chat_id, :migrate_to_chat_id, :pinned_message
......@@ -855,6 +864,7 @@ class DB
$sticker = $message->getSticker();
$video = $message->getVideo();
$voice = $message->getVoice();
$video_note = $message->getVideoNote();
$caption = $message->getCaption();
$contact = $message->getContact();
$location = $message->getLocation();
......@@ -868,13 +878,13 @@ class DB
$migrate_to_chat_id = $message->getMigrateToChatId();
$pinned_message = $message->getPinnedMessage();
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $from_id, PDO::PARAM_INT);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $from_id, PDO::PARAM_STR);
$sth->bindParam(':date', $date, PDO::PARAM_STR);
$sth->bindParam(':forward_from', $forward_from, PDO::PARAM_INT);
$sth->bindParam(':forward_from_chat', $forward_from_chat, PDO::PARAM_INT);
$sth->bindParam(':forward_from_message_id', $forward_from_message_id, PDO::PARAM_INT);
$sth->bindParam(':forward_from', $forward_from, PDO::PARAM_STR);
$sth->bindParam(':forward_from_chat', $forward_from_chat, PDO::PARAM_STR);
$sth->bindParam(':forward_from_message_id', $forward_from_message_id, PDO::PARAM_STR);
$sth->bindParam(':forward_date', $forward_date, PDO::PARAM_STR);
$reply_to_chat_id = null;
......@@ -882,8 +892,8 @@ class DB
$reply_to_chat_id = $chat_id;
}
$sth->bindParam(':reply_to_chat', $reply_to_chat_id, PDO::PARAM_INT);
$sth->bindParam(':reply_to_message', $reply_to_message_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_STR);
$sth->bindParam(':text', $text, PDO::PARAM_STR);
$sth->bindParam(':entities', $entities, PDO::PARAM_STR);
$sth->bindParam(':audio', $audio, PDO::PARAM_STR);
......@@ -892,20 +902,21 @@ class DB
$sth->bindParam(':sticker', $sticker, PDO::PARAM_STR);
$sth->bindParam(':video', $video, 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(':contact', $contact, PDO::PARAM_STR);
$sth->bindParam(':location', $location, PDO::PARAM_STR);
$sth->bindParam(':venue', $venue, PDO::PARAM_STR);
$sth->bindParam(':new_chat_member', $new_chat_member, PDO::PARAM_INT);
$sth->bindParam(':left_chat_member', $left_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_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(':delete_chat_photo', $delete_chat_photo, 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(':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_to_chat_id', $migrate_to_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_STR);
$sth->bindParam(':pinned_message', $pinned_message, PDO::PARAM_STR);
return $sth->execute();
......@@ -964,9 +975,9 @@ class DB
$text = $edited_message->getText();
$caption = $edited_message->getCaption();
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $from_id, PDO::PARAM_INT);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $from_id, PDO::PARAM_STR);
$sth->bindParam(':edit_date', $edit_date, PDO::PARAM_STR);
$sth->bindParam(':text', $text, PDO::PARAM_STR);
$sth->bindParam(':entities', $entities, PDO::PARAM_STR);
......@@ -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 bool $select_super_groups
* @param bool $select_users
* @param string $date_from
* @param string $date_to
* @param int $chat_id
* @param string $text
* @param $select_chats_params
*
* @return array|bool (Selected chats or false if invalid arguments)
* @throws \Longman\TelegramBot\Exception\TelegramException
* @return array|bool
* @throws TelegramException
*/
public static function selectChats(
$select_groups = true,
$select_super_groups = true,
$select_users = true,
$date_from = null,
$date_to = null,
$chat_id = null,
$text = null
) {
public static function selectChats($select_chats_params)
{
if (!self::isDbConnected()) {
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;
}
......@@ -1013,10 +1023,11 @@ class DB
$query = '
SELECT * ,
' . TB_CHAT . '.`id` AS `chat_id`,
' . TB_CHAT . '.`username` AS `chat_username`,
' . TB_CHAT . '.`created_at` AS `chat_created_at`,
' . TB_CHAT . '.`updated_at` AS `chat_updated_at`
';
if ($select_users) {
if ($select['users']) {
$query .= '
, ' . TB_USER . '.`id` AS `user_id`
FROM `' . TB_CHAT . '`
......@@ -1031,33 +1042,34 @@ class DB
$where = [];
$tokens = [];
if (!$select_groups || !$select_users || !$select_super_groups) {
if (!$select['groups'] || !$select['users'] || !$select['supergroups']) {
$chat_or_user = [];
$select_groups && $chat_or_user[] = TB_CHAT . '.`type` = "group"';
$select_super_groups && $chat_or_user[] = TB_CHAT . '.`type` = "supergroup"';
$select_users && $chat_or_user[] = TB_CHAT . '.`type` = "private"';
$select['groups'] && $chat_or_user[] = TB_CHAT . '.`type` = "group"';
$select['supergroups'] && $chat_or_user[] = TB_CHAT . '.`type` = "supergroup"';
$select['channels'] && $chat_or_user[] = TB_CHAT . '.`type` = "channel"';
$select['users'] && $chat_or_user[] = TB_CHAT . '.`type` = "private"';
$where[] = '(' . implode(' OR ', $chat_or_user) . ')';
}
if (null !== $date_from) {
if (null !== $select['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';
$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';
$tokens[':chat_id'] = $chat_id;
$tokens[':chat_id'] = $select['chat_id'];
}
if (null !== $text) {
if ($select_users) {
if (null !== $select['text']) {
if ($select['users']) {
$where[] = '(
LOWER(' . TB_CHAT . '.`title`) LIKE :text
OR LOWER(' . TB_USER . '.`first_name`) LIKE :text
......@@ -1067,7 +1079,7 @@ class DB
} else {
$where[] = 'LOWER(' . TB_CHAT . '.`title`) LIKE :text';
}
$tokens[':text'] = '%' . strtolower($text) . '%';
$tokens[':text'] = '%' . strtolower($select['text']) . '%';
}
if (!empty($where)) {
......
......@@ -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 int getGifWidth() Optional. Width 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 getTitle() Optional. Title for the result
* @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;
* @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 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 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
......
......@@ -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 int getMpeg4Width() Optional. Video width
* @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 getTitle() Optional. Title for the result
* @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;
* @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 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 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
......
......@@ -15,35 +15,35 @@ namespace Longman\TelegramBot\Entities;
*
* @link https://core.telegram.org/bots/api#message
*
* @method int getMessageId() Unique message identifier
* @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 Chat getChat() Conversation the message belongs to
* @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 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 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 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 Sticker getSticker() Optional. Message is a sticker, information about the sticker
* @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 string getCaption() Optional. Caption for the document, photo or video, 0-200 characters
* @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 User getNewChatMember() Optional. A new member was added to 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 bool getDeleteChatPhoto() Optional. Service message: the chat photo was deleted
* @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 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 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 int getMessageId() Unique message identifier
* @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 Chat getChat() Conversation the message belongs to
* @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 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 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 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 Sticker getSticker() Optional. Message is a sticker, information about the sticker
* @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 Video Note getVideoNote() Optional. Message is a video note message, information about the video
* @method string getCaption() Optional. Caption for the document, photo or video, 0-200 characters
* @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 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
* @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 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 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.
*/
class Message extends Entity
{
......@@ -65,10 +65,11 @@ class Message extends Entity
'sticker' => Sticker::class,
'video' => Video::class,
'voice' => Voice::class,
'video_note' => VideoNote::class,
'contact' => Contact::class,
'location' => Location::class,
'venue' => Venue::class,
'new_chat_member' => User::class,
'new_chat_members' => User::class,
'left_chat_member' => User::class,
'new_chat_photo' => PhotoSize::class,
'pinned_message' => Message::class,
......@@ -85,16 +86,6 @@ class Message extends Entity
*/
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);
}
......@@ -128,6 +119,21 @@ class Message extends Entity
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
*
......@@ -221,12 +227,17 @@ class Message extends Entity
* Bot added in chat
*
* @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
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
'contact',
'location',
'venue',
'new_chat_member',
'new_chat_members',
'left_chat_member',
'new_chat_title',
'new_chat_photo',
......
......@@ -15,15 +15,11 @@ namespace Longman\TelegramBot\Entities;
*
* @link https://core.telegram.org/bots/api#user
*
* @property int $id Unique identifier for this user or bot
* @property string $first_name User's or bot’s first name
* @property string $last_name Optional. User's or bot’s last name
* @property string $username Optional. User's or bot’s username
*
* @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
* @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
* @method string getLanguageCode() Optional. User's system language
*/
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
'editMessageCaption',
'editMessageReplyMarkup',
'getWebhookInfo',
'deleteMessage',
];
/**
......@@ -104,16 +105,32 @@ class Request
*
* @param \Longman\TelegramBot\Telegram $telegram
*
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws TelegramException
*/
public static function initialize(Telegram $telegram)
{
if (is_object($telegram)) {
self::$telegram = $telegram;
self::$client = new Client(['base_uri' => self::$api_base_uri]);
} else {
throw new TelegramException('Telegram pointer is empty!');
if (!($telegram instanceof Telegram)) {
throw new TelegramException('Invalid Telegram pointer!');
}
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
*/
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();
$file_path = self::$telegram->getDownloadPath() . '/' . $tg_file_path;
$file_path = $download_path . '/' . $tg_file_path;
$file_dir = dirname($file_path);
//For safety reasons, first try to create the directory, then check that it exists.
......@@ -941,38 +962,30 @@ class Request
/**
* Send message to all active chats
*
* @param string $callback_function
* @param array $data
* @param boolean $send_groups
* @param boolean $send_super_groups
* @param boolean $send_users
* @param string $date_from
* @param string $date_to
* @param string $callback_function
* @param array $data
* @param array $select_chats_params
*
* @return array
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws TelegramException
*/
public static function sendToActiveChats(
$callback_function,
array $data,
$send_groups = true,
$send_super_groups = true,
$send_users = true,
$date_from = null,
$date_to = null
array $select_chats_params
) {
$callback_path = __NAMESPACE__ . '\Request';
if (!method_exists($callback_path, $callback_function)) {
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 = [];
if (is_array($chats)) {
foreach ($chats as $row) {
$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);
}
}
......@@ -1079,4 +1092,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
$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
$this->addCommandsPath(BASE_COMMANDS_PATH . '/SystemCommands');
......@@ -334,20 +330,25 @@ class Telegram
);
}
//DB Query
$last_update = DB::selectTelegramUpdate(1);
$last_update = reset($last_update);
//Take custom input into account.
if ($custom_input = $this->getCustomInput()) {
$response = new ServerResponse(json_decode($custom_input, true), $this->bot_username);
} else {
//DB Query
$last_update = DB::selectTelegramUpdate(1);
$last_update = reset($last_update);
//As explained in the telegram bot api documentation
$offset = isset($last_update['id']) ? $last_update['id'] + 1 : null;
//As explained in the telegram bot api documentation
$offset = isset($last_update['id']) ? $last_update['id'] + 1 : null;
$response = Request::getUpdates(
[
'offset' => $offset,
'limit' => $limit,
'timeout' => $timeout,
]
);
$response = Request::getUpdates(
[
'offset' => $offset,
'limit' => $limit,
'timeout' => $timeout,
]
);
}
if ($response->isOk()) {
//Process all updates
......@@ -890,7 +891,7 @@ class Telegram
/**
* Enable requests limiter
*
* @param array $options
* @param array $options
*
* @return \Longman\TelegramBot\Telegram
*/
......@@ -914,7 +915,7 @@ class Telegram
throw new TelegramException('No command(s) provided!');
}
$this->run_commands = true;
$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()->getResult();
......@@ -943,8 +944,8 @@ class Telegram
],
'date' => time(),
'chat' => [
'id' => $bot_id,
'type' => 'private',
'id' => $bot_id,
'type' => 'private',
],
'text' => $command,
],
......
CREATE TABLE IF NOT EXISTS `user` (
`id` bigint COMMENT 'Unique user identifier',
`first_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User\'s first name',
`last_name` CHAR(255) DEFAULT NULL COMMENT 'User\'s last name',
`username` CHAR(255) DEFAULT NULL COMMENT 'User\'s username',
`first_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User''s first name',
`last_name` CHAR(255) DEFAULT NULL COMMENT 'User''s last name',
`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',
`updated_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date update',
......@@ -30,10 +31,8 @@ CREATE TABLE IF NOT EXISTS `user_chat` (
PRIMARY KEY (`user_id`, `chat_id`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`)
ON DELETE CASCADE ON UPDATE CASCADE
FOREIGN KEY (`user_id`) REFERENCES `user` (`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;
CREATE TABLE IF NOT EXISTS `inline_query` (
......@@ -54,7 +53,7 @@ CREATE TABLE IF NOT EXISTS `chosen_inline_result` (
`id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',
`result_id` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Identifier for this result',
`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',
`query` TEXT NOT NULL COMMENT 'The query that was used to obtain the result',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
......@@ -84,19 +83,20 @@ CREATE TABLE IF NOT EXISTS `message` (
`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',
`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',
`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',
`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)',
`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)',
`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',
`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',
`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',
`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',
`pinned_message` TEXT NULL COMMENT 'Message object. Specified message was pinned',
......@@ -106,7 +106,6 @@ CREATE TABLE IF NOT EXISTS `message` (
KEY `forward_from_chat` (`forward_from_chat`),
KEY `reply_to_chat` (`reply_to_chat`),
KEY `reply_to_message` (`reply_to_message`),
KEY `new_chat_member` (`new_chat_member`),
KEY `left_chat_member` (`left_chat_member`),
KEY `migrate_from_chat_id` (`migrate_from_chat_id`),
KEY `migrate_to_chat_id` (`migrate_to_chat_id`),
......@@ -117,7 +116,6 @@ CREATE TABLE IF NOT EXISTS `message` (
FOREIGN KEY (`forward_from_chat`) REFERENCES `chat` (`id`),
FOREIGN KEY (`reply_to_chat`, `reply_to_message`) REFERENCES `message` (`chat_id`, `id`),
FOREIGN KEY (`forward_from`) REFERENCES `user` (`id`),
FOREIGN KEY (`new_chat_member`) REFERENCES `user` (`id`),
FOREIGN KEY (`left_chat_member`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
......@@ -160,7 +158,7 @@ CREATE TABLE IF NOT EXISTS `edited_message` (
) 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',
`id` bigint UNSIGNED COMMENT 'Update''s unique identifier',
`chat_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',
`message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique message identifier',
`inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique inline query identifier',
......@@ -221,4 +219,4 @@ CREATE TABLE IF NOT EXISTS `request_limiter` (
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
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