@mtcute/dispatcher 0.1.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 (190) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +26 -0
  3. package/cjs/callback-data-builder.d.ts +43 -0
  4. package/cjs/callback-data-builder.js +99 -0
  5. package/cjs/callback-data-builder.js.map +1 -0
  6. package/cjs/context/base.d.ts +8 -0
  7. package/cjs/context/base.js +3 -0
  8. package/cjs/context/base.js.map +1 -0
  9. package/cjs/context/callback-query.d.ts +27 -0
  10. package/cjs/context/callback-query.js +56 -0
  11. package/cjs/context/callback-query.js.map +1 -0
  12. package/cjs/context/chat-join-request.d.ts +16 -0
  13. package/cjs/context/chat-join-request.js +34 -0
  14. package/cjs/context/chat-join-request.js.map +1 -0
  15. package/cjs/context/chosen-inline-result.d.ts +21 -0
  16. package/cjs/context/chosen-inline-result.js +35 -0
  17. package/cjs/context/chosen-inline-result.js.map +1 -0
  18. package/cjs/context/index.d.ts +8 -0
  19. package/cjs/context/index.js +24 -0
  20. package/cjs/context/index.js.map +1 -0
  21. package/cjs/context/inline-query.d.ts +14 -0
  22. package/cjs/context/inline-query.js +22 -0
  23. package/cjs/context/inline-query.js.map +1 -0
  24. package/cjs/context/message.d.ts +72 -0
  25. package/cjs/context/message.js +142 -0
  26. package/cjs/context/message.js.map +1 -0
  27. package/cjs/context/parse.d.ts +1 -0
  28. package/cjs/context/parse.js +34 -0
  29. package/cjs/context/parse.js.map +1 -0
  30. package/cjs/context/pre-checkout-query.d.ts +16 -0
  31. package/cjs/context/pre-checkout-query.js +26 -0
  32. package/cjs/context/pre-checkout-query.js.map +1 -0
  33. package/cjs/dispatcher.d.ts +641 -0
  34. package/cjs/dispatcher.js +765 -0
  35. package/cjs/dispatcher.js.map +1 -0
  36. package/cjs/filters/bots.d.ts +70 -0
  37. package/cjs/filters/bots.js +129 -0
  38. package/cjs/filters/bots.js.map +1 -0
  39. package/cjs/filters/bundle.d.ts +10 -0
  40. package/cjs/filters/bundle.js +27 -0
  41. package/cjs/filters/bundle.js.map +1 -0
  42. package/cjs/filters/chat.d.ts +27 -0
  43. package/cjs/filters/chat.js +55 -0
  44. package/cjs/filters/chat.js.map +1 -0
  45. package/cjs/filters/group.d.ts +25 -0
  46. package/cjs/filters/group.js +72 -0
  47. package/cjs/filters/group.js.map +1 -0
  48. package/cjs/filters/index.d.ts +3 -0
  49. package/cjs/filters/index.js +29 -0
  50. package/cjs/filters/index.js.map +1 -0
  51. package/cjs/filters/logic.d.ts +29 -0
  52. package/cjs/filters/logic.js +114 -0
  53. package/cjs/filters/logic.js.map +1 -0
  54. package/cjs/filters/message.d.ts +295 -0
  55. package/cjs/filters/message.js +150 -0
  56. package/cjs/filters/message.js.map +1 -0
  57. package/cjs/filters/state.d.ts +15 -0
  58. package/cjs/filters/state.js +32 -0
  59. package/cjs/filters/state.js.map +1 -0
  60. package/cjs/filters/text.d.ts +64 -0
  61. package/cjs/filters/text.js +132 -0
  62. package/cjs/filters/text.js.map +1 -0
  63. package/cjs/filters/types.d.ts +91 -0
  64. package/cjs/filters/types.js +6 -0
  65. package/cjs/filters/types.js.map +1 -0
  66. package/cjs/filters/updates.d.ts +46 -0
  67. package/cjs/filters/updates.js +46 -0
  68. package/cjs/filters/updates.js.map +1 -0
  69. package/cjs/filters/user.d.ts +24 -0
  70. package/cjs/filters/user.js +76 -0
  71. package/cjs/filters/user.js.map +1 -0
  72. package/cjs/handler.d.ts +31 -0
  73. package/cjs/handler.js +4 -0
  74. package/cjs/handler.js.map +1 -0
  75. package/cjs/index.d.ts +8 -0
  76. package/cjs/index.js +25 -0
  77. package/cjs/index.js.map +1 -0
  78. package/cjs/package.json +3 -0
  79. package/cjs/propagation.d.ts +21 -0
  80. package/cjs/propagation.js +26 -0
  81. package/cjs/propagation.js.map +1 -0
  82. package/cjs/state/index.d.ts +3 -0
  83. package/cjs/state/index.js +20 -0
  84. package/cjs/state/index.js.map +1 -0
  85. package/cjs/state/key.d.ts +23 -0
  86. package/cjs/state/key.js +45 -0
  87. package/cjs/state/key.js.map +1 -0
  88. package/cjs/state/storage.d.ts +75 -0
  89. package/cjs/state/storage.js +17 -0
  90. package/cjs/state/storage.js.map +1 -0
  91. package/cjs/state/update-state.d.ts +151 -0
  92. package/cjs/state/update-state.js +211 -0
  93. package/cjs/state/update-state.js.map +1 -0
  94. package/cjs/wizard.d.ts +60 -0
  95. package/cjs/wizard.js +103 -0
  96. package/cjs/wizard.js.map +1 -0
  97. package/esm/callback-data-builder.d.ts +43 -0
  98. package/esm/callback-data-builder.js +95 -0
  99. package/esm/callback-data-builder.js.map +1 -0
  100. package/esm/context/base.d.ts +8 -0
  101. package/esm/context/base.js +2 -0
  102. package/esm/context/base.js.map +1 -0
  103. package/esm/context/callback-query.d.ts +27 -0
  104. package/esm/context/callback-query.js +52 -0
  105. package/esm/context/callback-query.js.map +1 -0
  106. package/esm/context/chat-join-request.d.ts +16 -0
  107. package/esm/context/chat-join-request.js +30 -0
  108. package/esm/context/chat-join-request.js.map +1 -0
  109. package/esm/context/chosen-inline-result.d.ts +21 -0
  110. package/esm/context/chosen-inline-result.js +31 -0
  111. package/esm/context/chosen-inline-result.js.map +1 -0
  112. package/esm/context/index.d.ts +8 -0
  113. package/esm/context/index.js +8 -0
  114. package/esm/context/index.js.map +1 -0
  115. package/esm/context/inline-query.d.ts +14 -0
  116. package/esm/context/inline-query.js +18 -0
  117. package/esm/context/inline-query.js.map +1 -0
  118. package/esm/context/message.d.ts +72 -0
  119. package/esm/context/message.js +138 -0
  120. package/esm/context/message.js.map +1 -0
  121. package/esm/context/parse.d.ts +1 -0
  122. package/esm/context/parse.js +30 -0
  123. package/esm/context/parse.js.map +1 -0
  124. package/esm/context/pre-checkout-query.d.ts +16 -0
  125. package/esm/context/pre-checkout-query.js +22 -0
  126. package/esm/context/pre-checkout-query.js.map +1 -0
  127. package/esm/dispatcher.d.ts +641 -0
  128. package/esm/dispatcher.js +761 -0
  129. package/esm/dispatcher.js.map +1 -0
  130. package/esm/filters/bots.d.ts +70 -0
  131. package/esm/filters/bots.js +125 -0
  132. package/esm/filters/bots.js.map +1 -0
  133. package/esm/filters/bundle.d.ts +10 -0
  134. package/esm/filters/bundle.js +11 -0
  135. package/esm/filters/bundle.js.map +1 -0
  136. package/esm/filters/chat.d.ts +27 -0
  137. package/esm/filters/chat.js +50 -0
  138. package/esm/filters/chat.js.map +1 -0
  139. package/esm/filters/group.d.ts +25 -0
  140. package/esm/filters/group.js +67 -0
  141. package/esm/filters/group.js.map +1 -0
  142. package/esm/filters/index.d.ts +3 -0
  143. package/esm/filters/index.js +3 -0
  144. package/esm/filters/index.js.map +1 -0
  145. package/esm/filters/logic.d.ts +29 -0
  146. package/esm/filters/logic.js +107 -0
  147. package/esm/filters/logic.js.map +1 -0
  148. package/esm/filters/message.d.ts +295 -0
  149. package/esm/filters/message.js +130 -0
  150. package/esm/filters/message.js.map +1 -0
  151. package/esm/filters/state.d.ts +15 -0
  152. package/esm/filters/state.js +27 -0
  153. package/esm/filters/state.js.map +1 -0
  154. package/esm/filters/text.d.ts +64 -0
  155. package/esm/filters/text.js +124 -0
  156. package/esm/filters/text.js.map +1 -0
  157. package/esm/filters/types.d.ts +91 -0
  158. package/esm/filters/types.js +5 -0
  159. package/esm/filters/types.js.map +1 -0
  160. package/esm/filters/updates.d.ts +46 -0
  161. package/esm/filters/updates.js +39 -0
  162. package/esm/filters/updates.js.map +1 -0
  163. package/esm/filters/user.d.ts +24 -0
  164. package/esm/filters/user.js +70 -0
  165. package/esm/filters/user.js.map +1 -0
  166. package/esm/handler.d.ts +31 -0
  167. package/esm/handler.js +3 -0
  168. package/esm/handler.js.map +1 -0
  169. package/esm/index.d.ts +8 -0
  170. package/esm/index.js +9 -0
  171. package/esm/index.js.map +1 -0
  172. package/esm/propagation.d.ts +21 -0
  173. package/esm/propagation.js +23 -0
  174. package/esm/propagation.js.map +1 -0
  175. package/esm/state/index.d.ts +3 -0
  176. package/esm/state/index.js +4 -0
  177. package/esm/state/index.js.map +1 -0
  178. package/esm/state/key.d.ts +23 -0
  179. package/esm/state/key.js +41 -0
  180. package/esm/state/key.js.map +1 -0
  181. package/esm/state/storage.d.ts +75 -0
  182. package/esm/state/storage.js +13 -0
  183. package/esm/state/storage.js.map +1 -0
  184. package/esm/state/update-state.d.ts +151 -0
  185. package/esm/state/update-state.js +206 -0
  186. package/esm/state/update-state.js.map +1 -0
  187. package/esm/wizard.d.ts +60 -0
  188. package/esm/wizard.js +99 -0
  189. package/esm/wizard.js.map +1 -0
  190. package/package.json +21 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callback-query.js","sourceRoot":"","sources":["../../../src/context/callback-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe,EAAE,sBAAsB,EAAkB,MAAM,gBAAgB,CAAA;AAIxH;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IAGnD,YACa,MAAsB,EAC/B,KAAoB;QAEpB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,gBAAgB,CAAA;IAOjC,CAAC;IAED,oCAAoC;IACpC,MAAM,CAAC,MAA4D;QAC/D,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,UAAU;QACZ,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,wBAAwB,EAAE;YACzC,MAAM,IAAI,eAAe,CAAC,8CAA8C,CAAC,CAAA;SAC5E;QAED,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAE1E,IAAI,CAAC,GAAG,EAAE;YACN,MAAM,IAAI,sBAAsB,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAA;SACxG;QAED,OAAO,GAAG,CAAA;IACd,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,MAA6E;QAC3F,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,8BAA8B,EAAE;YAC/C,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;gBACjC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK;gBACzB,GAAG,MAAM;aACZ,CAAC,CAAA;SACL;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;YAC3B,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI;YACrB,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK;YACvB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import { CallbackQuery, getMarkedPeerId, MtArgumentError, MtMessageNotFoundError, TelegramClient } from '@mtcute/client'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a callback query update.\n *\n * This is a subclass of {@link CallbackQuery}, so all its fields are also available.\n */\nexport class CallbackQueryContext extends CallbackQuery implements UpdateContext<CallbackQuery> {\n readonly _name = 'callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: CallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * * Message that contained the callback button that was clicked.\n *\n * Note that the message may have been deleted, in which case\n * `MessageNotFoundError` is thrown.\n *\n * Can only be used if `isInline = false`\n */\n async getMessage() {\n if (this.raw._ !== 'updateBotCallbackQuery') {\n throw new MtArgumentError('Cannot get message for inline callback query')\n }\n\n const [msg] = await this.client.getMessages(this.raw.peer, this.raw.msgId)\n\n if (!msg) {\n throw new MtMessageNotFoundError(getMarkedPeerId(this.raw.peer), this.raw.msgId, 'Message not found')\n }\n\n return msg\n }\n\n /**\n * Edit the message that contained the callback button that was clicked.\n */\n async editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>) {\n if (this.raw._ === 'updateInlineBotCallbackQuery') {\n return this.client.editInlineMessage({\n messageId: this.raw.msgId,\n ...params,\n })\n }\n\n return this.client.editMessage({\n chatId: this.raw.peer,\n message: this.raw.msgId,\n ...params,\n })\n }\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import { BotChatJoinRequestUpdate, TelegramClient } from '@mtcute/client';
2
+ import { UpdateContext } from './base.js';
3
+ /**
4
+ * Context of a chat join request update (for bots).
5
+ *
6
+ * This is a subclass of {@link BotChatJoinRequestUpdate}, so all its fields are also available.
7
+ */
8
+ export declare class ChatJoinRequestUpdateContext extends BotChatJoinRequestUpdate implements UpdateContext<BotChatJoinRequestUpdate> {
9
+ readonly client: TelegramClient;
10
+ readonly _name = "bot_chat_join_request";
11
+ constructor(client: TelegramClient, update: BotChatJoinRequestUpdate);
12
+ /** Approve the request */
13
+ approve(): Promise<void>;
14
+ /** Decline the request */
15
+ decline(): Promise<void>;
16
+ }
@@ -0,0 +1,30 @@
1
+ import { BotChatJoinRequestUpdate } from '@mtcute/client';
2
+ /**
3
+ * Context of a chat join request update (for bots).
4
+ *
5
+ * This is a subclass of {@link BotChatJoinRequestUpdate}, so all its fields are also available.
6
+ */
7
+ export class ChatJoinRequestUpdateContext extends BotChatJoinRequestUpdate {
8
+ constructor(client, update) {
9
+ super(update.raw, update._peers);
10
+ this.client = client;
11
+ this._name = 'bot_chat_join_request';
12
+ }
13
+ /** Approve the request */
14
+ approve() {
15
+ return this.client.hideJoinRequest({
16
+ action: 'approve',
17
+ user: this.user.inputPeer,
18
+ chatId: this.chat.inputPeer,
19
+ });
20
+ }
21
+ /** Decline the request */
22
+ decline() {
23
+ return this.client.hideJoinRequest({
24
+ action: 'decline',
25
+ user: this.user.inputPeer,
26
+ chatId: this.chat.inputPeer,
27
+ });
28
+ }
29
+ }
30
+ //# sourceMappingURL=chat-join-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-join-request.js","sourceRoot":"","sources":["../../../src/context/chat-join-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAkB,MAAM,gBAAgB,CAAA;AAIzE;;;;GAIG;AACH,MAAM,OAAO,4BACT,SAAQ,wBAAwB;IAIhC,YACa,MAAsB,EAC/B,MAAgC;QAEhC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAHvB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,uBAAuB,CAAA;IAOxC,CAAC;IAED,0BAA0B;IAC1B,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YAC/B,MAAM,EAAE,SAAS;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;SAC9B,CAAC,CAAA;IACN,CAAC;IAED,0BAA0B;IAC1B,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YAC/B,MAAM,EAAE,SAAS;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;SAC9B,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import { BotChatJoinRequestUpdate, TelegramClient } from '@mtcute/client'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a chat join request update (for bots).\n *\n * This is a subclass of {@link BotChatJoinRequestUpdate}, so all its fields are also available.\n */\nexport class ChatJoinRequestUpdateContext\n extends BotChatJoinRequestUpdate\n implements UpdateContext<BotChatJoinRequestUpdate> {\n readonly _name = 'bot_chat_join_request'\n\n constructor(\n readonly client: TelegramClient,\n update: BotChatJoinRequestUpdate,\n ) {\n super(update.raw, update._peers)\n }\n\n /** Approve the request */\n approve(): Promise<void> {\n return this.client.hideJoinRequest({\n action: 'approve',\n user: this.user.inputPeer,\n chatId: this.chat.inputPeer,\n })\n }\n\n /** Decline the request */\n decline(): Promise<void> {\n return this.client.hideJoinRequest({\n action: 'decline',\n user: this.user.inputPeer,\n chatId: this.chat.inputPeer,\n })\n }\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import { ChosenInlineResult, TelegramClient } from '@mtcute/client';
2
+ import { UpdateContext } from './base.js';
3
+ /**
4
+ * Context of a chosen inline result update.
5
+ *
6
+ * This is a subclass of {@link ChosenInlineResult}, so all its fields are also available.
7
+ *
8
+ * > **Note**: To receive these updates, you must enable
9
+ * > Inline feedback in [@BotFather](//t.me/botfather)
10
+ */
11
+ export declare class ChosenInlineResultContext extends ChosenInlineResult implements UpdateContext<ChosenInlineResult> {
12
+ readonly client: TelegramClient;
13
+ readonly _name = "chosen_inline_result";
14
+ constructor(client: TelegramClient, result: ChosenInlineResult);
15
+ /**
16
+ * Edit the message that was sent when this inline result that was chosen.
17
+ *
18
+ * > **Note**: This method can only be used if the message contained a reply markup
19
+ */
20
+ editMessage(params: Parameters<TelegramClient['editInlineMessage']>[0]): Promise<void>;
21
+ }
@@ -0,0 +1,31 @@
1
+ import { ChosenInlineResult, MtArgumentError } from '@mtcute/client';
2
+ /**
3
+ * Context of a chosen inline result update.
4
+ *
5
+ * This is a subclass of {@link ChosenInlineResult}, so all its fields are also available.
6
+ *
7
+ * > **Note**: To receive these updates, you must enable
8
+ * > Inline feedback in [@BotFather](//t.me/botfather)
9
+ */
10
+ export class ChosenInlineResultContext extends ChosenInlineResult {
11
+ constructor(client, result) {
12
+ super(result.raw, result._peers);
13
+ this.client = client;
14
+ this._name = 'chosen_inline_result';
15
+ }
16
+ /**
17
+ * Edit the message that was sent when this inline result that was chosen.
18
+ *
19
+ * > **Note**: This method can only be used if the message contained a reply markup
20
+ */
21
+ async editMessage(params) {
22
+ if (!this.raw.msgId) {
23
+ throw new MtArgumentError('No message ID, make sure you have included reply markup!');
24
+ }
25
+ return this.client.editInlineMessage({
26
+ ...params,
27
+ messageId: this.raw.msgId,
28
+ });
29
+ }
30
+ }
31
+ //# sourceMappingURL=chosen-inline-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chosen-inline-result.js","sourceRoot":"","sources":["../../../src/context/chosen-inline-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAkB,MAAM,gBAAgB,CAAA;AAIpF;;;;;;;GAOG;AACH,MAAM,OAAO,yBAA0B,SAAQ,kBAAkB;IAG7D,YACa,MAAsB,EAC/B,MAA0B;QAE1B,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAHvB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,sBAAsB,CAAA;IAOvC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,MAA0D;QACxE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;YACjB,MAAM,IAAI,eAAe,CAAC,0DAA0D,CAAC,CAAA;SACxF;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;YACjC,GAAG,MAAM;YACT,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK;SAC5B,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import { ChosenInlineResult, MtArgumentError, TelegramClient } from '@mtcute/client'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a chosen inline result update.\n *\n * This is a subclass of {@link ChosenInlineResult}, so all its fields are also available.\n *\n * > **Note**: To receive these updates, you must enable\n * > Inline feedback in [@BotFather](//t.me/botfather)\n */\nexport class ChosenInlineResultContext extends ChosenInlineResult implements UpdateContext<ChosenInlineResult> {\n readonly _name = 'chosen_inline_result'\n\n constructor(\n readonly client: TelegramClient,\n result: ChosenInlineResult,\n ) {\n super(result.raw, result._peers)\n }\n\n /**\n * Edit the message that was sent when this inline result that was chosen.\n *\n * > **Note**: This method can only be used if the message contained a reply markup\n */\n async editMessage(params: Parameters<TelegramClient['editInlineMessage']>[0]): Promise<void> {\n if (!this.raw.msgId) {\n throw new MtArgumentError('No message ID, make sure you have included reply markup!')\n }\n\n return this.client.editInlineMessage({\n ...params,\n messageId: this.raw.msgId,\n })\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ export * from './base.js';
2
+ export * from './callback-query.js';
3
+ export * from './chat-join-request.js';
4
+ export * from './chosen-inline-result.js';
5
+ export * from './inline-query.js';
6
+ export * from './message.js';
7
+ export { UpdateContextType } from './parse.js';
8
+ export * from './pre-checkout-query.js';
@@ -0,0 +1,8 @@
1
+ export * from './base.js';
2
+ export * from './callback-query.js';
3
+ export * from './chat-join-request.js';
4
+ export * from './chosen-inline-result.js';
5
+ export * from './inline-query.js';
6
+ export * from './message.js';
7
+ export * from './pre-checkout-query.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAE5B,cAAc,yBAAyB,CAAA","sourcesContent":["export * from './base.js'\nexport * from './callback-query.js'\nexport * from './chat-join-request.js'\nexport * from './chosen-inline-result.js'\nexport * from './inline-query.js'\nexport * from './message.js'\nexport { UpdateContextType } from './parse.js'\nexport * from './pre-checkout-query.js'\n"]}
@@ -0,0 +1,14 @@
1
+ import { InlineQuery, ParametersSkip1, TelegramClient } from '@mtcute/client';
2
+ import { UpdateContext } from './base.js';
3
+ /**
4
+ * Context of an inline query update.
5
+ *
6
+ * This is a subclass of {@link InlineQuery}, so all its fields are also available.
7
+ */
8
+ export declare class InlineQueryContext extends InlineQuery implements UpdateContext<InlineQuery> {
9
+ readonly client: TelegramClient;
10
+ readonly _name = "inline_query";
11
+ constructor(client: TelegramClient, query: InlineQuery);
12
+ /** Answer to this inline query */
13
+ answer(...params: ParametersSkip1<TelegramClient['answerInlineQuery']>): Promise<void>;
14
+ }
@@ -0,0 +1,18 @@
1
+ import { InlineQuery } from '@mtcute/client';
2
+ /**
3
+ * Context of an inline query update.
4
+ *
5
+ * This is a subclass of {@link InlineQuery}, so all its fields are also available.
6
+ */
7
+ export class InlineQueryContext extends InlineQuery {
8
+ constructor(client, query) {
9
+ super(query.raw, query._peers);
10
+ this.client = client;
11
+ this._name = 'inline_query';
12
+ }
13
+ /** Answer to this inline query */
14
+ answer(...params) {
15
+ return this.client.answerInlineQuery(this.id, ...params);
16
+ }
17
+ }
18
+ //# sourceMappingURL=inline-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-query.js","sourceRoot":"","sources":["../../../src/context/inline-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAmC,MAAM,gBAAgB,CAAA;AAI7E;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IAG/C,YACa,MAAsB,EAC/B,KAAkB;QAElB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,cAAc,CAAA;IAO/B,CAAC;IAED,kCAAkC;IAClC,MAAM,CAAC,GAAG,MAA4D;QAClE,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,CAAA;IAC5D,CAAC;CACJ","sourcesContent":["import { InlineQuery, ParametersSkip1, TelegramClient } from '@mtcute/client'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of an inline query update.\n *\n * This is a subclass of {@link InlineQuery}, so all its fields are also available.\n */\nexport class InlineQueryContext extends InlineQuery implements UpdateContext<InlineQuery> {\n readonly _name = 'inline_query'\n\n constructor(\n readonly client: TelegramClient,\n query: InlineQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this inline query */\n answer(...params: ParametersSkip1<TelegramClient['answerInlineQuery']>) {\n return this.client.answerInlineQuery(this.id, ...params)\n }\n}\n"]}
@@ -0,0 +1,72 @@
1
+ import { Message, OmitInputMessageId, ParametersSkip1, TelegramClient } from '@mtcute/client';
2
+ import { DeleteMessagesParams } from '@mtcute/client/methods/messages/delete-messages.js';
3
+ import { ForwardMessageOptions } from '@mtcute/client/methods/messages/forward-messages.js';
4
+ import { SendCopyParams } from '@mtcute/client/methods/messages/send-copy.js';
5
+ import { SendCopyGroupParams } from '@mtcute/client/methods/messages/send-copy-group.js';
6
+ import { UpdateContext } from './base.js';
7
+ /**
8
+ * Context of a message-related update.
9
+ *
10
+ * This is a subclass of {@link Message}, so all fields
11
+ * of the message are available.
12
+ *
13
+ * For message groups, own fields are related to the last message
14
+ * in the group. To access all messages, use {@link MessageContext#messages}.
15
+ */
16
+ export declare class MessageContext extends Message implements UpdateContext<Message> {
17
+ readonly client: TelegramClient;
18
+ readonly _name = "new_message";
19
+ /**
20
+ * List of messages in the message group.
21
+ *
22
+ * For other updates, this is a list with a single element (`this`).
23
+ */
24
+ readonly messages: MessageContext[];
25
+ /** Whether this update is about a message group */
26
+ readonly isMessageGroup: boolean;
27
+ constructor(client: TelegramClient, message: Message | Message[]);
28
+ /** Get a message that this message is a reply to */
29
+ getReplyTo(): Promise<Message | null>;
30
+ /** If this is a channel post, get its automatic forward in the discussion group */
31
+ getDiscussionMessage(): Promise<Message | null>;
32
+ /** Get all custom emojis contained in this message (message group), if any */
33
+ getCustomEmojis(): Promise<import("@mtcute/client").Sticker[]>;
34
+ /** Send a text message to the same chat (and topic, if applicable) as a given message */
35
+ answerText(...params: ParametersSkip1<TelegramClient['answerText']>): Promise<Message>;
36
+ /** Send a media to the same chat (and topic, if applicable) as a given message */
37
+ answerMedia(...params: ParametersSkip1<TelegramClient['answerMedia']>): Promise<Message>;
38
+ /** Send a media group to the same chat (and topic, if applicable) as a given message */
39
+ answerMediaGroup(...params: ParametersSkip1<TelegramClient['answerMediaGroup']>): Promise<Message[]>;
40
+ /** Send a text message in reply to this message */
41
+ replyText(...params: ParametersSkip1<TelegramClient['replyText']>): Promise<Message>;
42
+ /** Send a media in reply to this message */
43
+ replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>): Promise<Message>;
44
+ /** Send a media group in reply to this message */
45
+ replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>): Promise<Message[]>;
46
+ /** Send a text message in reply to this message */
47
+ quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]): Promise<Message>;
48
+ /** Send a media in reply to this message */
49
+ quoteWithMedia(params: Parameters<TelegramClient['quoteWithMedia']>[1]): Promise<Message>;
50
+ /** Send a media group in reply to this message */
51
+ quoteWithMediaGroup(params: Parameters<TelegramClient['quoteWithMediaGroup']>[1]): Promise<Message[]>;
52
+ /** Send a text as a comment to this message */
53
+ commentText(...params: ParametersSkip1<TelegramClient['commentText']>): Promise<Message>;
54
+ /** Send a media as a comment to this message */
55
+ commentMedia(...params: ParametersSkip1<TelegramClient['commentMedia']>): Promise<Message>;
56
+ /** Send a media group as a comment to this message */
57
+ commentMediaGroup(...params: ParametersSkip1<TelegramClient['commentMediaGroup']>): Promise<Message[]>;
58
+ /** Delete this message (message group) */
59
+ delete(params?: DeleteMessagesParams): Promise<void>;
60
+ /** Pin this message */
61
+ pin(params?: OmitInputMessageId<Parameters<TelegramClient['pinMessage']>[0]>): Promise<Message | null>;
62
+ /** Unpin this message */
63
+ unpin(): Promise<void>;
64
+ /** Edit this message */
65
+ edit(params: OmitInputMessageId<Parameters<TelegramClient['editMessage']>[0]>): Promise<Message>;
66
+ /** Forward this message (message group) */
67
+ forwardTo(params: ForwardMessageOptions): Promise<Message[]>;
68
+ /** Send a copy of this message (message group) */
69
+ copy(params: SendCopyParams & SendCopyGroupParams): Promise<Message> | Promise<Message[]>;
70
+ /** React to this message */
71
+ react(params: OmitInputMessageId<Parameters<TelegramClient['sendReaction']>[0]>): Promise<Message>;
72
+ }
@@ -0,0 +1,138 @@
1
+ import { Message } from '@mtcute/client';
2
+ /**
3
+ * Context of a message-related update.
4
+ *
5
+ * This is a subclass of {@link Message}, so all fields
6
+ * of the message are available.
7
+ *
8
+ * For message groups, own fields are related to the last message
9
+ * in the group. To access all messages, use {@link MessageContext#messages}.
10
+ */
11
+ export class MessageContext extends Message {
12
+ constructor(client, message) {
13
+ const msg = Array.isArray(message) ? message[message.length - 1] : message;
14
+ super(msg.raw, msg._peers, msg.isScheduled);
15
+ this.client = client;
16
+ // this is primarily for proper types in filters, so don't bother much with actual value
17
+ this._name = 'new_message';
18
+ this.messages = Array.isArray(message) ? message.map((it) => new MessageContext(client, it)) : [this];
19
+ this.isMessageGroup = Array.isArray(message);
20
+ }
21
+ /** Get a message that this message is a reply to */
22
+ getReplyTo() {
23
+ return this.client.getReplyTo(this);
24
+ }
25
+ /** If this is a channel post, get its automatic forward in the discussion group */
26
+ getDiscussionMessage() {
27
+ return this.client.getDiscussionMessage({ chatId: this.chat.inputPeer, message: this.id });
28
+ }
29
+ /** Get all custom emojis contained in this message (message group), if any */
30
+ getCustomEmojis() {
31
+ return this.client.getCustomEmojisFromMessages(this.messages);
32
+ }
33
+ /** Send a text message to the same chat (and topic, if applicable) as a given message */
34
+ answerText(...params) {
35
+ return this.client.answerText(this, ...params);
36
+ }
37
+ /** Send a media to the same chat (and topic, if applicable) as a given message */
38
+ answerMedia(...params) {
39
+ return this.client.answerMedia(this, ...params);
40
+ }
41
+ /** Send a media group to the same chat (and topic, if applicable) as a given message */
42
+ answerMediaGroup(...params) {
43
+ return this.client.answerMediaGroup(this, ...params);
44
+ }
45
+ /** Send a text message in reply to this message */
46
+ replyText(...params) {
47
+ return this.client.replyText(this, ...params);
48
+ }
49
+ /** Send a media in reply to this message */
50
+ replyMedia(...params) {
51
+ return this.client.replyMedia(this, ...params);
52
+ }
53
+ /** Send a media group in reply to this message */
54
+ replyMediaGroup(...params) {
55
+ return this.client.replyMediaGroup(this, ...params);
56
+ }
57
+ /** Send a text message in reply to this message */
58
+ quoteWithText(params) {
59
+ return this.client.quoteWithText(this, params);
60
+ }
61
+ /** Send a media in reply to this message */
62
+ quoteWithMedia(params) {
63
+ return this.client.quoteWithMedia(this, params);
64
+ }
65
+ /** Send a media group in reply to this message */
66
+ quoteWithMediaGroup(params) {
67
+ return this.client.quoteWithMediaGroup(this, params);
68
+ }
69
+ /** Send a text as a comment to this message */
70
+ commentText(...params) {
71
+ return this.client.commentText(this, ...params);
72
+ }
73
+ /** Send a media as a comment to this message */
74
+ commentMedia(...params) {
75
+ return this.client.commentMedia(this, ...params);
76
+ }
77
+ /** Send a media group as a comment to this message */
78
+ commentMediaGroup(...params) {
79
+ return this.client.commentMediaGroup(this, ...params);
80
+ }
81
+ /** Delete this message (message group) */
82
+ delete(params) {
83
+ return this.client.deleteMessagesById(this.chat.inputPeer, this.messages.map((it) => it.id), params);
84
+ }
85
+ /** Pin this message */
86
+ pin(params) {
87
+ return this.client.pinMessage({
88
+ chatId: this.chat.inputPeer,
89
+ message: this.id,
90
+ ...params,
91
+ });
92
+ }
93
+ /** Unpin this message */
94
+ unpin() {
95
+ return this.client.unpinMessage({
96
+ chatId: this.chat.inputPeer,
97
+ message: this.id,
98
+ });
99
+ }
100
+ /** Edit this message */
101
+ edit(params) {
102
+ return this.client.editMessage({
103
+ chatId: this.chat.inputPeer,
104
+ message: this.id,
105
+ ...params,
106
+ });
107
+ }
108
+ /** Forward this message (message group) */
109
+ forwardTo(params) {
110
+ return this.client.forwardMessagesById({
111
+ fromChatId: this.chat.inputPeer,
112
+ messages: this.messages.map((it) => it.id),
113
+ ...params,
114
+ });
115
+ }
116
+ /** Send a copy of this message (message group) */
117
+ copy(params) {
118
+ if (this.isMessageGroup) {
119
+ return this.client.sendCopyGroup({
120
+ messages: this.messages,
121
+ ...params,
122
+ });
123
+ }
124
+ return this.client.sendCopy({
125
+ message: this,
126
+ ...params,
127
+ });
128
+ }
129
+ /** React to this message */
130
+ react(params) {
131
+ return this.client.sendReaction({
132
+ chatId: this.chat.inputPeer,
133
+ message: this.id,
134
+ ...params,
135
+ });
136
+ }
137
+ }
138
+ //# sourceMappingURL=message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/context/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAuD,MAAM,gBAAgB,CAAA;AAQ7F;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAe,SAAQ,OAAO;IAcvC,YACa,MAAsB,EAC/B,OAA4B;QAE5B,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;QAC1E,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC,CAAA;QAJlC,WAAM,GAAN,MAAM,CAAgB;QAdnC,wFAAwF;QAC/E,UAAK,GAAG,aAAa,CAAA;QAmB1B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QACrG,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACh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C5B,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YAC3B,OAAO,EAAE,IAAI,CAAC,EAAE;YAChB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import { Message, OmitInputMessageId, ParametersSkip1, TelegramClient } from '@mtcute/client'\nimport { DeleteMessagesParams } from '@mtcute/client/src/methods/messages/delete-messages.js'\nimport { ForwardMessageOptions } from '@mtcute/client/src/methods/messages/forward-messages.js'\nimport { SendCopyParams } from '@mtcute/client/src/methods/messages/send-copy.js'\nimport { SendCopyGroupParams } from '@mtcute/client/src/methods/messages/send-copy-group.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a message-related update.\n *\n * This is a subclass of {@link Message}, so all fields\n * of the message are available.\n *\n * For message groups, own fields are related to the last message\n * in the group. To access all messages, use {@link MessageContext#messages}.\n */\nexport class MessageContext extends Message implements UpdateContext<Message> {\n // this is primarily for proper types in filters, so don't bother much with actual value\n readonly _name = 'new_message'\n\n /**\n * List of messages in the message group.\n *\n * For other updates, this is a list with a single element (`this`).\n */\n readonly messages: MessageContext[]\n\n /** Whether this update is about a message group */\n readonly isMessageGroup: boolean\n\n constructor(\n readonly client: TelegramClient,\n message: Message | Message[],\n ) {\n const msg = Array.isArray(message) ? message[message.length - 1] : message\n super(msg.raw, msg._peers, msg.isScheduled)\n\n this.messages = Array.isArray(message) ? message.map((it) => new MessageContext(client, it)) : [this]\n this.isMessageGroup = Array.isArray(message)\n }\n\n /** Get a message that this message is a reply to */\n getReplyTo() {\n return this.client.getReplyTo(this)\n }\n\n /** If this is a channel post, get its automatic forward in the discussion group */\n getDiscussionMessage() {\n return this.client.getDiscussionMessage({ chatId: this.chat.inputPeer, message: this.id })\n }\n\n /** Get all custom emojis contained in this message (message group), if any */\n getCustomEmojis() {\n return this.client.getCustomEmojisFromMessages(this.messages)\n }\n\n /** Send a text message to the same chat (and topic, if applicable) as a given message */\n answerText(...params: ParametersSkip1<TelegramClient['answerText']>) {\n return this.client.answerText(this, ...params)\n }\n\n /** Send a media to the same chat (and topic, if applicable) as a given message */\n answerMedia(...params: ParametersSkip1<TelegramClient['answerMedia']>) {\n return this.client.answerMedia(this, ...params)\n }\n\n /** Send a media group to the same chat (and topic, if applicable) as a given message */\n answerMediaGroup(...params: ParametersSkip1<TelegramClient['answerMediaGroup']>) {\n return this.client.answerMediaGroup(this, ...params)\n }\n\n /** Send a text message in reply to this message */\n replyText(...params: ParametersSkip1<TelegramClient['replyText']>) {\n return this.client.replyText(this, ...params)\n }\n\n /** Send a media in reply to this message */\n replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>) {\n return this.client.replyMedia(this, ...params)\n }\n\n /** Send a media group in reply to this message */\n replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>) {\n return this.client.replyMediaGroup(this, ...params)\n }\n\n /** Send a text message in reply to this message */\n quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]) {\n return this.client.quoteWithText(this, params)\n }\n\n /** Send a media in reply to this message */\n quoteWithMedia(params: Parameters<TelegramClient['quoteWithMedia']>[1]) {\n return this.client.quoteWithMedia(this, params)\n }\n\n /** Send a media group in reply to this message */\n quoteWithMediaGroup(params: Parameters<TelegramClient['quoteWithMediaGroup']>[1]) {\n return this.client.quoteWithMediaGroup(this, params)\n }\n\n /** Send a text as a comment to this message */\n commentText(...params: ParametersSkip1<TelegramClient['commentText']>) {\n return this.client.commentText(this, ...params)\n }\n\n /** Send a media as a comment to this message */\n commentMedia(...params: ParametersSkip1<TelegramClient['commentMedia']>) {\n return this.client.commentMedia(this, ...params)\n }\n\n /** Send a media group as a comment to this message */\n commentMediaGroup(...params: ParametersSkip1<TelegramClient['commentMediaGroup']>) {\n return this.client.commentMediaGroup(this, ...params)\n }\n\n /** Delete this message (message group) */\n delete(params?: DeleteMessagesParams) {\n return this.client.deleteMessagesById(\n this.chat.inputPeer,\n this.messages.map((it) => it.id),\n params,\n )\n }\n\n /** Pin this message */\n pin(params?: OmitInputMessageId<Parameters<TelegramClient['pinMessage']>[0]>) {\n return this.client.pinMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n\n /** Unpin this message */\n unpin() {\n return this.client.unpinMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n })\n }\n\n /** Edit this message */\n edit(params: OmitInputMessageId<Parameters<TelegramClient['editMessage']>[0]>) {\n return this.client.editMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n\n /** Forward this message (message group) */\n forwardTo(params: ForwardMessageOptions) {\n return this.client.forwardMessagesById({\n fromChatId: this.chat.inputPeer,\n messages: this.messages.map((it) => it.id),\n ...params,\n })\n }\n\n /** Send a copy of this message (message group) */\n copy(params: SendCopyParams & SendCopyGroupParams) {\n if (this.isMessageGroup) {\n return this.client.sendCopyGroup({\n messages: this.messages,\n ...params,\n })\n }\n\n return this.client.sendCopy({\n message: this,\n ...params,\n })\n }\n\n /** React to this message */\n react(params: OmitInputMessageId<Parameters<TelegramClient['sendReaction']>[0]>) {\n return this.client.sendReaction({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export type UpdateContextType = ReturnType<typeof _parsedUpdateToContext>;
@@ -0,0 +1,30 @@
1
+ import { CallbackQueryContext } from './callback-query.js';
2
+ import { ChatJoinRequestUpdateContext } from './chat-join-request.js';
3
+ import { ChosenInlineResultContext } from './chosen-inline-result.js';
4
+ import { InlineQueryContext } from './inline-query.js';
5
+ import { MessageContext } from './message.js';
6
+ import { PreCheckoutQueryContext } from './pre-checkout-query.js';
7
+ /** @internal */
8
+ export 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 'bot_chat_join_request':
21
+ return new ChatJoinRequestUpdateContext(client, update.data);
22
+ case 'pre_checkout_query':
23
+ return new PreCheckoutQueryContext(client, update.data);
24
+ }
25
+ const _update = update.data;
26
+ _update.client = client;
27
+ _update._name = update.name;
28
+ return _update;
29
+ }
30
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/context/parse.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AAEjE,gBAAgB;AAChB,MAAM,UAAU,sBAAsB,CAAC,MAAsB,EAAE,MAAoB;IAC/E,QAAQ,MAAM,CAAC,IAAI,EAAE;QACjB,KAAK,aAAa,CAAC;QACnB,KAAK,cAAc,CAAC;QACpB,KAAK,eAAe;YAChB,OAAO,IAAI,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAClD,KAAK,cAAc;YACf,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACtD,KAAK,sBAAsB;YACvB,OAAO,IAAI,yBAAyB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC7D,KAAK,gBAAgB;YACjB,OAAO,IAAI,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,KAAK,uBAAuB;YACxB,OAAO,IAAI,4BAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAChE,KAAK,oBAAoB;YACrB,OAAO,IAAI,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;KAC9D;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,IAAoD,CAAA;IAC3E,OAAO,CAAC,MAAM,GAAG,MAAM,CAAA;IACvB,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAA;IAE3B,OAAO,OAAO,CAAA;AAClB,CAAC","sourcesContent":["import { ParsedUpdate, TelegramClient } from '@mtcute/client'\n\nimport { UpdateContextDistributed } from './base.js'\nimport { CallbackQueryContext } from './callback-query.js'\nimport { ChatJoinRequestUpdateContext } from './chat-join-request.js'\nimport { ChosenInlineResultContext } from './chosen-inline-result.js'\nimport { InlineQueryContext } from './inline-query.js'\nimport { MessageContext } from './message.js'\nimport { PreCheckoutQueryContext } from './pre-checkout-query.js'\n\n/** @internal */\nexport function _parsedUpdateToContext(client: TelegramClient, update: ParsedUpdate) {\n switch (update.name) {\n case 'new_message':\n case 'edit_message':\n case 'message_group':\n return new MessageContext(client, update.data)\n case 'inline_query':\n return new InlineQueryContext(client, update.data)\n case 'chosen_inline_result':\n return new ChosenInlineResultContext(client, update.data)\n case 'callback_query':\n return new CallbackQueryContext(client, update.data)\n case 'bot_chat_join_request':\n return new ChatJoinRequestUpdateContext(client, update.data)\n case 'pre_checkout_query':\n return new PreCheckoutQueryContext(client, update.data)\n }\n\n const _update = update.data as UpdateContextDistributed<typeof update.data>\n _update.client = client\n _update._name = update.name\n\n return _update\n}\n\nexport type UpdateContextType = ReturnType<typeof _parsedUpdateToContext>\n"]}
@@ -0,0 +1,16 @@
1
+ import { PreCheckoutQuery, TelegramClient } from '@mtcute/client';
2
+ import { UpdateContext } from './base.js';
3
+ /**
4
+ * Context of a pre-checkout query update
5
+ *
6
+ * This is a subclass of {@link PreCheckoutQuery}, so all its fields are also available.
7
+ */
8
+ export declare class PreCheckoutQueryContext extends PreCheckoutQuery implements UpdateContext<PreCheckoutQuery> {
9
+ readonly client: TelegramClient;
10
+ readonly _name = "pre_checkout_query";
11
+ constructor(client: TelegramClient, query: PreCheckoutQuery);
12
+ /** Approve the query */
13
+ approve(): Promise<void>;
14
+ /** Decline the query, optionally with an error */
15
+ decline(error?: string): Promise<void>;
16
+ }
@@ -0,0 +1,22 @@
1
+ import { PreCheckoutQuery } from '@mtcute/client';
2
+ /**
3
+ * Context of a pre-checkout query update
4
+ *
5
+ * This is a subclass of {@link PreCheckoutQuery}, so all its fields are also available.
6
+ */
7
+ export class PreCheckoutQueryContext extends PreCheckoutQuery {
8
+ constructor(client, query) {
9
+ super(query.raw, query._peers);
10
+ this.client = client;
11
+ this._name = 'pre_checkout_query';
12
+ }
13
+ /** Approve the query */
14
+ approve() {
15
+ return this.client.answerPreCheckoutQuery(this.raw.queryId);
16
+ }
17
+ /** Decline the query, optionally with an error */
18
+ decline(error = '') {
19
+ return this.client.answerPreCheckoutQuery(this.raw.queryId, { error });
20
+ }
21
+ }
22
+ //# sourceMappingURL=pre-checkout-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pre-checkout-query.js","sourceRoot":"","sources":["../../../src/context/pre-checkout-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAkB,MAAM,gBAAgB,CAAA;AAIjE;;;;GAIG;AACH,MAAM,OAAO,uBAAwB,SAAQ,gBAAgB;IAGzD,YACa,MAAsB,EAC/B,KAAuB;QAEvB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,oBAAoB,CAAA;IAOrC,CAAC;IAED,wBAAwB;IACxB,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAC/D,CAAC;IAED,kDAAkD;IAClD,OAAO,CAAC,KAAK,GAAG,EAAE;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IAC1E,CAAC;CACJ","sourcesContent":["import { PreCheckoutQuery, TelegramClient } from '@mtcute/client'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a pre-checkout query update\n *\n * This is a subclass of {@link PreCheckoutQuery}, so all its fields are also available.\n */\nexport class PreCheckoutQueryContext extends PreCheckoutQuery implements UpdateContext<PreCheckoutQuery> {\n readonly _name = 'pre_checkout_query'\n\n constructor(\n readonly client: TelegramClient,\n query: PreCheckoutQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Approve the query */\n approve(): Promise<void> {\n return this.client.answerPreCheckoutQuery(this.raw.queryId)\n }\n\n /** Decline the query, optionally with an error */\n decline(error = ''): Promise<void> {\n return this.client.answerPreCheckoutQuery(this.raw.queryId, { error })\n }\n}\n"]}