grammy 1.4.2 → 1.5.2
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/README.md +27 -16
- package/out/context.d.ts +21 -3
- package/out/context.js +28 -6
- package/out/convenience/frameworks.node.d.ts +39 -0
- package/out/convenience/frameworks.node.js +64 -0
- package/out/convenience/keyboard.d.ts +2 -2
- package/out/convenience/keyboard.js +2 -2
- package/out/convenience/session.d.ts +2 -2
- package/out/convenience/webhook.d.ts +73 -2
- package/out/convenience/webhook.js +18 -63
- package/out/core/api.d.ts +20 -0
- package/out/core/api.js +43 -109
- package/out/core/client.js +9 -6
- package/out/core/payload.js +5 -9
- package/out/filter.d.ts +7 -3
- package/out/filter.js +2 -1
- package/out/platform.node.d.ts +16 -8
- package/out/platform.node.js +49 -23
- package/package.json +14 -7
package/out/core/api.d.ts
CHANGED
|
@@ -459,6 +459,26 @@ export declare class Api<R extends RawApi = RawApi> {
|
|
|
459
459
|
* **Official reference:** https://core.telegram.org/bots/api#setchatadministratorcustomtitle
|
|
460
460
|
*/
|
|
461
461
|
setChatAdministratorCustomTitle(chat_id: number | string, user_id: number, custom_title: string, signal?: AbortSignal): Promise<true>;
|
|
462
|
+
/**
|
|
463
|
+
* Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
464
|
+
*
|
|
465
|
+
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
466
|
+
* @param sender_chat_id Unique identifier of the target sender chat
|
|
467
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
468
|
+
*
|
|
469
|
+
* **Official reference:** https://core.telegram.org/bots/api#banchatsenderchat
|
|
470
|
+
*/
|
|
471
|
+
banChatSenderChat(chat_id: number | string, sender_chat_id: number, signal?: AbortSignal): Promise<true>;
|
|
472
|
+
/**
|
|
473
|
+
* Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
474
|
+
*
|
|
475
|
+
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
476
|
+
* @param sender_chat_id Unique identifier of the target sender chat
|
|
477
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
478
|
+
*
|
|
479
|
+
* **Official reference:** https://core.telegram.org/bots/api#unbanchatsenderchat
|
|
480
|
+
*/
|
|
481
|
+
unbanChatSenderChat(chat_id: number | string, sender_chat_id: number, signal?: AbortSignal): Promise<true>;
|
|
462
482
|
/**
|
|
463
483
|
* Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members administrator rights. Returns True on success.
|
|
464
484
|
*
|
package/out/core/api.js
CHANGED
|
@@ -166,12 +166,7 @@ class Api {
|
|
|
166
166
|
* **Official reference:** https://core.telegram.org/bots/api#forwardmessage
|
|
167
167
|
*/
|
|
168
168
|
forwardMessage(chat_id, from_chat_id, message_id, other, signal) {
|
|
169
|
-
return this.raw.forwardMessage({
|
|
170
|
-
chat_id,
|
|
171
|
-
from_chat_id,
|
|
172
|
-
message_id,
|
|
173
|
-
...other,
|
|
174
|
-
}, signal);
|
|
169
|
+
return this.raw.forwardMessage({ chat_id, from_chat_id, message_id, ...other }, signal);
|
|
175
170
|
}
|
|
176
171
|
/**
|
|
177
172
|
* Use this method to copy messages of any kind. Service messages and invoice messages can't be copied. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success.
|
|
@@ -185,12 +180,7 @@ class Api {
|
|
|
185
180
|
* **Official reference:** https://core.telegram.org/bots/api#copymessage
|
|
186
181
|
*/
|
|
187
182
|
copyMessage(chat_id, from_chat_id, message_id, other, signal) {
|
|
188
|
-
return this.raw.copyMessage({
|
|
189
|
-
chat_id,
|
|
190
|
-
from_chat_id,
|
|
191
|
-
message_id,
|
|
192
|
-
...other,
|
|
193
|
-
}, signal);
|
|
183
|
+
return this.raw.copyMessage({ chat_id, from_chat_id, message_id, ...other }, signal);
|
|
194
184
|
}
|
|
195
185
|
/**
|
|
196
186
|
* Use this method to send photos. On success, the sent Message is returned.
|
|
@@ -326,13 +316,7 @@ class Api {
|
|
|
326
316
|
* **Official reference:** https://core.telegram.org/bots/api#editmessagelivelocation
|
|
327
317
|
*/
|
|
328
318
|
editMessageLiveLocation(chat_id, message_id, latitude, longitude, other, signal) {
|
|
329
|
-
return this.raw.editMessageLiveLocation({
|
|
330
|
-
chat_id,
|
|
331
|
-
message_id,
|
|
332
|
-
latitude,
|
|
333
|
-
longitude,
|
|
334
|
-
...other,
|
|
335
|
-
}, signal);
|
|
319
|
+
return this.raw.editMessageLiveLocation({ chat_id, message_id, latitude, longitude, ...other }, signal);
|
|
336
320
|
}
|
|
337
321
|
/**
|
|
338
322
|
* Use this method to edit live location inline messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.
|
|
@@ -346,12 +330,7 @@ class Api {
|
|
|
346
330
|
* **Official reference:** https://core.telegram.org/bots/api#editmessagelivelocation
|
|
347
331
|
*/
|
|
348
332
|
editMessageLiveLocationInline(inline_message_id, latitude, longitude, other, signal) {
|
|
349
|
-
return this.raw.editMessageLiveLocation({
|
|
350
|
-
inline_message_id,
|
|
351
|
-
latitude,
|
|
352
|
-
longitude,
|
|
353
|
-
...other,
|
|
354
|
-
}, signal);
|
|
333
|
+
return this.raw.editMessageLiveLocation({ inline_message_id, latitude, longitude, ...other }, signal);
|
|
355
334
|
}
|
|
356
335
|
/**
|
|
357
336
|
* Use this method to stop updating a live location message before live_period expires. On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned.
|
|
@@ -364,11 +343,7 @@ class Api {
|
|
|
364
343
|
* **Official reference:** https://core.telegram.org/bots/api#stopmessagelivelocation
|
|
365
344
|
*/
|
|
366
345
|
stopMessageLiveLocation(chat_id, message_id, other, signal) {
|
|
367
|
-
return this.raw.stopMessageLiveLocation({
|
|
368
|
-
chat_id,
|
|
369
|
-
message_id,
|
|
370
|
-
...other,
|
|
371
|
-
}, signal);
|
|
346
|
+
return this.raw.stopMessageLiveLocation({ chat_id, message_id, ...other }, signal);
|
|
372
347
|
}
|
|
373
348
|
/**
|
|
374
349
|
* Use this method to stop updating a live location message before live_period expires. On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned.
|
|
@@ -396,14 +371,7 @@ class Api {
|
|
|
396
371
|
* **Official reference:** https://core.telegram.org/bots/api#sendvenue
|
|
397
372
|
*/
|
|
398
373
|
sendVenue(chat_id, latitude, longitude, title, address, other, signal) {
|
|
399
|
-
return this.raw.sendVenue({
|
|
400
|
-
chat_id,
|
|
401
|
-
latitude,
|
|
402
|
-
longitude,
|
|
403
|
-
title,
|
|
404
|
-
address,
|
|
405
|
-
...other,
|
|
406
|
-
}, signal);
|
|
374
|
+
return this.raw.sendVenue({ chat_id, latitude, longitude, title, address, ...other }, signal);
|
|
407
375
|
}
|
|
408
376
|
/**
|
|
409
377
|
* Use this method to send phone contacts. On success, the sent Message is returned.
|
|
@@ -417,12 +385,7 @@ class Api {
|
|
|
417
385
|
* **Official reference:** https://core.telegram.org/bots/api#sendcontact
|
|
418
386
|
*/
|
|
419
387
|
sendContact(chat_id, phone_number, first_name, other, signal) {
|
|
420
|
-
return this.raw.sendContact({
|
|
421
|
-
chat_id,
|
|
422
|
-
phone_number,
|
|
423
|
-
first_name,
|
|
424
|
-
...other,
|
|
425
|
-
}, signal);
|
|
388
|
+
return this.raw.sendContact({ chat_id, phone_number, first_name, ...other }, signal);
|
|
426
389
|
}
|
|
427
390
|
/**
|
|
428
391
|
* Use this method to send a native poll. On success, the sent Message is returned.
|
|
@@ -534,12 +497,7 @@ class Api {
|
|
|
534
497
|
* **Official reference:** https://core.telegram.org/bots/api#restrictchatmember
|
|
535
498
|
*/
|
|
536
499
|
restrictChatMember(chat_id, user_id, permissions, other, signal) {
|
|
537
|
-
return this.raw.restrictChatMember({
|
|
538
|
-
chat_id,
|
|
539
|
-
user_id,
|
|
540
|
-
permissions,
|
|
541
|
-
...other,
|
|
542
|
-
}, signal);
|
|
500
|
+
return this.raw.restrictChatMember({ chat_id, user_id, permissions, ...other }, signal);
|
|
543
501
|
}
|
|
544
502
|
/**
|
|
545
503
|
* Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Pass False for all boolean parameters to demote a user. Returns True on success.
|
|
@@ -565,11 +523,31 @@ class Api {
|
|
|
565
523
|
* **Official reference:** https://core.telegram.org/bots/api#setchatadministratorcustomtitle
|
|
566
524
|
*/
|
|
567
525
|
setChatAdministratorCustomTitle(chat_id, user_id, custom_title, signal) {
|
|
568
|
-
return this.raw.setChatAdministratorCustomTitle({
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
526
|
+
return this.raw.setChatAdministratorCustomTitle({ chat_id, user_id, custom_title }, signal);
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Use this method to ban a channel chat in a supergroup or a channel. Until the chat is unbanned, the owner of the banned chat won't be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
530
|
+
*
|
|
531
|
+
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
532
|
+
* @param sender_chat_id Unique identifier of the target sender chat
|
|
533
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
534
|
+
*
|
|
535
|
+
* **Official reference:** https://core.telegram.org/bots/api#banchatsenderchat
|
|
536
|
+
*/
|
|
537
|
+
banChatSenderChat(chat_id, sender_chat_id, signal) {
|
|
538
|
+
return this.raw.banChatSenderChat({ chat_id, sender_chat_id }, signal);
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
542
|
+
*
|
|
543
|
+
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
544
|
+
* @param sender_chat_id Unique identifier of the target sender chat
|
|
545
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
546
|
+
*
|
|
547
|
+
* **Official reference:** https://core.telegram.org/bots/api#unbanchatsenderchat
|
|
548
|
+
*/
|
|
549
|
+
unbanChatSenderChat(chat_id, sender_chat_id, signal) {
|
|
550
|
+
return this.raw.unbanChatSenderChat({ chat_id, sender_chat_id }, signal);
|
|
573
551
|
}
|
|
574
552
|
/**
|
|
575
553
|
* Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members administrator rights. Returns True on success.
|
|
@@ -811,10 +789,7 @@ class Api {
|
|
|
811
789
|
* **Official reference:** https://core.telegram.org/bots/api#setchatstickerset
|
|
812
790
|
*/
|
|
813
791
|
setChatStickerSet(chat_id, sticker_set_name, signal) {
|
|
814
|
-
return this.raw.setChatStickerSet({
|
|
815
|
-
chat_id,
|
|
816
|
-
sticker_set_name,
|
|
817
|
-
}, signal);
|
|
792
|
+
return this.raw.setChatStickerSet({ chat_id, sticker_set_name }, signal);
|
|
818
793
|
}
|
|
819
794
|
/**
|
|
820
795
|
* Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Use the field can_set_sticker_set ly returned in getChat requests to check if the bot can use this method. Returns True on success.
|
|
@@ -938,12 +913,7 @@ class Api {
|
|
|
938
913
|
* **Official reference:** https://core.telegram.org/bots/api#editmessagemedia
|
|
939
914
|
*/
|
|
940
915
|
editMessageMedia(chat_id, message_id, media, other, signal) {
|
|
941
|
-
return this.raw.editMessageMedia({
|
|
942
|
-
chat_id,
|
|
943
|
-
message_id,
|
|
944
|
-
media,
|
|
945
|
-
...other,
|
|
946
|
-
}, signal);
|
|
916
|
+
return this.raw.editMessageMedia({ chat_id, message_id, media, ...other }, signal);
|
|
947
917
|
}
|
|
948
918
|
/**
|
|
949
919
|
* Use this method to edit animation, audio, document, photo, or video messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.
|
|
@@ -969,11 +939,7 @@ class Api {
|
|
|
969
939
|
* **Official reference:** https://core.telegram.org/bots/api#editmessagereplymarkup
|
|
970
940
|
*/
|
|
971
941
|
editMessageReplyMarkup(chat_id, message_id, other, signal) {
|
|
972
|
-
return this.raw.editMessageReplyMarkup({
|
|
973
|
-
chat_id,
|
|
974
|
-
message_id,
|
|
975
|
-
...other,
|
|
976
|
-
}, signal);
|
|
942
|
+
return this.raw.editMessageReplyMarkup({ chat_id, message_id, ...other }, signal);
|
|
977
943
|
}
|
|
978
944
|
/**
|
|
979
945
|
* Use this method to edit only the reply markup of inline messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned.
|
|
@@ -1069,13 +1035,7 @@ class Api {
|
|
|
1069
1035
|
* **Official reference:** https://core.telegram.org/bots/api#createnewstickerset
|
|
1070
1036
|
*/
|
|
1071
1037
|
createNewStickerSet(user_id, name, title, emojis, other, signal) {
|
|
1072
|
-
return this.raw.createNewStickerSet({
|
|
1073
|
-
user_id,
|
|
1074
|
-
name,
|
|
1075
|
-
title,
|
|
1076
|
-
emojis,
|
|
1077
|
-
...other,
|
|
1078
|
-
}, signal);
|
|
1038
|
+
return this.raw.createNewStickerSet({ user_id, name, title, emojis, ...other }, signal);
|
|
1079
1039
|
}
|
|
1080
1040
|
/**
|
|
1081
1041
|
* Use this method to add a new sticker to a set created by the bot. You must use exactly one of the fields png_sticker or tgs_sticker. Animated stickers can be added to animated sticker sets and only to them. Animated sticker sets can have up to 50 stickers. Static sticker sets can have up to 120 stickers. Returns True on success.
|
|
@@ -1141,11 +1101,7 @@ class Api {
|
|
|
1141
1101
|
* **Official reference:** https://core.telegram.org/bots/api#answerinlinequery
|
|
1142
1102
|
*/
|
|
1143
1103
|
answerInlineQuery(inline_query_id, results, other, signal) {
|
|
1144
|
-
return this.raw.answerInlineQuery({
|
|
1145
|
-
inline_query_id,
|
|
1146
|
-
results,
|
|
1147
|
-
...other,
|
|
1148
|
-
}, signal);
|
|
1104
|
+
return this.raw.answerInlineQuery({ inline_query_id, results, ...other }, signal);
|
|
1149
1105
|
}
|
|
1150
1106
|
/**
|
|
1151
1107
|
* Use this method to send invoices. On success, the sent Message is returned.
|
|
@@ -1198,11 +1154,7 @@ class Api {
|
|
|
1198
1154
|
* **Official reference:** https://core.telegram.org/bots/api#answerprecheckoutquery
|
|
1199
1155
|
*/
|
|
1200
1156
|
answerPreCheckoutQuery(pre_checkout_query_id, ok, other, signal) {
|
|
1201
|
-
return this.raw.answerPreCheckoutQuery({
|
|
1202
|
-
pre_checkout_query_id,
|
|
1203
|
-
ok,
|
|
1204
|
-
...other,
|
|
1205
|
-
}, signal);
|
|
1157
|
+
return this.raw.answerPreCheckoutQuery({ pre_checkout_query_id, ok, ...other }, signal);
|
|
1206
1158
|
}
|
|
1207
1159
|
/**
|
|
1208
1160
|
* Informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change). Returns True on success.
|
|
@@ -1244,13 +1196,7 @@ class Api {
|
|
|
1244
1196
|
* **Official reference:** https://core.telegram.org/bots/api#setgamescore
|
|
1245
1197
|
*/
|
|
1246
1198
|
setGameScore(chat_id, message_id, user_id, score, other, signal) {
|
|
1247
|
-
return this.raw.setGameScore({
|
|
1248
|
-
chat_id,
|
|
1249
|
-
message_id,
|
|
1250
|
-
user_id,
|
|
1251
|
-
score,
|
|
1252
|
-
...other,
|
|
1253
|
-
}, signal);
|
|
1199
|
+
return this.raw.setGameScore({ chat_id, message_id, user_id, score, ...other }, signal);
|
|
1254
1200
|
}
|
|
1255
1201
|
/**
|
|
1256
1202
|
* Use this method to set the score of the specified user in a game message. On success, if the message is not an inline message, the Message is returned, otherwise True is returned. Returns an error, if the new score is not greater than the user's current score in the chat and force is False.
|
|
@@ -1264,12 +1210,7 @@ class Api {
|
|
|
1264
1210
|
* **Official reference:** https://core.telegram.org/bots/api#setgamescore
|
|
1265
1211
|
*/
|
|
1266
1212
|
setGameScoreInline(inline_message_id, user_id, score, other, signal) {
|
|
1267
|
-
return this.raw.setGameScore({
|
|
1268
|
-
inline_message_id,
|
|
1269
|
-
user_id,
|
|
1270
|
-
score,
|
|
1271
|
-
...other,
|
|
1272
|
-
}, signal);
|
|
1213
|
+
return this.raw.setGameScore({ inline_message_id, user_id, score, ...other }, signal);
|
|
1273
1214
|
}
|
|
1274
1215
|
/**
|
|
1275
1216
|
* Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. On success, returns an Array of GameHighScore objects.
|
|
@@ -1284,11 +1225,7 @@ class Api {
|
|
|
1284
1225
|
* **Official reference:** https://core.telegram.org/bots/api#getgamehighscores
|
|
1285
1226
|
*/
|
|
1286
1227
|
getGameHighScores(chat_id, message_id, user_id, signal) {
|
|
1287
|
-
return this.raw.getGameHighScores({
|
|
1288
|
-
chat_id,
|
|
1289
|
-
message_id,
|
|
1290
|
-
user_id,
|
|
1291
|
-
}, signal);
|
|
1228
|
+
return this.raw.getGameHighScores({ chat_id, message_id, user_id }, signal);
|
|
1292
1229
|
}
|
|
1293
1230
|
/**
|
|
1294
1231
|
* Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in an inline game. On success, returns an Array of GameHighScore objects.
|
|
@@ -1302,10 +1239,7 @@ class Api {
|
|
|
1302
1239
|
* **Official reference:** https://core.telegram.org/bots/api#getgamehighscores
|
|
1303
1240
|
*/
|
|
1304
1241
|
getGameHighScoresInline(inline_message_id, user_id, signal) {
|
|
1305
|
-
return this.raw.getGameHighScores({
|
|
1306
|
-
inline_message_id,
|
|
1307
|
-
user_id,
|
|
1308
|
-
}, signal);
|
|
1242
|
+
return this.raw.getGameHighScores({ inline_message_id, user_id }, signal);
|
|
1309
1243
|
}
|
|
1310
1244
|
}
|
|
1311
1245
|
exports.Api = Api;
|
package/out/core/client.js
CHANGED
|
@@ -11,7 +11,7 @@ function concatTransformer(prev, trans) {
|
|
|
11
11
|
}
|
|
12
12
|
class ApiClient {
|
|
13
13
|
constructor(token, options = {}, webhookReplyEnvelope = {}) {
|
|
14
|
-
var _a, _b, _c, _d
|
|
14
|
+
var _a, _b, _c, _d;
|
|
15
15
|
Object.defineProperty(this, "token", {
|
|
16
16
|
enumerable: true,
|
|
17
17
|
configurable: true,
|
|
@@ -57,7 +57,6 @@ class ApiClient {
|
|
|
57
57
|
this.hasUsedWebhookReply = true;
|
|
58
58
|
const config = (0, payload_js_1.createJsonPayload)({ ...payload, method });
|
|
59
59
|
await this.webhookReplyEnvelope.send(config.body);
|
|
60
|
-
// deno-lint-ignore no-explicit-any
|
|
61
60
|
return { ok: true, result: true };
|
|
62
61
|
}
|
|
63
62
|
else {
|
|
@@ -86,12 +85,16 @@ class ApiClient {
|
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
});
|
|
88
|
+
const apiRoot = (_a = options.apiRoot) !== null && _a !== void 0 ? _a : "https://api.telegram.org";
|
|
89
89
|
this.options = {
|
|
90
|
-
apiRoot
|
|
90
|
+
apiRoot,
|
|
91
91
|
buildUrl: (_b = options.buildUrl) !== null && _b !== void 0 ? _b : ((root, token, method) => `${root}/bot${token}/${method}`),
|
|
92
|
-
baseFetchConfig:
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
baseFetchConfig: {
|
|
93
|
+
...(0, platform_node_js_1.baseFetchConfig)(apiRoot),
|
|
94
|
+
...options.baseFetchConfig,
|
|
95
|
+
},
|
|
96
|
+
canUseWebhookReply: (_c = options.canUseWebhookReply) !== null && _c !== void 0 ? _c : (() => false),
|
|
97
|
+
sensitiveLogs: (_d = options.sensitiveLogs) !== null && _d !== void 0 ? _d : false,
|
|
95
98
|
};
|
|
96
99
|
if (this.options.apiRoot.endsWith("/")) {
|
|
97
100
|
throw new Error(`Remove the trailing '/' from the 'apiRoot' option (use '${this.options.apiRoot.substr(0, this.options.apiRoot.length - 1)}' instead of '${this.options.apiRoot}')`);
|
package/out/core/payload.js
CHANGED
|
@@ -154,8 +154,7 @@ function valuePart(key, value) {
|
|
|
154
154
|
}
|
|
155
155
|
/** Turns an InputFile into a generator of `Uint8Array`s */
|
|
156
156
|
async function* filePart(id, origin, input) {
|
|
157
|
-
|
|
158
|
-
const filename = (_a = input.filename) !== null && _a !== void 0 ? _a : `${origin}.${getExt(origin)}`;
|
|
157
|
+
const filename = input.filename || `${origin}.${getExt(origin)}`;
|
|
159
158
|
if (filename.includes("\r") || filename.includes("\n")) {
|
|
160
159
|
throw new Error(`File paths cannot contain carriage-return (\\r) \
|
|
161
160
|
or newline (\\n) characters! Filename for property '${origin}' was:
|
|
@@ -164,14 +163,11 @@ ${filename}
|
|
|
164
163
|
"""`);
|
|
165
164
|
}
|
|
166
165
|
yield enc.encode(`content-disposition:form-data;name="${id}";filename=${filename}\r\n\r\n`);
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
yield fileData;
|
|
171
|
-
else if (typeof fileData === "string")
|
|
172
|
-
yield* await (0, platform_node_js_1.streamFile)(fileData);
|
|
166
|
+
const data = await input[platform_node_js_1.toRaw]();
|
|
167
|
+
if (data instanceof Uint8Array)
|
|
168
|
+
yield data;
|
|
173
169
|
else
|
|
174
|
-
yield*
|
|
170
|
+
yield* data;
|
|
175
171
|
}
|
|
176
172
|
/** Returns the default file extension for an API property name */
|
|
177
173
|
function getExt(key) {
|
package/out/filter.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare type FilterFunction<C extends Context, D extends C> = (ctx: C) => ctx is
|
|
|
17
17
|
* ```
|
|
18
18
|
*
|
|
19
19
|
* Check out the
|
|
20
|
-
* [documentation](https://doc.deno.land/https
|
|
20
|
+
* [documentation](https://doc.deno.land/https://deno.land/x/grammy/mod.ts/~/Composer)
|
|
21
21
|
* of `bot.on` for examples. In addition, the
|
|
22
22
|
* [website](https://grammy.dev/guide/filter-queries.html) contains more
|
|
23
23
|
* information about how filter queries work in grammY.
|
|
@@ -61,6 +61,7 @@ declare const UPDATE_KEYS: {
|
|
|
61
61
|
readonly voice_chat_ended: {};
|
|
62
62
|
readonly voice_chat_participants_invited: {};
|
|
63
63
|
readonly forward_date: {};
|
|
64
|
+
readonly is_automatic_forward: {};
|
|
64
65
|
readonly text: {};
|
|
65
66
|
readonly animation: {};
|
|
66
67
|
readonly audio: {};
|
|
@@ -140,6 +141,7 @@ declare const UPDATE_KEYS: {
|
|
|
140
141
|
readonly voice_chat_ended: {};
|
|
141
142
|
readonly voice_chat_participants_invited: {};
|
|
142
143
|
readonly forward_date: {};
|
|
144
|
+
readonly is_automatic_forward: {};
|
|
143
145
|
readonly text: {};
|
|
144
146
|
readonly animation: {};
|
|
145
147
|
readonly audio: {};
|
|
@@ -205,6 +207,7 @@ declare const UPDATE_KEYS: {
|
|
|
205
207
|
readonly voice_chat_ended: {};
|
|
206
208
|
readonly voice_chat_participants_invited: {};
|
|
207
209
|
readonly forward_date: {};
|
|
210
|
+
readonly is_automatic_forward: {};
|
|
208
211
|
readonly text: {};
|
|
209
212
|
readonly animation: {};
|
|
210
213
|
readonly audio: {};
|
|
@@ -270,6 +273,7 @@ declare const UPDATE_KEYS: {
|
|
|
270
273
|
readonly voice_chat_ended: {};
|
|
271
274
|
readonly voice_chat_participants_invited: {};
|
|
272
275
|
readonly forward_date: {};
|
|
276
|
+
readonly is_automatic_forward: {};
|
|
273
277
|
readonly text: {};
|
|
274
278
|
readonly animation: {};
|
|
275
279
|
readonly audio: {};
|
|
@@ -398,8 +402,8 @@ declare type PerformQuery<C extends Context, U extends SomeObject> = U extends u
|
|
|
398
402
|
declare type FilteredContext<C extends Context, U extends Update> = C & Record<"update", U> & AliasProps<Omit<U, "update_id">> & Shortcuts<U>;
|
|
399
403
|
interface Shortcuts<U extends Update> {
|
|
400
404
|
msg: [U["callback_query"]] extends [SomeObject] ? U["callback_query"]["message"] : [U["message"]] extends [SomeObject] ? U["message"] : [U["edited_message"]] extends [SomeObject] ? U["edited_message"] : [U["channel_post"]] extends [SomeObject] ? U["channel_post"] : [U["edited_channel_post"]] extends [SomeObject] ? U["edited_channel_post"] : undefined;
|
|
401
|
-
chat: [U["callback_query"]] extends [SomeObject] ? NonNullable<U["callback_query"]["message"]>["chat"] | undefined : [Shortcuts<U>["msg"]] extends [SomeObject] ? Shortcuts<U>["msg"]["chat"] : [U["my_chat_member"]] extends [SomeObject] ? U["my_chat_member"]["chat"] : [U["chat_member"]] extends [SomeObject] ? U["chat_member"]["chat"] : undefined;
|
|
402
|
-
from: [U["callback_query"]] extends [SomeObject] ? U["callback_query"]["from"] : [U["inline_query"]] extends [SomeObject] ? U["inline_query"]["from"] : [U["shipping_query"]] extends [SomeObject] ? U["shipping_query"]["from"] : [U["pre_checkout_query"]] extends [SomeObject] ? U["pre_checkout_query"]["from"] : [U["chosen_inline_result"]] extends [SomeObject] ? U["chosen_inline_result"]["from"] : [U["message"]] extends [SomeObject] ? NonNullable<U["message"]["from"]> : [U["edited_message"]] extends [SomeObject] ? NonNullable<U["edited_message"]["from"]> : [U["my_chat_member"]] extends [SomeObject] ? U["my_chat_member"]["from"] : [U["chat_member"]] extends [SomeObject] ? U["chat_member"]["from"] : undefined;
|
|
405
|
+
chat: [U["callback_query"]] extends [SomeObject] ? NonNullable<U["callback_query"]["message"]>["chat"] | undefined : [Shortcuts<U>["msg"]] extends [SomeObject] ? Shortcuts<U>["msg"]["chat"] : [U["my_chat_member"]] extends [SomeObject] ? U["my_chat_member"]["chat"] : [U["chat_member"]] extends [SomeObject] ? U["chat_member"]["chat"] : [U["chat_join_request"]] extends [SomeObject] ? U["chat_join_request"]["chat"] : undefined;
|
|
406
|
+
from: [U["callback_query"]] extends [SomeObject] ? U["callback_query"]["from"] : [U["inline_query"]] extends [SomeObject] ? U["inline_query"]["from"] : [U["shipping_query"]] extends [SomeObject] ? U["shipping_query"]["from"] : [U["pre_checkout_query"]] extends [SomeObject] ? U["pre_checkout_query"]["from"] : [U["chosen_inline_result"]] extends [SomeObject] ? U["chosen_inline_result"]["from"] : [U["message"]] extends [SomeObject] ? NonNullable<U["message"]["from"]> : [U["edited_message"]] extends [SomeObject] ? NonNullable<U["edited_message"]["from"]> : [U["my_chat_member"]] extends [SomeObject] ? U["my_chat_member"]["from"] : [U["chat_member"]] extends [SomeObject] ? U["chat_member"]["from"] : [U["chat_join_request"]] extends [SomeObject] ? U["chat_join_request"]["from"] : undefined;
|
|
403
407
|
}
|
|
404
408
|
declare const L1_SHORTCUTS: {
|
|
405
409
|
readonly "": readonly ["message", "channel_post"];
|
package/out/filter.js
CHANGED
|
@@ -18,7 +18,7 @@ exports.matchFilter = void 0;
|
|
|
18
18
|
* ```
|
|
19
19
|
*
|
|
20
20
|
* Check out the
|
|
21
|
-
* [documentation](https://doc.deno.land/https
|
|
21
|
+
* [documentation](https://doc.deno.land/https://deno.land/x/grammy/mod.ts/~/Composer)
|
|
22
22
|
* of `bot.on` for examples. In addition, the
|
|
23
23
|
* [website](https://grammy.dev/guide/filter-queries.html) contains more
|
|
24
24
|
* information about how filter queries work in grammY.
|
|
@@ -249,6 +249,7 @@ const COMMON_MESSAGE_KEYS = {
|
|
|
249
249
|
voice_chat_ended: {},
|
|
250
250
|
voice_chat_participants_invited: {},
|
|
251
251
|
forward_date: {},
|
|
252
|
+
is_automatic_forward: {},
|
|
252
253
|
};
|
|
253
254
|
const MESSAGE_KEYS = {
|
|
254
255
|
...COMMON_MESSAGE_KEYS,
|
package/out/platform.node.d.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { InputFileProxy } from "@grammyjs/types";
|
|
3
|
-
import { Agent } from "
|
|
3
|
+
import { Agent as HttpAgent } from "http";
|
|
4
|
+
import { Agent as HttpsAgent } from "https";
|
|
4
5
|
import { Readable } from "stream";
|
|
5
6
|
import type { ReadStream } from "fs";
|
|
6
7
|
import { URL } from "url";
|
|
7
8
|
export * from "@grammyjs/types";
|
|
8
|
-
|
|
9
|
+
import { debug as d } from "debug";
|
|
10
|
+
export { d as debug };
|
|
9
11
|
export declare const itrToStream: (itr: AsyncIterable<Uint8Array>) => Readable;
|
|
10
|
-
export
|
|
11
|
-
export declare const baseFetchConfig: {
|
|
12
|
+
export declare function baseFetchConfig(apiRoot: string): {
|
|
12
13
|
compress: boolean;
|
|
13
|
-
agent:
|
|
14
|
+
agent: HttpsAgent;
|
|
15
|
+
} | {
|
|
16
|
+
agent: HttpAgent;
|
|
17
|
+
compress?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
compress?: undefined;
|
|
20
|
+
agent?: undefined;
|
|
14
21
|
};
|
|
15
22
|
/** Something that looks like a URL. */
|
|
16
23
|
interface URLLike {
|
|
@@ -20,7 +27,7 @@ interface URLLike {
|
|
|
20
27
|
*/
|
|
21
28
|
url: string;
|
|
22
29
|
}
|
|
23
|
-
export declare const
|
|
30
|
+
export declare const toRaw: unique symbol;
|
|
24
31
|
/**
|
|
25
32
|
* An `InputFile` wraps a number of different sources for [sending
|
|
26
33
|
* files](https://grammy.dev/guide/files.html#uploading-your-own-file).
|
|
@@ -45,8 +52,9 @@ export declare class InputFile {
|
|
|
45
52
|
* @param file A path to a local file or a `Buffer` or a `fs.ReadStream` that specifies the file data
|
|
46
53
|
* @param filename Optional name of the file
|
|
47
54
|
*/
|
|
48
|
-
constructor(file: string | URL | URLLike | Uint8Array | ReadStream | AsyncIterable<Uint8Array>, filename?: string);
|
|
49
|
-
|
|
55
|
+
constructor(file: string | URL | URLLike | Uint8Array | ReadStream | Iterable<Uint8Array> | AsyncIterable<Uint8Array>, filename?: string);
|
|
56
|
+
private guessFilename;
|
|
57
|
+
[toRaw](): Uint8Array | Iterable<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
50
58
|
}
|
|
51
59
|
declare type GrammyTypes = InputFileProxy<InputFile>;
|
|
52
60
|
/** Wrapper type to bundle all methods of the Telegram API */
|
package/out/platform.node.js
CHANGED
|
@@ -10,31 +10,38 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.InputFile = exports.
|
|
13
|
+
exports.InputFile = exports.toRaw = exports.baseFetchConfig = exports.itrToStream = exports.debug = void 0;
|
|
14
|
+
const http_1 = require("http");
|
|
14
15
|
const https_1 = require("https");
|
|
15
16
|
const path_1 = require("path");
|
|
16
17
|
const stream_1 = require("stream");
|
|
17
18
|
const url_1 = require("url");
|
|
19
|
+
const fs_1 = require("fs");
|
|
18
20
|
// === Export all API types
|
|
19
21
|
__exportStar(require("@grammyjs/types"), exports);
|
|
20
22
|
// === Export debug
|
|
21
|
-
|
|
23
|
+
const debug_1 = require("debug");
|
|
22
24
|
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return debug_1.debug; } });
|
|
25
|
+
const debug = (0, debug_1.debug)("grammy:warn");
|
|
23
26
|
// === Export system-specific operations
|
|
24
27
|
// Turn an AsyncIterable<Uint8Array> into a stream
|
|
25
28
|
const itrToStream = (itr) => stream_1.Readable.from(itr, { objectMode: false });
|
|
26
29
|
exports.itrToStream = itrToStream;
|
|
27
|
-
// Turn a file path into an AsyncIterable<Uint8Array>
|
|
28
|
-
var fs_1 = require("fs");
|
|
29
|
-
Object.defineProperty(exports, "streamFile", { enumerable: true, get: function () { return fs_1.createReadStream; } });
|
|
30
30
|
// === Base configuration for `fetch` calls
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
31
|
+
function baseFetchConfig(apiRoot) {
|
|
32
|
+
if (apiRoot.startsWith("https:")) {
|
|
33
|
+
return { compress: true, agent: new https_1.Agent({ keepAlive: true }) };
|
|
34
|
+
}
|
|
35
|
+
else if (apiRoot.startsWith("http:")) {
|
|
36
|
+
return { agent: new http_1.Agent({ keepAlive: true }) };
|
|
37
|
+
}
|
|
38
|
+
else
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
exports.baseFetchConfig = baseFetchConfig;
|
|
35
42
|
// === InputFile handling and File augmenting
|
|
36
43
|
// Accessor for file data in `InputFile` instances
|
|
37
|
-
exports.
|
|
44
|
+
exports.toRaw = Symbol("InputFile data");
|
|
38
45
|
/**
|
|
39
46
|
* An `InputFile` wraps a number of different sources for [sending
|
|
40
47
|
* files](https://grammy.dev/guide/files.html#uploading-your-own-file).
|
|
@@ -76,31 +83,50 @@ class InputFile {
|
|
|
76
83
|
value: void 0
|
|
77
84
|
});
|
|
78
85
|
this.fileData = file;
|
|
79
|
-
|
|
80
|
-
filename = (0, path_1.basename)(file);
|
|
81
|
-
}
|
|
86
|
+
filename !== null && filename !== void 0 ? filename : (filename = this.guessFilename(file));
|
|
82
87
|
this.filename = filename;
|
|
88
|
+
if (typeof file === "string" &&
|
|
89
|
+
(file.startsWith("http:") || file.startsWith("https:"))) {
|
|
90
|
+
debug(`InputFile received the local file path '${file}' that looks like a URL. Is this a mistake?`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
guessFilename(file) {
|
|
94
|
+
if (typeof file === "string")
|
|
95
|
+
return (0, path_1.basename)(file);
|
|
96
|
+
if (typeof file !== "object")
|
|
97
|
+
return undefined;
|
|
98
|
+
if ("url" in file)
|
|
99
|
+
return (0, path_1.basename)(file.url);
|
|
100
|
+
if (!(file instanceof url_1.URL))
|
|
101
|
+
return undefined;
|
|
102
|
+
return (0, path_1.basename)(file.pathname) || (0, path_1.basename)(file.hostname);
|
|
83
103
|
}
|
|
84
|
-
|
|
104
|
+
[exports.toRaw]() {
|
|
85
105
|
if (this.consumed) {
|
|
86
106
|
throw new Error("Cannot reuse InputFile data source!");
|
|
87
107
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
108
|
+
const data = this.fileData;
|
|
109
|
+
// Handle local files
|
|
110
|
+
if (typeof data === "string")
|
|
111
|
+
return (0, fs_1.createReadStream)(data);
|
|
112
|
+
// Handle URLs and URLLike objects
|
|
113
|
+
if (data instanceof url_1.URL) {
|
|
114
|
+
return data.protocol === "file" // node-fetch does not support file URLs
|
|
115
|
+
? (0, fs_1.createReadStream)(data.pathname)
|
|
116
|
+
: fetchFile(data);
|
|
94
117
|
}
|
|
118
|
+
if ("url" in data)
|
|
119
|
+
return fetchFile(data.url);
|
|
120
|
+
// Mark streams and iterators as consumed
|
|
121
|
+
if (!(data instanceof Uint8Array))
|
|
122
|
+
this.consumed = true;
|
|
123
|
+
// Return buffers and byte streams as-is
|
|
95
124
|
return data;
|
|
96
125
|
}
|
|
97
126
|
}
|
|
98
127
|
exports.InputFile = InputFile;
|
|
99
128
|
async function* fetchFile(url) {
|
|
100
129
|
const { body } = await (0, shim_node_js_1.fetch)(url);
|
|
101
|
-
if (body === null) {
|
|
102
|
-
throw new Error(`Download failed, no response body from '${url}'`);
|
|
103
|
-
}
|
|
104
130
|
for await (const chunk of body) {
|
|
105
131
|
if (typeof chunk === "string") {
|
|
106
132
|
throw new Error(`Could not transfer file, received string data instead of bytes from '${url}'`);
|