Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit d9a3d5e

Browse files
committed
Support for Bot API v4.7
1 parent 5e49394 commit d9a3d5e

File tree

12 files changed

+401
-53
lines changed

12 files changed

+401
-53
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[![License](https://poser.pugx.org/unreal4u/telegram-api/license)](https://packagist.org/packages/unreal4u/telegram-api)
1111

1212
This is a PHP7 bot API implementation for Telegram implementing the **vast majority** of
13-
[Bot API up until v4.6](https://core.telegram.org/bots/api-changelog#january-23-2020). The only thing it does not implement
13+
[Bot API up until v4.7](https://core.telegram.org/bots/api-changelog#march-30-2020). The only thing it does not implement
1414
is Telegram Passport which was introduced in [Bot API v4.0](https://core.telegram.org/bots/api#july-26-2018). It is
1515
unlikely to be introduced as it may introduce security vulnerabilities. However, if you think you have a strong case for
1616
the need, feel free to let me know.

src/Telegram/Methods/AddStickerToSet.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
namespace unreal4u\TelegramAPI\Telegram\Methods;
66

@@ -16,7 +16,7 @@
1616
/**
1717
* Use this method to add a new sticker to a set created by the bot. Returns True on success
1818
*
19-
* Objects defined as-is july 2017
19+
* Objects defined as-is June 2020, Bot API v4.9
2020
*
2121
* @see https://core.telegram.org/bots/api#addstickertoset
2222
*/
@@ -45,6 +45,14 @@ class AddStickerToSet extends TelegramMethods
4545
*/
4646
public $png_sticker;
4747

48+
/**
49+
* TGS animation with the sticker, uploaded using multipart/form-data.
50+
*
51+
* @see https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
52+
* @var InputFile
53+
*/
54+
public $tgs_sticker;
55+
4856
/**
4957
* One or more emoji corresponding to the sticker
5058
* @var string
@@ -64,21 +72,29 @@ public static function bindToObject(TelegramResponse $data, LoggerInterface $log
6472

6573
public function getMandatoryFields(): array
6674
{
67-
return [
75+
$return = [
6876
'user_id',
6977
'name',
70-
'png_sticker',
7178
'emojis',
7279
];
80+
81+
// Define property as mandatory when not filled in
82+
if (empty($this->png_sticker) && empty($this->tgs_sticker)) {
83+
$return[] = 'png_sticker';
84+
$return[] = 'tgs_sticker';
85+
}
86+
87+
return $return;
7388
}
7489

7590
public function hasLocalFiles(): bool
7691
{
77-
return $this->png_sticker instanceof InputFile;
92+
return $this->png_sticker instanceof InputFile || $this->tgs_sticker instanceof InputFile;
7893
}
7994

8095
public function getLocalFiles(): Generator
8196
{
8297
yield 'png_sticker' => $this->png_sticker;
98+
yield 'tgs_sticker' => $this->tgs_sticker;
8399
}
84100
}

src/Telegram/Methods/CreateNewStickerSet.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
namespace unreal4u\TelegramAPI\Telegram\Methods;
66

@@ -17,7 +17,7 @@
1717
* Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set.
1818
* Returns True on success
1919
*
20-
* Objects defined as-is july 2017
20+
* Objects defined as-is June 2020, Bot API v4.9
2121
*
2222
* @see https://core.telegram.org/bots/api#createnewstickerset
2323
*/
@@ -52,20 +52,28 @@ class CreateNewStickerSet extends TelegramMethods
5252
*/
5353
public $png_sticker;
5454

55+
/**
56+
* TGS animation with the sticker, uploaded using multipart/form-data.
57+
*
58+
* @see https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
59+
* @var InputFile
60+
*/
61+
public $tgs_sticker;
62+
5563
/**
5664
* One or more emoji corresponding to the sticker
5765
* @var string
5866
*/
5967
public $emojis = '';
6068

6169
/**
62-
* Pass True, if a set of mask stickers should be created
70+
* Optional. Pass True, if a set of mask stickers should be created
6371
* @var bool
6472
*/
65-
public $is_masks = false;
73+
public $is_masks;
6674

6775
/**
68-
* Position where the mask should be placed on faces
76+
* Optional. Position where the mask should be placed on faces
6977
* @var MaskPosition
7078
*/
7179
public $mask_position;
@@ -77,22 +85,30 @@ public static function bindToObject(TelegramResponse $data, LoggerInterface $log
7785

7886
public function getMandatoryFields(): array
7987
{
80-
return [
88+
$return = [
8189
'user_id',
8290
'name',
8391
'title',
84-
'png_sticker',
8592
'emojis',
8693
];
94+
95+
// Define property as mandatory when not filled in
96+
if (empty($this->png_sticker) && empty($this->tgs_sticker)) {
97+
$return[] = 'png_sticker';
98+
$return[] = 'tgs_sticker';
99+
}
100+
101+
return $return;
87102
}
88103

89104
public function hasLocalFiles(): bool
90105
{
91-
return $this->png_sticker instanceof InputFile;
106+
return $this->png_sticker instanceof InputFile || $this->tgs_sticker instanceof InputFile;
92107
}
93108

94109
public function getLocalFiles(): Generator
95110
{
96111
yield 'png_sticker' => $this->png_sticker;
112+
yield 'tgs_sticker' => $this->tgs_sticker;
97113
}
98114
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Methods;
6+
7+
use Psr\Log\LoggerInterface;
8+
use unreal4u\TelegramAPI\Abstracts\TelegramMethods;
9+
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
10+
use unreal4u\TelegramAPI\InternalFunctionality\TelegramResponse;
11+
use unreal4u\TelegramAPI\Telegram\Types\Custom\BotCommandArray;
12+
13+
/**
14+
* Use this method to get the current list of the bot's commands. Requires no parameters. Returns Array of BotCommand on
15+
* success.
16+
*
17+
* Objects defined as-is June 2020, Bot API v4.9
18+
*
19+
* @see https://core.telegram.org/bots/api#getmycommands
20+
*/
21+
class GetMyCommands extends TelegramMethods
22+
{
23+
public static function bindToObject(TelegramResponse $data, LoggerInterface $logger): TelegramTypes
24+
{
25+
return new BotCommandArray($data->getResult(), $logger);
26+
}
27+
28+
public function getMandatoryFields(): array
29+
{
30+
return [];
31+
}
32+
}

src/Telegram/Methods/SendDice.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Methods;
6+
7+
use unreal4u\TelegramAPI\Abstracts\KeyboardMethods;
8+
use unreal4u\TelegramAPI\Abstracts\TelegramMethods;
9+
10+
/**
11+
* Use this method to send an animated emoji that will display a random value. On success, the sent Message is returned.
12+
*
13+
* Objects defined as-is June 2020, Bot API v4.9
14+
*
15+
* @see https://core.telegram.org/bots/api#senddice
16+
*/
17+
class SendDice extends TelegramMethods
18+
{
19+
/**
20+
* Unique identifier for the target chat or username of the target channel (in the format @channelusername)
21+
* @var string
22+
*/
23+
public $chat_id = '';
24+
25+
/**
26+
* Optional. Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, or “🏀”. Dice can
27+
* have values 1-6 for “🎲” and “🎯”, and values 1-5 for “🏀”. Defaults to “🎲”
28+
*
29+
* @var string
30+
*/
31+
public $emoji = '🎲';
32+
33+
/**
34+
* Optional. Sends the message silently. iOS users will not receive a notification, Android users will receive a
35+
* notification with no sound.
36+
* @see https://telegram.org/blog/channels-2-0#silent-messages
37+
* @var bool
38+
*/
39+
public $disable_notification = false;
40+
41+
/**
42+
* If the message is a reply, ID of the original message
43+
* @var int
44+
*/
45+
public $reply_to_message_id = 0;
46+
47+
/**
48+
* Optional. Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to
49+
* hide keyboard or to force a reply from the user.
50+
* @var KeyboardMethods
51+
*/
52+
public $reply_markup;
53+
54+
public function getMandatoryFields(): array
55+
{
56+
return [
57+
'chat_id',
58+
];
59+
}
60+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Methods;
6+
7+
use Psr\Log\LoggerInterface;
8+
use unreal4u\TelegramAPI\Abstracts\TelegramMethods;
9+
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
10+
use unreal4u\TelegramAPI\InternalFunctionality\TelegramResponse;
11+
use unreal4u\TelegramAPI\Telegram\Types\BotCommand;
12+
use unreal4u\TelegramAPI\Telegram\Types\Custom\ResultBoolean;
13+
14+
/**
15+
* Use this method to change the list of the bot's commands. Returns True on success.
16+
*
17+
* Objects defined as-is June 2020, Bot API v4.9
18+
*
19+
* @see https://core.telegram.org/bots/api#setmycommands
20+
*/
21+
class SetMyCommands extends TelegramMethods
22+
{
23+
/**
24+
* A JSON-serialized list of bot commands to be set as the list of the bot's commands. At most 100 commands can be
25+
* specified.
26+
*
27+
* @var BotCommand[]
28+
*/
29+
public $commands;
30+
31+
public static function bindToObject(TelegramResponse $data, LoggerInterface $logger): TelegramTypes
32+
{
33+
return new ResultBoolean($data->getResultBoolean(), $logger);
34+
}
35+
36+
public function getMandatoryFields(): array
37+
{
38+
return [
39+
'commands',
40+
];
41+
}
42+
43+
public function performSpecialConditions(): TelegramMethods
44+
{
45+
$this->commands = json_encode($this->commands);
46+
return parent::performSpecialConditions();
47+
}
48+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Methods;
6+
7+
use Generator;
8+
use Psr\Log\LoggerInterface;
9+
use unreal4u\TelegramAPI\Abstracts\TelegramMethods;
10+
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
11+
use unreal4u\TelegramAPI\InternalFunctionality\TelegramResponse;
12+
use unreal4u\TelegramAPI\Telegram\Types\Custom\InputFile;
13+
use unreal4u\TelegramAPI\Telegram\Types\Custom\ResultBoolean;
14+
15+
/**
16+
* Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only.
17+
* Returns True on success.
18+
*
19+
* Objects defined as-is June 2020, Bot API v4.9
20+
*
21+
* @see https://core.telegram.org/bots/api#setstickersetthumb
22+
*/
23+
class SetStickerSetThumb extends TelegramMethods
24+
{
25+
/**
26+
* Sticker set name
27+
* @var string
28+
*/
29+
public $name;
30+
31+
/**
32+
* User identifier of the sticker set owner
33+
* @var int
34+
*/
35+
public $user_id;
36+
37+
/**
38+
* A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px, or a
39+
* TGS animation with the thumbnail up to 32 kilobytes in size; see
40+
* https://core.telegram.org/animated_stickers#technical-requirements for animated sticker technical requirements.
41+
* Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a
42+
* String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More info on
43+
* Sending Files ». Animated sticker set thumbnail can't be uploaded via HTTP URL.
44+
*
45+
* @var InputFile|string
46+
*/
47+
public $thumb;
48+
49+
public static function bindToObject(TelegramResponse $data, LoggerInterface $logger): TelegramTypes
50+
{
51+
return new ResultBoolean($data->getResultBoolean(), $logger);
52+
}
53+
54+
public function getMandatoryFields(): array
55+
{
56+
return [
57+
'name',
58+
'user_id',
59+
];
60+
}
61+
62+
public function hasLocalFiles(): bool
63+
{
64+
return $this->thumb instanceof InputFile;
65+
}
66+
67+
public function getLocalFiles(): Generator
68+
{
69+
yield 'thumb' => $this->thumb;
70+
}
71+
}

0 commit comments

Comments
 (0)