Skip to content

Commit e0f0919

Browse files
committed
Added support for editing the media content of messages
Added the method editMessageMedia and new types inputMediaAnimation, inputMediaAudio, and inputMediaDocument.
1 parent 4e98760 commit e0f0919

File tree

6 files changed

+231
-1
lines changed

6 files changed

+231
-1
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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\Exceptions\InvalidResultType;
11+
use unreal4u\TelegramAPI\InternalFunctionality\TelegramRawData;
12+
use unreal4u\TelegramAPI\Telegram\Types\Custom\ResultBoolean;
13+
use unreal4u\TelegramAPI\Telegram\Types\Inline\Keyboard\Markup;
14+
use unreal4u\TelegramAPI\Telegram\Types\InputMedia;
15+
use unreal4u\TelegramAPI\Telegram\Types\Message;
16+
17+
/**
18+
* Use this method to edit audio, document, photo, or video messages. If a message is a part of a message album, then it
19+
* can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is
20+
* edited, new file can't be uploaded. Use previously uploaded file via its file_id or specify a URL. On success, if the
21+
* edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
22+
*
23+
* Objects defined as-is july 2018
24+
*
25+
* @see https://core.telegram.org/bots/api#editmessagemedia
26+
*/
27+
class EditMessageMedia extends TelegramMethods
28+
{
29+
/**
30+
* Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target
31+
* channel (in the format @channelusername)
32+
* @var string
33+
*/
34+
public $chat_id = '';
35+
36+
/**
37+
* Required if inline_message_id is not specified. Unique identifier of the sent message
38+
* @var int
39+
*/
40+
public $message_id = 0;
41+
42+
/**
43+
* Required if chat_id and message_id are not specified. Identifier of the inline message
44+
* @var string
45+
*/
46+
public $inline_message_id = '';
47+
48+
/**
49+
* A JSON-serialized object for a new media content of the message
50+
* @var InputMedia
51+
*/
52+
public $media;
53+
54+
/**
55+
* Optional. A JSON-serialized object for an inline keyboard.
56+
* @var Markup
57+
*/
58+
public $reply_markup;
59+
60+
public function getMandatoryFields(): array
61+
{
62+
$returnValue[] = 'media';
63+
$this->mandatoryUserOrInlineMessageId($returnValue);
64+
return $returnValue;
65+
}
66+
67+
/**
68+
* @param TelegramRawData $data
69+
* @param LoggerInterface $logger
70+
* @return TelegramTypes
71+
* @throws InvalidResultType
72+
*/
73+
public static function bindToObject(TelegramRawData $data, LoggerInterface $logger): TelegramTypes
74+
{
75+
$typeOfResult = $data->getTypeOfResult();
76+
switch ($typeOfResult) {
77+
case 'array':
78+
return new Message($data->getResult(), $logger);
79+
case 'boolean':
80+
return new ResultBoolean($data->getResultBoolean(), $logger);
81+
default:
82+
throw new InvalidResultType(sprintf(
83+
'Result is of type: %s. Expecting one of array or boolean',
84+
$typeOfResult
85+
));
86+
}
87+
}
88+
}

src/Telegram/Methods/SendPhoto.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use unreal4u\TelegramAPI\Abstracts\TelegramMethods;
88
use unreal4u\TelegramAPI\Telegram\Types\Custom\InputFile;
9+
use unreal4u\TelegramAPI\Telegram\Types\Inline\Keyboard\Markup;
910

1011
/**
1112
* Use this method to send photos. On success, the sent Message is returned
@@ -61,7 +62,7 @@ class SendPhoto extends TelegramMethods
6162
/**
6263
* Optional. Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to
6364
* hide keyboard or to force a reply from the user
64-
* @var null
65+
* @var Markup
6566
*/
6667
public $reply_markup;
6768

src/Telegram/Methods/SendVideo.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ class SendVideo extends TelegramMethods
5252
*/
5353
public $height = 0;
5454

55+
/**
56+
*
57+
* @var InputFile
58+
*/
59+
public $thumb;
60+
5561
/**
5662
* Video caption (may also be used when resending videos by file_id).
5763
* @var string
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Types\InputMedia;
6+
7+
use unreal4u\TelegramAPI\Telegram\Types\Custom\InputFile;
8+
use unreal4u\TelegramAPI\Telegram\Types\InputMedia;
9+
10+
/**
11+
* Represents a video to be sent.
12+
*
13+
* Objects defined as-is February 2018
14+
*
15+
* @see https://core.telegram.org/bots/api#inputmediavideo
16+
*/
17+
class Animation extends InputMedia
18+
{
19+
/**
20+
* Type of the result, must be video
21+
* @var string
22+
*/
23+
public $type = 'animation';
24+
25+
/**
26+
* Optional. Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A
27+
* thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data.
28+
* Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>”
29+
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
30+
* @var InputFile
31+
*/
32+
public $thumb;
33+
34+
/**
35+
* Optional. Animation width
36+
* @var int
37+
*/
38+
public $width = 0;
39+
40+
/**
41+
* Optional. Animation height
42+
* @var int
43+
*/
44+
public $height = 0;
45+
46+
/**
47+
* Optional. Duration of the audio in seconds
48+
* @var int
49+
*/
50+
public $duration = 0;
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Types\InputMedia;
6+
7+
use unreal4u\TelegramAPI\Telegram\Types\Custom\InputFile;
8+
use unreal4u\TelegramAPI\Telegram\Types\InputMedia;
9+
10+
/**
11+
* Represents a video to be sent.
12+
*
13+
* Objects defined as-is February 2018
14+
*
15+
* @see https://core.telegram.org/bots/api#inputmediavideo
16+
*/
17+
class Audio extends InputMedia
18+
{
19+
/**
20+
* Type of the result, must be video
21+
* @var string
22+
*/
23+
public $type = 'audio';
24+
25+
/**
26+
* Optional. Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A
27+
* thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data.
28+
* Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>”
29+
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
30+
* @var InputFile
31+
*/
32+
public $thumb;
33+
34+
/**
35+
* Optional. Duration of the audio in seconds
36+
* @var int
37+
*/
38+
public $duration = 0;
39+
40+
/**
41+
* Optional. Performer of the audio
42+
* @var string
43+
*/
44+
public $performer = '';
45+
46+
/**
47+
* Optional. Title of the audio
48+
* @var string
49+
*/
50+
public $title = '';
51+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Types\InputMedia;
6+
7+
use unreal4u\TelegramAPI\Telegram\Types\Custom\InputFile;
8+
use unreal4u\TelegramAPI\Telegram\Types\InputMedia;
9+
10+
/**
11+
* Represents a photo to be sent.
12+
*
13+
* Objects defined as-is november 2017
14+
*
15+
* @see https://core.telegram.org/bots/api#inputmediaphoto
16+
*/
17+
class Document extends InputMedia
18+
{
19+
/**
20+
* Type of the result, must be photo
21+
* @var string
22+
*/
23+
public $type = 'document';
24+
25+
/**
26+
* Optional. Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A
27+
* thumbnail‘s width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data.
28+
* Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>”
29+
* if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
30+
* @var InputFile
31+
*/
32+
public $thumb;
33+
}

0 commit comments

Comments
 (0)