-
Notifications
You must be signed in to change notification settings - Fork 3
/
core.clj
281 lines (235 loc) · 9.82 KB
/
core.clj
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
(ns telegrambot-lib.edit.core
"Telegram Bot API Updating/Modifying Messages - function implementations.
- <https://core.telegram.org/bots/api#updating-messages>
Most functions are multi-arity with the following options:
- Send all parameters in a 'content' map.
- Send only the required parameters as simple values.
- Send the required paraemters as simple values and then 'optional' parameters in a map."
(:gen-class)
(:require [telegrambot-lib.http :as http]))
(defn edit-message-text
"Use this method to edit text and game messages.
On success, if edited message is sent by the bot, the edited Message is
returned, otherwise True is returned.
Required
- this ; a bot instance
- chat_id ; target chat or username (@user)
- message_id ; id of message to edit
- text ; new text of message
Optional
- parse_mode ; entity parsing in message
- entities ; list of MessageEntity - can use instead of parse_mode
- disable_web_page_preview ; disable link previews
- reply_markup ; inline keyboard markup"
([this content]
(http/request this "editMessageText" content))
([this chat_id message_id text]
(let [content {:chat_id chat_id
:message_id message_id
:text text}]
(edit-message-text this content)))
([this chat_id message_id text & optional]
(let [content (merge (first optional)
{:chat_id chat_id
:message_id message_id
:text text})]
(edit-message-text this content))))
(defn edit-message-text-inline
"Use this method to edit inline text and game messages.
On success, if edited message is sent by the bot, the edited Message is
returned, otherwise True is returned.
Required
- this ; a bot instance
- inline_message_id ; id of the inline message
- text ; new text of message
Optional
- parse_mode ; entity parsing in message
- disable_web_page_preview ; disable link previews
- reply_markup ; inline keyboard markup"
([this content]
(http/request this "editMessageText" content))
([this inline_message_id text]
(let [content {:inline_message_id inline_message_id
:text text}]
(edit-message-text-inline this content)))
([this inline_message_id text & optional]
(let [content (merge (first optional)
{:inline_message_id inline_message_id
:text text})]
(edit-message-text-inline this content))))
(defn edit-message-caption
"Use this method to edit captions of messages.
On success, if edited message is sent by the bot, the edited Message is
returned, otherwise True is returned.
Required
- this ; a bot instance
- chat_id ; target chat or username (@user)
- message_id ; id of message to edit
- caption ; new caption of message
Optional
- parse_mode ; entity parsing in message
- caption_entities ; list of MessageEntity - can use instead of parse_mode
- reply_markup ; inline keyboard markup"
([this content]
(http/request this "editMessageCaption" content))
([this chat_id message_id caption]
(let [content {:chat_id chat_id
:message_id message_id
:caption caption}]
(edit-message-caption this content)))
([this chat_id message_id caption & optional]
(let [content (merge (first optional)
{:chat_id chat_id
:message_id message_id
:caption caption})]
(edit-message-caption this content))))
(defn edit-message-caption-inline
"Use this method to edit captions of inline messages.
On success, if edited message is sent by the bot, the edited Message is
returned, otherwise True is returned.
Required
- this ; a bot instance
- inline_message_id ; id of the inline message
- caption ; new caption of message
Optional
- parse_mode ; entity parsing in message
- reply_markup ; inline keyboard markup"
([this content]
(http/request this "editMessageCaption" content))
([this inline_message_id caption]
(let [content {:inline_message_id inline_message_id
:caption caption}]
(edit-message-caption-inline this content)))
([this inline_message_id caption & optional]
(let [content (merge (first optional)
{:inline_message_id inline_message_id
:caption caption})]
(edit-message-caption-inline this content))))
(defn edit-message-media
"Use this method to edit animation, audio, document, photo, or video messages.
If a message is a part of a message album, then it can be edited only to a
photo or a video. Otherwise, message type can be changed arbitrarily.
When inline message is edited, new file can't be uploaded.
Use previously uploaded file via its file_id or specify a URL.
On success, if the edited message was sent by the bot, the edited Message
is returned, otherwise True is returned.
Required
- this ; a bot instance
- chat_id ; target chat or username (@user)
- message_id ; id of message to edit
- media ; json object for new media content
Optional
- reply_markup ; inline keyboard markup"
([this content]
(http/request this "editMessageMedia" content))
([this chat_id message_id media]
(let [content {:chat_id chat_id
:message_id message_id
:media media}]
(edit-message-media this content)))
([this chat_id message_id media & optional]
(let [content (merge (first optional)
{:chat_id chat_id
:message_id message_id
:media media})]
(edit-message-media this content))))
(defn edit-message-media-inline
"Use this method to edit inline animation, audio, document, photo, or video messages.
If a message is a part of a message album, then it can be edited only to a
photo or a video. Otherwise, message type can be changed arbitrarily.
When inline message is edited, new file can't be uploaded.
Use previously uploaded file via its file_id or specify a URL.
On success, if the edited message was sent by the bot, the edited Message
is returned, otherwise True is returned.
Required
- this ; a bot instance
- inline_message_id ; id of the inline message
- media ; json object for new media content
Optional
- reply_markup ; inline keyboard markup"
([this content]
(http/request this "editMessageMedia" content))
([this inline_message_id media]
(let [content {:inline_message_id inline_message_id
:media media}]
(edit-message-media-inline this content)))
([this inline_message_id media & optional]
(let [content (merge (first optional)
{:inline_message_id inline_message_id
:media media})]
(edit-message-media-inline this content))))
(defn edit-message-reply-markup
"Use this method to edit only the reply markup of messages.
On success, if edited message is sent by the bot, the edited Message is
returned, otherwise True is returned.
Required
- this ; a bot instance
- chat_id ; target chat or username (@user)
- message_id ; id of message to edit
- reply_markup ; inline keyboard markup"
([this content]
(http/request this "editMessageReplyMarkup" content))
([this chat_id message_id reply_markup]
(let [content {:chat_id chat_id
:message_id message_id
:reply_markup reply_markup}]
(edit-message-reply-markup this content))))
(defn edit-message-reply-markup-inline
"Use this method to edit only the reply markup of inline messages.
On success, if edited message is sent by the bot, the edited Message is
returned, otherwise True is returned.
Required
- this ; a bot instance
- inline_message_id ; id of the inline message
- reply_markup ; inline keyboard markup"
([this content]
(http/request this "editMessageReplyMarkup" content))
([this inline_message_id reply_markup]
(let [content {:inline_message_id inline_message_id
:reply_markup reply_markup}]
(edit-message-reply-markup-inline this content))))
(defn stop-poll
"Use this method to stop a poll which was sent by the bot.
On success, the stopped Poll with the final results is returned.
Required
- this ; a bot instance
- chat_id ; target chat or username (@user)
- message_id ; id of original message with the poll
Optional
- reply_markup ; inline keyboard markup"
([this content]
(http/request this "stopPoll" content))
([this chat_id message_id]
(let [content {:chat_id chat_id
:message_id message_id}]
(stop-poll this content)))
([this chat_id message_id & optional]
(let [content (merge (first optional)
{:chat_id chat_id
:message_id message_id})]
(stop-poll this content))))
(defn delete-message
"Use this method to delete a message, including service messages.
Returns True on success.
Required
- this ; a bot instance
- chat_id ; target chat or username (@user)
- message_id ; id of message to delete"
([this content]
(http/request this "deleteMessage" content))
([this chat_id message_id]
(let [content {:chat_id chat_id
:message_id message_id}]
(delete-message this content))))
(def behavior
"Map for extending the core TBot record with functions."
{:edit-message-text edit-message-text
:edit-message-text-inline edit-message-text-inline
:edit-message-caption edit-message-caption
:edit-message-caption-inline edit-message-caption-inline
:edit-message-media edit-message-media
:edit-message-media-inline edit-message-media-inline
:edit-message-reply-markup edit-message-reply-markup
:edit-message-reply-markup-inline edit-message-reply-markup-inline
:stop-poll stop-poll
:delete-message delete-message})