grammy 1.3.4 → 1.4.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 +28 -11
- package/out/bot.js +29 -3
- package/out/composer.d.ts +1 -1
- package/out/composer.js +4 -2
- package/out/context.d.ts +44 -24
- package/out/context.js +50 -24
- package/out/convenience/webhook.js +8 -2
- package/out/core/api.d.ts +40 -20
- package/out/core/api.js +44 -20
- package/out/core/client.js +44 -20
- package/out/core/payload.d.ts +1 -1
- package/out/core/payload.js +13 -2
- package/out/filter.d.ts +25 -0
- package/out/filter.js +4 -0
- package/out/platform.node.d.ts +13 -2
- package/out/platform.node.js +35 -4
- package/package.json +7 -3
package/out/core/api.js
CHANGED
|
@@ -112,7 +112,7 @@ class Api {
|
|
|
112
112
|
return this.raw.getWebhookInfo(signal);
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
|
-
* A simple method for testing your bot's
|
|
115
|
+
* A simple method for testing your bot's authentication token. Requires no parameters. Returns basic information about the bot in form of a User object.
|
|
116
116
|
*
|
|
117
117
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
118
118
|
*
|
|
@@ -459,7 +459,7 @@ class Api {
|
|
|
459
459
|
* We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
|
|
460
460
|
*
|
|
461
461
|
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
462
|
-
* @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_voice or upload_voice for voice notes, upload_document for general files, find_location for location data, record_video_note or upload_video_note for video notes.
|
|
462
|
+
* @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_voice or upload_voice for voice notes, upload_document for general files, choose_sticker for stickers, find_location for location data, record_video_note or upload_video_note for video notes.
|
|
463
463
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
464
464
|
*
|
|
465
465
|
* **Official reference:** https://core.telegram.org/bots/api#sendchataction
|
|
@@ -497,7 +497,7 @@ class Api {
|
|
|
497
497
|
return this.banChatMember(...args);
|
|
498
498
|
}
|
|
499
499
|
/**
|
|
500
|
-
* Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate
|
|
500
|
+
* Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
501
501
|
*
|
|
502
502
|
* @param chat_id Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)
|
|
503
503
|
* @param user_id Unique identifier of the target user
|
|
@@ -523,7 +523,7 @@ class Api {
|
|
|
523
523
|
return this.raw.unbanChatMember({ chat_id, user_id, ...other }, signal);
|
|
524
524
|
}
|
|
525
525
|
/**
|
|
526
|
-
* Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate
|
|
526
|
+
* Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate administrator rights. Pass True for all permissions to lift restrictions from a user. Returns True on success.
|
|
527
527
|
*
|
|
528
528
|
* @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
|
529
529
|
* @param user_id Unique identifier of the target user
|
|
@@ -542,7 +542,7 @@ class Api {
|
|
|
542
542
|
}, signal);
|
|
543
543
|
}
|
|
544
544
|
/**
|
|
545
|
-
* 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
|
|
545
|
+
* 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.
|
|
546
546
|
*
|
|
547
547
|
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
548
548
|
* @param user_id Unique identifier of the target user
|
|
@@ -572,7 +572,7 @@ class Api {
|
|
|
572
572
|
}, signal);
|
|
573
573
|
}
|
|
574
574
|
/**
|
|
575
|
-
* 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
|
|
575
|
+
* 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.
|
|
576
576
|
*
|
|
577
577
|
* @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
|
578
578
|
* @param permissions New default chat permissions
|
|
@@ -584,7 +584,7 @@ class Api {
|
|
|
584
584
|
return this.raw.setChatPermissions({ chat_id, permissions }, signal);
|
|
585
585
|
}
|
|
586
586
|
/**
|
|
587
|
-
* Use this method to generate a new primary invite link for a chat; any previously generated primary link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate
|
|
587
|
+
* Use this method to generate a new primary invite link for a chat; any previously generated primary link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the new invite link as String on success.
|
|
588
588
|
*
|
|
589
589
|
* Note: Each administrator in a chat generates their own invite links. Bots can't use invite links generated by other administrators. If you want your bot to work with invite links, it will need to generate its own link using exportChatInviteLink or by calling the getChat method. If your bot needs to generate a new primary invite link replacing its previous one, use exportChatInviteLink again.
|
|
590
590
|
*
|
|
@@ -597,7 +597,7 @@ class Api {
|
|
|
597
597
|
return this.raw.exportChatInviteLink({ chat_id }, signal);
|
|
598
598
|
}
|
|
599
599
|
/**
|
|
600
|
-
* Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate
|
|
600
|
+
* Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. The link can be revoked using the method revokeChatInviteLink. Returns the new invite link as ChatInviteLink object.
|
|
601
601
|
*
|
|
602
602
|
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
603
603
|
* @param other Optional remaining parameters, confer the official reference below
|
|
@@ -609,7 +609,7 @@ class Api {
|
|
|
609
609
|
return this.raw.createChatInviteLink({ chat_id, ...other }, signal);
|
|
610
610
|
}
|
|
611
611
|
/**
|
|
612
|
-
* Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate
|
|
612
|
+
* Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the edited invite link as a ChatInviteLink object.
|
|
613
613
|
*
|
|
614
614
|
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
615
615
|
* @param invite_link The invite link to edit
|
|
@@ -622,7 +622,7 @@ class Api {
|
|
|
622
622
|
return this.raw.editChatInviteLink({ chat_id, invite_link, ...other }, signal);
|
|
623
623
|
}
|
|
624
624
|
/**
|
|
625
|
-
* Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate
|
|
625
|
+
* Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the revoked invite link as ChatInviteLink object.
|
|
626
626
|
*
|
|
627
627
|
* @param chat_id Unique identifier of the target chat or username of the target channel (in the format @channelusername)
|
|
628
628
|
* @param invite_link The invite link to revoke
|
|
@@ -634,7 +634,31 @@ class Api {
|
|
|
634
634
|
return this.raw.revokeChatInviteLink({ chat_id, invite_link }, signal);
|
|
635
635
|
}
|
|
636
636
|
/**
|
|
637
|
-
* Use this method to
|
|
637
|
+
* Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.
|
|
638
|
+
*
|
|
639
|
+
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
640
|
+
* @param user_id Unique identifier of the target user
|
|
641
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
642
|
+
*
|
|
643
|
+
* **Official reference:** https://core.telegram.org/bots/api#approvechatjoinrequest
|
|
644
|
+
*/
|
|
645
|
+
approveChatJoinRequest(chat_id, user_id, signal) {
|
|
646
|
+
return this.raw.approveChatJoinRequest({ chat_id, user_id }, signal);
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.
|
|
650
|
+
*
|
|
651
|
+
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
652
|
+
* @param user_id Unique identifier of the target user
|
|
653
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
654
|
+
*
|
|
655
|
+
* **Official reference:** https://core.telegram.org/bots/api#declinechatjoinrequest
|
|
656
|
+
*/
|
|
657
|
+
declineChatJoinRequest(chat_id, user_id, signal) {
|
|
658
|
+
return this.raw.declineChatJoinRequest({ chat_id, user_id }, signal);
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
638
662
|
*
|
|
639
663
|
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
640
664
|
* @param photo New chat photo, uploaded using multipart/form-data
|
|
@@ -646,7 +670,7 @@ class Api {
|
|
|
646
670
|
return this.raw.setChatPhoto({ chat_id, photo }, signal);
|
|
647
671
|
}
|
|
648
672
|
/**
|
|
649
|
-
* Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate
|
|
673
|
+
* Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
650
674
|
*
|
|
651
675
|
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
652
676
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
@@ -657,7 +681,7 @@ class Api {
|
|
|
657
681
|
return this.raw.deleteChatPhoto({ chat_id }, signal);
|
|
658
682
|
}
|
|
659
683
|
/**
|
|
660
|
-
* Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate
|
|
684
|
+
* Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.
|
|
661
685
|
*
|
|
662
686
|
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
663
687
|
* @param title New chat title, 1-255 characters
|
|
@@ -669,7 +693,7 @@ class Api {
|
|
|
669
693
|
return this.raw.setChatTitle({ chat_id, title }, signal);
|
|
670
694
|
}
|
|
671
695
|
/**
|
|
672
|
-
* Use this method to change the description of a group, a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate
|
|
696
|
+
* Use this method to change the description of a group, 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. Returns True on success.
|
|
673
697
|
*
|
|
674
698
|
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
675
699
|
* @param description New chat description, 0-255 characters
|
|
@@ -681,7 +705,7 @@ class Api {
|
|
|
681
705
|
return this.raw.setChatDescription({ chat_id, description }, signal);
|
|
682
706
|
}
|
|
683
707
|
/**
|
|
684
|
-
* Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages'
|
|
708
|
+
* Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns True on success.
|
|
685
709
|
*
|
|
686
710
|
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
687
711
|
* @param message_id Identifier of a message to pin
|
|
@@ -694,7 +718,7 @@ class Api {
|
|
|
694
718
|
return this.raw.pinChatMessage({ chat_id, message_id, ...other }, signal);
|
|
695
719
|
}
|
|
696
720
|
/**
|
|
697
|
-
* Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages'
|
|
721
|
+
* Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns True on success.
|
|
698
722
|
*
|
|
699
723
|
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
700
724
|
* @param message_id Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned.
|
|
@@ -707,7 +731,7 @@ class Api {
|
|
|
707
731
|
return this.raw.unpinChatMessage({ chat_id, message_id }, signal);
|
|
708
732
|
}
|
|
709
733
|
/**
|
|
710
|
-
* Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages'
|
|
734
|
+
* Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. Returns True on success.
|
|
711
735
|
*
|
|
712
736
|
* @param chat_id Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
|
713
737
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
@@ -778,7 +802,7 @@ class Api {
|
|
|
778
802
|
return this.raw.getChatMember({ chat_id, user_id }, signal);
|
|
779
803
|
}
|
|
780
804
|
/**
|
|
781
|
-
* Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate
|
|
805
|
+
* Use this method to set a new group sticker set for 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.
|
|
782
806
|
*
|
|
783
807
|
* @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
|
784
808
|
* @param sticker_set_name Name of the sticker set to be set as the group sticker set
|
|
@@ -793,7 +817,7 @@ class Api {
|
|
|
793
817
|
}, signal);
|
|
794
818
|
}
|
|
795
819
|
/**
|
|
796
|
-
* 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
|
|
820
|
+
* 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.
|
|
797
821
|
*
|
|
798
822
|
* @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
|
799
823
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
@@ -1107,7 +1131,7 @@ class Api {
|
|
|
1107
1131
|
* Use this method to send answers to an inline query. On success, True is returned.
|
|
1108
1132
|
* No more than 50 results per query are allowed.
|
|
1109
1133
|
*
|
|
1110
|
-
* Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account to adapt search results accordingly. To do this, it displays a 'Connect your YouTube account' button above the results, or even before showing any. The user presses the button, switches to a private chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an
|
|
1134
|
+
* Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account to adapt search results accordingly. To do this, it displays a 'Connect your YouTube account' button above the results, or even before showing any. The user presses the button, switches to a private chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an OAuth link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where they wanted to use the bot's inline capabilities.
|
|
1111
1135
|
*
|
|
1112
1136
|
* @param inline_query_id Unique identifier for the answered query
|
|
1113
1137
|
* @param results An array of results for the inline query
|
package/out/core/client.js
CHANGED
|
@@ -57,32 +57,32 @@ 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
|
|
60
61
|
return { ok: true, result: true };
|
|
61
62
|
}
|
|
62
63
|
else {
|
|
63
64
|
const p = payload !== null && payload !== void 0 ? payload : {};
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
const sensLogs = this.options.sensitiveLogs;
|
|
66
|
+
const abortController = new shim_node_js_1.AbortController();
|
|
67
|
+
const abort = combineAborts(abortController, signal);
|
|
68
|
+
const res = await new Promise((resolve, reject) => {
|
|
69
|
+
function onStreamError(err) {
|
|
70
|
+
abort();
|
|
71
|
+
reject(err);
|
|
72
|
+
}
|
|
73
|
+
const onHttpError = toHttpError(method, sensLogs, reject);
|
|
74
|
+
const config = formDataRequired
|
|
75
|
+
? (0, payload_js_1.createFormDataPayload)(p, onStreamError)
|
|
76
|
+
: (0, payload_js_1.createJsonPayload)(p);
|
|
77
|
+
const opts = {
|
|
70
78
|
...this.options.baseFetchConfig,
|
|
71
|
-
signal,
|
|
79
|
+
signal: abortController.signal,
|
|
72
80
|
...config,
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
msg += ` (${err.status}: ${err.statusText})`;
|
|
79
|
-
}
|
|
80
|
-
if (this.options.sensitiveLogs && err instanceof Error) {
|
|
81
|
-
msg += ` ${err.message}`;
|
|
82
|
-
}
|
|
83
|
-
throw new error_js_1.HttpError(msg, err);
|
|
84
|
-
}
|
|
85
|
-
return await res.json();
|
|
81
|
+
};
|
|
82
|
+
(0, shim_node_js_1.fetch)(url, opts).then((res) => res.json()).then(resolve)
|
|
83
|
+
.catch(onHttpError);
|
|
84
|
+
});
|
|
85
|
+
return res;
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
});
|
|
@@ -167,4 +167,28 @@ function isTelegramError(err) {
|
|
|
167
167
|
"status" in err &&
|
|
168
168
|
"statusText" in err);
|
|
169
169
|
}
|
|
170
|
+
function toHttpError(method, sensitiveLogs, reject) {
|
|
171
|
+
return (err) => {
|
|
172
|
+
let msg = `Network request for '${method}' failed!`;
|
|
173
|
+
if (isTelegramError(err))
|
|
174
|
+
msg += ` (${err.status}: ${err.statusText})`;
|
|
175
|
+
if (sensitiveLogs && err instanceof Error)
|
|
176
|
+
msg += ` ${err.message}`;
|
|
177
|
+
reject(new error_js_1.HttpError(msg, err));
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function combineAborts(abortController, signal) {
|
|
181
|
+
if (signal === undefined)
|
|
182
|
+
return () => abortController.abort();
|
|
183
|
+
const sig = signal;
|
|
184
|
+
function abort() {
|
|
185
|
+
abortController.abort();
|
|
186
|
+
sig.removeEventListener("abort", abort);
|
|
187
|
+
}
|
|
188
|
+
if (sig.aborted)
|
|
189
|
+
abort();
|
|
190
|
+
else
|
|
191
|
+
sig.addEventListener("abort", abort);
|
|
192
|
+
return abort;
|
|
193
|
+
}
|
|
170
194
|
const shim_node_js_1 = require("../shim.node.js");
|
package/out/core/payload.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare function createJsonPayload(payload: Record<string, unknown>): {
|
|
|
30
30
|
*
|
|
31
31
|
* @param payload The payload to wrap
|
|
32
32
|
*/
|
|
33
|
-
export declare function createFormDataPayload(payload: Record<string, unknown
|
|
33
|
+
export declare function createFormDataPayload(payload: Record<string, unknown>, onError: (err: unknown) => void): {
|
|
34
34
|
method: string;
|
|
35
35
|
headers: {
|
|
36
36
|
"content-type": string;
|
package/out/core/payload.js
CHANGED
|
@@ -46,6 +46,14 @@ function createJsonPayload(payload) {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
exports.createJsonPayload = createJsonPayload;
|
|
49
|
+
async function* protectItr(itr, onError) {
|
|
50
|
+
try {
|
|
51
|
+
yield* itr;
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
onError(err);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
49
57
|
/**
|
|
50
58
|
* Turns a payload into an options object that can be passed to a `fetch` call
|
|
51
59
|
* by setting the necessary headers and method. Note that this method creates a
|
|
@@ -54,15 +62,18 @@ exports.createJsonPayload = createJsonPayload;
|
|
|
54
62
|
*
|
|
55
63
|
* @param payload The payload to wrap
|
|
56
64
|
*/
|
|
57
|
-
function createFormDataPayload(payload) {
|
|
65
|
+
function createFormDataPayload(payload, onError) {
|
|
58
66
|
const boundary = createBoundary();
|
|
67
|
+
const itr = payloadToMultipartItr(payload, boundary);
|
|
68
|
+
const safeItr = protectItr(itr, onError);
|
|
69
|
+
const stream = (0, platform_node_js_1.itrToStream)(safeItr);
|
|
59
70
|
return {
|
|
60
71
|
method: "POST",
|
|
61
72
|
headers: {
|
|
62
73
|
"content-type": `multipart/form-data; boundary=${boundary}`,
|
|
63
74
|
connection: "keep-alive",
|
|
64
75
|
},
|
|
65
|
-
body:
|
|
76
|
+
body: stream,
|
|
66
77
|
};
|
|
67
78
|
}
|
|
68
79
|
exports.createFormDataPayload = createFormDataPayload;
|
package/out/filter.d.ts
CHANGED
|
@@ -82,6 +82,9 @@ declare const UPDATE_KEYS: {
|
|
|
82
82
|
readonly underline: {};
|
|
83
83
|
readonly strikethrough: {};
|
|
84
84
|
readonly code: {};
|
|
85
|
+
readonly pre: {};
|
|
86
|
+
readonly text_link: {};
|
|
87
|
+
readonly text_mention: {};
|
|
85
88
|
};
|
|
86
89
|
readonly caption_entities: {
|
|
87
90
|
readonly mention: {};
|
|
@@ -96,6 +99,9 @@ declare const UPDATE_KEYS: {
|
|
|
96
99
|
readonly underline: {};
|
|
97
100
|
readonly strikethrough: {};
|
|
98
101
|
readonly code: {};
|
|
102
|
+
readonly pre: {};
|
|
103
|
+
readonly text_link: {};
|
|
104
|
+
readonly text_mention: {};
|
|
99
105
|
};
|
|
100
106
|
readonly caption: {};
|
|
101
107
|
};
|
|
@@ -155,6 +161,9 @@ declare const UPDATE_KEYS: {
|
|
|
155
161
|
readonly underline: {};
|
|
156
162
|
readonly strikethrough: {};
|
|
157
163
|
readonly code: {};
|
|
164
|
+
readonly pre: {};
|
|
165
|
+
readonly text_link: {};
|
|
166
|
+
readonly text_mention: {};
|
|
158
167
|
};
|
|
159
168
|
readonly caption_entities: {
|
|
160
169
|
readonly mention: {};
|
|
@@ -169,6 +178,9 @@ declare const UPDATE_KEYS: {
|
|
|
169
178
|
readonly underline: {};
|
|
170
179
|
readonly strikethrough: {};
|
|
171
180
|
readonly code: {};
|
|
181
|
+
readonly pre: {};
|
|
182
|
+
readonly text_link: {};
|
|
183
|
+
readonly text_mention: {};
|
|
172
184
|
};
|
|
173
185
|
readonly caption: {};
|
|
174
186
|
};
|
|
@@ -214,6 +226,9 @@ declare const UPDATE_KEYS: {
|
|
|
214
226
|
readonly underline: {};
|
|
215
227
|
readonly strikethrough: {};
|
|
216
228
|
readonly code: {};
|
|
229
|
+
readonly pre: {};
|
|
230
|
+
readonly text_link: {};
|
|
231
|
+
readonly text_mention: {};
|
|
217
232
|
};
|
|
218
233
|
readonly caption_entities: {
|
|
219
234
|
readonly mention: {};
|
|
@@ -228,6 +243,9 @@ declare const UPDATE_KEYS: {
|
|
|
228
243
|
readonly underline: {};
|
|
229
244
|
readonly strikethrough: {};
|
|
230
245
|
readonly code: {};
|
|
246
|
+
readonly pre: {};
|
|
247
|
+
readonly text_link: {};
|
|
248
|
+
readonly text_mention: {};
|
|
231
249
|
};
|
|
232
250
|
readonly caption: {};
|
|
233
251
|
};
|
|
@@ -273,6 +291,9 @@ declare const UPDATE_KEYS: {
|
|
|
273
291
|
readonly underline: {};
|
|
274
292
|
readonly strikethrough: {};
|
|
275
293
|
readonly code: {};
|
|
294
|
+
readonly pre: {};
|
|
295
|
+
readonly text_link: {};
|
|
296
|
+
readonly text_mention: {};
|
|
276
297
|
};
|
|
277
298
|
readonly caption_entities: {
|
|
278
299
|
readonly mention: {};
|
|
@@ -287,6 +308,9 @@ declare const UPDATE_KEYS: {
|
|
|
287
308
|
readonly underline: {};
|
|
288
309
|
readonly strikethrough: {};
|
|
289
310
|
readonly code: {};
|
|
311
|
+
readonly pre: {};
|
|
312
|
+
readonly text_link: {};
|
|
313
|
+
readonly text_mention: {};
|
|
290
314
|
};
|
|
291
315
|
readonly caption: {};
|
|
292
316
|
};
|
|
@@ -312,6 +336,7 @@ declare const UPDATE_KEYS: {
|
|
|
312
336
|
readonly is_bot: {};
|
|
313
337
|
};
|
|
314
338
|
};
|
|
339
|
+
readonly chat_join_request: {};
|
|
315
340
|
};
|
|
316
341
|
declare type KeyOf<T> = string & keyof T;
|
|
317
342
|
declare type S = typeof UPDATE_KEYS;
|
package/out/filter.js
CHANGED
|
@@ -206,6 +206,9 @@ const ENTITY_KEYS = {
|
|
|
206
206
|
underline: {},
|
|
207
207
|
strikethrough: {},
|
|
208
208
|
code: {},
|
|
209
|
+
pre: {},
|
|
210
|
+
text_link: {},
|
|
211
|
+
text_mention: {},
|
|
209
212
|
};
|
|
210
213
|
const USER_KEYS = {
|
|
211
214
|
me: {},
|
|
@@ -280,6 +283,7 @@ const UPDATE_KEYS = {
|
|
|
280
283
|
poll_answer: {},
|
|
281
284
|
my_chat_member: CHAT_MEMBER_UPDATED_KEYS,
|
|
282
285
|
chat_member: CHAT_MEMBER_UPDATED_KEYS,
|
|
286
|
+
chat_join_request: {},
|
|
283
287
|
};
|
|
284
288
|
// === Define some helpers for handling shortcuts, e.g. in 'edit:photo'
|
|
285
289
|
const L1_SHORTCUTS = {
|
package/out/platform.node.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { InputFileProxy } from "@grammyjs/types";
|
|
|
3
3
|
import { Agent } from "https";
|
|
4
4
|
import { Readable } from "stream";
|
|
5
5
|
import type { ReadStream } from "fs";
|
|
6
|
+
import { URL } from "url";
|
|
6
7
|
export * from "@grammyjs/types";
|
|
7
8
|
export { debug } from "debug";
|
|
8
9
|
export declare const itrToStream: (itr: AsyncIterable<Uint8Array>) => Readable;
|
|
@@ -11,6 +12,14 @@ export declare const baseFetchConfig: {
|
|
|
11
12
|
compress: boolean;
|
|
12
13
|
agent: Agent;
|
|
13
14
|
};
|
|
15
|
+
/** Something that looks like a URL. */
|
|
16
|
+
interface URLLike {
|
|
17
|
+
/**
|
|
18
|
+
* Identifier of the resouce. Must be in a format that can be parsed by the
|
|
19
|
+
* URL constructor.
|
|
20
|
+
*/
|
|
21
|
+
url: string;
|
|
22
|
+
}
|
|
14
23
|
export declare const inputFileData: unique symbol;
|
|
15
24
|
/**
|
|
16
25
|
* An `InputFile` wraps a number of different sources for [sending
|
|
@@ -20,7 +29,8 @@ export declare const inputFileData: unique symbol;
|
|
|
20
29
|
* Reference](https://core.telegram.org/bots/api#inputfile).
|
|
21
30
|
*/
|
|
22
31
|
export declare class InputFile {
|
|
23
|
-
|
|
32
|
+
private consumed;
|
|
33
|
+
private readonly fileData;
|
|
24
34
|
/**
|
|
25
35
|
* Optional name of the constructed `InputFile` instance.
|
|
26
36
|
*
|
|
@@ -35,7 +45,8 @@ export declare class InputFile {
|
|
|
35
45
|
* @param file A path to a local file or a `Buffer` or a `fs.ReadStream` that specifies the file data
|
|
36
46
|
* @param filename Optional name of the file
|
|
37
47
|
*/
|
|
38
|
-
constructor(file: string | Uint8Array | ReadStream | AsyncIterable<Uint8Array>, filename?: string);
|
|
48
|
+
constructor(file: string | URL | URLLike | Uint8Array | ReadStream | AsyncIterable<Uint8Array>, filename?: string);
|
|
49
|
+
get [inputFileData](): string | Uint8Array | AsyncIterable<Uint8Array> | ReadStream;
|
|
39
50
|
}
|
|
40
51
|
declare type GrammyTypes = InputFileProxy<InputFile>;
|
|
41
52
|
/** Wrapper type to bundle all methods of the Telegram API */
|
package/out/platform.node.js
CHANGED
|
@@ -9,12 +9,12 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
9
9
|
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
|
-
var _a;
|
|
13
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
13
|
exports.InputFile = exports.inputFileData = exports.baseFetchConfig = exports.streamFile = exports.itrToStream = exports.debug = void 0;
|
|
15
14
|
const https_1 = require("https");
|
|
16
15
|
const path_1 = require("path");
|
|
17
16
|
const stream_1 = require("stream");
|
|
17
|
+
const url_1 = require("url");
|
|
18
18
|
// === Export all API types
|
|
19
19
|
__exportStar(require("@grammyjs/types"), exports);
|
|
20
20
|
// === Export debug
|
|
@@ -50,7 +50,13 @@ class InputFile {
|
|
|
50
50
|
* @param filename Optional name of the file
|
|
51
51
|
*/
|
|
52
52
|
constructor(file, filename) {
|
|
53
|
-
Object.defineProperty(this,
|
|
53
|
+
Object.defineProperty(this, "consumed", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: false
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(this, "fileData", {
|
|
54
60
|
enumerable: true,
|
|
55
61
|
configurable: true,
|
|
56
62
|
writable: true,
|
|
@@ -69,12 +75,37 @@ class InputFile {
|
|
|
69
75
|
writable: true,
|
|
70
76
|
value: void 0
|
|
71
77
|
});
|
|
72
|
-
this
|
|
78
|
+
this.fileData = file;
|
|
73
79
|
if (filename === undefined && typeof file === "string") {
|
|
74
80
|
filename = (0, path_1.basename)(file);
|
|
75
81
|
}
|
|
76
82
|
this.filename = filename;
|
|
77
83
|
}
|
|
84
|
+
get [exports.inputFileData]() {
|
|
85
|
+
if (this.consumed) {
|
|
86
|
+
throw new Error("Cannot reuse InputFile data source!");
|
|
87
|
+
}
|
|
88
|
+
let data = this.fileData;
|
|
89
|
+
if (typeof data === "object" && ("url" in data || data instanceof url_1.URL)) {
|
|
90
|
+
data = fetchFile(data instanceof url_1.URL ? data : data.url);
|
|
91
|
+
}
|
|
92
|
+
else if (typeof data !== "string" && (!(data instanceof Uint8Array))) {
|
|
93
|
+
this.consumed = false;
|
|
94
|
+
}
|
|
95
|
+
return data;
|
|
96
|
+
}
|
|
78
97
|
}
|
|
79
98
|
exports.InputFile = InputFile;
|
|
80
|
-
|
|
99
|
+
async function* fetchFile(url) {
|
|
100
|
+
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
|
+
for await (const chunk of body) {
|
|
105
|
+
if (typeof chunk === "string") {
|
|
106
|
+
throw new Error(`Could not transfer file, received string data instead of bytes from '${url}'`);
|
|
107
|
+
}
|
|
108
|
+
yield chunk;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const shim_node_js_1 = require("./shim.node.js");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grammy",
|
|
3
3
|
"description": "grammY core package ported to Node.js",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.2",
|
|
5
5
|
"author": "KnorpelSenf",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"engines": {
|
|
@@ -14,17 +14,21 @@
|
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"prepare": "npm run backport",
|
|
17
|
+
"cache": "deno cache src/mod.ts",
|
|
18
|
+
"lint": "deno lint --config deno.json",
|
|
19
|
+
"fmt": "deno fmt --config deno.json",
|
|
20
|
+
"test": "deno test ./test/",
|
|
17
21
|
"backport": "deno2node tsconfig.json"
|
|
18
22
|
},
|
|
19
23
|
"dependencies": {
|
|
20
|
-
"@grammyjs/types": "^2.
|
|
24
|
+
"@grammyjs/types": "^2.3.1",
|
|
21
25
|
"abort-controller": "^3.0.0",
|
|
22
26
|
"debug": "^4.3.2",
|
|
23
27
|
"node-fetch": "^2.6.5"
|
|
24
28
|
},
|
|
25
29
|
"devDependencies": {
|
|
26
30
|
"@types/debug": "^4.1.7",
|
|
27
|
-
"@types/node": "^12.20.
|
|
31
|
+
"@types/node": "^12.20.33",
|
|
28
32
|
"@types/node-fetch": "^2.5.12",
|
|
29
33
|
"deno2node": "^1.0.0"
|
|
30
34
|
},
|