forked from defstudio/telegraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Telegraph.php
executable file
·176 lines (150 loc) · 6.87 KB
/
Telegraph.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/** @noinspection PhpUnused */
/** @noinspection PhpDocMissingThrowsInspection */
/** @noinspection PhpUnhandledExceptionInspection */
namespace DefStudio\Telegraph;
use DefStudio\Telegraph\Client\TelegraphResponse;
use DefStudio\Telegraph\Concerns\AnswersInlineQueries;
use DefStudio\Telegraph\Concerns\CallTraitsMethods;
use DefStudio\Telegraph\Concerns\ComposesMessages;
use DefStudio\Telegraph\Concerns\CreatesScopedPayloads;
use DefStudio\Telegraph\Concerns\HasBotsAndChats;
use DefStudio\Telegraph\Concerns\InteractsWithCommands;
use DefStudio\Telegraph\Concerns\InteractsWithTelegram;
use DefStudio\Telegraph\Concerns\InteractsWithWebhooks;
use DefStudio\Telegraph\Concerns\InteractWithUsers;
use DefStudio\Telegraph\Concerns\ManagesKeyboards;
use DefStudio\Telegraph\Concerns\SendsAttachments;
use DefStudio\Telegraph\Concerns\StoresFiles;
use DefStudio\Telegraph\DTO\Attachment;
use Illuminate\Foundation\Bus\PendingDispatch;
use Illuminate\Support\Collection;
use Illuminate\Support\Traits\Conditionable;
class Telegraph
{
use CallTraitsMethods;
use InteractsWithTelegram;
use HasBotsAndChats;
use ComposesMessages;
use ManagesKeyboards;
use InteractsWithWebhooks;
use SendsAttachments;
use StoresFiles;
use AnswersInlineQueries;
use CreatesScopedPayloads;
use InteractWithUsers;
use InteractsWithCommands;
use Conditionable;
public const PARSE_HTML = 'html';
public const PARSE_MARKDOWN = 'markdown';
public const PARSE_MARKDOWNV2 = 'MarkdownV2';
protected const TELEGRAM_API_BASE_URL = 'https://api.telegram.org/bot';
protected const TELEGRAM_API_FILE_BASE_URL = 'https://api.telegram.org/file/bot';
public const ENDPOINT_GET_BOT_UPDATES = 'getUpdates';
public const ENDPOINT_GET_BOT_INFO = 'getMe';
public const ENDPOINT_REGISTER_BOT_COMMANDS = 'setMyCommands';
public const ENDPOINT_GET_REGISTERED_BOT_COMMANDS = 'getMyCommands';
public const ENDPOINT_UNREGISTER_BOT_COMMANDS = 'deleteMyCommands';
public const ENDPOINT_SET_WEBHOOK = 'setWebhook';
public const ENDPOINT_UNSET_WEBHOOK = 'deleteWebhook';
public const ENDPOINT_GET_WEBHOOK_DEBUG_INFO = 'getWebhookInfo';
public const ENDPOINT_ANSWER_WEBHOOK = 'answerCallbackQuery';
public const ENDPOINT_REPLACE_KEYBOARD = 'editMessageReplyMarkup';
public const ENDPOINT_MESSAGE = 'sendMessage';
public const ENDPOINT_DELETE_MESSAGE = 'deleteMessage';
public const ENDPOINT_DELETE_MESSAGES = 'deleteMessages';
public const ENDPOINT_PIN_MESSAGE = 'pinChatMessage';
public const ENDPOINT_UNPIN_MESSAGE = 'unpinChatMessage';
public const ENDPOINT_UNPIN_ALL_MESSAGES = 'unpinAllChatMessages';
public const ENDPOINT_EDIT_MESSAGE = 'editMessageText';
public const ENDPOINT_EDIT_CAPTION = 'editMessageCaption';
public const ENDPOINT_EDIT_MEDIA = 'editMessageMedia';
public const ENDPOINT_SEND_LOCATION = 'sendLocation';
public const ENDPOINT_SEND_ANIMATION = 'sendAnimation';
public const ENDPOINT_SEND_VOICE = 'sendVoice';
public const ENDPOINT_SEND_MEDIA_GROUP = 'sendMediaGroup';
public const ENDPOINT_SEND_CHAT_ACTION = 'sendChatAction';
public const ENDPOINT_SEND_DOCUMENT = 'sendDocument';
public const ENDPOINT_SEND_PHOTO = 'sendPhoto';
public const ENDPOINT_SEND_VIDEO = 'sendVideo';
public const ENDPOINT_SEND_AUDIO = 'sendAudio';
public const ENDPOINT_SEND_CONTACT = 'sendContact';
public const ENDPOINT_GET_FILE = 'getFile';
public const ENDPOINT_ANSWER_INLINE_QUERY = 'answerInlineQuery';
public const ENDPOINT_SET_CHAT_TITLE = 'setChatTitle';
public const ENDPOINT_SET_CHAT_DESCRIPTION = 'setChatDescription';
public const ENDPOINT_SET_CHAT_PHOTO = 'setChatPhoto';
public const ENDPOINT_SET_MESSAGE_REACTION = 'setMessageReaction';
public const ENDPOINT_DELETE_CHAT_PHOTO = 'deleteChatPhoto';
public const ENDPOINT_EXPORT_CHAT_INVITE_LINK = 'exportChatInviteLink';
public const ENDPOINT_CREATE_CHAT_INVITE_LINK = 'createChatInviteLink';
public const ENDPOINT_CREATE_FORUM_TOPIC = 'createForumTopic';
public const ENDPOINT_EDIT_FORUM_TOPIC = 'editForumTopic';
public const ENDPOINT_CLOSE_FORUM_TOPIC = 'closeForumTopic';
public const ENDPOINT_REOPEN_FORUM_TOPIC = 'reopenForumTopic';
public const ENDPOINT_DELETE_FORUM_TOPIC = 'deleteForumTopic';
public const ENDPOINT_EDIT_CHAT_INVITE_LINK = 'editChatInviteLink';
public const ENDPOINT_REVOKE_CHAT_INVITE_LINK = 'revokeChatInviteLink';
public const ENDPOINT_LEAVE_CHAT = 'leaveChat';
public const ENDPOINT_GET_CHAT_INFO = 'getChat';
public const ENDPOINT_GET_CHAT_MEMBER_COUNT = 'getChatMemberCount';
public const ENDPOINT_GET_CHAT_MEMBER = 'getChatMember';
public const ENDPOINT_GET_CHAT_ADMINISTRATORS = 'getChatAdministrators';
public const ENDPOINT_SET_CHAT_PERMISSIONS = 'setChatPermissions';
public const ENDPOINT_BAN_CHAT_MEMBER = 'banChatMember';
public const ENDPOINT_UNBAN_CHAT_MEMBER = 'unbanChatMember';
public const ENDPOINT_RESTRICT_CHAT_MEMBER = 'restrictChatMember';
public const ENDPOINT_PROMOTE_CHAT_MEMBER = 'promoteChatMember';
public const ENDPOINT_SEND_POLL = 'sendPoll';
public const ENDPOINT_FORWARD_MESSAGE = 'forwardMessage';
public const ENDPOINT_COPY_MESSAGE = 'copyMessage';
public const ENDPOINT_GET_USER_PROFILE_PHOTOS = 'getUserProfilePhotos';
public const ENDPOINT_SET_CHAT_MENU_BUTTON = 'setChatMenuButton';
public const ENDPOINT_GET_CHAT_MENU_BUTTON = 'getChatMenuButton';
public const ENDPOINT_DICE = 'sendDice';
public const ENDPOINT_SEND_STICKER = 'sendSticker';
public const ENDPOINT_SEND_VENUE = 'sendVenue';
public const ENDPOINT_APPROVE_CHAT_JOIN_REQUEST = 'approveChatJoinRequest';
public const ENDPOINT_DECLINE_CHAT_JOIN_REQUEST = 'declineChatJoinRequest';
/** @var array<string, mixed> */
protected array $data = [];
/** @var Collection<string, Attachment> */
protected Collection $files;
public function __construct()
{
$this->files = Collection::empty();
}
public function send(): TelegraphResponse
{
$response = $this->sendRequestToTelegram();
return TelegraphResponse::fromResponse($response);
}
public function dispatch(?string $queue = null): PendingDispatch
{
return $this->dispatchRequestToTelegram($queue);
}
/**
* @return never-returns
*/
public function dd(): void
{
dd($this->toArray());
}
public function dump(): Telegraph
{
dump($this->toArray());
return $this;
}
public function withData(string $key, mixed $value): static
{
$telegraph = clone $this;
data_set($telegraph->data, $key, $value);
return $telegraph;
}
public function inThread(int $thread_id): static
{
$telegraph = clone $this;
data_set($telegraph->data, 'message_thread_id', $thread_id);
return $telegraph;
}
}