@mtcute/dispatcher 0.17.2 → 0.18.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.
Files changed (111) hide show
  1. package/callback-data-builder.cjs +126 -0
  2. package/callback-data-builder.d.cts +49 -0
  3. package/callback-data-builder.js +121 -0
  4. package/callback-data-builder.test.d.cts +1 -0
  5. package/context/base.d.cts +9 -0
  6. package/context/business-message.cjs +143 -0
  7. package/context/business-message.d.cts +60 -0
  8. package/context/business-message.js +138 -0
  9. package/context/callback-query.cjs +92 -0
  10. package/context/callback-query.d.cts +62 -0
  11. package/context/callback-query.js +87 -0
  12. package/context/chat-join-request.cjs +32 -0
  13. package/context/chat-join-request.d.cts +17 -0
  14. package/context/chat-join-request.d.ts +1 -1
  15. package/context/chat-join-request.js +27 -0
  16. package/context/chosen-inline-result.cjs +30 -0
  17. package/context/chosen-inline-result.d.cts +22 -0
  18. package/context/chosen-inline-result.d.ts +1 -1
  19. package/context/chosen-inline-result.js +25 -0
  20. package/context/index.d.cts +9 -0
  21. package/context/inline-query.cjs +20 -0
  22. package/context/inline-query.d.cts +15 -0
  23. package/context/inline-query.js +15 -0
  24. package/context/message.cjs +182 -0
  25. package/context/message.d.cts +82 -0
  26. package/context/message.d.ts +2 -2
  27. package/context/message.js +177 -0
  28. package/context/parse.cjs +45 -0
  29. package/context/parse.d.cts +13 -0
  30. package/context/parse.js +40 -0
  31. package/context/pre-checkout-query.cjs +24 -0
  32. package/context/pre-checkout-query.d.cts +17 -0
  33. package/context/pre-checkout-query.d.ts +1 -1
  34. package/context/pre-checkout-query.js +19 -0
  35. package/context/scene-transition.cjs +52 -0
  36. package/context/scene-transition.d.cts +24 -0
  37. package/context/scene-transition.d.ts +1 -1
  38. package/context/scene-transition.js +47 -0
  39. package/dispatcher.cjs +860 -0
  40. package/dispatcher.d.cts +880 -0
  41. package/dispatcher.d.ts +4 -4
  42. package/dispatcher.js +855 -0
  43. package/filters/bots.cjs +94 -0
  44. package/filters/bots.d.cts +62 -0
  45. package/filters/bots.d.ts +2 -4
  46. package/filters/bots.js +89 -0
  47. package/filters/bots.test.d.cts +1 -0
  48. package/filters/bundle.cjs +79 -0
  49. package/filters/bundle.d.cts +10 -0
  50. package/filters/bundle.js +74 -0
  51. package/filters/chat.cjs +43 -0
  52. package/filters/chat.d.cts +29 -0
  53. package/filters/chat.d.ts +8 -6
  54. package/filters/chat.js +38 -0
  55. package/filters/group.cjs +49 -0
  56. package/filters/group.d.cts +26 -0
  57. package/filters/group.js +44 -0
  58. package/filters/index.d.cts +4 -0
  59. package/filters/logic.cjs +57 -0
  60. package/filters/logic.d.cts +29 -0
  61. package/filters/logic.js +52 -0
  62. package/filters/logic.test.d.cts +1 -0
  63. package/filters/message.cjs +130 -0
  64. package/filters/message.d.cts +223 -0
  65. package/filters/message.d.ts +5 -1
  66. package/filters/message.js +125 -0
  67. package/filters/state.cjs +21 -0
  68. package/filters/state.d.cts +15 -0
  69. package/filters/state.js +16 -0
  70. package/filters/text.cjs +87 -0
  71. package/filters/text.d.cts +64 -0
  72. package/filters/text.d.ts +2 -2
  73. package/filters/text.js +82 -0
  74. package/filters/types.d.cts +91 -0
  75. package/filters/updates.cjs +27 -0
  76. package/filters/updates.d.cts +39 -0
  77. package/filters/updates.js +22 -0
  78. package/filters/user.cjs +57 -0
  79. package/filters/user.d.cts +24 -0
  80. package/filters/user.js +52 -0
  81. package/handler.d.cts +41 -0
  82. package/handler.d.ts +1 -1
  83. package/index.cjs +37 -2528
  84. package/index.js +16 -2507
  85. package/package.json +10 -9
  86. package/propagation.cjs +15 -0
  87. package/propagation.d.cts +22 -0
  88. package/propagation.js +10 -0
  89. package/state/index.d.cts +5 -0
  90. package/state/key.cjs +32 -0
  91. package/state/key.d.cts +24 -0
  92. package/state/key.js +27 -0
  93. package/state/provider.d.cts +5 -0
  94. package/state/providers/index.d.cts +2 -0
  95. package/state/providers/memory.cjs +79 -0
  96. package/state/providers/memory.d.cts +29 -0
  97. package/state/providers/memory.js +74 -0
  98. package/state/providers/sqlite.cjs +99 -0
  99. package/state/providers/sqlite.d.cts +28 -0
  100. package/state/providers/sqlite.js +94 -0
  101. package/state/repository.d.cts +62 -0
  102. package/state/service.cjs +69 -0
  103. package/state/service.d.cts +20 -0
  104. package/state/service.js +64 -0
  105. package/state/update-state.cjs +206 -0
  106. package/state/update-state.d.cts +151 -0
  107. package/state/update-state.d.ts +1 -1
  108. package/state/update-state.js +201 -0
  109. package/wizard.cjs +90 -0
  110. package/wizard.d.cts +64 -0
  111. package/wizard.js +85 -0
@@ -0,0 +1,82 @@
1
+ import { OmitInputMessageId, ParametersSkip1, Peer, Sticker, Message } from '@mtcute/core';
2
+ import { TelegramClient } from '@mtcute/core/client.js';
3
+ import { DeleteMessagesParams, ForwardMessageOptions, SendCopyGroupParams, SendCopyParams } from '@mtcute/core/methods.js';
4
+ import { UpdateContext } from './base.js';
5
+ /**
6
+ * Context of a message-related update.
7
+ *
8
+ * This is a subclass of {@link Message}, so all fields
9
+ * of the message are available.
10
+ *
11
+ * For message groups, own fields are related to the last message
12
+ * in the group. To access all messages, use {@link MessageContext#messages}.
13
+ */
14
+ export declare class MessageContext extends Message implements UpdateContext<Message> {
15
+ readonly client: TelegramClient;
16
+ readonly _name: "new_message";
17
+ /**
18
+ * List of messages in the message group.
19
+ *
20
+ * For other updates, this is a list with a single element (`this`).
21
+ */
22
+ readonly messages: MessageContext[];
23
+ /** Whether this update is about a message group */
24
+ readonly isMessageGroup: boolean;
25
+ constructor(client: TelegramClient, message: Message | Message[]);
26
+ /**
27
+ * Get complete information about {@link sender}
28
+ *
29
+ * Learn more: [Incomplete peers](https://mtcute.dev/guide/topics/peers.html#incomplete-peers)
30
+ */
31
+ getCompleteSender(): Promise<Peer>;
32
+ /**
33
+ * Get complete information about {@link chat}
34
+ *
35
+ * Learn more: [Incomplete peers](https://mtcute.dev/guide/topics/peers.html#incomplete-peers)
36
+ */
37
+ getCompleteChat(): Promise<Peer>;
38
+ /** Get a message that this message is a reply to */
39
+ getReplyTo(): Promise<Message | null>;
40
+ /** If this is a channel post, get its automatic forward in the discussion group */
41
+ getDiscussionMessage(): Promise<Message | null>;
42
+ /** Get all custom emojis contained in this message (message group), if any */
43
+ getCustomEmojis(): Promise<Sticker[]>;
44
+ /** Send a text message to the same chat (and topic, if applicable) as a given message */
45
+ answerText(...params: ParametersSkip1<TelegramClient['answerText']>): Promise<Message>;
46
+ /** Send a media to the same chat (and topic, if applicable) as a given message */
47
+ answerMedia(...params: ParametersSkip1<TelegramClient['answerMedia']>): Promise<Message>;
48
+ /** Send a media group to the same chat (and topic, if applicable) as a given message */
49
+ answerMediaGroup(...params: ParametersSkip1<TelegramClient['answerMediaGroup']>): Promise<Message[]>;
50
+ /** Send a text message in reply to this message */
51
+ replyText(...params: ParametersSkip1<TelegramClient['replyText']>): Promise<Message>;
52
+ /** Send a media in reply to this message */
53
+ replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>): Promise<Message>;
54
+ /** Send a media group in reply to this message */
55
+ replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>): Promise<Message[]>;
56
+ /** Send a text message in reply to this message */
57
+ quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]): Promise<Message>;
58
+ /** Send a media in reply to this message */
59
+ quoteWithMedia(params: Parameters<TelegramClient['quoteWithMedia']>[1]): Promise<Message>;
60
+ /** Send a media group in reply to this message */
61
+ quoteWithMediaGroup(params: Parameters<TelegramClient['quoteWithMediaGroup']>[1]): Promise<Message[]>;
62
+ /** Send a text as a comment to this message */
63
+ commentText(...params: ParametersSkip1<TelegramClient['commentText']>): Promise<Message>;
64
+ /** Send a media as a comment to this message */
65
+ commentMedia(...params: ParametersSkip1<TelegramClient['commentMedia']>): Promise<Message>;
66
+ /** Send a media group as a comment to this message */
67
+ commentMediaGroup(...params: ParametersSkip1<TelegramClient['commentMediaGroup']>): Promise<Message[]>;
68
+ /** Delete this message (message group) */
69
+ delete(params?: DeleteMessagesParams): Promise<void>;
70
+ /** Pin this message */
71
+ pin(params?: OmitInputMessageId<Parameters<TelegramClient['pinMessage']>[0]>): Promise<Message | null>;
72
+ /** Unpin this message */
73
+ unpin(): Promise<void>;
74
+ /** Edit this message */
75
+ edit(params: OmitInputMessageId<Parameters<TelegramClient['editMessage']>[0]>): Promise<Message>;
76
+ /** Forward this message (message group) */
77
+ forwardTo(params: ForwardMessageOptions): Promise<Message[]>;
78
+ /** Send a copy of this message (message group) */
79
+ copy(params: SendCopyParams & SendCopyGroupParams): Promise<Message> | Promise<Message[]>;
80
+ /** React to this message */
81
+ react(params: OmitInputMessageId<Parameters<TelegramClient['sendReaction']>[0]>): Promise<Message | null>;
82
+ }
@@ -1,4 +1,4 @@
1
- import { Chat, OmitInputMessageId, ParametersSkip1, Peer, Sticker, Message } from '@mtcute/core';
1
+ import { OmitInputMessageId, ParametersSkip1, Peer, Sticker, Message } from '@mtcute/core';
2
2
  import { TelegramClient } from '@mtcute/core/client.js';
3
3
  import { DeleteMessagesParams, ForwardMessageOptions, SendCopyGroupParams, SendCopyParams } from '@mtcute/core/methods.js';
4
4
  import { UpdateContext } from './base.js';
@@ -34,7 +34,7 @@ export declare class MessageContext extends Message implements UpdateContext<Mes
34
34
  *
35
35
  * Learn more: [Incomplete peers](https://mtcute.dev/guide/topics/peers.html#incomplete-peers)
36
36
  */
37
- getCompleteChat(): Promise<Chat>;
37
+ getCompleteChat(): Promise<Peer>;
38
38
  /** Get a message that this message is a reply to */
39
39
  getReplyTo(): Promise<Message | null>;
40
40
  /** If this is a channel post, get its automatic forward in the discussion group */
@@ -0,0 +1,177 @@
1
+ import { Message, MtPeerNotFoundError } from "@mtcute/core";
2
+ class MessageContext extends Message {
3
+ constructor(client, message) {
4
+ const msg = Array.isArray(message) ? message[message.length - 1] : message;
5
+ super(msg.raw, msg._peers, msg.isScheduled);
6
+ this.client = client;
7
+ this.messages = Array.isArray(message) ? message.map((it) => new MessageContext(client, it)) : [this];
8
+ this.isMessageGroup = Array.isArray(message);
9
+ }
10
+ // this is primarily for proper types in filters, so don't bother much with actual value
11
+ _name = "new_message";
12
+ /**
13
+ * List of messages in the message group.
14
+ *
15
+ * For other updates, this is a list with a single element (`this`).
16
+ */
17
+ messages;
18
+ /** Whether this update is about a message group */
19
+ isMessageGroup;
20
+ /**
21
+ * Get complete information about {@link sender}
22
+ *
23
+ * Learn more: [Incomplete peers](https://mtcute.dev/guide/topics/peers.html#incomplete-peers)
24
+ */
25
+ async getCompleteSender() {
26
+ if (!this.sender.isMin) return this.sender;
27
+ let res;
28
+ if (this.sender.type === "user") {
29
+ res = await this.client.getUser(this.sender);
30
+ } else {
31
+ res = await this.client.getChat(this.sender);
32
+ }
33
+ if (!res) throw new MtPeerNotFoundError("Failed to fetch sender");
34
+ Object.defineProperty(this, "sender", { value: res });
35
+ return res;
36
+ }
37
+ /**
38
+ * Get complete information about {@link chat}
39
+ *
40
+ * Learn more: [Incomplete peers](https://mtcute.dev/guide/topics/peers.html#incomplete-peers)
41
+ */
42
+ async getCompleteChat() {
43
+ if (!this.chat.isMin) return this.chat;
44
+ let res;
45
+ if (this.chat.type === "user") {
46
+ res = await this.client.getUser(this.chat);
47
+ } else {
48
+ res = await this.client.getChat(this.chat);
49
+ }
50
+ if (!res) throw new MtPeerNotFoundError("Failed to fetch chat");
51
+ Object.defineProperty(this, "chat", { value: res });
52
+ return res;
53
+ }
54
+ /** Get a message that this message is a reply to */
55
+ getReplyTo() {
56
+ return this.client.getReplyTo(this);
57
+ }
58
+ /** If this is a channel post, get its automatic forward in the discussion group */
59
+ getDiscussionMessage() {
60
+ return this.client.getDiscussionMessage({ chatId: this.chat.inputPeer, message: this.id });
61
+ }
62
+ /** Get all custom emojis contained in this message (message group), if any */
63
+ getCustomEmojis() {
64
+ return this.client.getCustomEmojisFromMessages(this.messages);
65
+ }
66
+ /** Send a text message to the same chat (and topic, if applicable) as a given message */
67
+ answerText(...params) {
68
+ return this.client.answerText(this, ...params);
69
+ }
70
+ /** Send a media to the same chat (and topic, if applicable) as a given message */
71
+ answerMedia(...params) {
72
+ return this.client.answerMedia(this, ...params);
73
+ }
74
+ /** Send a media group to the same chat (and topic, if applicable) as a given message */
75
+ answerMediaGroup(...params) {
76
+ return this.client.answerMediaGroup(this, ...params);
77
+ }
78
+ /** Send a text message in reply to this message */
79
+ replyText(...params) {
80
+ return this.client.replyText(this, ...params);
81
+ }
82
+ /** Send a media in reply to this message */
83
+ replyMedia(...params) {
84
+ return this.client.replyMedia(this, ...params);
85
+ }
86
+ /** Send a media group in reply to this message */
87
+ replyMediaGroup(...params) {
88
+ return this.client.replyMediaGroup(this, ...params);
89
+ }
90
+ /** Send a text message in reply to this message */
91
+ quoteWithText(params) {
92
+ return this.client.quoteWithText(this, params);
93
+ }
94
+ /** Send a media in reply to this message */
95
+ quoteWithMedia(params) {
96
+ return this.client.quoteWithMedia(this, params);
97
+ }
98
+ /** Send a media group in reply to this message */
99
+ quoteWithMediaGroup(params) {
100
+ return this.client.quoteWithMediaGroup(this, params);
101
+ }
102
+ /** Send a text as a comment to this message */
103
+ commentText(...params) {
104
+ return this.client.commentText(this, ...params);
105
+ }
106
+ /** Send a media as a comment to this message */
107
+ commentMedia(...params) {
108
+ return this.client.commentMedia(this, ...params);
109
+ }
110
+ /** Send a media group as a comment to this message */
111
+ commentMediaGroup(...params) {
112
+ return this.client.commentMediaGroup(this, ...params);
113
+ }
114
+ /** Delete this message (message group) */
115
+ delete(params) {
116
+ return this.client.deleteMessagesById(
117
+ this.chat.inputPeer,
118
+ this.messages.map((it) => it.id),
119
+ params
120
+ );
121
+ }
122
+ /** Pin this message */
123
+ pin(params) {
124
+ return this.client.pinMessage({
125
+ chatId: this.chat.inputPeer,
126
+ message: this.id,
127
+ ...params
128
+ });
129
+ }
130
+ /** Unpin this message */
131
+ unpin() {
132
+ return this.client.unpinMessage({
133
+ chatId: this.chat.inputPeer,
134
+ message: this.id
135
+ });
136
+ }
137
+ /** Edit this message */
138
+ edit(params) {
139
+ return this.client.editMessage({
140
+ chatId: this.chat.inputPeer,
141
+ message: this.id,
142
+ ...params
143
+ });
144
+ }
145
+ /** Forward this message (message group) */
146
+ forwardTo(params) {
147
+ return this.client.forwardMessagesById({
148
+ fromChatId: this.chat.inputPeer,
149
+ messages: this.messages.map((it) => it.id),
150
+ ...params
151
+ });
152
+ }
153
+ /** Send a copy of this message (message group) */
154
+ copy(params) {
155
+ if (this.isMessageGroup) {
156
+ return this.client.sendCopyGroup({
157
+ messages: this.messages,
158
+ ...params
159
+ });
160
+ }
161
+ return this.client.sendCopy({
162
+ message: this,
163
+ ...params
164
+ });
165
+ }
166
+ /** React to this message */
167
+ react(params) {
168
+ return this.client.sendReaction({
169
+ chatId: this.chat.inputPeer,
170
+ message: this.id,
171
+ ...params
172
+ });
173
+ }
174
+ }
175
+ export {
176
+ MessageContext
177
+ };
@@ -0,0 +1,45 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const businessMessage = require("./business-message.cjs");
9
+ const callbackQuery = require("./callback-query.cjs");
10
+ const chatJoinRequest = require("./chat-join-request.cjs");
11
+ const chosenInlineResult = require("./chosen-inline-result.cjs");
12
+ const inlineQuery = require("./inline-query.cjs");
13
+ const message = require("./message.cjs");
14
+ const preCheckoutQuery = require("./pre-checkout-query.cjs");
15
+ function _parsedUpdateToContext(client, update) {
16
+ switch (update.name) {
17
+ case "new_message":
18
+ case "edit_message":
19
+ case "message_group":
20
+ return new message.MessageContext(client, update.data);
21
+ case "inline_query":
22
+ return new inlineQuery.InlineQueryContext(client, update.data);
23
+ case "chosen_inline_result":
24
+ return new chosenInlineResult.ChosenInlineResultContext(client, update.data);
25
+ case "callback_query":
26
+ return new callbackQuery.CallbackQueryContext(client, update.data);
27
+ case "inline_callback_query":
28
+ return new callbackQuery.InlineCallbackQueryContext(client, update.data);
29
+ case "business_callback_query":
30
+ return new callbackQuery.BusinessCallbackQueryContext(client, update.data);
31
+ case "bot_chat_join_request":
32
+ return new chatJoinRequest.ChatJoinRequestUpdateContext(client, update.data);
33
+ case "pre_checkout_query":
34
+ return new preCheckoutQuery.PreCheckoutQueryContext(client, update.data);
35
+ case "new_business_message":
36
+ case "edit_business_message":
37
+ case "business_message_group":
38
+ return new businessMessage.BusinessMessageContext(client, update.data);
39
+ }
40
+ const _update = update.data;
41
+ _update.client = client;
42
+ _update._name = update.name;
43
+ return _update;
44
+ }
45
+ exports._parsedUpdateToContext = _parsedUpdateToContext;
@@ -0,0 +1,13 @@
1
+ import { BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, BusinessConnection, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteBusinessMessageUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, ParsedUpdate, PollUpdate, PollVoteUpdate, StoryUpdate, UserStatusUpdate, UserTypingUpdate } from '@mtcute/core';
2
+ import { TelegramClient } from '@mtcute/core/client.js';
3
+ import { UpdateContextDistributed } from './base.js';
4
+ import { BusinessMessageContext } from './business-message.js';
5
+ import { BusinessCallbackQueryContext, CallbackQueryContext, InlineCallbackQueryContext } from './callback-query.js';
6
+ import { ChatJoinRequestUpdateContext } from './chat-join-request.js';
7
+ import { ChosenInlineResultContext } from './chosen-inline-result.js';
8
+ import { InlineQueryContext } from './inline-query.js';
9
+ import { MessageContext } from './message.js';
10
+ import { PreCheckoutQueryContext } from './pre-checkout-query.js';
11
+ export type UpdateContextType = MessageContext | InlineQueryContext | ChosenInlineResultContext | CallbackQueryContext | InlineCallbackQueryContext | BusinessCallbackQueryContext | ChatJoinRequestUpdateContext | PreCheckoutQueryContext | BusinessMessageContext | UpdateContextDistributed<DeleteMessageUpdate | ChatMemberUpdate | PollUpdate | PollVoteUpdate | UserStatusUpdate | UserTypingUpdate | HistoryReadUpdate | BotStoppedUpdate | ChatJoinRequestUpdate | StoryUpdate | DeleteStoryUpdate | BotReactionUpdate | BotReactionCountUpdate | BusinessConnection | DeleteBusinessMessageUpdate>;
12
+ /** @internal */
13
+ export declare function _parsedUpdateToContext(client: TelegramClient, update: ParsedUpdate): UpdateContextType;
@@ -0,0 +1,40 @@
1
+ import { BusinessMessageContext } from "./business-message.js";
2
+ import { BusinessCallbackQueryContext, InlineCallbackQueryContext, CallbackQueryContext } from "./callback-query.js";
3
+ import { ChatJoinRequestUpdateContext } from "./chat-join-request.js";
4
+ import { ChosenInlineResultContext } from "./chosen-inline-result.js";
5
+ import { InlineQueryContext } from "./inline-query.js";
6
+ import { MessageContext } from "./message.js";
7
+ import { PreCheckoutQueryContext } from "./pre-checkout-query.js";
8
+ function _parsedUpdateToContext(client, update) {
9
+ switch (update.name) {
10
+ case "new_message":
11
+ case "edit_message":
12
+ case "message_group":
13
+ return new MessageContext(client, update.data);
14
+ case "inline_query":
15
+ return new InlineQueryContext(client, update.data);
16
+ case "chosen_inline_result":
17
+ return new ChosenInlineResultContext(client, update.data);
18
+ case "callback_query":
19
+ return new CallbackQueryContext(client, update.data);
20
+ case "inline_callback_query":
21
+ return new InlineCallbackQueryContext(client, update.data);
22
+ case "business_callback_query":
23
+ return new BusinessCallbackQueryContext(client, update.data);
24
+ case "bot_chat_join_request":
25
+ return new ChatJoinRequestUpdateContext(client, update.data);
26
+ case "pre_checkout_query":
27
+ return new PreCheckoutQueryContext(client, update.data);
28
+ case "new_business_message":
29
+ case "edit_business_message":
30
+ case "business_message_group":
31
+ return new BusinessMessageContext(client, update.data);
32
+ }
33
+ const _update = update.data;
34
+ _update.client = client;
35
+ _update._name = update.name;
36
+ return _update;
37
+ }
38
+ export {
39
+ _parsedUpdateToContext
40
+ };
@@ -0,0 +1,24 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const core = require("@mtcute/core");
9
+ class PreCheckoutQueryContext extends core.PreCheckoutQuery {
10
+ constructor(client, query) {
11
+ super(query.raw, query._peers);
12
+ this.client = client;
13
+ }
14
+ _name = "pre_checkout_query";
15
+ /** Approve the query */
16
+ approve() {
17
+ return this.client.answerPreCheckoutQuery(this.raw.queryId);
18
+ }
19
+ /** Decline the query, optionally with an error */
20
+ decline(error = "") {
21
+ return this.client.answerPreCheckoutQuery(this.raw.queryId, { error });
22
+ }
23
+ }
24
+ exports.PreCheckoutQueryContext = PreCheckoutQueryContext;
@@ -0,0 +1,17 @@
1
+ import { TelegramClient } from '@mtcute/core/client.js';
2
+ import { UpdateContext } from './base.js';
3
+ import { PreCheckoutQuery } from '@mtcute/core';
4
+ /**
5
+ * Context of a pre-checkout query update
6
+ *
7
+ * This is a subclass of {@link PreCheckoutQuery}, so all its fields are also available.
8
+ */
9
+ export declare class PreCheckoutQueryContext extends PreCheckoutQuery implements UpdateContext<PreCheckoutQuery> {
10
+ readonly client: TelegramClient;
11
+ readonly _name: "pre_checkout_query";
12
+ constructor(client: TelegramClient, query: PreCheckoutQuery);
13
+ /** Approve the query */
14
+ approve(): Promise<void>;
15
+ /** Decline the query, optionally with an error */
16
+ decline(error?: string): Promise<void>;
17
+ }
@@ -1,6 +1,6 @@
1
- import { PreCheckoutQuery } from '@mtcute/core';
2
1
  import { TelegramClient } from '@mtcute/core/client.js';
3
2
  import { UpdateContext } from './base.js';
3
+ import { PreCheckoutQuery } from '@mtcute/core';
4
4
  /**
5
5
  * Context of a pre-checkout query update
6
6
  *
@@ -0,0 +1,19 @@
1
+ import { PreCheckoutQuery } from "@mtcute/core";
2
+ class PreCheckoutQueryContext extends PreCheckoutQuery {
3
+ constructor(client, query) {
4
+ super(query.raw, query._peers);
5
+ this.client = client;
6
+ }
7
+ _name = "pre_checkout_query";
8
+ /** Approve the query */
9
+ approve() {
10
+ return this.client.answerPreCheckoutQuery(this.raw.queryId);
11
+ }
12
+ /** Decline the query, optionally with an error */
13
+ decline(error = "") {
14
+ return this.client.answerPreCheckoutQuery(this.raw.queryId, { error });
15
+ }
16
+ }
17
+ export {
18
+ PreCheckoutQueryContext
19
+ };
@@ -0,0 +1,52 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const core = require("@mtcute/core");
9
+ const utils_js = require("@mtcute/core/utils.js");
10
+ const businessMessage = require("./business-message.cjs");
11
+ const callbackQuery = require("./callback-query.cjs");
12
+ const message = require("./message.cjs");
13
+ class SceneTransitionContext {
14
+ constructor(previousScene, update) {
15
+ this.previousScene = previousScene;
16
+ this.update = update;
17
+ }
18
+ /** Get {@link update}, asserting it is a message-related update */
19
+ get message() {
20
+ if (this.update instanceof message.MessageContext) {
21
+ return this.update;
22
+ }
23
+ throw new core.MtTypeAssertionError("SceneTransitionContext.message", "message", this.update._name);
24
+ }
25
+ /** Get {@link update}, asserting it is a business message-related update */
26
+ get businessMessage() {
27
+ if (this.update instanceof businessMessage.BusinessMessageContext) {
28
+ return this.update;
29
+ }
30
+ throw new core.MtTypeAssertionError("SceneTransitionContext.businessMessage", "business message", this.update._name);
31
+ }
32
+ /** Get {@link update}, asserting it is a callback query update */
33
+ get callbackQuery() {
34
+ if (this.update instanceof callbackQuery.CallbackQueryContext) {
35
+ return this.update;
36
+ }
37
+ throw new core.MtTypeAssertionError("SceneTransitionContext.callbackQuery", "callback query", this.update._name);
38
+ }
39
+ /** Get {@link update}, asserting it is an inline callback query update */
40
+ get inlineCallbackQuery() {
41
+ if (this.update instanceof callbackQuery.InlineCallbackQueryContext) {
42
+ return this.update;
43
+ }
44
+ throw new core.MtTypeAssertionError(
45
+ "SceneTransitionContext.inlineCallbackQuery",
46
+ "inline callback query",
47
+ this.update._name
48
+ );
49
+ }
50
+ }
51
+ utils_js.makeInspectable(SceneTransitionContext);
52
+ exports.SceneTransitionContext = SceneTransitionContext;
@@ -0,0 +1,24 @@
1
+ import { UpdateContextType } from './parse.js';
2
+ import { BusinessMessageContext } from './business-message.js';
3
+ import { CallbackQueryContext, InlineCallbackQueryContext } from './callback-query.js';
4
+ import { MessageContext } from './message.js';
5
+ /** Update which is dispatched whenever scene is entered or exited */
6
+ export declare class SceneTransitionContext {
7
+ /** Name of the previous scene, if any */
8
+ readonly previousScene: string | null;
9
+ /** Update, handler for which triggered the transition */
10
+ readonly update: UpdateContextType;
11
+ constructor(
12
+ /** Name of the previous scene, if any */
13
+ previousScene: string | null,
14
+ /** Update, handler for which triggered the transition */
15
+ update: UpdateContextType);
16
+ /** Get {@link update}, asserting it is a message-related update */
17
+ get message(): MessageContext;
18
+ /** Get {@link update}, asserting it is a business message-related update */
19
+ get businessMessage(): BusinessMessageContext;
20
+ /** Get {@link update}, asserting it is a callback query update */
21
+ get callbackQuery(): CallbackQueryContext;
22
+ /** Get {@link update}, asserting it is an inline callback query update */
23
+ get inlineCallbackQuery(): InlineCallbackQueryContext;
24
+ }
@@ -1,7 +1,7 @@
1
+ import { UpdateContextType } from './parse.js';
1
2
  import { BusinessMessageContext } from './business-message.js';
2
3
  import { CallbackQueryContext, InlineCallbackQueryContext } from './callback-query.js';
3
4
  import { MessageContext } from './message.js';
4
- import { UpdateContextType } from './parse.js';
5
5
  /** Update which is dispatched whenever scene is entered or exited */
6
6
  export declare class SceneTransitionContext {
7
7
  /** Name of the previous scene, if any */
@@ -0,0 +1,47 @@
1
+ import { MtTypeAssertionError } from "@mtcute/core";
2
+ import { makeInspectable } from "@mtcute/core/utils.js";
3
+ import { BusinessMessageContext } from "./business-message.js";
4
+ import { CallbackQueryContext, InlineCallbackQueryContext } from "./callback-query.js";
5
+ import { MessageContext } from "./message.js";
6
+ class SceneTransitionContext {
7
+ constructor(previousScene, update) {
8
+ this.previousScene = previousScene;
9
+ this.update = update;
10
+ }
11
+ /** Get {@link update}, asserting it is a message-related update */
12
+ get message() {
13
+ if (this.update instanceof MessageContext) {
14
+ return this.update;
15
+ }
16
+ throw new MtTypeAssertionError("SceneTransitionContext.message", "message", this.update._name);
17
+ }
18
+ /** Get {@link update}, asserting it is a business message-related update */
19
+ get businessMessage() {
20
+ if (this.update instanceof BusinessMessageContext) {
21
+ return this.update;
22
+ }
23
+ throw new MtTypeAssertionError("SceneTransitionContext.businessMessage", "business message", this.update._name);
24
+ }
25
+ /** Get {@link update}, asserting it is a callback query update */
26
+ get callbackQuery() {
27
+ if (this.update instanceof CallbackQueryContext) {
28
+ return this.update;
29
+ }
30
+ throw new MtTypeAssertionError("SceneTransitionContext.callbackQuery", "callback query", this.update._name);
31
+ }
32
+ /** Get {@link update}, asserting it is an inline callback query update */
33
+ get inlineCallbackQuery() {
34
+ if (this.update instanceof InlineCallbackQueryContext) {
35
+ return this.update;
36
+ }
37
+ throw new MtTypeAssertionError(
38
+ "SceneTransitionContext.inlineCallbackQuery",
39
+ "inline callback query",
40
+ this.update._name
41
+ );
42
+ }
43
+ }
44
+ makeInspectable(SceneTransitionContext);
45
+ export {
46
+ SceneTransitionContext
47
+ };