@pipedream/telegram_bot_api 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/actions/create-chat-invite-link/create-chat-invite-link.mjs +52 -0
- package/actions/delete-message/delete-message.mjs +29 -0
- package/actions/edit-media-message/edit-media-message.mjs +89 -0
- package/actions/edit-text-message/edit-text-message.mjs +45 -0
- package/actions/export-chat-invite-link/export-chat-invite-link.mjs +23 -0
- package/actions/forward-message/forward-message.mjs +48 -0
- package/actions/get-num-members-in-chat/get-num-members-in-chat.mjs +23 -0
- package/actions/kick-chat-member/kick-chat-member.mjs +38 -0
- package/actions/list-administrators-in-chat/list-administrators-in-chat.mjs +25 -0
- package/actions/list-chats/list-chats.mjs +73 -0
- package/actions/list-updates/list-updates.mjs +49 -0
- package/actions/pin-message/pin-message.mjs +37 -0
- package/actions/promote-chat-member/promote-chat-member.mjs +86 -0
- package/actions/restrict-chat-member/restrict-chat-member.mjs +66 -0
- package/actions/send-album/send-album.mjs +53 -0
- package/actions/send-audio-file/send-audio-file.mjs +98 -0
- package/actions/send-document-or-image/send-document-or-image.mjs +83 -0
- package/actions/send-media-by-url-or-id/send-media-by-url-or-id.mjs +73 -0
- package/actions/send-photo/send-photo.mjs +84 -0
- package/actions/send-sticker/send-sticker.mjs +53 -0
- package/actions/send-text-message-or-reply/send-text-message-or-reply.mjs +66 -0
- package/actions/send-video/send-video.mjs +86 -0
- package/actions/send-video-note/send-video-note.mjs +76 -0
- package/actions/send-voice-message/send-voice-message.mjs +85 -0
- package/actions/unpin-message/unpin-message.mjs +29 -0
- package/constants.mjs +198 -0
- package/content-types.mjs +115 -0
- package/env.mjs +14 -0
- package/package.json +21 -0
- package/sources/channel-updates/channel-updates.mjs +50 -0
- package/sources/message-updates/message-updates.mjs +50 -0
- package/sources/new-updates/new-updates.mjs +63 -0
- package/telegram_bot_api.app.mjs +682 -0
- package/update-types.mjs +50 -0
- package/utils.mjs +27 -0
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
import "./env.mjs";
|
|
2
|
+
import TelegramBot from "node-telegram-bot-api";
|
|
3
|
+
import { axios } from "@pipedream/platform";
|
|
4
|
+
import {
|
|
5
|
+
TELEGRAM_BOT_API_UI_MEDIA_AUDIO,
|
|
6
|
+
TELEGRAM_BOT_API_UI_MEDIA_DOCUMENT,
|
|
7
|
+
TELEGRAM_BOT_API_UI_MEDIA_PHOTO,
|
|
8
|
+
TELEGRAM_BOT_API_UI_MEDIA_VIDEO,
|
|
9
|
+
TELEGRAM_BOT_API_UI_MEDIA_VIDEO_NOTE,
|
|
10
|
+
TELEGRAM_BOT_API_UI_MEDIA_STICKER,
|
|
11
|
+
TELEGRAM_BOT_API_UI_MEDIA_VOICE,
|
|
12
|
+
TELEGRAM_BOT_API_FORMATTING_MODES,
|
|
13
|
+
} from "./constants.mjs";
|
|
14
|
+
import updateTypes from "./update-types.mjs";
|
|
15
|
+
import { toSingleLineString } from "./utils.mjs";
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
type: "app",
|
|
19
|
+
app: "telegram_bot_api",
|
|
20
|
+
propDefinitions: {
|
|
21
|
+
updateTypes: {
|
|
22
|
+
type: "string[]",
|
|
23
|
+
label: "Update Types",
|
|
24
|
+
optional: true,
|
|
25
|
+
description:
|
|
26
|
+
"Only emit events for the selected update types.",
|
|
27
|
+
options: updateTypes,
|
|
28
|
+
},
|
|
29
|
+
chatId: {
|
|
30
|
+
type: "string",
|
|
31
|
+
label: "Chat ID",
|
|
32
|
+
description: toSingleLineString(`
|
|
33
|
+
Enter the unique identifier for the target chat (e.g. \`1035597319\`) or username of the
|
|
34
|
+
target public chat (in the format \`@channelusername\` or \`@supergroupusername\`). For
|
|
35
|
+
example, if the group's public link is \`t.me/mygroup\`, the username is \`@mygroup\`.
|
|
36
|
+
`),
|
|
37
|
+
},
|
|
38
|
+
text: {
|
|
39
|
+
type: "string",
|
|
40
|
+
label: "Text",
|
|
41
|
+
description: "Enter or map the message text to send.",
|
|
42
|
+
optional: true,
|
|
43
|
+
},
|
|
44
|
+
parse_mode: {
|
|
45
|
+
type: "string",
|
|
46
|
+
label: "Parse Mode",
|
|
47
|
+
description: toSingleLineString(`
|
|
48
|
+
Select [MarkdownV2-style](https://core.telegram.org/bots/api#markdownv2-style),
|
|
49
|
+
[HTML-style](https://core.telegram.org/bots/api#html-style), or
|
|
50
|
+
[Markdown-style](https://core.telegram.org/bots/api#markdown-style) of the text if you want
|
|
51
|
+
Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
|
|
52
|
+
`),
|
|
53
|
+
options: TELEGRAM_BOT_API_FORMATTING_MODES,
|
|
54
|
+
optional: true,
|
|
55
|
+
},
|
|
56
|
+
disable_notification: {
|
|
57
|
+
type: "boolean",
|
|
58
|
+
label: "Disable Notifications",
|
|
59
|
+
description: toSingleLineString(`
|
|
60
|
+
Choose if to send the message silently. iOS users will not receive a notification, Android
|
|
61
|
+
users will receive a notification with no sound.
|
|
62
|
+
`),
|
|
63
|
+
optional: true,
|
|
64
|
+
},
|
|
65
|
+
disable_web_page_preview: {
|
|
66
|
+
type: "boolean",
|
|
67
|
+
label: "Disable Link Previews",
|
|
68
|
+
description: "Choose if to disable link previews for links in this message.",
|
|
69
|
+
optional: true,
|
|
70
|
+
},
|
|
71
|
+
reply_to_message_id: {
|
|
72
|
+
type: "string",
|
|
73
|
+
label: "Original Message ID",
|
|
74
|
+
description: "Enter the ID of the original message.",
|
|
75
|
+
optional: true,
|
|
76
|
+
},
|
|
77
|
+
reply_markup: {
|
|
78
|
+
type: "string",
|
|
79
|
+
label: "Reply Markup",
|
|
80
|
+
description: toSingleLineString(`
|
|
81
|
+
Enter additional interface options that are a JSON-serialized object including an [inline
|
|
82
|
+
keyboard](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating), a
|
|
83
|
+
[custom reply keyboard](https://core.telegram.org/bots#keyboards), instructions to remove
|
|
84
|
+
the reply keyboard or instructions to force a reply from the user, e.g.
|
|
85
|
+
\`{"inline_keyboard":[[{"text":"Some button text 2","url":"https://botpress.org"}]]}\` or
|
|
86
|
+
\`{"keyboard":[["Yes","No"],["Maybe"]]}\`. Note: keyboard cannot be used with channels. [See
|
|
87
|
+
the docs](https://core.telegram.org/bots/api#inlinekeyboardmarkup) for more information.
|
|
88
|
+
`),
|
|
89
|
+
optional: true,
|
|
90
|
+
},
|
|
91
|
+
messageId: {
|
|
92
|
+
type: "string",
|
|
93
|
+
label: "Message ID",
|
|
94
|
+
description: "Enter the message ID.",
|
|
95
|
+
},
|
|
96
|
+
fromChatId: {
|
|
97
|
+
type: "string",
|
|
98
|
+
label: "From Chat ID",
|
|
99
|
+
description: toSingleLineString(`
|
|
100
|
+
Enter the unique identifier for the chat where the original message was sent (or channel
|
|
101
|
+
username in the format \`@channelusername\`).
|
|
102
|
+
`),
|
|
103
|
+
optional: true,
|
|
104
|
+
},
|
|
105
|
+
caption: {
|
|
106
|
+
type: "string",
|
|
107
|
+
label: "Caption",
|
|
108
|
+
description: "Enter the caption.",
|
|
109
|
+
optional: true,
|
|
110
|
+
},
|
|
111
|
+
filename: {
|
|
112
|
+
type: "string",
|
|
113
|
+
label: "File Name",
|
|
114
|
+
description: "Enter a filename.",
|
|
115
|
+
optional: true,
|
|
116
|
+
},
|
|
117
|
+
media: {
|
|
118
|
+
type: "string",
|
|
119
|
+
label: "Media File Source",
|
|
120
|
+
description: toSingleLineString(`
|
|
121
|
+
File to send. Pass a file_id to send a file that exists on the Telegram servers, pass an
|
|
122
|
+
HTTP URL for Telegram to get a file from the Internet, or pass the path to the file (e.g.,
|
|
123
|
+
\`/tmp/myFile.ext\`) to upload a new one using a file [downloaded to
|
|
124
|
+
\`/tmp\`](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#download-a-file-to-tmp).
|
|
125
|
+
File must meet Telegram's [requirements](https://core.telegram.org/bots/api#sending-files)
|
|
126
|
+
for MIME type and size.
|
|
127
|
+
`),
|
|
128
|
+
},
|
|
129
|
+
duration: {
|
|
130
|
+
type: "integer",
|
|
131
|
+
label: "Duration",
|
|
132
|
+
description: "Enter duration of sent video in seconds.",
|
|
133
|
+
optional: true,
|
|
134
|
+
},
|
|
135
|
+
performer: {
|
|
136
|
+
type: "string",
|
|
137
|
+
label: "Performer",
|
|
138
|
+
description: "Enter a performer.",
|
|
139
|
+
optional: true,
|
|
140
|
+
},
|
|
141
|
+
title: {
|
|
142
|
+
type: "string",
|
|
143
|
+
label: "Title",
|
|
144
|
+
description: "Enter a track name.",
|
|
145
|
+
optional: true,
|
|
146
|
+
},
|
|
147
|
+
contentType: {
|
|
148
|
+
type: "string",
|
|
149
|
+
label: "Content Type",
|
|
150
|
+
description: "Select or enter the MIME type of data.",
|
|
151
|
+
optional: true,
|
|
152
|
+
},
|
|
153
|
+
width: {
|
|
154
|
+
type: "integer",
|
|
155
|
+
label: "Width",
|
|
156
|
+
description: "Enter the video width.",
|
|
157
|
+
optional: true,
|
|
158
|
+
},
|
|
159
|
+
height: {
|
|
160
|
+
type: "integer",
|
|
161
|
+
label: "Height",
|
|
162
|
+
description: "Enter the video height.",
|
|
163
|
+
optional: true,
|
|
164
|
+
},
|
|
165
|
+
length: {
|
|
166
|
+
type: "integer",
|
|
167
|
+
label: "Length",
|
|
168
|
+
description: "Enter the video width and height, i.e. diameter of the video message, in pixels (px).",
|
|
169
|
+
optional: true,
|
|
170
|
+
},
|
|
171
|
+
type: {
|
|
172
|
+
type: "string",
|
|
173
|
+
label: "Media Type",
|
|
174
|
+
description: "Select the media type.",
|
|
175
|
+
options: [
|
|
176
|
+
TELEGRAM_BOT_API_UI_MEDIA_PHOTO,
|
|
177
|
+
TELEGRAM_BOT_API_UI_MEDIA_VIDEO,
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
offset: {
|
|
181
|
+
type: "string",
|
|
182
|
+
label: "Start offset (Update ID)",
|
|
183
|
+
description: toSingleLineString(`
|
|
184
|
+
Enter the update ID <1, last update ID> you want to list from. Note: you can use this field
|
|
185
|
+
to set your pagination - map last update ID from the result and increase this value by one
|
|
186
|
+
to get next page.
|
|
187
|
+
`),
|
|
188
|
+
optional: true,
|
|
189
|
+
},
|
|
190
|
+
limit: {
|
|
191
|
+
type: "integer",
|
|
192
|
+
label: "Limit",
|
|
193
|
+
description: "Limits the number of updates to be retrieved <1-100>.",
|
|
194
|
+
optional: true,
|
|
195
|
+
},
|
|
196
|
+
autoPaging: {
|
|
197
|
+
type: "boolean",
|
|
198
|
+
label: "Confirm processed requests by increasing the offset in the Telegram server [auto-paging]",
|
|
199
|
+
description: toSingleLineString(`
|
|
200
|
+
Check if to increasing the offset for the next request automatically. Caution: updates
|
|
201
|
+
listed with \`auto-paging\` can be listed only once.
|
|
202
|
+
`),
|
|
203
|
+
optional: true,
|
|
204
|
+
},
|
|
205
|
+
userId: {
|
|
206
|
+
type: "string",
|
|
207
|
+
label: "User ID",
|
|
208
|
+
description: "Enter the unique identifier of the target user.",
|
|
209
|
+
optional: true,
|
|
210
|
+
},
|
|
211
|
+
until_date: {
|
|
212
|
+
type: "string",
|
|
213
|
+
label: "Until Date",
|
|
214
|
+
description: toSingleLineString(`
|
|
215
|
+
Enter the date when the restrictions on the user will be lifted, in [unix
|
|
216
|
+
time](https://en.wikipedia.org/wiki/Unix_time) (e.g. \`1567780450\`).
|
|
217
|
+
`),
|
|
218
|
+
optional: true,
|
|
219
|
+
},
|
|
220
|
+
link_name: {
|
|
221
|
+
type: "string",
|
|
222
|
+
label: "Invite link name",
|
|
223
|
+
description: toSingleLineString(`
|
|
224
|
+
Invite link name; 0-32 characters
|
|
225
|
+
`),
|
|
226
|
+
optional: true,
|
|
227
|
+
},
|
|
228
|
+
expire_date: {
|
|
229
|
+
type: "integer",
|
|
230
|
+
label: "Invite link expire date",
|
|
231
|
+
description: toSingleLineString(`
|
|
232
|
+
Point in time (Unix timestamp) when the link will expire, in [unix
|
|
233
|
+
time](https://en.wikipedia.org/wiki/Unix_time) (e.g. \`1567780450\`).
|
|
234
|
+
`),
|
|
235
|
+
optional: true,
|
|
236
|
+
},
|
|
237
|
+
member_limit: {
|
|
238
|
+
type: "integer",
|
|
239
|
+
label: "Maximum number of users",
|
|
240
|
+
description: toSingleLineString(`
|
|
241
|
+
Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
|
|
242
|
+
`),
|
|
243
|
+
optional: true,
|
|
244
|
+
},
|
|
245
|
+
creates_join_request: {
|
|
246
|
+
type: "boolean",
|
|
247
|
+
label: "Creates join request",
|
|
248
|
+
description: toSingleLineString(`
|
|
249
|
+
True, if users joining the chat via the link need to be approved by chat administrators.
|
|
250
|
+
If True, member_limit can't be specified
|
|
251
|
+
`),
|
|
252
|
+
optional: true,
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
methods: {
|
|
256
|
+
_getBaseUrl() {
|
|
257
|
+
return `https://api.telegram.org/bot${this.$auth.token}`;
|
|
258
|
+
},
|
|
259
|
+
_getHeaders() {
|
|
260
|
+
return {
|
|
261
|
+
"Accept": "application/json",
|
|
262
|
+
"Content-Type": "application/json",
|
|
263
|
+
};
|
|
264
|
+
},
|
|
265
|
+
/**
|
|
266
|
+
* Returns an instance of the Telegram Bot SDK authenticated with the bot's
|
|
267
|
+
* token
|
|
268
|
+
*
|
|
269
|
+
* @returns The Telegram Bot object
|
|
270
|
+
*/
|
|
271
|
+
sdk() {
|
|
272
|
+
return new TelegramBot(this.$auth.token, {
|
|
273
|
+
polling: false,
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
async createHook(url, allowedUpdates) {
|
|
277
|
+
const config = {
|
|
278
|
+
method: "POST",
|
|
279
|
+
url: `${this._getBaseUrl()}/setWebhook`,
|
|
280
|
+
headers: this._getHeaders(),
|
|
281
|
+
data: {
|
|
282
|
+
url: `${url}/${this.$auth.token}`,
|
|
283
|
+
allowed_updates: allowedUpdates,
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
return axios(this, config);
|
|
287
|
+
},
|
|
288
|
+
async deleteHook() {
|
|
289
|
+
const config = {
|
|
290
|
+
method: "GET",
|
|
291
|
+
url: `${await this._getBaseUrl()}/deleteWebhook`,
|
|
292
|
+
headers: await this._getHeaders(),
|
|
293
|
+
};
|
|
294
|
+
return axios(this, config);
|
|
295
|
+
},
|
|
296
|
+
/**
|
|
297
|
+
* Send a text message
|
|
298
|
+
*
|
|
299
|
+
* @param {String} chatId - Unique identifier for the target chat or
|
|
300
|
+
* username of the target channel (in the format `@channelusername`)
|
|
301
|
+
* @param {String} text - Text of the message to be sent, 1-4096 characters
|
|
302
|
+
* after entities parsing
|
|
303
|
+
* @param {Object} [opts] - An object containing additional configuration
|
|
304
|
+
* options for this method, as defined in [the API
|
|
305
|
+
* docs](https://core.telegram.org/bots/api#sendmessage)
|
|
306
|
+
* @returns The sent Message
|
|
307
|
+
*/
|
|
308
|
+
async sendMessage(chatId, text, opts) {
|
|
309
|
+
return this.sdk().sendMessage(chatId, text, opts);
|
|
310
|
+
},
|
|
311
|
+
/**
|
|
312
|
+
* Edit a text message
|
|
313
|
+
*
|
|
314
|
+
* One of chat_id, message_id, or inline_message_id must be provided in the
|
|
315
|
+
* `opts` parameter
|
|
316
|
+
*
|
|
317
|
+
* @param {String} text - New text of the message
|
|
318
|
+
* @param {Object} [opts] - An object containing additional configuration
|
|
319
|
+
* options for this method
|
|
320
|
+
* @param {Number|String} [opts.chatId] - Required if `inline_message_id` is
|
|
321
|
+
* not specified. Unique identifier for the target chat or username of the
|
|
322
|
+
* target channel (in the format `@channelusername`)
|
|
323
|
+
* @param {Number|String} [opts.messageId] - Required if inline_message_id
|
|
324
|
+
* is not specified. Identifier of the message to edit
|
|
325
|
+
* @param {Number|String} [opts.inlineMessageId] - Required if chat_id and
|
|
326
|
+
* message_id are not specified. Identifier of the inline message
|
|
327
|
+
* @param {...*} [opts.extraOpts] - Additional Telegram query options to be
|
|
328
|
+
* fed to the Telegram Bot API call, as defined in [the API
|
|
329
|
+
* docs](https://core.telegram.org/bots/api#editmessagetext)
|
|
330
|
+
* @returns The edited Message
|
|
331
|
+
*/
|
|
332
|
+
async editMessageText(text, opts) {
|
|
333
|
+
const {
|
|
334
|
+
chatId,
|
|
335
|
+
messageId,
|
|
336
|
+
inlineMessageId,
|
|
337
|
+
...extraOpts
|
|
338
|
+
} = opts;
|
|
339
|
+
const hasChatIdAndMessageId = chatId && messageId;
|
|
340
|
+
if (!hasChatIdAndMessageId && !inlineMessageId) {
|
|
341
|
+
throw new Error("chatId, messageId, or inlineMessageId is required");
|
|
342
|
+
}
|
|
343
|
+
return this.sdk().editMessageText(text, {
|
|
344
|
+
chat_id: chatId,
|
|
345
|
+
message_id: messageId,
|
|
346
|
+
inline_message_id: inlineMessageId,
|
|
347
|
+
...extraOpts,
|
|
348
|
+
});
|
|
349
|
+
},
|
|
350
|
+
/**
|
|
351
|
+
* Forward a message of any kind
|
|
352
|
+
*
|
|
353
|
+
* @param {Number|String} chatId - Unique identifier for the message
|
|
354
|
+
* recipient
|
|
355
|
+
* @param {Number|String} fromChatId - Unique identifier for the chat where
|
|
356
|
+
* the original message was sent
|
|
357
|
+
* @param {Number|String} messageId - Unique message identifier
|
|
358
|
+
* @param {Object} [opts] - Additional Telegram query options to be fed to
|
|
359
|
+
* the Telegram Bot API call, as defined in [the API
|
|
360
|
+
* docs](https://core.telegram.org/bots/api#forwardmessage)
|
|
361
|
+
* @return The sent message
|
|
362
|
+
*/
|
|
363
|
+
async forwardMessage(chatId, fromChatId, messageId, opts) {
|
|
364
|
+
return this.sdk().forwardMessage(chatId, fromChatId, messageId, opts);
|
|
365
|
+
},
|
|
366
|
+
/**
|
|
367
|
+
* Delete a message
|
|
368
|
+
*
|
|
369
|
+
* @param {Number|String} chatId - Unique identifier of the target chat
|
|
370
|
+
* @param {Number} messageId - Unique identifier of the target message
|
|
371
|
+
* @returns `True` on success
|
|
372
|
+
*/
|
|
373
|
+
async deleteMessage(chatId, messageId) {
|
|
374
|
+
return this.sdk().deleteMessage(chatId, messageId);
|
|
375
|
+
},
|
|
376
|
+
/**
|
|
377
|
+
* Use this method to add a message to the list of pinned messages in a
|
|
378
|
+
* chat. If the chat is not a private chat, the bot must be an administrator
|
|
379
|
+
* in the chat for this to work and must have the 'can_pin_messages' admin
|
|
380
|
+
* right in a supergroup or 'can_edit_messages' admin right in a channel.
|
|
381
|
+
*
|
|
382
|
+
* @param {Number|String} chatId - Unique identifier for the message
|
|
383
|
+
* recipient
|
|
384
|
+
* @param {Number} messageId - Identifier of a message to pin
|
|
385
|
+
* @param {Object} [opts] - Additional Telegram query options to be fed to
|
|
386
|
+
* the Telegram Bot API call, as defined in [the API
|
|
387
|
+
* docs](https://core.telegram.org/bots/api#pinchatmessage)
|
|
388
|
+
* @return `True` on success
|
|
389
|
+
*/
|
|
390
|
+
async pinChatMessage(chatId, messageId, opts) {
|
|
391
|
+
return this.sdk().pinChatMessage(chatId, messageId, opts);
|
|
392
|
+
},
|
|
393
|
+
/**
|
|
394
|
+
* Use this method to remove a message from the list of pinned messages in a
|
|
395
|
+
* chat. If the chat is not a private chat, the bot must be an administrator
|
|
396
|
+
* in the chat for this to work and must have the 'can_pin_messages' admin
|
|
397
|
+
* right in a supergroup or 'can_edit_messages' admin right in a channel.
|
|
398
|
+
*
|
|
399
|
+
* @param {Number|String} chatId - Unique identifier for the message
|
|
400
|
+
* recipient
|
|
401
|
+
* @param {Object} [opts] - Additional Telegram query options to be fed to
|
|
402
|
+
* the Telegram Bot API call, as defined in [the API
|
|
403
|
+
* docs](https://core.telegram.org/bots/api#unpinchatmessage)
|
|
404
|
+
* @return `True` on success
|
|
405
|
+
*/
|
|
406
|
+
async unpinChatMessage(chatId, messageId) {
|
|
407
|
+
return this.sdk().unpinChatMessage(chatId, {
|
|
408
|
+
message_id: messageId,
|
|
409
|
+
});
|
|
410
|
+
},
|
|
411
|
+
/**
|
|
412
|
+
* Send a file (Document/Image, Photo, Audio, Video, Video Note, Voice,
|
|
413
|
+
* Sticker)
|
|
414
|
+
*
|
|
415
|
+
* @param {Function} sendFn - the function to use to send the media
|
|
416
|
+
* @param {String} chatId - Unique identifier for the target chat or
|
|
417
|
+
* username of the target channel (in the format `@channelusername`)
|
|
418
|
+
* @param {String|stream.Stream|Buffer} media - A file path or a Stream. Can
|
|
419
|
+
* also be a `file_id` previously uploaded
|
|
420
|
+
* @param {Object} [opts] - An object containing additional configuration
|
|
421
|
+
* options for this method
|
|
422
|
+
* @param {Number|String} [opts.filename] - The name of the file to send
|
|
423
|
+
* @param {Number|String} [opts.contentType] - The MIME type of the file to
|
|
424
|
+
* send
|
|
425
|
+
* @param {...*} [opts.extraOpts] - Additional Telegram query options to be
|
|
426
|
+
* fed to the Telegram Bot API call, as defined in [the API
|
|
427
|
+
* docs](https://core.telegram.org/bots/api)
|
|
428
|
+
* @returns {Promise<TelegramBot.Message>} The sent message
|
|
429
|
+
*/
|
|
430
|
+
async sendMedia(sendFn, chatId, media, opts) {
|
|
431
|
+
const {
|
|
432
|
+
filename,
|
|
433
|
+
contentType,
|
|
434
|
+
...extraOpts
|
|
435
|
+
} = opts;
|
|
436
|
+
return sendFn(chatId, media, extraOpts, {
|
|
437
|
+
filename,
|
|
438
|
+
contentType,
|
|
439
|
+
});
|
|
440
|
+
},
|
|
441
|
+
async sendAudio(chatId, audio, opts) {
|
|
442
|
+
const sdk = this.sdk();
|
|
443
|
+
return this.sendMedia(sdk.sendAudio.bind(sdk), chatId, audio, opts);
|
|
444
|
+
},
|
|
445
|
+
async sendDocument(chatId, doc, opts) {
|
|
446
|
+
const sdk = this.sdk();
|
|
447
|
+
return this.sendMedia(sdk.sendDocument.bind(sdk), chatId, doc, opts);
|
|
448
|
+
},
|
|
449
|
+
async sendPhoto(chatId, photo, opts) {
|
|
450
|
+
const sdk = this.sdk();
|
|
451
|
+
return this.sendMedia(sdk.sendPhoto.bind(sdk), chatId, photo, opts);
|
|
452
|
+
},
|
|
453
|
+
async sendSticker(chatId, sticker, opts) {
|
|
454
|
+
const sdk = this.sdk();
|
|
455
|
+
return this.sendMedia(sdk.sendSticker.bind(sdk), chatId, sticker, opts);
|
|
456
|
+
},
|
|
457
|
+
async sendVideo(chatId, video, opts) {
|
|
458
|
+
const sdk = this.sdk();
|
|
459
|
+
return this.sendMedia(sdk.sendVideo.bind(sdk), chatId, video, opts);
|
|
460
|
+
},
|
|
461
|
+
async sendVideoNote(chatId, videoNote, opts) {
|
|
462
|
+
const sdk = this.sdk();
|
|
463
|
+
return this.sendMedia(sdk.sendVideoNote.bind(sdk), chatId, videoNote, opts);
|
|
464
|
+
},
|
|
465
|
+
async sendVoice(chatId, voice, opts) {
|
|
466
|
+
const sdk = this.sdk();
|
|
467
|
+
return this.sendMedia(sdk.sendVoice.bind(sdk), chatId, voice, opts);
|
|
468
|
+
},
|
|
469
|
+
/**
|
|
470
|
+
* Send a file (Document/Image, Photo, Audio, Video, Video Note, Voice,
|
|
471
|
+
* Sticker) as the media type specified by the `type` parameter
|
|
472
|
+
*
|
|
473
|
+
* @typedef {import("./constants.js").UIMediaType} UIMediaType
|
|
474
|
+
*
|
|
475
|
+
* @param {UIMediaType} type - The media type of the file
|
|
476
|
+
* @param {String} chatId - Unique identifier for the target chat or
|
|
477
|
+
* username of the target channel (in the format `@channelusername`)
|
|
478
|
+
* @param {String|stream.Stream|Buffer} media - A file path or a Stream. Can
|
|
479
|
+
* also be a `file_id` previously uploaded
|
|
480
|
+
* @param {Object} [opts] - An object containing additional configuration
|
|
481
|
+
* options for this method
|
|
482
|
+
* @param {Number|String} [opts.filename] - The name of the file to send
|
|
483
|
+
* @param {Number|String} [opts.contentType] - The MIME type of the file to
|
|
484
|
+
* send
|
|
485
|
+
* @param {...*} [opts.extraOpts] - Additional Telegram query options to be
|
|
486
|
+
* fed to the Telegram Bot API call, as defined in [the API
|
|
487
|
+
* docs](https://core.telegram.org/bots/api)
|
|
488
|
+
* @returns {Promise<TelegramBot.Message>} The sent message
|
|
489
|
+
*/
|
|
490
|
+
async sendMediaByType(type, chatId, media, opts) {
|
|
491
|
+
const typeToSendMediaFn = {
|
|
492
|
+
[TELEGRAM_BOT_API_UI_MEDIA_DOCUMENT]: this.sendDocument,
|
|
493
|
+
[TELEGRAM_BOT_API_UI_MEDIA_PHOTO]: this.sendPhoto,
|
|
494
|
+
[TELEGRAM_BOT_API_UI_MEDIA_AUDIO]: this.sendAudio,
|
|
495
|
+
[TELEGRAM_BOT_API_UI_MEDIA_VIDEO]: this.sendVideo,
|
|
496
|
+
[TELEGRAM_BOT_API_UI_MEDIA_VIDEO_NOTE]: this.sendVideoNote,
|
|
497
|
+
[TELEGRAM_BOT_API_UI_MEDIA_VOICE]: this.sendVoice,
|
|
498
|
+
[TELEGRAM_BOT_API_UI_MEDIA_STICKER]: this.sendSticker,
|
|
499
|
+
};
|
|
500
|
+
if (!typeToSendMediaFn[type]) {
|
|
501
|
+
throw new Error("type is not a valid file media type");
|
|
502
|
+
}
|
|
503
|
+
return typeToSendMediaFn[type](chatId, media, opts);
|
|
504
|
+
},
|
|
505
|
+
/**
|
|
506
|
+
* Use this method to send a group of photos or videos as an album. On success, an array of the
|
|
507
|
+
* sent [Messages](https://core.telegram.org/bots/api#message) is returned.
|
|
508
|
+
*
|
|
509
|
+
* @param {String} chatId - Unique identifier for the target chat or
|
|
510
|
+
* username of the target channel (in the format `@channelusername`)
|
|
511
|
+
* @param {Array} media A JSON-serialized array describing photos and videos to be sent, must
|
|
512
|
+
* include 2–10 items
|
|
513
|
+
* @param {Object} [options] Additional Telegram query options
|
|
514
|
+
* @return {Promise}
|
|
515
|
+
*/
|
|
516
|
+
async sendMediaGroup(chatId, media, opts) {
|
|
517
|
+
return this.sdk().sendMediaGroup(chatId, media, opts);
|
|
518
|
+
},
|
|
519
|
+
/**
|
|
520
|
+
* Use this method to edit audio, document, photo, or video messages. If a
|
|
521
|
+
* message is a part of a message album, then it can be edited only to a
|
|
522
|
+
* photo or a video. Otherwise, message type can be changed arbitrarily.
|
|
523
|
+
* When inline message is edited, new file can't be uploaded. Use previously
|
|
524
|
+
* uploaded file via its file_id or specify a URL.
|
|
525
|
+
*
|
|
526
|
+
* One of chat_id, message_id, or inline_message_id must be provided in the
|
|
527
|
+
* `opts` object param.
|
|
528
|
+
*
|
|
529
|
+
* @param {Object} media - A JSON-serialized object for a new media content
|
|
530
|
+
* of the message, as specified in [the API
|
|
531
|
+
* docs](https://core.telegram.org/bots/api#editmessagemedia)
|
|
532
|
+
* @param {Object} [opts] - Additional Telegram query options (one of
|
|
533
|
+
* chat_id, message_id, or inline_message_is required)
|
|
534
|
+
* @param {Number|String} [opts.chatId] - Required if `inline_message_id` is
|
|
535
|
+
* not specified. Unique identifier for the target chat or username of the
|
|
536
|
+
* target channel (in the format `@channelusername`)
|
|
537
|
+
* @param {Number|String} [opts.messageId] - Required if inline_message_id
|
|
538
|
+
* is not specified. Identifier of the message to edit
|
|
539
|
+
* @param {Number|String} [opts.inlineMessageId] - Required if chat_id and
|
|
540
|
+
* message_id are not specified. Identifier of the inline message
|
|
541
|
+
* @param {...*} [opts.extraOpts] - Additional Telegram query options to be
|
|
542
|
+
* fed to the Telegram Bot API call, as defined in [the API
|
|
543
|
+
* docs](https://core.telegram.org/bots/api#editmessagemedia)
|
|
544
|
+
* @returns The edited Message if the edited message is not an inline
|
|
545
|
+
* message, otherwise `true`
|
|
546
|
+
*/
|
|
547
|
+
async editMessageMedia(media, opts) {
|
|
548
|
+
const {
|
|
549
|
+
chatId,
|
|
550
|
+
messageId,
|
|
551
|
+
inlineMessageId,
|
|
552
|
+
...extraOpts
|
|
553
|
+
} = opts;
|
|
554
|
+
const hasChatIdAndMessageId = chatId && messageId;
|
|
555
|
+
if (!hasChatIdAndMessageId && !inlineMessageId) {
|
|
556
|
+
throw new Error("chatId, messageId, or inlineMessageId is required");
|
|
557
|
+
}
|
|
558
|
+
return this.sdk().editMessageMedia(media, {
|
|
559
|
+
chat_id: chatId,
|
|
560
|
+
message_id: messageId,
|
|
561
|
+
inline_message_id: inlineMessageId,
|
|
562
|
+
...extraOpts,
|
|
563
|
+
});
|
|
564
|
+
},
|
|
565
|
+
/**
|
|
566
|
+
* Use this method to receive incoming updates using long polling
|
|
567
|
+
*
|
|
568
|
+
* @param {Object} [opts] - Additional Telegram query options to be fed to
|
|
569
|
+
* the Telegram Bot API call, as defined in [the API
|
|
570
|
+
* docs](https://core.telegram.org/bots/api#getupdates)
|
|
571
|
+
* @returns An Array of Update objects
|
|
572
|
+
*/
|
|
573
|
+
async getUpdates(opts) {
|
|
574
|
+
return this.sdk().getUpdates(opts);
|
|
575
|
+
},
|
|
576
|
+
/**
|
|
577
|
+
* Use this method to get a list of administrators in a chat
|
|
578
|
+
*
|
|
579
|
+
* @param {Number|String} chatId - Unique identifier for the target group or
|
|
580
|
+
* username of the target supergroup
|
|
581
|
+
* @returns An Array of `ChatMember` objects that contains information about
|
|
582
|
+
* all chat administrators except other bots
|
|
583
|
+
*/
|
|
584
|
+
async getChatAdministrators(chatId) {
|
|
585
|
+
return this.sdk().getChatAdministrators(chatId);
|
|
586
|
+
},
|
|
587
|
+
/**
|
|
588
|
+
* Use this method to get the number of members in a chat
|
|
589
|
+
*
|
|
590
|
+
* @param {Number|String} chatId - Unique identifier for the target group or
|
|
591
|
+
* username of the target supergroup
|
|
592
|
+
* @param {Object} [opts] - Additional Telegram query options to be fed to
|
|
593
|
+
* the Telegram Bot API call, as defined in [the API
|
|
594
|
+
* docs](https://core.telegram.org/bots/api#getchatmembercount)
|
|
595
|
+
* @returns The number of members in the chat
|
|
596
|
+
*/
|
|
597
|
+
async getChatMemberCount(chatId) {
|
|
598
|
+
return this.sdk().getChatMemberCount(chatId);
|
|
599
|
+
},
|
|
600
|
+
/**
|
|
601
|
+
* Use this method to ban a user in a group, a supergroup or a channel. In
|
|
602
|
+
* the case of supergroups and channels, the user will not be able to return
|
|
603
|
+
* to the chat on their own using invite links, etc., unless unbanned first.
|
|
604
|
+
* The bot must be an administrator in the chat for this to work and must
|
|
605
|
+
* have the appropriate admin rights.
|
|
606
|
+
*
|
|
607
|
+
* @param {Number|String} chatId - Unique identifier for the target group or
|
|
608
|
+
* username of the target supergroup
|
|
609
|
+
* @param {Number} userId - Unique identifier of the target user
|
|
610
|
+
* @param {Object} [opts] - Additional Telegram query options to be fed to
|
|
611
|
+
* the Telegram Bot API call, as defined in [the API
|
|
612
|
+
* docs](https://core.telegram.org/bots/api#banchatmember)
|
|
613
|
+
* @returns `True` on success
|
|
614
|
+
*/
|
|
615
|
+
async banChatMember(chatId, userId, opts) {
|
|
616
|
+
return this.sdk().banChatMember(chatId, userId, opts);
|
|
617
|
+
},
|
|
618
|
+
/**
|
|
619
|
+
* Use this method to promote or demote a user in a supergroup or a channel.
|
|
620
|
+
* The bot must be an administrator in the chat for this to work and must
|
|
621
|
+
* have the appropriate admin rights. Pass False for all boolean parameters
|
|
622
|
+
* in `opts` to demote a user.
|
|
623
|
+
*
|
|
624
|
+
* @param {Number|String} chatId - Unique identifier for the target chat or
|
|
625
|
+
* username of the target supergroup
|
|
626
|
+
* @param {Number} userId - Unique identifier of the target user
|
|
627
|
+
* @param {Object} [opts] - Additional Telegram query options to be fed to
|
|
628
|
+
* the Telegram Bot API call, as defined in [the API
|
|
629
|
+
* docs](https://core.telegram.org/bots/api#promotechatmember)
|
|
630
|
+
* @returns `True` on success
|
|
631
|
+
*/
|
|
632
|
+
async promoteChatMember(chatId, userId, opts) {
|
|
633
|
+
return this.sdk().promoteChatMember(chatId, userId, opts);
|
|
634
|
+
},
|
|
635
|
+
/**
|
|
636
|
+
* Use this method to restrict a user in a supergroup. The bot must be an
|
|
637
|
+
* administrator in the supergroup for this to work and must have the
|
|
638
|
+
* appropriate admin rights. Pass True for all boolean parameters in `opts`
|
|
639
|
+
* to lift restrictions from a user.
|
|
640
|
+
*
|
|
641
|
+
* @param {Number|String} chatId - Unique identifier for the target chat or
|
|
642
|
+
* username of the target supergroup
|
|
643
|
+
* @param {Number} userId - Unique identifier of the target user
|
|
644
|
+
* @param {Object} [opts] - Additional Telegram query options to be fed to
|
|
645
|
+
* the Telegram Bot API call, as defined in [the API
|
|
646
|
+
* docs](https://core.telegram.org/bots/api#restrictchatmember)
|
|
647
|
+
* @returns `True` on success
|
|
648
|
+
*/
|
|
649
|
+
async restrictChatMember(chatId, userId, opts) {
|
|
650
|
+
return this.sdk().restrictChatMember(chatId, userId, opts);
|
|
651
|
+
},
|
|
652
|
+
/**
|
|
653
|
+
* Use this method to export an invite link to a supergroup or a channel.
|
|
654
|
+
* The bot must be an administrator in the chat for this to work and must
|
|
655
|
+
* have the appropriate admin rights. Returns exported invite link as
|
|
656
|
+
* String on success.
|
|
657
|
+
*
|
|
658
|
+
* @param {Number|String} chatId - Unique identifier for the target chat or
|
|
659
|
+
* username of the target supergroup
|
|
660
|
+
* @returns the new invite link as String on success.
|
|
661
|
+
*/
|
|
662
|
+
async exportChatInviteLink(chatId) {
|
|
663
|
+
return this.sdk().exportChatInviteLink(chatId);
|
|
664
|
+
},
|
|
665
|
+
/**
|
|
666
|
+
* Use this method to export an invite link to a supergroup or a channel.
|
|
667
|
+
* The bot must be an administrator in the chat for this to work and must
|
|
668
|
+
* have the appropriate admin rights. Returns exported invite link as
|
|
669
|
+
* String on success.
|
|
670
|
+
*
|
|
671
|
+
* @param {Number|String} chatId - Unique identifier for the target chat or
|
|
672
|
+
* username of the target supergroup
|
|
673
|
+
* @param {Object} [opts] - Additional Telegram query options to be fed to
|
|
674
|
+
* the Telegram Bot API call, as defined in [the API docs]
|
|
675
|
+
* (https://core.telegram.org/bots/api#createchatinvitelink)
|
|
676
|
+
* @returns the new invite link as ChatInviteLink object.
|
|
677
|
+
*/
|
|
678
|
+
async createChatInviteLink(chatId, opts) {
|
|
679
|
+
return this.sdk().createChatInviteLink(chatId, opts);
|
|
680
|
+
},
|
|
681
|
+
},
|
|
682
|
+
};
|