1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PhpBotFramework. |
5
|
|
|
* |
6
|
|
|
* PhpBotFramework is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU Lesser General Public License as |
8
|
|
|
* published by the Free Software Foundation, version 3. |
9
|
|
|
* |
10
|
|
|
* PhpBotFramework is distributed in the hope that it will be useful, but |
11
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13
|
|
|
* Lesser General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
16
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace PhpBotFramework\Core; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* \class Edit |
23
|
|
|
* \brief All API Methods that edit a message. |
24
|
|
|
*/ |
25
|
|
|
trait Edit |
26
|
|
|
{ |
27
|
|
|
abstract protected function execRequest(string $url); |
28
|
|
|
|
29
|
|
|
/** @internal |
30
|
|
|
* \brief Contains parameters of the next request. */ |
31
|
|
|
protected $parameters; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* \addtogroup Api Api Methods |
35
|
|
|
* @{ |
36
|
|
|
*/ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* \brief Edit text of a message sent by the bot. |
40
|
|
|
* \details Use this method to edit text and game messages sent by the bot. [API reference](https://core.telegram.org/bots/api#editmessagetext) |
41
|
|
|
* @param int $message_id Unique identifier of the sent message. |
42
|
|
|
* @param string $text New text of the message. |
43
|
|
|
* @param string $reply_markup Reply markup of the message will have (will be removed if this is null). |
44
|
|
|
* @param string $parse_mode <i>Optional</i>. Send Markdown or HTML. |
45
|
|
|
* @param bool $disable_web_preview <i>Optional</i>. Disables link previews for links in this message. |
46
|
|
|
* @return Message|false Message edited, false otherwise. |
47
|
|
|
*/ |
48
|
1 |
View Code Duplication |
public function editMessageText(int $message_id, string $text, string $reply_markup = null, string $parse_mode = 'HTML', bool $disable_web_preview = true) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
|
51
|
1 |
|
$this->parameters = [ |
52
|
1 |
|
'chat_id' => $this->_chat_id, |
|
|
|
|
53
|
1 |
|
'message_id' => $message_id, |
54
|
1 |
|
'text' => $text, |
55
|
1 |
|
'reply_markup' => $reply_markup, |
56
|
1 |
|
'parse_mode' => $parse_mode, |
57
|
1 |
|
'disable_web_page_preview' => $disable_web_preview, |
58
|
|
|
]; |
59
|
|
|
|
60
|
1 |
|
return $this->processRequest('editMessageText', 'Message'); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* \brief Edit text of a message sent via the bot. |
65
|
|
|
* \details Use this method to edit text messages sent via the bot (for inline queries). [API reference](https://core.telegram.org/bots/api#editmessagetext) |
66
|
|
|
* @param string $inline_message_id Identifier of the inline message. |
67
|
|
|
* @param string $text New text of the message. |
68
|
|
|
* @param string $reply_markup Reply markup of the message will have (will be removed if this is null). |
69
|
|
|
* @param string $parse_mode <i>Optional</i>. Send Markdown or HTML. |
70
|
|
|
* @param bool $disable_web_preview <i>Optional</i>. Disables link previews for links in this message. |
71
|
|
|
* @return bool True on success. |
72
|
|
|
*/ |
73
|
|
|
public function editInlineMessageText(string $inline_message_id, string $text, string $reply_markup = null, string $parse_mode = 'HTML', bool $disable_web_preview = false) : bool |
74
|
|
|
{ |
75
|
|
|
|
76
|
|
|
$parameters = [ |
77
|
|
|
'inline_message_id' => $inline_message_id, |
78
|
|
|
'text' => $text, |
79
|
|
|
'reply_markup' => $reply_markup, |
80
|
|
|
'parse_mode' => $parse_mode, |
81
|
|
|
'disable_web_page_preview' => $disable_web_preview, |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
return $this->execRequest('editMessageText?' . http_build_query($parameters)); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* \brief Edit only the inline keyboard of a message. |
89
|
|
|
* \details[API reference](https://core.telegram.org/bots/api#editmessagereplymarkup) |
90
|
|
|
* @param int $message_id Identifier of the message to edit |
91
|
|
|
* @param string $inline_keyboard Inlike keyboard array. [API reference](https://core.telegram.org/bots/api#inlinekeyboardmarkup) |
92
|
|
|
* @return Message|false Message edited, false otherwise. |
93
|
|
|
*/ |
94
|
|
|
public function editMessageReplyMarkup(int $message_id, string $inline_keyboard) |
95
|
|
|
{ |
96
|
|
|
|
97
|
|
|
$this->parameters = [ |
98
|
|
|
'chat_id' => $this->_chat_id, |
99
|
|
|
'message_id' => $message_id, |
100
|
|
|
'reply_markup' => $inline_keyboard, |
101
|
|
|
]; |
102
|
|
|
|
103
|
|
|
return $this->processRequest('editMessageReplyMarkup', 'Message'); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** @} */ |
107
|
|
|
} |
108
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.