Skip to content

Commit ff7ac51

Browse files
authored
Merge pull request #605 from noplanman/bot_api_3.3
Bot API 3.3
2 parents 4e284cd + a237104 commit ff7ac51

File tree

7 files changed

+16
-3
lines changed

7 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
44
Exclamation symbols (:exclamation:) note something of importance e.g. breaking changes. Click them to learn more.
55

66
## [Unreleased]
7+
**Note:** After updating to this version, you will need to execute the [SQL migration script][unreleased-sql-migration] on your database.
78
### Added
89
- New entities, methods, update types and inline keyboard button for Payments (Bot API 3.0).
910
- Add new methods, fields and objects for working with stickers (Bot API 3.2).
11+
- New fields for Chat, User and Message objects (Bot API 3.3). `is_bot` added to `user` DB table.
1012
### Changed
1113
- [:exclamation:][unreleased-correct-printerror] Corrected `ServerResponse->printError` method to print by default and return by setting `$return` parameter.
1214
- Ensure command names are handled as lower case.
@@ -149,6 +151,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
149151
### Deprecated
150152
- Move `hideKeyboard` to `removeKeyboard`.
151153

154+
[unreleased-sql-migration]: https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/0.47.1-unreleased.sql
152155
[unreleased-correct-printerror]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#correct-printerror
153156
[0.47.0-private-only-admin-commands]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#private-only-admin-commands
154157
[0.46.0-bc-request-class-refactor]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#request-class-refactor

src/DB.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ public static function insertUser(User $user, $date, Chat $chat = null)
358358
}
359359

360360
$user_id = $user->getId();
361+
$is_bot = $user->getIsBot();
361362
$username = $user->getUsername();
362363
$first_name = $user->getFirstName();
363364
$last_name = $user->getLastName();
@@ -366,10 +367,11 @@ public static function insertUser(User $user, $date, Chat $chat = null)
366367
try {
367368
$sth = self::$pdo->prepare('
368369
INSERT INTO `' . TB_USER . '`
369-
(`id`, `username`, `first_name`, `last_name`, `language_code`, `created_at`, `updated_at`)
370+
(`id`, `is_bot`, `username`, `first_name`, `last_name`, `language_code`, `created_at`, `updated_at`)
370371
VALUES
371-
(:id, :username, :first_name, :last_name, :language_code, :created_at, :updated_at)
372+
(:id, :is_bot,:username, :first_name, :last_name, :language_code, :created_at, :updated_at)
372373
ON DUPLICATE KEY UPDATE
374+
`is_bot` = VALUES(`is_bot`),
373375
`username` = VALUES(`username`),
374376
`first_name` = VALUES(`first_name`),
375377
`last_name` = VALUES(`last_name`),
@@ -378,6 +380,7 @@ public static function insertUser(User $user, $date, Chat $chat = null)
378380
');
379381

380382
$sth->bindParam(':id', $user_id, PDO::PARAM_STR);
383+
$sth->bindParam(':is_bot', $is_bot, PDO::PARAM_INT);
381384
$sth->bindParam(':username', $username, PDO::PARAM_STR, 255);
382385
$sth->bindParam(':first_name', $first_name, PDO::PARAM_STR, 255);
383386
$sth->bindParam(':last_name', $last_name, PDO::PARAM_STR, 255);

src/Entities/Chat.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* @method ChatPhoto getPhoto() Optional. Chat photo. Returned only in getChat.
3636
* @method string getDescription() Optional. Description, for supergroups and channel chats. Returned only in getChat.
3737
* @method string getInviteLink() Optional. Chat invite link, for supergroups and channel chats. Returned only in getChat.
38+
* @method Message getPinnedMessage() Optional. Pinned message, for supergroups. Returned only in getChat.
3839
*/
3940
class Chat extends Entity
4041
{
@@ -44,7 +45,8 @@ class Chat extends Entity
4445
public function subEntities()
4546
{
4647
return [
47-
'photo' => ChatPhoto::class,
48+
'photo' => ChatPhoto::class,
49+
'pinned_message' => Message::class,
4850
];
4951
}
5052

src/Entities/Message.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
* @method User getForwardFrom() Optional. For forwarded messages, sender of the original message
2323
* @method Chat getForwardFromChat() Optional. For messages forwarded from a channel, information about the original channel
2424
* @method int getForwardFromMessageId() Optional. For forwarded channel posts, identifier of the original message in the channel
25+
* @method string getForwardSignature() Optional. For messages forwarded from channels, signature of the post author if present
2526
* @method int getForwardDate() Optional. For forwarded messages, date the original message was sent in Unix time
2627
* @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.
2728
* @method int getEditDate() Optional. Date the message was last edited in Unix time
29+
* @method string getAuthorSignature() Optional. Signature of the post author for messages in channels
2830
* @method Audio getAudio() Optional. Message is an audio file, information about the file
2931
* @method Document getDocument() Optional. Message is a general file, information about the file
3032
* @method Sticker getSticker() Optional. Message is a sticker, information about the sticker

src/Entities/User.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* @link https://core.telegram.org/bots/api#user
1717
*
1818
* @method int getId() Unique identifier for this user or bot
19+
* @method bool getIsBot() True, if this user is a bot
1920
* @method string getFirstName() User's or bot’s first name
2021
* @method string getLastName() Optional. User's or bot’s last name
2122
* @method string getUsername() Optional. User's or bot’s username

structure.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CREATE TABLE IF NOT EXISTS `user` (
22
`id` bigint COMMENT 'Unique user identifier',
3+
`is_bot` tinyint(1) DEFAULT 0 COMMENT 'True if this user is a bot',
34
`first_name` CHAR(255) NOT NULL DEFAULT '' COMMENT 'User''s first name',
45
`last_name` CHAR(255) DEFAULT NULL COMMENT 'User''s last name',
56
`username` CHAR(191) DEFAULT NULL COMMENT 'User''s username',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE `user` ADD COLUMN `is_bot` tinyint(1) DEFAULT 0 COMMENT 'True if this user is a bot' AFTER `id`;

0 commit comments

Comments
 (0)