grammy 1.28.0 → 1.30.0
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 +5 -1
- package/out/context.d.ts +55 -18
- package/out/context.js +96 -41
- package/out/convenience/frameworks.js +1 -0
- package/out/convenience/session.d.ts +13 -15
- package/out/convenience/session.js +5 -5
- package/out/core/api.d.ts +33 -10
- package/out/core/api.js +36 -9
- package/out/filter.d.ts +85 -20
- package/out/filter.js +10 -4
- package/out/web.mjs +71 -27
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
<!-- deno-fmt-ignore-start -->
|
|
12
12
|
|
|
13
|
-
[](https://core.telegram.org/bots/api)
|
|
14
14
|
[](https://deno.land/x/grammy)
|
|
15
15
|
[](https://www.npmjs.org/package/grammy)
|
|
16
16
|
[](#contributors-)
|
|
@@ -306,6 +306,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
306
306
|
<td align="center" valign="top" width="11.11%"><a href="https://consortiumkey.com/"><img src="https://avatars.githubusercontent.com/u/95214604?v=4?s=100" width="100px;" alt="lexomis"/><br /><sub><b>lexomis</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Alexomis" title="Reviewed Pull Requests">👀</a></td>
|
|
307
307
|
<td align="center" valign="top" width="11.11%"><a href="https://github.com/asologor"><img src="https://avatars.githubusercontent.com/u/97506048?v=4?s=100" width="100px;" alt="Andrew Sologor"/><br /><sub><b>Andrew Sologor</b></sub></a><br /><a href="https://github.com/grammyjs/grammY/pulls?q=is%3Apr+reviewed-by%3Aandrew-sol" title="Reviewed Pull Requests">👀</a></td>
|
|
308
308
|
</tr>
|
|
309
|
+
<tr>
|
|
310
|
+
<td align="center" valign="top" width="11.11%"><a href="https://github.com/rayz1065"><img src="https://avatars.githubusercontent.com/u/37779815?v=4?s=100" width="100px;" alt="rayz"/><br /><sub><b>rayz</b></sub></a><br /><a href="#question-rayz1065" title="Answering Questions">💬</a> <a href="#ideas-rayz1065" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/grammyjs/grammY/commits?author=rayz1065" title="Code">💻</a></td>
|
|
311
|
+
<td align="center" valign="top" width="11.11%"><a href="https://github.com/z44d"><img src="https://avatars.githubusercontent.com/u/162994967?v=4?s=100" width="100px;" alt="Zaid"/><br /><sub><b>Zaid</b></sub></a><br /><a href="#tool-z44d" title="Tools">🔧</a></td>
|
|
312
|
+
</tr>
|
|
309
313
|
</tbody>
|
|
310
314
|
</table>
|
|
311
315
|
|
package/out/context.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { type Filter, type FilterCore, type FilterQuery } from "./filter.js";
|
|
|
4
4
|
import { type Chat, type ChatPermissions, type InlineQueryResult, type InputFile, type InputMedia, type InputMediaAudio, type InputMediaDocument, type InputMediaPhoto, type InputMediaVideo, type InputPaidMedia, type InputPollOption, type LabeledPrice, type Message, type MessageEntity, type PassportElementError, type ReactionType, type ReactionTypeEmoji, type Update, type User, type UserFromGetMe } from "./types.js";
|
|
5
5
|
export type MaybeArray<T> = T | T[];
|
|
6
6
|
/** permits `string` but gives hints */
|
|
7
|
-
export type StringWithCommandSuggestions = (string & Record<never, never>) | "start" | "help" | "settings" | "privacy";
|
|
7
|
+
export type StringWithCommandSuggestions = (string & Record<never, never>) | "start" | "help" | "settings" | "privacy" | "developer_info";
|
|
8
8
|
type Other<M extends Methods<RawApi>, X extends string = never> = OtherApi<RawApi, M, X>;
|
|
9
9
|
type SnakeToCamelCase<S extends string> = S extends `${infer L}_${infer R}` ? `${L}${Capitalize<SnakeToCamelCase<R>>}` : S;
|
|
10
10
|
type AliasProps<U> = {
|
|
@@ -216,6 +216,8 @@ export declare class Context implements RenamedUpdate {
|
|
|
216
216
|
get chatBoost(): import("@grammyjs/types/manage.js").ChatBoostUpdated | undefined;
|
|
217
217
|
/** Alias for `ctx.update.removed_chat_boost` */
|
|
218
218
|
get removedChatBoost(): import("@grammyjs/types/manage.js").ChatBoostRemoved | undefined;
|
|
219
|
+
/** Alias for `ctx.update.purchased_paid_media` */
|
|
220
|
+
get purchasedPaidMedia(): import("@grammyjs/types/payment.js").PaidMediaPurchased | undefined;
|
|
219
221
|
/**
|
|
220
222
|
* Get the message object from wherever possible. Alias for `this.message ??
|
|
221
223
|
* this.editedMessage ?? this.channelPost ?? this.editedChannelPost ??
|
|
@@ -241,7 +243,8 @@ export declare class Context implements RenamedUpdate {
|
|
|
241
243
|
* (this.chatBoost?.boost ?? this.removedChatBoost)?.source)?.user ??
|
|
242
244
|
* (this.callbackQuery ?? this.msg ?? this.inlineQuery ??
|
|
243
245
|
* this.chosenInlineResult ?? this.shippingQuery ?? this.preCheckoutQuery ??
|
|
244
|
-
* this.myChatMember ?? this.chatMember ?? this.chatJoinRequest
|
|
246
|
+
* this.myChatMember ?? this.chatMember ?? this.chatJoinRequest ??
|
|
247
|
+
* this.purchasedPaidMedia)?.from`.
|
|
245
248
|
*/
|
|
246
249
|
get from(): User | undefined;
|
|
247
250
|
/**
|
|
@@ -308,15 +311,18 @@ export declare class Context implements RenamedUpdate {
|
|
|
308
311
|
* customEmojiAdded: [],
|
|
309
312
|
* customEmojiKept: [],
|
|
310
313
|
* customEmojiRemoved: ['id0123'],
|
|
314
|
+
* paid: true,
|
|
315
|
+
* paidAdded: false,
|
|
316
|
+
* paidRemoved: false,
|
|
311
317
|
* }
|
|
312
318
|
* ```
|
|
313
319
|
* In the above example, a tada reaction was added by the user, and a custom
|
|
314
320
|
* emoji reaction with the custom emoji 'id0123' was removed in the same
|
|
315
|
-
* update. The user had already reacted with a thumbs up reaction
|
|
316
|
-
* they left unchanged. As a result, the current
|
|
317
|
-
* thumbs up
|
|
318
|
-
* emoji in one list)
|
|
319
|
-
* `ctx.messageReaction.new_reaction`.
|
|
321
|
+
* update. The user had already reacted with a thumbs up reaction and a paid
|
|
322
|
+
* star reaction, which they left both unchanged. As a result, the current
|
|
323
|
+
* reaction by the user is thumbs up, tada, and a paid reaction. Note that
|
|
324
|
+
* the current reaction (all emoji reactions regardless of type in one list)
|
|
325
|
+
* can also be obtained from `ctx.messageReaction.new_reaction`.
|
|
320
326
|
*
|
|
321
327
|
* Remember that reaction updates only include information about the
|
|
322
328
|
* reaction of a specific user. The respective message may have many more
|
|
@@ -341,6 +347,16 @@ export declare class Context implements RenamedUpdate {
|
|
|
341
347
|
customEmojiKept: string[];
|
|
342
348
|
/** Custom emoji removed from this user's reaction */
|
|
343
349
|
customEmojiRemoved: string[];
|
|
350
|
+
/**
|
|
351
|
+
* `true` if a paid reaction is currently present in this user's
|
|
352
|
+
* reaction, and `false` otherwise
|
|
353
|
+
*/
|
|
354
|
+
paid: boolean;
|
|
355
|
+
/**
|
|
356
|
+
* `true` if a paid reaction was newly added to this user's reaction,
|
|
357
|
+
* and `false` otherwise
|
|
358
|
+
*/
|
|
359
|
+
paidAdded: boolean;
|
|
344
360
|
};
|
|
345
361
|
/**
|
|
346
362
|
* `Context.has` is an object that contains a number of useful functions for
|
|
@@ -617,7 +633,7 @@ export declare class Context implements RenamedUpdate {
|
|
|
617
633
|
location: import("@grammyjs/types/message.js").Location;
|
|
618
634
|
})>;
|
|
619
635
|
/**
|
|
620
|
-
* Context-aware alias for `api.sendPaidMedia`. Use this method to send paid media
|
|
636
|
+
* Context-aware alias for `api.sendPaidMedia`. Use this method to send paid media. On success, the sent Message is returned.
|
|
621
637
|
*
|
|
622
638
|
* @param star_count The number of Telegram Stars that must be paid to buy access to the media
|
|
623
639
|
* @param media An array describing the media to be sent; up to 10 items
|
|
@@ -665,13 +681,13 @@ export declare class Context implements RenamedUpdate {
|
|
|
665
681
|
/**
|
|
666
682
|
* Context-aware alias for `api.sendDice`. Use this method to send an animated emoji that will display a random value. On success, the sent Message is returned.
|
|
667
683
|
*
|
|
668
|
-
* @param emoji Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6 for
|
|
684
|
+
* @param emoji Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, “🏀”, “⚽”, “🎳”, or “🎰”. Dice can have values 1-6 for “🎲”, “🎯” and “🎳”, values 1-5 for “🏀” and “⚽”, and values 1-64 for “🎰”. Defaults to “🎲”
|
|
669
685
|
* @param other Optional remaining parameters, confer the official reference below
|
|
670
686
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
671
687
|
*
|
|
672
688
|
* **Official reference:** https://core.telegram.org/bots/api#senddice
|
|
673
689
|
*/
|
|
674
|
-
replyWithDice(emoji: string, other?: Other<"sendDice", "chat_id" | "emoji">, signal?: AbortSignal): Promise<Message.DiceMessage>;
|
|
690
|
+
replyWithDice(emoji: (string & Record<never, never>) | "🎲" | "🎯" | "🏀" | "⚽" | "🎳" | "🎰", other?: Other<"sendDice", "chat_id" | "emoji">, signal?: AbortSignal): Promise<Message.DiceMessage>;
|
|
675
691
|
/**
|
|
676
692
|
* Context-aware alias for `api.sendChatAction`. Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success.
|
|
677
693
|
*
|
|
@@ -687,9 +703,9 @@ export declare class Context implements RenamedUpdate {
|
|
|
687
703
|
*/
|
|
688
704
|
replyWithChatAction(action: "typing" | "upload_photo" | "record_video" | "upload_video" | "record_voice" | "upload_voice" | "upload_document" | "choose_sticker" | "find_location" | "record_video_note" | "upload_video_note", other?: Other<"sendChatAction", "chat_id" | "action">, signal?: AbortSignal): Promise<true>;
|
|
689
705
|
/**
|
|
690
|
-
* Context-aware alias for `api.setMessageReaction`. Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel.
|
|
706
|
+
* Context-aware alias for `api.setMessageReaction`. Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success.
|
|
691
707
|
*
|
|
692
|
-
* @param reaction A list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators.
|
|
708
|
+
* @param reaction A list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. Paid reactions can't be used by bots.
|
|
693
709
|
* @param other Optional remaining parameters, confer the official reference below
|
|
694
710
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
695
711
|
*
|
|
@@ -716,7 +732,7 @@ export declare class Context implements RenamedUpdate {
|
|
|
716
732
|
*/
|
|
717
733
|
getUserChatBoosts(chat_id: number | string, signal?: AbortSignal): Promise<import("@grammyjs/types/manage.js").UserChatBoosts>;
|
|
718
734
|
/**
|
|
719
|
-
*
|
|
735
|
+
* Context-aware alias for `api.getBusinessConnection`. Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success.
|
|
720
736
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
721
737
|
*
|
|
722
738
|
* **Official reference:** https://core.telegram.org/bots/api#getbusinessconnection
|
|
@@ -872,7 +888,7 @@ export declare class Context implements RenamedUpdate {
|
|
|
872
888
|
*/
|
|
873
889
|
createChatInviteLink(other?: Other<"createChatInviteLink", "chat_id">, signal?: AbortSignal): Promise<import("@grammyjs/types/manage.js").ChatInviteLink>;
|
|
874
890
|
/**
|
|
875
|
-
*
|
|
891
|
+
* Context-aware alias for `api.editChatInviteLink`. 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.
|
|
876
892
|
*
|
|
877
893
|
* @param invite_link The invite link to edit
|
|
878
894
|
* @param other Optional remaining parameters, confer the official reference below
|
|
@@ -882,7 +898,28 @@ export declare class Context implements RenamedUpdate {
|
|
|
882
898
|
*/
|
|
883
899
|
editChatInviteLink(invite_link: string, other?: Other<"editChatInviteLink", "chat_id" | "invite_link">, signal?: AbortSignal): Promise<import("@grammyjs/types/manage.js").ChatInviteLink>;
|
|
884
900
|
/**
|
|
885
|
-
*
|
|
901
|
+
* Context-aware alias for `api.createChatSubscriptionInviteLink`. Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights. The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink. Returns the new invite link as a ChatInviteLink object.
|
|
902
|
+
*
|
|
903
|
+
* @param subscription_period The number of seconds the subscription will be active for before the next payment. Currently, it must always be 2592000 (30 days).
|
|
904
|
+
* @param subscription_price The amount of Telegram Stars a user must pay initially and after each subsequent subscription period to be a member of the chat; 1-2500
|
|
905
|
+
* @param other Optional remaining parameters, confer the official reference below
|
|
906
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
907
|
+
*
|
|
908
|
+
* **Official reference:** https://core.telegram.org/bots/api#createchatsubscriptioninvitelink
|
|
909
|
+
*/
|
|
910
|
+
createChatSubscriptionInviteLink(subscription_period: number, subscription_price: number, other?: Other<"createChatSubscriptionInviteLink", "chat_id" | "subscription_period" | "subscription_price">, signal?: AbortSignal): Promise<import("@grammyjs/types/manage.js").ChatInviteLink>;
|
|
911
|
+
/**
|
|
912
|
+
* Context-aware alias for `api.editChatSubscriptionInviteLink`. Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights. Returns the edited invite link as a ChatInviteLink object.
|
|
913
|
+
*
|
|
914
|
+
* @param invite_link The invite link to edit
|
|
915
|
+
* @param other Optional remaining parameters, confer the official reference below
|
|
916
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
917
|
+
*
|
|
918
|
+
* **Official reference:** https://core.telegram.org/bots/api#editchatsubscriptioninvitelink
|
|
919
|
+
*/
|
|
920
|
+
editChatSubscriptionInviteLink(invite_link: string, other?: Other<"editChatSubscriptionInviteLink", "chat_id" | "invite_link">, signal?: AbortSignal): Promise<import("@grammyjs/types/manage.js").ChatInviteLink>;
|
|
921
|
+
/**
|
|
922
|
+
* Context-aware alias for `api.revokeChatInviteLink`. 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.
|
|
886
923
|
*
|
|
887
924
|
* @param invite_link The invite link to revoke
|
|
888
925
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
@@ -1049,7 +1086,7 @@ export declare class Context implements RenamedUpdate {
|
|
|
1049
1086
|
*/
|
|
1050
1087
|
createForumTopic(name: string, other?: Other<"createForumTopic", "chat_id" | "name">, signal?: AbortSignal): Promise<import("@grammyjs/types/manage.js").ForumTopic>;
|
|
1051
1088
|
/**
|
|
1052
|
-
* Context-aware alias for `api.editForumTopic`. Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
|
|
1089
|
+
* Context-aware alias for `api.editForumTopic`. Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
|
|
1053
1090
|
*
|
|
1054
1091
|
* @param other Optional remaining parameters, confer the official reference below
|
|
1055
1092
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
@@ -1090,7 +1127,7 @@ export declare class Context implements RenamedUpdate {
|
|
|
1090
1127
|
*/
|
|
1091
1128
|
unpinAllForumTopicMessages(signal?: AbortSignal): Promise<true>;
|
|
1092
1129
|
/**
|
|
1093
|
-
* Context-aware alias for `api.editGeneralForumTopic`. Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.
|
|
1130
|
+
* Context-aware alias for `api.editGeneralForumTopic`. Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
|
|
1094
1131
|
*
|
|
1095
1132
|
* @param name New topic name, 1-128 characters
|
|
1096
1133
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
@@ -1164,7 +1201,7 @@ export declare class Context implements RenamedUpdate {
|
|
|
1164
1201
|
* @param other Optional remaining parameters, confer the official reference below
|
|
1165
1202
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
1166
1203
|
*
|
|
1167
|
-
* **Official reference:** https://core.telegram.org/bots/api#
|
|
1204
|
+
* **Official reference:** https://core.telegram.org/bots/api#getchatmenubutton
|
|
1168
1205
|
*/
|
|
1169
1206
|
getChatMenuButton(other?: Other<"getChatMenuButton">, signal?: AbortSignal): Promise<import("@grammyjs/types/settings.js").MenuButton>;
|
|
1170
1207
|
/**
|
package/out/context.js
CHANGED
|
@@ -67,11 +67,18 @@ const checker = {
|
|
|
67
67
|
const normalized = typeof reaction === "string"
|
|
68
68
|
? [{ type: "emoji", emoji: reaction }]
|
|
69
69
|
: (Array.isArray(reaction) ? reaction : [reaction]).map((emoji) => typeof emoji === "string" ? { type: "emoji", emoji } : emoji);
|
|
70
|
+
const emoji = new Set(normalized.filter((r) => r.type === "emoji")
|
|
71
|
+
.map((r) => r.emoji));
|
|
72
|
+
const customEmoji = new Set(normalized.filter((r) => r.type === "custom_emoji")
|
|
73
|
+
.map((r) => r.custom_emoji_id));
|
|
74
|
+
const paid = normalized.some((r) => r.type === "paid");
|
|
70
75
|
return (ctx) => {
|
|
71
76
|
if (!hasMessageReaction(ctx))
|
|
72
77
|
return false;
|
|
73
78
|
const { old_reaction, new_reaction } = ctx.messageReaction;
|
|
79
|
+
// try to find a wanted reaction that is new and not old
|
|
74
80
|
for (const reaction of new_reaction) {
|
|
81
|
+
// first check if the reaction existed previously
|
|
75
82
|
let isOld = false;
|
|
76
83
|
if (reaction.type === "emoji") {
|
|
77
84
|
for (const old of old_reaction) {
|
|
@@ -93,34 +100,38 @@ const checker = {
|
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
102
|
}
|
|
103
|
+
else if (reaction.type === "paid") {
|
|
104
|
+
for (const old of old_reaction) {
|
|
105
|
+
if (old.type !== "paid")
|
|
106
|
+
continue;
|
|
107
|
+
isOld = true;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
96
111
|
else {
|
|
97
112
|
// always regard unsupported emoji types as new
|
|
98
113
|
}
|
|
99
|
-
if
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else if (reaction.type === "custom_emoji") {
|
|
110
|
-
for (const wanted of normalized) {
|
|
111
|
-
if (wanted.type !== "custom_emoji")
|
|
112
|
-
continue;
|
|
113
|
-
if (wanted.custom_emoji_id ===
|
|
114
|
-
reaction.custom_emoji_id) {
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
// always regard unsupported emoji types as new
|
|
114
|
+
// disregard reaction if it is not new
|
|
115
|
+
if (isOld)
|
|
116
|
+
continue;
|
|
117
|
+
// check if the new reaction is wanted and short-circuit
|
|
118
|
+
if (reaction.type === "emoji") {
|
|
119
|
+
if (emoji.has(reaction.emoji))
|
|
121
120
|
return true;
|
|
122
|
-
}
|
|
123
121
|
}
|
|
122
|
+
else if (reaction.type === "custom_emoji") {
|
|
123
|
+
if (customEmoji.has(reaction.custom_emoji_id))
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
else if (reaction.type === "paid") {
|
|
127
|
+
if (paid)
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// always regard unsupported emoji types as new
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
// new reaction not wanted, check next one
|
|
124
135
|
}
|
|
125
136
|
return false;
|
|
126
137
|
};
|
|
@@ -222,6 +233,7 @@ class Context {
|
|
|
222
233
|
this.me = me;
|
|
223
234
|
}
|
|
224
235
|
// UPDATE SHORTCUTS
|
|
236
|
+
// Keep in sync with types in `filter.ts`.
|
|
225
237
|
/** Alias for `ctx.update.message` */
|
|
226
238
|
get message() {
|
|
227
239
|
return this.update.message;
|
|
@@ -310,6 +322,10 @@ class Context {
|
|
|
310
322
|
get removedChatBoost() {
|
|
311
323
|
return this.update.removed_chat_boost;
|
|
312
324
|
}
|
|
325
|
+
/** Alias for `ctx.update.purchased_paid_media` */
|
|
326
|
+
get purchasedPaidMedia() {
|
|
327
|
+
return this.update.purchased_paid_media;
|
|
328
|
+
}
|
|
313
329
|
// AGGREGATION SHORTCUTS
|
|
314
330
|
/**
|
|
315
331
|
* Get the message object from wherever possible. Alias for `this.message ??
|
|
@@ -348,12 +364,13 @@ class Context {
|
|
|
348
364
|
* (this.chatBoost?.boost ?? this.removedChatBoost)?.source)?.user ??
|
|
349
365
|
* (this.callbackQuery ?? this.msg ?? this.inlineQuery ??
|
|
350
366
|
* this.chosenInlineResult ?? this.shippingQuery ?? this.preCheckoutQuery ??
|
|
351
|
-
* this.myChatMember ?? this.chatMember ?? this.chatJoinRequest
|
|
367
|
+
* this.myChatMember ?? this.chatMember ?? this.chatJoinRequest ??
|
|
368
|
+
* this.purchasedPaidMedia)?.from`.
|
|
352
369
|
*/
|
|
353
370
|
get from() {
|
|
354
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
371
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
355
372
|
// Keep in sync with types in `filter.ts`.
|
|
356
|
-
return (_g = (_f = ((_b = (_a = this.businessConnection) !== null && _a !== void 0 ? _a : this.messageReaction) !== null && _b !== void 0 ? _b : (_e = ((_d = (_c = this.chatBoost) === null || _c === void 0 ? void 0 : _c.boost) !== null && _d !== void 0 ? _d : this.removedChatBoost)) === null || _e === void 0 ? void 0 : _e.source)) === null || _f === void 0 ? void 0 : _f.user) !== null && _g !== void 0 ? _g : (_r = (
|
|
373
|
+
return (_g = (_f = ((_b = (_a = this.businessConnection) !== null && _a !== void 0 ? _a : this.messageReaction) !== null && _b !== void 0 ? _b : (_e = ((_d = (_c = this.chatBoost) === null || _c === void 0 ? void 0 : _c.boost) !== null && _d !== void 0 ? _d : this.removedChatBoost)) === null || _e === void 0 ? void 0 : _e.source)) === null || _f === void 0 ? void 0 : _f.user) !== null && _g !== void 0 ? _g : (_s = ((_r = (_q = (_p = (_o = (_m = (_l = (_k = (_j = (_h = this.callbackQuery) !== null && _h !== void 0 ? _h : this.msg) !== null && _j !== void 0 ? _j : this.inlineQuery) !== null && _k !== void 0 ? _k : this.chosenInlineResult) !== null && _l !== void 0 ? _l : this.shippingQuery) !== null && _m !== void 0 ? _m : this.preCheckoutQuery) !== null && _o !== void 0 ? _o : this.myChatMember) !== null && _p !== void 0 ? _p : this.chatMember) !== null && _q !== void 0 ? _q : this.chatJoinRequest) !== null && _r !== void 0 ? _r : this.purchasedPaidMedia)) === null || _s === void 0 ? void 0 : _s.from;
|
|
357
374
|
}
|
|
358
375
|
/**
|
|
359
376
|
* Get the message identifier from wherever possible. Alias for
|
|
@@ -427,15 +444,18 @@ class Context {
|
|
|
427
444
|
* customEmojiAdded: [],
|
|
428
445
|
* customEmojiKept: [],
|
|
429
446
|
* customEmojiRemoved: ['id0123'],
|
|
447
|
+
* paid: true,
|
|
448
|
+
* paidAdded: false,
|
|
449
|
+
* paidRemoved: false,
|
|
430
450
|
* }
|
|
431
451
|
* ```
|
|
432
452
|
* In the above example, a tada reaction was added by the user, and a custom
|
|
433
453
|
* emoji reaction with the custom emoji 'id0123' was removed in the same
|
|
434
|
-
* update. The user had already reacted with a thumbs up reaction
|
|
435
|
-
* they left unchanged. As a result, the current
|
|
436
|
-
* thumbs up
|
|
437
|
-
* emoji in one list)
|
|
438
|
-
* `ctx.messageReaction.new_reaction`.
|
|
454
|
+
* update. The user had already reacted with a thumbs up reaction and a paid
|
|
455
|
+
* star reaction, which they left both unchanged. As a result, the current
|
|
456
|
+
* reaction by the user is thumbs up, tada, and a paid reaction. Note that
|
|
457
|
+
* the current reaction (all emoji reactions regardless of type in one list)
|
|
458
|
+
* can also be obtained from `ctx.messageReaction.new_reaction`.
|
|
439
459
|
*
|
|
440
460
|
* Remember that reaction updates only include information about the
|
|
441
461
|
* reaction of a specific user. The respective message may have many more
|
|
@@ -452,6 +472,8 @@ class Context {
|
|
|
452
472
|
const customEmojiAdded = [];
|
|
453
473
|
const customEmojiKept = [];
|
|
454
474
|
const customEmojiRemoved = [];
|
|
475
|
+
let paid = false;
|
|
476
|
+
let paidAdded = false;
|
|
455
477
|
const r = this.messageReaction;
|
|
456
478
|
if (r !== undefined) {
|
|
457
479
|
const { old_reaction, new_reaction } = r;
|
|
@@ -463,6 +485,9 @@ class Context {
|
|
|
463
485
|
else if (reaction.type === "custom_emoji") {
|
|
464
486
|
customEmoji.push(reaction.custom_emoji_id);
|
|
465
487
|
}
|
|
488
|
+
else if (reaction.type === "paid") {
|
|
489
|
+
paid = paidAdded = true;
|
|
490
|
+
}
|
|
466
491
|
}
|
|
467
492
|
// temporarily move all old emoji to the *Removed arrays
|
|
468
493
|
for (const reaction of old_reaction) {
|
|
@@ -472,6 +497,9 @@ class Context {
|
|
|
472
497
|
else if (reaction.type === "custom_emoji") {
|
|
473
498
|
customEmojiRemoved.push(reaction.custom_emoji_id);
|
|
474
499
|
}
|
|
500
|
+
else if (reaction.type === "paid") {
|
|
501
|
+
paidAdded = false;
|
|
502
|
+
}
|
|
475
503
|
}
|
|
476
504
|
// temporarily move all new emoji to the *Added arrays
|
|
477
505
|
emojiAdded.push(...emoji);
|
|
@@ -518,6 +546,8 @@ class Context {
|
|
|
518
546
|
customEmojiAdded,
|
|
519
547
|
customEmojiKept,
|
|
520
548
|
customEmojiRemoved,
|
|
549
|
+
paid,
|
|
550
|
+
paidAdded,
|
|
521
551
|
};
|
|
522
552
|
}
|
|
523
553
|
/**
|
|
@@ -831,7 +861,7 @@ class Context {
|
|
|
831
861
|
: this.api.stopMessageLiveLocation(orThrow(this.chatId, "stopMessageLiveLocation"), orThrow(this.msgId, "stopMessageLiveLocation"), other, signal);
|
|
832
862
|
}
|
|
833
863
|
/**
|
|
834
|
-
* Context-aware alias for `api.sendPaidMedia`. Use this method to send paid media
|
|
864
|
+
* Context-aware alias for `api.sendPaidMedia`. Use this method to send paid media. On success, the sent Message is returned.
|
|
835
865
|
*
|
|
836
866
|
* @param star_count The number of Telegram Stars that must be paid to buy access to the media
|
|
837
867
|
* @param media An array describing the media to be sent; up to 10 items
|
|
@@ -887,7 +917,7 @@ class Context {
|
|
|
887
917
|
/**
|
|
888
918
|
* Context-aware alias for `api.sendDice`. Use this method to send an animated emoji that will display a random value. On success, the sent Message is returned.
|
|
889
919
|
*
|
|
890
|
-
* @param emoji Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6 for
|
|
920
|
+
* @param emoji Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, “🏀”, “⚽”, “🎳”, or “🎰”. Dice can have values 1-6 for “🎲”, “🎯” and “🎳”, values 1-5 for “🏀” and “⚽”, and values 1-64 for “🎰”. Defaults to “🎲”
|
|
891
921
|
* @param other Optional remaining parameters, confer the official reference below
|
|
892
922
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
893
923
|
*
|
|
@@ -913,9 +943,9 @@ class Context {
|
|
|
913
943
|
return this.api.sendChatAction(orThrow(this.chatId, "sendChatAction"), action, { business_connection_id: this.businessConnectionId, ...other }, signal);
|
|
914
944
|
}
|
|
915
945
|
/**
|
|
916
|
-
* Context-aware alias for `api.setMessageReaction`. Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel.
|
|
946
|
+
* Context-aware alias for `api.setMessageReaction`. Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success.
|
|
917
947
|
*
|
|
918
|
-
* @param reaction A list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators.
|
|
948
|
+
* @param reaction A list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. Paid reactions can't be used by bots.
|
|
919
949
|
* @param other Optional remaining parameters, confer the official reference below
|
|
920
950
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
921
951
|
*
|
|
@@ -953,7 +983,7 @@ class Context {
|
|
|
953
983
|
return this.api.getUserChatBoosts(chat_id, orThrow(this.from, "getUserChatBoosts").id, signal);
|
|
954
984
|
}
|
|
955
985
|
/**
|
|
956
|
-
*
|
|
986
|
+
* Context-aware alias for `api.getBusinessConnection`. Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success.
|
|
957
987
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
958
988
|
*
|
|
959
989
|
* **Official reference:** https://core.telegram.org/bots/api#getbusinessconnection
|
|
@@ -1150,7 +1180,7 @@ class Context {
|
|
|
1150
1180
|
return this.api.createChatInviteLink(orThrow(this.chatId, "createChatInviteLink"), other, signal);
|
|
1151
1181
|
}
|
|
1152
1182
|
/**
|
|
1153
|
-
*
|
|
1183
|
+
* Context-aware alias for `api.editChatInviteLink`. 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.
|
|
1154
1184
|
*
|
|
1155
1185
|
* @param invite_link The invite link to edit
|
|
1156
1186
|
* @param other Optional remaining parameters, confer the official reference below
|
|
@@ -1162,7 +1192,32 @@ class Context {
|
|
|
1162
1192
|
return this.api.editChatInviteLink(orThrow(this.chatId, "editChatInviteLink"), invite_link, other, signal);
|
|
1163
1193
|
}
|
|
1164
1194
|
/**
|
|
1165
|
-
*
|
|
1195
|
+
* Context-aware alias for `api.createChatSubscriptionInviteLink`. Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights. The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink. Returns the new invite link as a ChatInviteLink object.
|
|
1196
|
+
*
|
|
1197
|
+
* @param subscription_period The number of seconds the subscription will be active for before the next payment. Currently, it must always be 2592000 (30 days).
|
|
1198
|
+
* @param subscription_price The amount of Telegram Stars a user must pay initially and after each subsequent subscription period to be a member of the chat; 1-2500
|
|
1199
|
+
* @param other Optional remaining parameters, confer the official reference below
|
|
1200
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
1201
|
+
*
|
|
1202
|
+
* **Official reference:** https://core.telegram.org/bots/api#createchatsubscriptioninvitelink
|
|
1203
|
+
*/
|
|
1204
|
+
createChatSubscriptionInviteLink(subscription_period, subscription_price, other, signal) {
|
|
1205
|
+
return this.api.createChatSubscriptionInviteLink(orThrow(this.chatId, "createChatSubscriptionInviteLink"), subscription_period, subscription_price, other, signal);
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Context-aware alias for `api.editChatSubscriptionInviteLink`. Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights. Returns the edited invite link as a ChatInviteLink object.
|
|
1209
|
+
*
|
|
1210
|
+
* @param invite_link The invite link to edit
|
|
1211
|
+
* @param other Optional remaining parameters, confer the official reference below
|
|
1212
|
+
* @param signal Optional `AbortSignal` to cancel the request
|
|
1213
|
+
*
|
|
1214
|
+
* **Official reference:** https://core.telegram.org/bots/api#editchatsubscriptioninvitelink
|
|
1215
|
+
*/
|
|
1216
|
+
editChatSubscriptionInviteLink(invite_link, other, signal) {
|
|
1217
|
+
return this.api.editChatSubscriptionInviteLink(orThrow(this.chatId, "editChatSubscriptionInviteLink"), invite_link, other, signal);
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* Context-aware alias for `api.revokeChatInviteLink`. 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.
|
|
1166
1221
|
*
|
|
1167
1222
|
* @param invite_link The invite link to revoke
|
|
1168
1223
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
@@ -1369,7 +1424,7 @@ class Context {
|
|
|
1369
1424
|
return this.api.createForumTopic(orThrow(this.chatId, "createForumTopic"), name, other, signal);
|
|
1370
1425
|
}
|
|
1371
1426
|
/**
|
|
1372
|
-
* Context-aware alias for `api.editForumTopic`. Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
|
|
1427
|
+
* Context-aware alias for `api.editForumTopic`. Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
|
|
1373
1428
|
*
|
|
1374
1429
|
* @param other Optional remaining parameters, confer the official reference below
|
|
1375
1430
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
@@ -1430,7 +1485,7 @@ class Context {
|
|
|
1430
1485
|
return this.api.unpinAllForumTopicMessages(message.chat.id, thread, signal);
|
|
1431
1486
|
}
|
|
1432
1487
|
/**
|
|
1433
|
-
* Context-aware alias for `api.editGeneralForumTopic`. Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.
|
|
1488
|
+
* Context-aware alias for `api.editGeneralForumTopic`. Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
|
|
1434
1489
|
*
|
|
1435
1490
|
* @param name New topic name, 1-128 characters
|
|
1436
1491
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
@@ -1520,7 +1575,7 @@ class Context {
|
|
|
1520
1575
|
* @param other Optional remaining parameters, confer the official reference below
|
|
1521
1576
|
* @param signal Optional `AbortSignal` to cancel the request
|
|
1522
1577
|
*
|
|
1523
|
-
* **Official reference:** https://core.telegram.org/bots/api#
|
|
1578
|
+
* **Official reference:** https://core.telegram.org/bots/api#getchatmenubutton
|
|
1524
1579
|
*/
|
|
1525
1580
|
getChatMenuButton(other, signal) {
|
|
1526
1581
|
return this.api.getChatMenuButton(other, signal);
|
|
@@ -177,6 +177,7 @@ const http = (req, res) => {
|
|
|
177
177
|
req.on("data", (chunk) => chunks.push(chunk))
|
|
178
178
|
.once("end", () => {
|
|
179
179
|
// @ts-ignore `Buffer` is Node-only
|
|
180
|
+
// deno-lint-ignore no-node-globals
|
|
180
181
|
const raw = Buffer.concat(chunks).toString("utf-8");
|
|
181
182
|
resolve(JSON.parse(raw));
|
|
182
183
|
})
|
|
@@ -7,22 +7,21 @@ type MaybePromise<T> = Promise<T> | T;
|
|
|
7
7
|
*
|
|
8
8
|
* Session middleware will load the session data of a specific chat from your
|
|
9
9
|
* storage solution, and make it available to you on the context object. Check
|
|
10
|
-
* out the
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* the [website](https://grammy.dev/plugins/session).
|
|
10
|
+
* out the [documentation](https://grammy.dev/ref/core/session) on session
|
|
11
|
+
* middleware to know more, and read the section about sessions on the
|
|
12
|
+
* [website](https://grammy.dev/plugins/session).
|
|
14
13
|
*/
|
|
15
14
|
export interface SessionFlavor<S> {
|
|
16
15
|
/**
|
|
17
16
|
* Session data on the context object.
|
|
18
17
|
*
|
|
19
18
|
* **WARNING:** You have to make sure that your session data is not
|
|
20
|
-
* undefined by _providing an initial value to the session middleware_, or
|
|
21
|
-
* making sure that `ctx.session` is assigned if it is empty! The type
|
|
19
|
+
* undefined by _providing an initial value to the session middleware_, or
|
|
20
|
+
* by making sure that `ctx.session` is assigned if it is empty! The type
|
|
22
21
|
* system does not include `| undefined` because this is really annoying to
|
|
23
22
|
* work with.
|
|
24
23
|
*
|
|
25
|
-
*
|
|
24
|
+
* Accessing `ctx.session` by reading or writing will throw if
|
|
26
25
|
* `getSessionKey(ctx) === undefined` for the respective context object
|
|
27
26
|
* `ctx`.
|
|
28
27
|
*/
|
|
@@ -37,9 +36,8 @@ export interface SessionFlavor<S> {
|
|
|
37
36
|
* object. Once you access `ctx.session`, the storage will be queried and the
|
|
38
37
|
* session data becomes available. If you access `ctx.session` again for the
|
|
39
38
|
* same context object, the cached value will be used. Check out the
|
|
40
|
-
* [documentation](https://grammy.dev/ref/core/lazysession)
|
|
41
|
-
*
|
|
42
|
-
* sessions on the
|
|
39
|
+
* [documentation](https://grammy.dev/ref/core/lazysession) on lazy session
|
|
40
|
+
* middleware to know more, and read the section about lazy sessions on the
|
|
43
41
|
* [website](https://grammy.dev/plugins/session#lazy-sessions).
|
|
44
42
|
*/
|
|
45
43
|
export interface LazySessionFlavor<S> {
|
|
@@ -301,11 +299,11 @@ export declare function enhanceStorage<T>(options: MigrationOptions<T>): Storage
|
|
|
301
299
|
* This class is used as default if you do not provide a storage adapter, e.g.
|
|
302
300
|
* to your database.
|
|
303
301
|
*
|
|
304
|
-
* This storage adapter features expiring sessions. When instantiating this
|
|
305
|
-
* yourself, you can pass a time to live in milliseconds that will be used
|
|
306
|
-
* each session object. If a session for a user expired, the session data
|
|
307
|
-
* be discarded on its first read, and a fresh session object as returned
|
|
308
|
-
* `initial` option (or undefined) will be put into place.
|
|
302
|
+
* This storage adapter features expiring sessions. When instantiating this
|
|
303
|
+
* class yourself, you can pass a time to live in milliseconds that will be used
|
|
304
|
+
* for each session object. If a session for a user expired, the session data
|
|
305
|
+
* will be discarded on its first read, and a fresh session object as returned
|
|
306
|
+
* by the `initial` option (or undefined) will be put into place.
|
|
309
307
|
*/
|
|
310
308
|
export declare class MemorySessionStorage<S> implements StorageAdapter<S> {
|
|
311
309
|
private readonly timeToLive?;
|
|
@@ -375,11 +375,11 @@ function wrapStorage(storage) {
|
|
|
375
375
|
* This class is used as default if you do not provide a storage adapter, e.g.
|
|
376
376
|
* to your database.
|
|
377
377
|
*
|
|
378
|
-
* This storage adapter features expiring sessions. When instantiating this
|
|
379
|
-
* yourself, you can pass a time to live in milliseconds that will be used
|
|
380
|
-
* each session object. If a session for a user expired, the session data
|
|
381
|
-
* be discarded on its first read, and a fresh session object as returned
|
|
382
|
-
* `initial` option (or undefined) will be put into place.
|
|
378
|
+
* This storage adapter features expiring sessions. When instantiating this
|
|
379
|
+
* class yourself, you can pass a time to live in milliseconds that will be used
|
|
380
|
+
* for each session object. If a session for a user expired, the session data
|
|
381
|
+
* will be discarded on its first read, and a fresh session object as returned
|
|
382
|
+
* by the `initial` option (or undefined) will be put into place.
|
|
383
383
|
*/
|
|
384
384
|
class MemorySessionStorage {
|
|
385
385
|
/**
|