Skip to content

Commit a22afbb

Browse files
committed
Support Bot API 4.2
1 parent 2115acf commit a22afbb

File tree

6 files changed

+122
-4
lines changed

6 files changed

+122
-4
lines changed

src/Api.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Telegram\Bot\Objects\ChatMember;
1313
use Telegram\Bot\Objects\File;
1414
use Telegram\Bot\Objects\Message;
15+
use Telegram\Bot\Objects\Poll;
1516
use Telegram\Bot\Objects\StickerSet;
1617
use Telegram\Bot\Objects\UnknownObject;
1718
use Telegram\Bot\Objects\Update;
@@ -1069,6 +1070,42 @@ public function sendContact(array $params)
10691070
return new Message($response->getDecodedBody());
10701071
}
10711072

1073+
/**
1074+
* Send a native pol.
1075+
*
1076+
* <code>
1077+
* $params = [
1078+
* 'chat_id' => '',
1079+
* 'question' => '',
1080+
* 'options' => '',
1081+
* 'disable_notification' => '',
1082+
* 'reply_to_message_id' => '',
1083+
* 'reply_markup' => '',
1084+
* ];
1085+
* </code>
1086+
*
1087+
* @link https://core.telegram.org/bots/api#sendpoll
1088+
*
1089+
* @param array $params
1090+
*
1091+
* @var int|string $params ['chat_id']
1092+
* @var string $params ['question']
1093+
* @var string $params ['options']
1094+
* @var string $params ['disable_notification']
1095+
* @var int $params ['reply_to_message_id']
1096+
* @var string $params ['reply_markup']
1097+
*
1098+
* @throws TelegramSDKException
1099+
*
1100+
* @return Message
1101+
*/
1102+
public function sendPoll(array $params)
1103+
{
1104+
$response = $this->post('sendPoll', $params);
1105+
1106+
return new Message($response->getDecodedBody());
1107+
}
1108+
10721109
/**
10731110
* Broadcast a Chat Action.
10741111
*
@@ -1519,6 +1556,37 @@ public function editMessageReplyMarkup(array $params)
15191556
return new Message($response->getDecodedBody());
15201557
}
15211558

1559+
1560+
/**
1561+
* Stop a poll which was sent by the bot.
1562+
*
1563+
* <code>
1564+
* $params = [
1565+
* 'chat_id' => '',
1566+
* 'message_id' => '',
1567+
* 'reply_markup' => '',
1568+
* ];
1569+
* </code>
1570+
*
1571+
* @link https://core.telegram.org/bots/api#stoppoll
1572+
*
1573+
* @param array $params
1574+
*
1575+
* @var int|string $params ['chat_id']
1576+
* @var int $params ['message_id']
1577+
* @var string $params ['reply_markup']
1578+
*
1579+
* @throws TelegramSDKException
1580+
*
1581+
* @return Poll
1582+
*/
1583+
public function stopPoll(array $params)
1584+
{
1585+
$response = $this->post('stopPoll', $params);
1586+
1587+
return new Poll($response->getDecodedBody());
1588+
}
1589+
15221590
/**
15231591
* Use this method to send answers to an inline query.
15241592
*

src/Objects/ChatMember.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
/**
66
* Class ChatMember.
77
*
8-
* @method User getUser() Information about the user.
9-
* @method string getStatus() (Optional). The member's status in the chat. Can be “creator”, “administrator”, “member”, “left” or “kicked”
10-
* @method int getUntilDate() (Optional). Restictred and kicked only. Date when restrictions will be lifted for this user, unix time
8+
* @method User getUser() Information about the user.
9+
* @method string getStatus() (Optional). The member's status in the chat. Can be “creator”, “administrator”, “member”, “left” or “kicked”
10+
* @method int getUntilDate() (Optional). Restictred and kicked only. Date when restrictions will be lifted for this user, unix time
1111
* @method bool getCanBeEdited() (Optional). Administrators only. True, if the bot is allowed to edit administrator privileges of that user
1212
* @method bool getCanChangeInfo() (Optional). Administrators only. True, if the administrator can change the chat title, photo and other settings
1313
* @method bool getCanPostMessages() (Optional). Administrators only. True, if the administrator can post in the channel, channels only
@@ -17,6 +17,7 @@
1717
* @method bool getCanRestrictMembers() (Optional). Administrators only. True, if the administrator can restrict, ban or unban chat members
1818
* @method bool getCanPinMessages() (Optional). Administrators only. True, if the administrator can pin messages, supergroups only
1919
* @method bool getCanPromoteMembers() (Optional). Administrators only. True, if the administrator can add new administrators with a subset of his own privileges
20+
* @method bool getIsMember() (Optional). Restricted only. True, if the user is a member of the chat at the moment of the request
2021
* @method bool getCanSendMessages() (Optional). Restricted only. True, if the user can send text messages, contacts, locations and venues
2122
* @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
2223
* @method bool getCanSendOtherMessages() (Optional). Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages

src/Objects/Message.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
* @method int getDate() Date the message was sent in Unix time.
1212
* @method Chat getChat() Conversation the message belongs to.
1313
* @method User getForwardFrom() (Optional). For forwarded messages, sender of the original message.
14-
* @method Chat getForwardFromChat() (Optional). Optional. For messages forwarded from a channel, information about the original channel
14+
* @method Chat getForwardFromChat() (Optional). For messages forwarded from a channel, information about the original channel
1515
* @method string getForwardSignature() (Optional). For messages forwarded from channels, signature of the post author if present
16+
* @method string getForwardSenderName() (Optional). Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages
1617
* @method int getForwardDate() (Optional). For forwarded messages, date the original message was sent in Unix time.
1718
* @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.
1819
* @method int getEditDate() (Optional). Date the message was last edited in Unix time.
@@ -31,6 +32,7 @@
3132
* @method Contact getContact() (Optional). Message is a shared contact, information about the contact.
3233
* @method Location getLocation() (Optional). Message is a shared location, information about the location.
3334
* @method Venue getVenue() (Optional). Message is a venue, information about the venue.
35+
* @method Poll getPoll() (Optional). Message is a native poll, information about the poll.
3436
* @method User getNewChatMember() (Optional). A new member was added to the group, information about them (this member may be the bot itself).
3537
* @method User[] getNewChatMembers() (Optional). New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)
3638
* @method User getLeftChatMember() (Optional). A member was removed from the group, information about them (this member may be the bot itself).

src/Objects/Poll.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Telegram\Bot\Objects;
4+
5+
/**
6+
* Class Poll.
7+
*
8+
*
9+
* @method string getId() Unique poll identifier
10+
* @method string getQuestion() Poll question
11+
* @method PollOption[] getOptions() List of poll options
12+
* @method bool getIsClosed() True, if the poll is closed
13+
*/
14+
class Poll extends BaseObject
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function relations()
20+
{
21+
return [
22+
'options' => PollOption::class,
23+
];
24+
}
25+
}

src/Objects/PollOption.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Telegram\Bot\Objects;
4+
5+
/**
6+
* Class PollOption.
7+
*
8+
*
9+
* @method string getText() Option text, 1-100 characters
10+
* @method int getVoterCount() Number of users that voted for this option
11+
*/
12+
class PollOption extends BaseObject
13+
{
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
public function relations()
18+
{
19+
return [];
20+
}
21+
}

src/Objects/Update.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* @method CallbackQuery getCallbackQuery() (Optional). Incoming callback query.
1717
* @method ShippingQuery getShippingQuery() (Optional). New incoming shipping query.
1818
* @method PreCheckoutQuery getPreCheckoutQuery() (Optional). New incoming pre-checkout query.
19+
* @method Poll getPoll() (Optional). New poll state. Bots receive only updates about polls, which are sent or stopped by the bot.
1920
*
2021
* @link https://core.telegram.org/bots/api#update
2122
*/

0 commit comments

Comments
 (0)