Unverified Commit d8ddc0e2 authored by Maxiride's avatar Maxiride Committed by GitHub

Merge branch 'develop' into logo

parents 753d681d 9e132d31
......@@ -4,11 +4,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
Exclamation symbols (:exclamation:) note something of importance e.g. breaking changes. Click them to learn more.
## [Unreleased]
:exclamation: After updating to this version, you will need to execute the [SQL migration script][unreleased-sql-migration] on your database.
### Added
- Bot API 4.2 (Polls).
- `getIsMember()` method to `ChatMember` entity.
- `getForwardSenderName()` method to `Message` entity.
- `forward_sender_name` (and forgotten `forward_signature`) DB fields.
- Added missing API fields to Entities and DB.
- Created database tables for `shipping_query` and `pre_checkout_query`.
### Changed
### Deprecated
### Removed
### Fixed
- Missing DB table name specifier in `/cleanup` command. (#947)
### Security
## [0.56.0] - 2019-04-15
......@@ -248,6 +256,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Deprecated
- Move `hideKeyboard` to `removeKeyboard`.
[unreleased-sql-migration]: https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/unreleased.sql
[0.55.0-sql-migration]: https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.54.1-0.55.0.sql
[0.55.0-bc-move-animation-out-of-games-namespace]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#move-animation-out-of-games-namespace
[0.54.0-sql-migration]: https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.53.0-0.54.0.sql
......
......@@ -306,7 +306,7 @@ class CleanupCommand extends AdminCommand
SELECT id
FROM (
SELECT id
FROM `message`
FROM `%1$s`
WHERE `date` < \'%2$s\'
AND `id` NOT IN (
SELECT `message_id`
......
......@@ -15,6 +15,9 @@ use Longman\TelegramBot\Entities\CallbackQuery;
use Longman\TelegramBot\Entities\ChosenInlineResult;
use Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\Payments\PreCheckoutQuery;
use Longman\TelegramBot\Entities\Payments\ShippingQuery;
use Longman\TelegramBot\Entities\Poll;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Telegram;
......@@ -31,6 +34,9 @@ use Longman\TelegramBot\Telegram;
* @method InlineQuery getInlineQuery() Optional. New incoming inline query
* @method ChosenInlineResult getChosenInlineResult() Optional. The result of an inline query that was chosen by a user and sent to their chat partner.
* @method CallbackQuery getCallbackQuery() Optional. New incoming callback query
* @method ShippingQuery getShippingQuery() Optional. New incoming shipping query. Only for invoices with flexible price
* @method PreCheckoutQuery getPreCheckoutQuery() Optional. New incoming pre-checkout query. Contains full information about checkout
* @method Poll getPoll() Optional. New poll state. Bots receive only updates about polls, which are sent or stopped by the bot
*/
abstract class Command
{
......
......@@ -11,12 +11,14 @@
namespace Longman\TelegramBot;
use Exception;
use Longman\TelegramBot\Entities\CallbackQuery;
use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\ChosenInlineResult;
use Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\Payments\PreCheckoutQuery;
use Longman\TelegramBot\Entities\Payments\ShippingQuery;
use Longman\TelegramBot\Entities\Poll;
use Longman\TelegramBot\Entities\ReplyToMessage;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Entities\User;
......@@ -141,7 +143,10 @@ class DB
'edited_message',
'inline_query',
'message',
'pre_checkout_query',
'poll',
'request_limiter',
'shipping_query',
'telegram_update',
'user',
'user_chat',
......@@ -300,30 +305,38 @@ class DB
/**
* Insert entry to telegram_update table
*
* @todo Add missing values! See https://core.telegram.org/bots/api#update
*
* @param string $id
* @param string $chat_id
* @param string $message_id
* @param string $inline_query_id
* @param string $chosen_inline_result_id
* @param string $callback_query_id
* @param string $edited_message_id
* @param string $update_id
* @param string|null $chat_id
* @param string|null $message_id
* @param string|null $edited_message_id
* @param string|null $channel_post_id
* @param string|null $edited_channel_post_id
* @param string|null $inline_query_id
* @param string|null $chosen_inline_result_id
* @param string|null $callback_query_id
* @param string|null $shipping_query_id
* @param string|null $pre_checkout_query_id
* @param string|null $poll_id
*
* @return bool If the insert was successful
* @throws TelegramException
*/
public static function insertTelegramUpdate(
$id,
protected static function insertTelegramUpdate(
$update_id,
$chat_id = null,
$message_id = null,
$edited_message_id = null,
$channel_post_id = null,
$edited_channel_post_id = null,
$inline_query_id = null,
$chosen_inline_result_id = null,
$callback_query_id = null,
$edited_message_id = null
$shipping_query_id = null,
$pre_checkout_query_id = null,
$poll_id = null
) {
if ($message_id === null && $inline_query_id === null && $chosen_inline_result_id === null && $callback_query_id === null && $edited_message_id === null) {
throw new TelegramException('message_id, inline_query_id, chosen_inline_result_id, callback_query_id, edited_message_id are all null');
if ($message_id === null && $edited_message_id === null && $channel_post_id === null && $edited_channel_post_id === null && $inline_query_id === null && $chosen_inline_result_id === null && $callback_query_id === null && $shipping_query_id === null && $pre_checkout_query_id === null && $poll_id === null) {
throw new TelegramException('message_id, edited_message_id, channel_post_id, edited_channel_post_id, inline_query_id, chosen_inline_result_id, callback_query_id, shipping_query_id, pre_checkout_query_id, poll_id are all null');
}
if (!self::isDbConnected()) {
......@@ -333,18 +346,23 @@ class DB
try {
$sth = self::$pdo->prepare('
INSERT IGNORE INTO `' . TB_TELEGRAM_UPDATE . '`
(`id`, `chat_id`, `message_id`, `inline_query_id`, `chosen_inline_result_id`, `callback_query_id`, `edited_message_id`)
(`id`, `chat_id`, `message_id`, `edited_message_id`, `channel_post_id`, `edited_channel_post_id`, `inline_query_id`, `chosen_inline_result_id`, `callback_query_id`, `shipping_query_id`, `pre_checkout_query_id`, `poll_id`)
VALUES
(:id, :chat_id, :message_id, :inline_query_id, :chosen_inline_result_id, :callback_query_id, :edited_message_id)
(:id, :chat_id, :message_id, :edited_message_id, :channel_post_id, :edited_channel_post_id, :inline_query_id, :chosen_inline_result_id, :callback_query_id, :shipping_query_id, :pre_checkout_query_id, :poll_id)
');
$sth->bindValue(':id', $id);
$sth->bindValue(':id', $update_id);
$sth->bindValue(':chat_id', $chat_id);
$sth->bindValue(':message_id', $message_id);
$sth->bindValue(':edited_message_id', $edited_message_id);
$sth->bindValue(':channel_post_id', $channel_post_id);
$sth->bindValue(':edited_channel_post_id', $edited_channel_post_id);
$sth->bindValue(':inline_query_id', $inline_query_id);
$sth->bindValue(':chosen_inline_result_id', $chosen_inline_result_id);
$sth->bindValue(':callback_query_id', $callback_query_id);
$sth->bindValue(':shipping_query_id', $shipping_query_id);
$sth->bindValue(':pre_checkout_query_id', $pre_checkout_query_id);
$sth->bindValue(':poll_id', $poll_id);
return $sth->execute();
} catch (PDOException $e) {
......@@ -439,13 +457,15 @@ class DB
try {
$sth = self::$pdo->prepare('
INSERT IGNORE INTO `' . TB_CHAT . '`
(`id`, `type`, `title`, `username`, `all_members_are_administrators`, `created_at` ,`updated_at`, `old_id`)
(`id`, `type`, `title`, `username`, `first_name`, `last_name`, `all_members_are_administrators`, `created_at` ,`updated_at`, `old_id`)
VALUES
(:id, :type, :title, :username, :all_members_are_administrators, :created_at, :updated_at, :old_id)
(:id, :type, :title, :username, :first_name, :last_name, :all_members_are_administrators, :created_at, :updated_at, :old_id)
ON DUPLICATE KEY UPDATE
`type` = VALUES(`type`),
`title` = VALUES(`title`),
`username` = VALUES(`username`),
`first_name` = VALUES(`first_name`),
`last_name` = VALUES(`last_name`),
`all_members_are_administrators` = VALUES(`all_members_are_administrators`),
`updated_at` = VALUES(`updated_at`)
');
......@@ -466,6 +486,8 @@ class DB
$sth->bindValue(':type', $chat_type);
$sth->bindValue(':title', $chat->getTitle());
$sth->bindValue(':username', $chat->getUsername());
$sth->bindValue(':first_name', $chat->getFirstName());
$sth->bindValue(':last_name', $chat->getLastName());
$sth->bindValue(':all_members_are_administrators', $chat->getAllMembersAreAdministrators(), PDO::PARAM_INT);
$date = $date ?: self::getTimestamp();
$sth->bindValue(':created_at', $date);
......@@ -493,115 +515,60 @@ class DB
return false;
}
$update_id = $update->getUpdateId();
$update_type = $update->getUpdateType();
// @todo Make this simpler: if ($message = $update->getMessage()) ...
if ($update_type === 'message') {
$message = $update->getMessage();
if (self::insertMessageRequest($message)) {
$message_id = $message->getMessageId();
$chat_id = $message->getChat()->getId();
return self::insertTelegramUpdate(
$update_id,
$chat_id,
$message_id
);
}
} elseif ($update_type === 'edited_message') {
$edited_message = $update->getEditedMessage();
if (self::insertEditedMessageRequest($edited_message)) {
$edited_message_local_id = self::$pdo->lastInsertId();
$chat_id = $edited_message->getChat()->getId();
return self::insertTelegramUpdate(
$update_id,
$chat_id,
null,
null,
null,
null,
$edited_message_local_id
);
}
} elseif ($update_type === 'channel_post') {
$channel_post = $update->getChannelPost();
if (self::insertMessageRequest($channel_post)) {
$message_id = $channel_post->getMessageId();
$chat_id = $channel_post->getChat()->getId();
return self::insertTelegramUpdate(
$update_id,
$chat_id,
$message_id
);
}
} elseif ($update_type === 'edited_channel_post') {
$edited_channel_post = $update->getEditedChannelPost();
if (self::insertEditedMessageRequest($edited_channel_post)) {
$edited_channel_post_local_id = self::$pdo->lastInsertId();
$chat_id = $edited_channel_post->getChat()->getId();
return self::insertTelegramUpdate(
$update_id,
$chat_id,
null,
null,
null,
null,
$edited_channel_post_local_id
);
}
} elseif ($update_type === 'inline_query') {
$inline_query = $update->getInlineQuery();
if (self::insertInlineQueryRequest($inline_query)) {
$inline_query_id = $inline_query->getId();
return self::insertTelegramUpdate(
$update_id,
null,
null,
$inline_query_id
);
}
} elseif ($update_type === 'chosen_inline_result') {
$chosen_inline_result = $update->getChosenInlineResult();
if (self::insertChosenInlineResultRequest($chosen_inline_result)) {
$chosen_inline_result_local_id = self::$pdo->lastInsertId();
return self::insertTelegramUpdate(
$update_id,
null,
null,
null,
$chosen_inline_result_local_id
);
}
} elseif ($update_type === 'callback_query') {
$callback_query = $update->getCallbackQuery();
if (self::insertCallbackQueryRequest($callback_query)) {
$callback_query_id = $callback_query->getId();
return self::insertTelegramUpdate(
$update_id,
null,
null,
null,
null,
$callback_query_id
);
}
$chat_id = null;
$message_id = null;
$edited_message_id = null;
$channel_post_id = null;
$edited_channel_post_id = null;
$inline_query_id = null;
$chosen_inline_result_id = null;
$callback_query_id = null;
$shipping_query_id = null;
$pre_checkout_query_id = null;
$poll_id = null;
if (($message = $update->getMessage()) && self::insertMessageRequest($message)) {
$chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
} elseif (($edited_message = $update->getEditedMessage()) && self::insertEditedMessageRequest($edited_message)) {
$chat_id = $edited_message->getChat()->getId();
$edited_message_id = self::$pdo->lastInsertId();
} elseif (($channel_post = $update->getChannelPost()) && self::insertMessageRequest($channel_post)) {
$chat_id = $channel_post->getChat()->getId();
$channel_post_id = $channel_post->getMessageId();
} elseif (($edited_channel_post = $update->getEditedChannelPost()) && self::insertEditedMessageRequest($edited_channel_post)) {
$chat_id = $edited_channel_post->getChat()->getId();
$edited_channel_post_id = self::$pdo->lastInsertId();
} elseif (($inline_query = $update->getInlineQuery()) && self::insertInlineQueryRequest($inline_query)) {
$inline_query_id = $inline_query->getId();
} elseif (($chosen_inline_result = $update->getChosenInlineResult()) && self::insertChosenInlineResultRequest($chosen_inline_result)) {
$chosen_inline_result_id = self::$pdo->lastInsertId();
} elseif (($callback_query = $update->getCallbackQuery()) && self::insertCallbackQueryRequest($callback_query)) {
$callback_query_id = $callback_query->getId();
} elseif (($shipping_query = $update->getShippingQuery()) && self::insertShippingQueryRequest($shipping_query)) {
$shipping_query_id = $shipping_query->getId();
} elseif (($pre_checkout_query = $update->getPreCheckoutQuery()) && self::insertPreCheckoutQueryRequest($pre_checkout_query)) {
$pre_checkout_query_id = $pre_checkout_query->getId();
} elseif (($poll = $update->getPoll()) && self::insertPollRequest($poll)) {
$poll_id = $poll->getId();
} else {
return false;
}
return false;
return self::insertTelegramUpdate(
$update->getUpdateId(),
$chat_id,
$message_id,
$edited_message_id,
$channel_post_id,
$edited_channel_post_id,
$inline_query_id,
$chosen_inline_result_id,
$callback_query_id,
$shipping_query_id,
$pre_checkout_query_id,
$poll_id
);
}
/**
......@@ -709,9 +676,9 @@ class DB
try {
$sth = self::$pdo->prepare('
INSERT IGNORE INTO `' . TB_CALLBACK_QUERY . '`
(`id`, `user_id`, `chat_id`, `message_id`, `inline_message_id`, `data`, `created_at`)
(`id`, `user_id`, `chat_id`, `message_id`, `inline_message_id`, `chat_instance`, `data`, `game_short_name`, `created_at`)
VALUES
(:id, :user_id, :chat_id, :message_id, :inline_message_id, :data, :created_at)
(:id, :user_id, :chat_id, :message_id, :inline_message_id, :chat_instance, :data, :game_short_name, :created_at)
');
$date = self::getTimestamp();
......@@ -750,7 +717,9 @@ class DB
$sth->bindValue(':chat_id', $chat_id);
$sth->bindValue(':message_id', $message_id);
$sth->bindValue(':inline_message_id', $callback_query->getInlineMessageId());
$sth->bindValue(':chat_instance', $callback_query->getChatInstance());
$sth->bindValue(':data', $callback_query->getData());
$sth->bindValue(':game_short_name', $callback_query->getGameShortName());
$sth->bindValue(':created_at', $date);
return $sth->execute();
......@@ -760,9 +729,133 @@ class DB
}
/**
* Insert Message request in db
* Insert shipping query request into database
*
* @param ShippingQuery $shipping_query
*
* @return bool If the insert was successful
* @throws TelegramException
*/
public static function insertShippingQueryRequest(ShippingQuery $shipping_query)
{
if (!self::isDbConnected()) {
return false;
}
try {
$sth = self::$pdo->prepare('
INSERT IGNORE INTO `' . TB_SHIPPING_QUERY . '`
(`id`, `user_id`, `invoice_payload`, `shipping_address`, `created_at`)
VALUES
(:id, :user_id, :invoice_payload, :shipping_address, :created_at)
');
$date = self::getTimestamp();
$user_id = null;
$user = $shipping_query->getFrom();
if ($user instanceof User) {
$user_id = $user->getId();
self::insertUser($user, $date);
}
$sth->bindValue(':id', $shipping_query->getId());
$sth->bindValue(':user_id', $user_id);
$sth->bindValue(':invoice_payload', $shipping_query->getInvoicePayload());
$sth->bindValue(':shipping_address', $shipping_query->getShippingAddress());
$sth->bindValue(':created_at', $date);
return $sth->execute();
} catch (PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
/**
* Insert pre checkout query request into database
*
* @todo Complete with new fields: https://core.telegram.org/bots/api#message
* @param PreCheckoutQuery $pre_checkout_query
*
* @return bool If the insert was successful
* @throws TelegramException
*/
public static function insertPreCheckoutQueryRequest(PreCheckoutQuery $pre_checkout_query)
{
if (!self::isDbConnected()) {
return false;
}
try {
$sth = self::$pdo->prepare('
INSERT IGNORE INTO `' . TB_PRE_CHECKOUT_QUERY . '`
(`id`, `user_id`, `currency`, `total_amount`, `invoice_payload`, `shipping_option_id`, `order_info`, `created_at`)
VALUES
(:id, :user_id, :currency, :total_amount, :invoice_payload, :shipping_option_id, :order_info, :created_at)
');
$date = self::getTimestamp();
$user_id = null;
$user = $pre_checkout_query->getFrom();
if ($user instanceof User) {
$user_id = $user->getId();
self::insertUser($user, $date);
}
$sth->bindValue(':id', $pre_checkout_query->getId());
$sth->bindValue(':user_id', $user_id);
$sth->bindValue(':currency', $pre_checkout_query->getCurrency());
$sth->bindValue(':total_amount', $pre_checkout_query->getTotalAmount());
$sth->bindValue(':invoice_payload', $pre_checkout_query->getInvoicePayload());
$sth->bindValue(':shipping_option_id', $pre_checkout_query->getShippingOptionId());
$sth->bindValue(':order_info', $pre_checkout_query->getOrderInfo());
$sth->bindValue(':created_at', $date);
return $sth->execute();
} catch (PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
/**
* Insert poll request into database
*
* @param Poll $poll
*
* @return bool If the insert was successful
* @throws TelegramException
*/
public static function insertPollRequest(Poll $poll)
{
if (!self::isDbConnected()) {
return false;
}
try {
$sth = self::$pdo->prepare('
INSERT INTO `' . TB_POLL . '`
(`id`, `question`, `options`, `is_closed`, `created_at`)
VALUES
(:id, :question, :options, :is_closed, :created_at)
ON DUPLICATE KEY UPDATE
`options` = VALUES(`options`),
`is_closed` = VALUES(`is_closed`)
');
$sth->bindValue(':id', $poll->getId());
$sth->bindValue(':question', $poll->getQuestion());
$sth->bindValue(':options', self::entitiesArrayToJson($poll->getOptions()));
$sth->bindValue(':is_closed', $poll->getIsClosed());
$sth->bindValue(':created_at', self::getTimestamp());
return $sth->execute();
} catch (PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
/**
* Insert Message request in db
*
* @param Message $message
*
......@@ -828,20 +921,22 @@ class DB
INSERT IGNORE INTO `' . TB_MESSAGE . '`
(
`id`, `user_id`, `chat_id`, `date`, `forward_from`, `forward_from_chat`, `forward_from_message_id`,
`forward_date`, `reply_to_chat`, `reply_to_message`, `media_group_id`, `text`, `entities`, `audio`, `document`,
`animation`, `game`, `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`, `connected_website`, `passport_data`
`forward_signature`, `forward_sender_name`, `forward_date`,
`reply_to_chat`, `reply_to_message`, `edit_date`, `media_group_id`, `author_signature`, `text`, `entities`, `caption_entities`,
`audio`, `document`, `animation`, `game`, `photo`, `sticker`, `video`, `voice`, `video_note`, `caption`, `contact`,
`location`, `venue`, `poll`, `new_chat_members`, `left_chat_member`,
`new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
`supergroup_chat_created`, `channel_chat_created`, `migrate_to_chat_id`, `migrate_from_chat_id`,
`pinned_message`, `invoice`, `successful_payment`, `connected_website`, `passport_data`
) 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, :media_group_id, :text, :entities, :audio, :document,
:animation, :game, :photo, :sticker, :video, :voice, :video_note, :caption, :contact,
:location, :venue, :new_chat_members, :left_chat_member,
:forward_signature, :forward_sender_name, :forward_date,
:reply_to_chat, :reply_to_message, :edit_date, :media_group_id, :author_signature, :text, :entities, :caption_entities,
:audio, :document, :animation, :game, :photo, :sticker, :video, :voice, :video_note, :caption, :contact,
:location, :venue, :poll, :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, :connected_website, :passport_data
:supergroup_chat_created, :channel_chat_created, :migrate_to_chat_id, :migrate_from_chat_id,
:pinned_message, :invoice, :successful_payment, :connected_website, :passport_data
)
');
......@@ -867,6 +962,8 @@ class DB
$sth->bindValue(':forward_from', $forward_from);
$sth->bindValue(':forward_from_chat', $forward_from_chat);
$sth->bindValue(':forward_from_message_id', $message->getForwardFromMessageId());
$sth->bindValue(':forward_signature', $message->getForwardSignature());
$sth->bindValue(':forward_sender_name', $message->getForwardSenderName());
$sth->bindValue(':forward_date', $forward_date);
$reply_to_chat_id = null;
......@@ -876,14 +973,17 @@ class DB
$sth->bindValue(':reply_to_chat', $reply_to_chat_id);
$sth->bindValue(':reply_to_message', $reply_to_message_id);
$sth->bindValue(':edit_date', $message->getEditDate());
$sth->bindValue(':media_group_id', $message->getMediaGroupId());
$sth->bindValue(':author_signature', $message->getAuthorSignature());
$sth->bindValue(':text', $message->getText());
$sth->bindValue(':entities', $t = self::entitiesArrayToJson($message->getEntities(), null));
$sth->bindValue(':entities', self::entitiesArrayToJson($message->getEntities()));
$sth->bindValue(':caption_entities', self::entitiesArrayToJson($message->getCaptionEntities()));
$sth->bindValue(':audio', $message->getAudio());
$sth->bindValue(':document', $message->getDocument());
$sth->bindValue(':animation', $message->getAnimation());
$sth->bindValue(':game', $message->getGame());
$sth->bindValue(':photo', $t = self::entitiesArrayToJson($message->getPhoto(), null));
$sth->bindValue(':photo', self::entitiesArrayToJson($message->getPhoto()));
$sth->bindValue(':sticker', $message->getSticker());
$sth->bindValue(':video', $message->getVideo());
$sth->bindValue(':voice', $message->getVoice());
......@@ -892,17 +992,20 @@ class DB
$sth->bindValue(':contact', $message->getContact());
$sth->bindValue(':location', $message->getLocation());
$sth->bindValue(':venue', $message->getVenue());
$sth->bindValue(':poll', $message->getPoll());
$sth->bindValue(':new_chat_members', $new_chat_members_ids);
$sth->bindValue(':left_chat_member', $left_chat_member_id);
$sth->bindValue(':new_chat_title', $message->getNewChatTitle());
$sth->bindValue(':new_chat_photo', $t = self::entitiesArrayToJson($message->getNewChatPhoto(), null));
$sth->bindValue(':new_chat_photo', self::entitiesArrayToJson($message->getNewChatPhoto()));
$sth->bindValue(':delete_chat_photo', $message->getDeleteChatPhoto());
$sth->bindValue(':group_chat_created', $message->getGroupChatCreated());
$sth->bindValue(':supergroup_chat_created', $message->getSupergroupChatCreated());
$sth->bindValue(':channel_chat_created', $message->getChannelChatCreated());
$sth->bindValue(':migrate_from_chat_id', $message->getMigrateFromChatId());
$sth->bindValue(':migrate_to_chat_id', $message->getMigrateToChatId());
$sth->bindValue(':migrate_from_chat_id', $message->getMigrateFromChatId());
$sth->bindValue(':pinned_message', $message->getPinnedMessage());
$sth->bindValue(':invoice', $message->getInvoice());
$sth->bindValue(':successful_payment', $message->getSuccessfulPayment());
$sth->bindValue(':connected_website', $message->getConnectedWebsite());
$sth->bindValue(':passport_data', $message->getPassportData());
......@@ -956,7 +1059,7 @@ class DB
$sth->bindValue(':user_id', $user_id);
$sth->bindValue(':edit_date', $edit_date);
$sth->bindValue(':text', $edited_message->getText());
$sth->bindValue(':entities', self::entitiesArrayToJson($edited_message->getEntities(), null));
$sth->bindValue(':entities', self::entitiesArrayToJson($edited_message->getEntities()));
$sth->bindValue(':caption', $edited_message->getCaption());
return $sth->execute();
......@@ -1094,7 +1197,7 @@ class DB
}
try {
$sth = self::$pdo->prepare('SELECT
$sth = self::$pdo->prepare('SELECT
(SELECT COUNT(DISTINCT `chat_id`) FROM `' . TB_REQUEST_LIMITER . '` WHERE `created_at` >= :created_at_1) AS LIMIT_PER_SEC_ALL,
(SELECT COUNT(*) FROM `' . TB_REQUEST_LIMITER . '` WHERE `created_at` >= :created_at_2 AND ((`chat_id` = :chat_id_1 AND `inline_message_id` IS NULL) OR (`inline_message_id` = :inline_message_id AND `chat_id` IS NULL))) AS LIMIT_PER_SEC,
(SELECT COUNT(*) FROM `' . TB_REQUEST_LIMITER . '` WHERE `created_at` >= :created_at_minute AND `chat_id` = :chat_id_2) AS LIMIT_PER_MINUTE
......@@ -1113,7 +1216,7 @@ class DB
$sth->execute();
return $sth->fetch();
} catch (Exception $e) {
} catch (PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
......@@ -1149,7 +1252,7 @@ class DB
$sth->bindValue(':created_at', self::getTimestamp());
return $sth->execute();
} catch (Exception $e) {
} catch (PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
......@@ -1192,7 +1295,7 @@ class DB
$sql .= count($where) > 0 ? ' WHERE ' . implode(' AND ', $where) : '';
return self::$pdo->prepare($sql)->execute($tokens);
} catch (Exception $e) {
} catch (PDOException $e) {
throw new TelegramException($e->getMessage());
}
}
......
......@@ -27,6 +27,7 @@ namespace Longman\TelegramBot\Entities;
* @method bool getCanRestrictMembers() Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members
* @method bool getCanPinMessages() Optional. Administrators only. True, if the administrator can pin messages, supergroups only
* @method bool getCanPromoteMembers() Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user)
* @method bool getIsMember() Optional. Restricted only. True, if the user is a member of the chat at the moment of the request
* @method bool getCanSendMessages() Optional. Restricted only. True, if the user can send text messages, contacts, locations and venues
* @method bool getCanSendMediaMessages() Optional. Restricted only. True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages
* @method bool getCanSendOtherMessages() Optional. Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages
......
......@@ -28,6 +28,7 @@ use Longman\TelegramBot\Entities\TelegramPassport\PassportData;
* @method Chat getForwardFromChat() Optional. For messages forwarded from a channel, information about the original channel
* @method int getForwardFromMessageId() Optional. For forwarded channel posts, identifier of the original message in the channel
* @method string getForwardSignature() Optional. For messages forwarded from channels, signature of the post author if present
* @method string getForwardSenderName() Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages
* @method int getForwardDate() Optional. For forwarded messages, date the original message was sent in Unix time
* @method Message getReplyToMessage() Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
* @method int getEditDate() Optional. Date the message was last edited in Unix time
......@@ -45,6 +46,7 @@ use Longman\TelegramBot\Entities\TelegramPassport\PassportData;
* @method Contact getContact() Optional. Message is a shared contact, information about the contact
* @method Location getLocation() Optional. Message is a shared location, information about the location
* @method Venue getVenue() Optional. Message is a venue, information about the venue
* @method Poll getPoll() Optional. Message is a native poll, information about the poll
* @method User getLeftChatMember() Optional. A member was removed from the group, information about them (this member may be the bot itself)
* @method string getNewChatTitle() Optional. A chat title was changed to this value
* @method bool getDeleteChatPhoto() Optional. Service message: the chat photo was deleted
......@@ -86,6 +88,7 @@ class Message extends Entity
'contact' => Contact::class,
'location' => Location::class,
'venue' => Venue::class,
'poll' => Poll::class,
'new_chat_members' => User::class,
'left_chat_member' => User::class,
'new_chat_photo' => PhotoSize::class,
......@@ -295,6 +298,7 @@ class Message extends Entity
'contact',
'location',
'venue',
'poll',
'new_chat_members',
'left_chat_member',
'new_chat_title',
......
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
/**
* Class Poll
*
* This entity contains information about a poll.
*
* @link https://core.telegram.org/bots/api#poll
*
* @method string getId() Unique poll identifier
* @method string getQuestion() Poll question, 1-255 characters
* @method bool getIsClosed() True, if the poll is closed
*/
class Poll extends Entity
{
/**
* {@inheritdoc}
*/
protected function subEntities()
{
return [
'options' => PollOption::class,
];
}
/**
* List of poll options
*
* This method overrides the default getOptions method
* and returns a nice array of PollOption objects.
*
* @return null|PollOption[]
*/
public function getOptions()
{
$pretty_array = $this->makePrettyObjectArray(PollOption::class, 'options');
return empty($pretty_array) ? null : $pretty_array;
}
}
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Entities;
/**
* Class PollOption
*
* This entity contains information about one answer option in a poll.
*
* @link https://core.telegram.org/bots/api#polloption
*
* @method string getText() Option text, 1-100 characters
* @method int getVoterCount() Number of users that voted for this option
*/
class PollOption extends Entity
{
}
......@@ -28,6 +28,7 @@ use Longman\TelegramBot\Entities\Payments\ShippingQuery;
* @method CallbackQuery getCallbackQuery() Optional. New incoming callback query
* @method ShippingQuery getShippingQuery() Optional. New incoming shipping query. Only for invoices with flexible price
* @method PreCheckoutQuery getPreCheckoutQuery() Optional. New incoming pre-checkout query. Contains full information about checkout
* @method Poll getPoll() Optional. New poll state. Bots receive only updates about polls, which are sent or stopped by the bot
*/
class Update extends Entity
{
......@@ -46,6 +47,7 @@ class Update extends Entity
'callback_query' => CallbackQuery::class,
'shipping_query' => ShippingQuery::class,
'pre_checkout_query' => PreCheckoutQuery::class,
'poll' => Poll::class,
];
}
......@@ -66,6 +68,7 @@ class Update extends Entity
'callback_query',
'shipping_query',
'pre_checkout_query',
'poll',
];
foreach ($types as $type) {
if ($this->getProperty($type)) {
......
......@@ -42,6 +42,7 @@ use Longman\TelegramBot\Exception\TelegramException;
* @method static ServerResponse stopMessageLiveLocation(array $data) Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots) before live_period expires. On success, if the message was sent by the bot, the sent Message is returned, otherwise True is returned.
* @method static ServerResponse sendVenue(array $data) Use this method to send information about a venue. On success, the sent Message is returned.
* @method static ServerResponse sendContact(array $data) Use this method to send phone contacts. On success, the sent Message is returned.
* @method static ServerResponse sendPoll(array $data) Use this method to send a native poll. A native poll can't be sent to a private chat. On success, the sent Message is returned.
* @method static ServerResponse sendChatAction(array $data) Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success.
* @method static ServerResponse getUserProfilePhotos(array $data) Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
* @method static ServerResponse getFile(array $data) Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again.
......@@ -69,6 +70,7 @@ use Longman\TelegramBot\Exception\TelegramException;
* @method static ServerResponse editMessageCaption(array $data) Use this method to edit captions of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
* @method static ServerResponse editMessageMedia(array $data) Use this method to edit audio, document, photo, or video messages. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
* @method static ServerResponse editMessageReplyMarkup(array $data) Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
* @method static ServerResponse stopPoll(array $data) Use this method to stop a poll which was sent by the bot. On success, the stopped Poll with the final results is returned.
* @method static ServerResponse deleteMessage(array $data) Use this method to delete a message, including service messages, with certain limitations. Returns True on success.
* @method static ServerResponse getStickerSet(array $data) Use this method to get a sticker set. On success, a StickerSet object is returned.
* @method static ServerResponse uploadStickerFile(array $data) Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times). Returns the uploaded File on success.
......@@ -166,6 +168,7 @@ class Request
'stopMessageLiveLocation',
'sendVenue',
'sendContact',
'sendPoll',
'sendChatAction',
'getUserProfilePhotos',
'getFile',
......@@ -193,6 +196,7 @@ class Request
'editMessageCaption',
'editMessageMedia',
'editMessageReplyMarkup',
'stopPoll',
'deleteMessage',
'getStickerSet',
'uploadStickerFile',
......@@ -807,6 +811,7 @@ class Request
'stopMessageLiveLocation',
'sendVenue',
'sendContact',
'sendPoll',
'sendInvoice',
'sendGame',
'setGameScore',
......@@ -814,6 +819,7 @@ class Request
'editMessageCaption',
'editMessageMedia',
'editMessageReplyMarkup',
'stopPoll',
'setChatTitle',
'setChatDescription',
'setChatStickerSet',
......
CREATE TABLE IF NOT EXISTS `user` (
`id` bigint COMMENT 'Unique user identifier',
`is_bot` tinyint(1) DEFAULT 0 COMMENT 'True if this user is a bot',
`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',
`id` bigint COMMENT 'Unique identifier for this user or bot',
`is_bot` tinyint(1) DEFAULT 0 COMMENT 'True, if this user is a bot',
`first_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User''s or bot''s first name',
`last_name` CHAR(255) DEFAULT NULL COMMENT 'User''s or bot''s last name',
`username` CHAR(191) DEFAULT NULL COMMENT 'User''s or bot''s username',
`language_code` CHAR(10) DEFAULT NULL COMMENT 'IETF language tag of the user''s language',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
`updated_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date update',
......@@ -13,10 +13,12 @@ CREATE TABLE IF NOT EXISTS `user` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `chat` (
`id` bigint COMMENT 'Unique user or chat identifier',
`type` ENUM('private', 'group', 'supergroup', 'channel') NOT NULL COMMENT 'Chat type, either private, group, supergroup or channel',
`title` CHAR(255) DEFAULT '' COMMENT 'Chat (group) title, is null if chat type is private',
`id` bigint COMMENT 'Unique identifier for this chat',
`type` ENUM('private', 'group', 'supergroup', 'channel') NOT NULL COMMENT 'Type of chat, can be either private, group, supergroup or channel',
`title` CHAR(255) DEFAULT '' COMMENT 'Title, for supergroups, channels and group chats',
`username` CHAR(255) DEFAULT NULL COMMENT 'Username, for private chats, supergroups and channels if available',
`first_name` CHAR(255) DEFAULT NULL COMMENT 'First name of the other party in a private chat',
`last_name` CHAR(255) DEFAULT NULL COMMENT 'Last name of the other party in a private chat',
`all_members_are_administrators` tinyint(1) DEFAULT 0 COMMENT 'True if a all members of this group are admins',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
`updated_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date update',
......@@ -52,9 +54,9 @@ CREATE TABLE IF NOT EXISTS `inline_query` (
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',
`result_id` CHAR(255) NOT NULL DEFAULT '' COMMENT 'The unique identifier for the result that was chosen',
`user_id` bigint NULL COMMENT 'The user that chose the result',
`location` CHAR(255) NULL DEFAULT NULL COMMENT 'Sender location, only for bots that require user 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',
......@@ -73,12 +75,17 @@ CREATE TABLE IF NOT EXISTS `message` (
`forward_from` bigint NULL DEFAULT NULL COMMENT 'Unique user identifier, sender of the original message',
`forward_from_chat` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier, chat the original message belongs to',
`forward_from_message_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier of the original message in the channel',
`forward_signature` TEXT NULL DEFAULT NULL COMMENT 'For messages forwarded from channels, signature of the post author if present',
`forward_sender_name` TEXT NULL DEFAULT NULL COMMENT 'Sender''s name for messages forwarded from users who disallow adding a link to their account in forwarded messages',
`forward_date` timestamp NULL DEFAULT NULL COMMENT 'date the original message was sent in timestamp format',
`reply_to_chat` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',
`reply_to_message` bigint UNSIGNED DEFAULT NULL COMMENT 'Message that this message is reply to',
`edit_date` bigint UNSIGNED DEFAULT NULL COMMENT 'Date the message was last edited in Unix time',
`media_group_id` TEXT COMMENT 'The unique identifier of a media message group this message belongs to',
`author_signature` TEXT COMMENT 'Signature of the post author for messages in channels',
`text` TEXT COMMENT 'For text messages, the actual UTF-8 text of the message max message length 4096 char utf8mb4',
`entities` TEXT COMMENT 'For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text',
`caption_entities` TEXT COMMENT 'For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption',
`audio` TEXT COMMENT 'Audio object. Message is an audio file, information about the file',
`document` TEXT COMMENT 'Document object. Message is a general file, information about the file',
`animation` TEXT COMMENT 'Message is an animation, information about the animation',
......@@ -88,10 +95,11 @@ CREATE TABLE IF NOT EXISTS `message` (
`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',
`caption` TEXT COMMENT 'For message with caption, the actual UTF-8 text of the caption',
`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',
`poll` TEXT COMMENT 'Poll object. Message is a native poll, information about the poll',
`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',
......@@ -103,6 +111,8 @@ CREATE TABLE IF NOT EXISTS `message` (
`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',
`invoice` TEXT NULL COMMENT 'Message is an invoice for a payment, information about the invoice',
`successful_payment` TEXT NULL COMMENT 'Message is a service message about a successful payment, information about the payment',
`connected_website` TEXT NULL COMMENT 'The domain name of the website on which the user has logged in.',
`passport_data` TEXT NULL COMMENT 'Telegram Passport data',
......@@ -125,13 +135,35 @@ CREATE TABLE IF NOT EXISTS `message` (
FOREIGN KEY (`left_chat_member`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `edited_message` (
`id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',
`chat_id` bigint COMMENT 'Unique chat identifier',
`message_id` bigint UNSIGNED COMMENT 'Unique message identifier',
`user_id` bigint NULL COMMENT 'Unique user identifier',
`edit_date` timestamp NULL DEFAULT NULL COMMENT 'Date the message was edited in timestamp format',
`text` TEXT COMMENT 'For text messages, the actual UTF-8 text of the message max message length 4096 char utf8',
`entities` TEXT COMMENT 'For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text',
`caption` TEXT COMMENT 'For message with caption, the actual UTF-8 text of the caption',
PRIMARY KEY (`id`),
KEY `chat_id` (`chat_id`),
KEY `message_id` (`message_id`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`),
FOREIGN KEY (`chat_id`, `message_id`) REFERENCES `message` (`chat_id`, `id`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `callback_query` (
`id` bigint UNSIGNED COMMENT 'Unique identifier for this query',
`user_id` bigint NULL COMMENT 'Unique user identifier',
`chat_id` bigint NULL COMMENT 'Unique chat identifier',
`message_id` bigint UNSIGNED COMMENT 'Unique message identifier',
`inline_message_id` CHAR(255) NULL DEFAULT NULL COMMENT 'Identifier of the message sent via the bot in inline mode, that originated the query',
`chat_instance` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent',
`data` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Data associated with the callback button',
`game_short_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Short name of a Game to be returned, serves as the unique identifier for the game',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`),
......@@ -143,47 +175,81 @@ CREATE TABLE IF NOT EXISTS `callback_query` (
FOREIGN KEY (`chat_id`, `message_id`) REFERENCES `message` (`chat_id`, `id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `edited_message` (
`id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for this entry',
`chat_id` bigint COMMENT 'Unique chat identifier',
`message_id` bigint UNSIGNED COMMENT 'Unique message identifier',
`user_id` bigint NULL COMMENT 'Unique user identifier',
`edit_date` timestamp NULL DEFAULT NULL COMMENT 'Date the message was edited in timestamp format',
`text` TEXT COMMENT 'For text messages, the actual UTF-8 text of the message max message length 4096 char utf8',
`entities` TEXT COMMENT 'For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text',
`caption` TEXT COMMENT 'For message with caption, the actual UTF-8 text of the caption',
CREATE TABLE IF NOT EXISTS `shipping_query` (
`id` bigint UNSIGNED COMMENT 'Unique query identifier',
`user_id` bigint COMMENT 'User who sent the query',
`invoice_payload` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Bot specified invoice payload',
`shipping_address` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User specified shipping address',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `pre_checkout_query` (
`id` bigint UNSIGNED COMMENT 'Unique query identifier',
`user_id` bigint COMMENT 'User who sent the query',
`currency` CHAR(3) COMMENT 'Three-letter ISO 4217 currency code',
`total_amount` bigint COMMENT 'Total price in the smallest units of the currency',
`invoice_payload` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Bot specified invoice payload',
`shipping_option_id` CHAR(255) NULL COMMENT 'Identifier of the shipping option chosen by the user',
`order_info` TEXT NULL COMMENT 'Order info provided by the user',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`),
KEY `chat_id` (`chat_id`),
KEY `message_id` (`message_id`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`),
FOREIGN KEY (`chat_id`, `message_id`) REFERENCES `message` (`chat_id`, `id`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `poll` (
`id` bigint UNSIGNED COMMENT 'Unique poll identifier',
`question` char(255) NOT NULL COMMENT 'Poll question',
`options` text NOT NULL COMMENT 'List of poll options',
`is_closed` tinyint(1) DEFAULT 0 COMMENT 'True, if the poll is closed',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `telegram_update` (
`id` bigint UNSIGNED COMMENT 'Update''s unique identifier',
`chat_id` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',
`message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique message identifier',
`inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique inline query identifier',
`chosen_inline_result_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Local chosen inline result identifier',
`callback_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique callback query identifier',
`edited_message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Local edited message identifier',
`message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming message of any kind - text, photo, sticker, etc.',
`edited_message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New version of a message that is known to the bot and was edited',
`channel_post_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming channel post of any kind - text, photo, sticker, etc.',
`edited_channel_post_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New version of a channel post that is known to the bot and was edited',
`inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming inline query',
`chosen_inline_result_id` bigint UNSIGNED DEFAULT NULL COMMENT 'The result of an inline query that was chosen by a user and sent to their chat partner',
`callback_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming callback query',
`shipping_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming shipping query. Only for invoices with flexible price',
`pre_checkout_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming pre-checkout query. Contains full information about checkout',
`poll_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New poll state. Bots receive only updates about polls, which are sent or stopped by the bot',
PRIMARY KEY (`id`),
KEY `message_id` (`chat_id`, `message_id`),
KEY `edited_message_id` (`edited_message_id`),
KEY `channel_post_id` (`channel_post_id`),
KEY `edited_channel_post_id` (`edited_channel_post_id`),
KEY `inline_query_id` (`inline_query_id`),
KEY `chosen_inline_result_id` (`chosen_inline_result_id`),
KEY `callback_query_id` (`callback_query_id`),
KEY `edited_message_id` (`edited_message_id`),
KEY `shipping_query_id` (`shipping_query_id`),
KEY `pre_checkout_query_id` (`pre_checkout_query_id`),
KEY `poll_id` (`poll_id`),
FOREIGN KEY (`chat_id`, `message_id`) REFERENCES `message` (`chat_id`, `id`),
FOREIGN KEY (`edited_message_id`) REFERENCES `edited_message` (`id`),
FOREIGN KEY (`chat_id`, `channel_post_id`) REFERENCES `message` (`chat_id`, `id`),
FOREIGN KEY (`edited_channel_post_id`) REFERENCES `edited_message` (`id`),
FOREIGN KEY (`inline_query_id`) REFERENCES `inline_query` (`id`),
FOREIGN KEY (`chosen_inline_result_id`) REFERENCES `chosen_inline_result` (`id`),
FOREIGN KEY (`callback_query_id`) REFERENCES `callback_query` (`id`),
FOREIGN KEY (`edited_message_id`) REFERENCES `edited_message` (`id`)
FOREIGN KEY (`shipping_query_id`) REFERENCES `shipping_query` (`id`),
FOREIGN KEY (`pre_checkout_query_id`) REFERENCES `pre_checkout_query` (`id`),
FOREIGN KEY (`poll_id`) REFERENCES `poll` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `conversation` (
......
ALTER TABLE `chat` ADD COLUMN `first_name` CHAR(255) DEFAULT NULL COMMENT 'First name of the other party in a private chat' AFTER `username`;
ALTER TABLE `chat` ADD COLUMN `last_name` CHAR(255) DEFAULT NULL COMMENT 'Last name of the other party in a private chat' AFTER `first_name`;
ALTER TABLE `message` ADD COLUMN `forward_signature` TEXT NULL DEFAULT NULL COMMENT 'For messages forwarded from channels, signature of the post author if present' AFTER `forward_from_message_id`;
ALTER TABLE `message` ADD COLUMN `forward_sender_name` TEXT NULL DEFAULT NULL COMMENT 'Sender''s name for messages forwarded from users who disallow adding a link to their account in forwarded messages' AFTER `forward_signature`;
ALTER TABLE `message` ADD COLUMN `edit_date` bigint UNSIGNED DEFAULT NULL COMMENT 'Date the message was last edited in Unix time' AFTER `reply_to_message`;
ALTER TABLE `message` ADD COLUMN `author_signature` TEXT COMMENT 'Signature of the post author for messages in channels' AFTER `media_group_id`;
ALTER TABLE `message` ADD COLUMN `caption_entities` TEXT COMMENT 'For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption';
ALTER TABLE `message` ADD COLUMN `animation` TEXT NULL COMMENT 'Message is an animation, information about the animation' AFTER `document`;
ALTER TABLE `message` ADD COLUMN `poll` TEXT COMMENT 'Poll object. Message is a native poll, information about the poll' AFTER `venue`;
ALTER TABLE `message` ADD COLUMN `invoice` TEXT NULL COMMENT 'Message is an invoice for a payment, information about the invoice' AFTER `pinned_message`;
ALTER TABLE `message` ADD COLUMN `successful_payment` TEXT NULL COMMENT 'Message is a service message about a successful payment, information about the payment' AFTER `invoice`;
ALTER TABLE `callback_query` ADD COLUMN `chat_instance` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent' AFTER `inline_message_id`;
ALTER TABLE `callback_query` ADD COLUMN `game_short_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Short name of a Game to be returned, serves as the unique identifier for the game' AFTER `data`;
CREATE TABLE IF NOT EXISTS `shipping_query` (
`id` bigint UNSIGNED COMMENT 'Unique query identifier',
`user_id` bigint COMMENT 'User who sent the query',
`invoice_payload` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Bot specified invoice payload',
`shipping_address` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User specified shipping address',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `pre_checkout_query` (
`id` bigint UNSIGNED COMMENT 'Unique query identifier',
`user_id` bigint COMMENT 'User who sent the query',
`currency` CHAR(3) COMMENT 'Three-letter ISO 4217 currency code',
`total_amount` bigint COMMENT 'Total price in the smallest units of the currency',
`invoice_payload` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Bot specified invoice payload',
`shipping_option_id` CHAR(255) NULL COMMENT 'Identifier of the shipping option chosen by the user',
`order_info` TEXT NULL COMMENT 'Order info provided by the user',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
CREATE TABLE IF NOT EXISTS `poll` (
`id` bigint UNSIGNED COMMENT 'Unique poll identifier',
`question` char(255) NOT NULL COMMENT 'Poll question',
`options` text NOT NULL COMMENT 'List of poll options',
`is_closed` tinyint(1) DEFAULT 0 COMMENT 'True, if the poll is closed',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
ALTER TABLE `telegram_update` ADD COLUMN `channel_post_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming channel post of any kind - text, photo, sticker, etc.';
ALTER TABLE `telegram_update` ADD COLUMN `edited_channel_post_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New version of a channel post that is known to the bot and was edited';
ALTER TABLE `telegram_update` ADD COLUMN `shipping_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming shipping query. Only for invoices with flexible price';
ALTER TABLE `telegram_update` ADD COLUMN `pre_checkout_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New incoming pre-checkout query. Contains full information about checkout';
ALTER TABLE `telegram_update` ADD COLUMN `poll_id` bigint UNSIGNED DEFAULT NULL COMMENT 'New poll state. Bots receive only updates about polls, which are sent or stopped by the bot';
ALTER TABLE `telegram_update` ADD KEY `channel_post_id` (`channel_post_id`);
ALTER TABLE `telegram_update` ADD KEY `edited_channel_post_id` (`edited_channel_post_id`);
ALTER TABLE `telegram_update` ADD KEY `shipping_query_id` (`shipping_query_id`);
ALTER TABLE `telegram_update` ADD KEY `pre_checkout_query_id` (`pre_checkout_query_id`);
ALTER TABLE `telegram_update` ADD KEY `poll_id` (`poll_id`);
ALTER TABLE `telegram_update` ADD FOREIGN KEY (`chat_id`, `channel_post_id`) REFERENCES `message` (`chat_id`, `id`);
ALTER TABLE `telegram_update` ADD FOREIGN KEY (`edited_channel_post_id`) REFERENCES `edited_message` (`id`);
ALTER TABLE `telegram_update` ADD FOREIGN KEY (`shipping_query_id`) REFERENCES `shipping_query` (`id`);
ALTER TABLE `telegram_update` ADD FOREIGN KEY (`pre_checkout_query_id`) REFERENCES `pre_checkout_query` (`id`);
ALTER TABLE `telegram_update` ADD FOREIGN KEY (`poll_id`) REFERENCES `poll` (`id`);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment