-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendMessageMethod.php
126 lines (117 loc) · 5.21 KB
/
SendMessageMethod.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
namespace Kolirt\Telegram\Core\Methods\Messages;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Client\PendingRequest;
use Kolirt\Telegram\Core\Enums\ParseModeEnum;
use Kolirt\Telegram\Core\Telegram;
use Kolirt\Telegram\Core\Types\Keyboard\InlineKeyboardMarkupType;
use Kolirt\Telegram\Core\Types\Keyboard\ReplyKeyboardMarkupType;
use Kolirt\Telegram\Core\Types\Keyboard\ReplyKeyboardRemoveType;
/**
* @see https://core.telegram.org/bots/api#sendmessage
*/
trait SendMessageMethod
{
/**
* Use this method to send text messages. On success, the sent Message is returned.
*
* @param string|int $chat_id
* @param string $text
* @param string|null $business_connection_id
* @param int|null $message_thread_id
* @param ParseModeEnum|null $parse_mode
* @param bool|null $disable_notification
* @param bool|null $protect_content
* @param InlineKeyboardMarkupType|ReplyKeyboardMarkupType|ReplyKeyboardRemoveType|null $reply_markup
*
* @return SendMessageResponse
*
* @throws ConnectionException
* @throws GuzzleException
*/
public function sendMessage(
string|int $chat_id,
string $text,
string $business_connection_id = null,
int $message_thread_id = null,
ParseModeEnum|null $parse_mode = null,
// $entities = null,
// $link_preview_options = null,
bool $disable_notification = null,
bool $protect_content = null,
// $reply_parameters = null,
InlineKeyboardMarkupType|ReplyKeyboardMarkupType|ReplyKeyboardRemoveType|null $reply_markup = null,
): SendMessageResponse
{
$reply_markup_formatted = null;
if (!$reply_markup) {
if ($this->attached_keyboard) {
$reply_markup_formatted = $this->attached_keyboard->render();
}
} else {
$reply_markup_formatted = $reply_markup->render();
}
/**
* @var PendingRequest $this ->client
*/
$response = $this->client->post('sendMessage', request_params([
'business_connection_id' => $business_connection_id,
'chat_id' => $chat_id,
'message_thread_id' => $message_thread_id,
'text' => $text,
'parse_mode' => $parse_mode,
// 'entities' => $entities,
// 'link_preview_options' => $link_preview_options,
'disable_notification' => $disable_notification,
'protect_content' => $protect_content,
// 'reply_parameters' => $reply_parameters,
'reply_markup' => $reply_markup_formatted
]))->getBody();
return new SendMessageResponse(json_decode($response, true));
}
/**
* @param string $text
* @param string|null $business_connection_id
* @param int|null $message_thread_id
* @param ParseModeEnum|null $parse_mode
* @param bool|null $disable_notification
* @param bool|null $protect_content
* @param InlineKeyboardMarkupType|ReplyKeyboardMarkupType|ReplyKeyboardRemoveType|null $reply_markup
*
* @return SendMessageResponse
*
* @throws ConnectionException
* @throws GuzzleException
*/
public function reply(
string $text,
string $business_connection_id = null,
int $message_thread_id = null,
ParseModeEnum|null $parse_mode = null,
// $entities = null,
// $link_preview_options = null,
bool $disable_notification = null,
bool $protect_content = null,
// $reply_parameters = null,
InlineKeyboardMarkupType|ReplyKeyboardMarkupType|ReplyKeyboardRemoveType|null $reply_markup = null,
): SendMessageResponse
{
/**
* @var $this Telegram
*/
return $this->sendMessage(
chat_id: $this->getChatId(),
text: $text,
business_connection_id: $business_connection_id,
message_thread_id: $message_thread_id,
parse_mode: $parse_mode,
// entities: $entities,
// link_preview_options: $link_preview_options,
disable_notification: $disable_notification,
protect_content: $protect_content,
// reply_parameters: $reply_parameters,
reply_markup: $reply_markup,
);
}
}