@mtcute/dispatcher 0.11.0 → 0.12.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 (60) hide show
  1. package/cjs/context/business-message.d.ts +60 -0
  2. package/cjs/context/business-message.js +146 -0
  3. package/cjs/context/business-message.js.map +1 -0
  4. package/cjs/context/parse.d.ts +12 -0
  5. package/cjs/context/parse.js +5 -0
  6. package/cjs/context/parse.js.map +1 -1
  7. package/cjs/dispatcher.d.ts +121 -2
  8. package/cjs/dispatcher.js +43 -1
  9. package/cjs/dispatcher.js.map +1 -1
  10. package/cjs/filters/bots.d.ts +6 -5
  11. package/cjs/filters/bots.js.map +1 -1
  12. package/cjs/filters/chat.d.ts +2 -2
  13. package/cjs/filters/chat.js.map +1 -1
  14. package/cjs/filters/group.d.ts +4 -3
  15. package/cjs/filters/group.js.map +1 -1
  16. package/cjs/filters/message.d.ts +27 -18
  17. package/cjs/filters/message.js +10 -3
  18. package/cjs/filters/message.js.map +1 -1
  19. package/cjs/filters/user.js +3 -1
  20. package/cjs/filters/user.js.map +1 -1
  21. package/cjs/handler.d.ts +8 -2
  22. package/cjs/handler.js.map +1 -1
  23. package/cjs/index.js +6 -0
  24. package/cjs/state/key.d.ts +2 -1
  25. package/cjs/state/key.js +1 -1
  26. package/cjs/state/key.js.map +1 -1
  27. package/cjs/wizard.d.ts +5 -1
  28. package/cjs/wizard.js +3 -0
  29. package/cjs/wizard.js.map +1 -1
  30. package/esm/context/business-message.d.ts +60 -0
  31. package/esm/context/business-message.js +142 -0
  32. package/esm/context/business-message.js.map +1 -0
  33. package/esm/context/parse.d.ts +12 -0
  34. package/esm/context/parse.js +5 -0
  35. package/esm/context/parse.js.map +1 -1
  36. package/esm/dispatcher.d.ts +121 -2
  37. package/esm/dispatcher.js +43 -1
  38. package/esm/dispatcher.js.map +1 -1
  39. package/esm/filters/bots.d.ts +6 -5
  40. package/esm/filters/bots.js.map +1 -1
  41. package/esm/filters/chat.d.ts +2 -2
  42. package/esm/filters/chat.js.map +1 -1
  43. package/esm/filters/group.d.ts +4 -3
  44. package/esm/filters/group.js.map +1 -1
  45. package/esm/filters/message.d.ts +27 -18
  46. package/esm/filters/message.js +8 -2
  47. package/esm/filters/message.js.map +1 -1
  48. package/esm/filters/user.js +3 -1
  49. package/esm/filters/user.js.map +1 -1
  50. package/esm/handler.d.ts +8 -2
  51. package/esm/handler.js.map +1 -1
  52. package/esm/state/key.d.ts +2 -1
  53. package/esm/state/key.js +1 -1
  54. package/esm/state/key.js.map +1 -1
  55. package/esm/wizard.d.ts +5 -1
  56. package/esm/wizard.js +3 -0
  57. package/esm/wizard.js.map +1 -1
  58. package/index.d.ts +1 -0
  59. package/index.js +1 -0
  60. package/package.json +3 -3
@@ -0,0 +1,60 @@
1
+ import { BusinessMessage, OmitInputMessageId, ParametersSkip1 } 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 business message related update.
7
+ *
8
+ * This is a subclass of {@link BusinessMessage}, 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 BusinessMessageContext#messages}.
13
+ */
14
+ export declare class BusinessMessageContext extends BusinessMessage implements UpdateContext<BusinessMessage> {
15
+ readonly client: TelegramClient;
16
+ readonly _name = "new_business_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: BusinessMessageContext[];
23
+ /** Whether this update is about a message group */
24
+ readonly isMessageGroup: boolean;
25
+ constructor(client: TelegramClient, message: BusinessMessage | BusinessMessage[]);
26
+ /** Get all custom emojis contained in this message (message group), if any */
27
+ getCustomEmojis(): Promise<import("@mtcute/core").Sticker[]>;
28
+ /** Send a text message to the same chat (and topic, if applicable) as a given message */
29
+ answerText(...params: ParametersSkip1<TelegramClient['answerText']>): Promise<import("@mtcute/core").Message>;
30
+ /** Send a media to the same chat (and topic, if applicable) as a given message */
31
+ answerMedia(...params: ParametersSkip1<TelegramClient['answerMedia']>): Promise<import("@mtcute/core").Message>;
32
+ /** Send a media group to the same chat (and topic, if applicable) as a given message */
33
+ answerMediaGroup(...params: ParametersSkip1<TelegramClient['answerMediaGroup']>): Promise<import("@mtcute/core").Message[]>;
34
+ /** Send a text message in reply to this message */
35
+ replyText(...params: ParametersSkip1<TelegramClient['replyText']>): Promise<import("@mtcute/core").Message>;
36
+ /** Send a media in reply to this message */
37
+ replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>): Promise<import("@mtcute/core").Message>;
38
+ /** Send a media group in reply to this message */
39
+ replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>): Promise<import("@mtcute/core").Message[]>;
40
+ /** Send a text message in reply to this message */
41
+ quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]): Promise<import("@mtcute/core").Message>;
42
+ /** Send a media in reply to this message */
43
+ quoteWithMedia(params: Parameters<TelegramClient['quoteWithMedia']>[1]): Promise<import("@mtcute/core").Message>;
44
+ /** Send a media group in reply to this message */
45
+ quoteWithMediaGroup(params: Parameters<TelegramClient['quoteWithMediaGroup']>[1]): Promise<import("@mtcute/core").Message[]>;
46
+ /** Delete this message (message group) */
47
+ delete(params?: DeleteMessagesParams): Promise<void>;
48
+ /** Pin this message */
49
+ pin(params?: OmitInputMessageId<Parameters<TelegramClient['pinMessage']>[0]>): Promise<import("@mtcute/core").Message | null>;
50
+ /** Unpin this message */
51
+ unpin(): Promise<void>;
52
+ /** Edit this message */
53
+ edit(params: OmitInputMessageId<Parameters<TelegramClient['editMessage']>[0]>): Promise<import("@mtcute/core").Message>;
54
+ /** Forward this message (message group) */
55
+ forwardTo(params: ForwardMessageOptions): Promise<import("@mtcute/core").Message[]>;
56
+ /** Send a copy of this message (message group) */
57
+ copy(params: SendCopyParams & SendCopyGroupParams): Promise<import("@mtcute/core").Message> | Promise<import("@mtcute/core").Message[]>;
58
+ /** React to this message */
59
+ react(params: OmitInputMessageId<Parameters<TelegramClient['sendReaction']>[0]>): Promise<import("@mtcute/core").Message | null>;
60
+ }
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BusinessMessageContext = void 0;
4
+ const core_1 = require("@mtcute/core");
5
+ /**
6
+ * Context of a business message related update.
7
+ *
8
+ * This is a subclass of {@link BusinessMessage}, 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 BusinessMessageContext#messages}.
13
+ */
14
+ class BusinessMessageContext extends core_1.BusinessMessage {
15
+ client;
16
+ // this is primarily for proper types in filters, so don't bother much with actual value
17
+ _name = 'new_business_message';
18
+ /**
19
+ * List of messages in the message group.
20
+ *
21
+ * For other updates, this is a list with a single element (`this`).
22
+ */
23
+ messages;
24
+ /** Whether this update is about a message group */
25
+ isMessageGroup;
26
+ constructor(client, message) {
27
+ const msg = Array.isArray(message) ? message[message.length - 1] : message;
28
+ super(msg.update, msg._peers);
29
+ this.client = client;
30
+ this.messages = Array.isArray(message) ? message.map((it) => new BusinessMessageContext(client, it)) : [this];
31
+ this.isMessageGroup = Array.isArray(message);
32
+ }
33
+ /** Get all custom emojis contained in this message (message group), if any */
34
+ getCustomEmojis() {
35
+ return this.client.getCustomEmojisFromMessages(this.messages);
36
+ }
37
+ /** Send a text message to the same chat (and topic, if applicable) as a given message */
38
+ answerText(...params) {
39
+ const [send, params_ = {}] = params;
40
+ params_.businessConnectionId = this.update.connectionId;
41
+ return this.client.answerText(this, send, params_);
42
+ }
43
+ /** Send a media to the same chat (and topic, if applicable) as a given message */
44
+ answerMedia(...params) {
45
+ const [send, params_ = {}] = params;
46
+ params_.businessConnectionId = this.update.connectionId;
47
+ return this.client.answerMedia(this, send, params_);
48
+ }
49
+ /** Send a media group to the same chat (and topic, if applicable) as a given message */
50
+ answerMediaGroup(...params) {
51
+ const [send, params_ = {}] = params;
52
+ params_.businessConnectionId = this.update.connectionId;
53
+ return this.client.answerMediaGroup(this, send, params_);
54
+ }
55
+ /** Send a text message in reply to this message */
56
+ replyText(...params) {
57
+ const [send, params_ = {}] = params;
58
+ params_.businessConnectionId = this.update.connectionId;
59
+ return this.client.replyText(this, send, params_);
60
+ }
61
+ /** Send a media in reply to this message */
62
+ replyMedia(...params) {
63
+ const [send, params_ = {}] = params;
64
+ params_.businessConnectionId = this.update.connectionId;
65
+ return this.client.replyMedia(this, send, params_);
66
+ }
67
+ /** Send a media group in reply to this message */
68
+ replyMediaGroup(...params) {
69
+ const [send, params_ = {}] = params;
70
+ params_.businessConnectionId = this.update.connectionId;
71
+ return this.client.replyMediaGroup(this, send, params_);
72
+ }
73
+ /** Send a text message in reply to this message */
74
+ quoteWithText(params) {
75
+ params.businessConnectionId = this.update.connectionId;
76
+ return this.client.quoteWithText(this, params);
77
+ }
78
+ /** Send a media in reply to this message */
79
+ quoteWithMedia(params) {
80
+ params.businessConnectionId = this.update.connectionId;
81
+ return this.client.quoteWithMedia(this, params);
82
+ }
83
+ /** Send a media group in reply to this message */
84
+ quoteWithMediaGroup(params) {
85
+ params.businessConnectionId = this.update.connectionId;
86
+ return this.client.quoteWithMediaGroup(this, params);
87
+ }
88
+ /** Delete this message (message group) */
89
+ delete(params) {
90
+ return this.client.deleteMessagesById(this.chat.inputPeer, this.messages.map((it) => it.id), params);
91
+ }
92
+ /** Pin this message */
93
+ pin(params) {
94
+ return this.client.pinMessage({
95
+ chatId: this.chat.inputPeer,
96
+ message: this.id,
97
+ ...params,
98
+ });
99
+ }
100
+ /** Unpin this message */
101
+ unpin() {
102
+ return this.client.unpinMessage({
103
+ chatId: this.chat.inputPeer,
104
+ message: this.id,
105
+ });
106
+ }
107
+ /** Edit this message */
108
+ edit(params) {
109
+ return this.client.editMessage({
110
+ chatId: this.chat.inputPeer,
111
+ message: this.id,
112
+ ...params,
113
+ });
114
+ }
115
+ /** Forward this message (message group) */
116
+ forwardTo(params) {
117
+ return this.client.forwardMessagesById({
118
+ fromChatId: this.chat.inputPeer,
119
+ messages: this.messages.map((it) => it.id),
120
+ ...params,
121
+ });
122
+ }
123
+ /** Send a copy of this message (message group) */
124
+ copy(params) {
125
+ if (this.isMessageGroup) {
126
+ return this.client.sendCopyGroup({
127
+ messages: this.messages,
128
+ ...params,
129
+ });
130
+ }
131
+ return this.client.sendCopy({
132
+ message: this,
133
+ ...params,
134
+ });
135
+ }
136
+ /** React to this message */
137
+ react(params) {
138
+ return this.client.sendReaction({
139
+ chatId: this.chat.inputPeer,
140
+ message: this.id,
141
+ ...params,
142
+ });
143
+ }
144
+ }
145
+ exports.BusinessMessageContext = BusinessMessageContext;
146
+ //# sourceMappingURL=business-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"business-message.js","sourceRoot":"","sources":["../../../src/context/business-message.ts"],"names":[],"mappings":";;;AAAA,uCAAmF;AAWnF;;;;;;;;GAQG;AACH,MAAa,sBAAuB,SAAQ,sBAAe;IAe1C;IAdb,wFAAwF;IAC/E,KAAK,GAAG,sBAAsB,CAAA;IAEvC;;;;OAIG;IACM,QAAQ,CAA0B;IAE3C,mDAAmD;IAC1C,cAAc,CAAS;IAEhC,YACa,MAAsB,EAC/B,OAA4C;QAE5C,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,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;QAJpB,WAAM,GAAN,MAAM,CAAgB;QAM/B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAA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YAC/B,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;YAC1C,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;IAED,kDAAkD;IAClD,IAAI,CAAC,MAA4C;QAC7C,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;gBAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,GAAG,MAAM;aACZ,CAAC,CAAA;QACN,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;YACxB,OAAO,EAAE,IAAI;YACb,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;IAED,4BAA4B;IAC5B,KAAK,CAAC,MAAyE;QAC3E,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;YAC5B,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YAC3B,OAAO,EAAE,IAAI,CAAC,EAAE;YAChB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;CACJ;AAtKD,wDAsKC","sourcesContent":["import { BusinessMessage, OmitInputMessageId, ParametersSkip1 } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\nimport {\n DeleteMessagesParams,\n ForwardMessageOptions,\n SendCopyGroupParams,\n SendCopyParams,\n} from '@mtcute/core/methods.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a business message related update.\n *\n * This is a subclass of {@link BusinessMessage}, 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 BusinessMessageContext#messages}.\n */\nexport class BusinessMessageContext extends BusinessMessage implements UpdateContext<BusinessMessage> {\n // this is primarily for proper types in filters, so don't bother much with actual value\n readonly _name = 'new_business_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: BusinessMessageContext[]\n\n /** Whether this update is about a message group */\n readonly isMessageGroup: boolean\n\n constructor(\n readonly client: TelegramClient,\n message: BusinessMessage | BusinessMessage[],\n ) {\n const msg = Array.isArray(message) ? message[message.length - 1] : message\n super(msg.update, msg._peers)\n\n this.messages = Array.isArray(message) ? message.map((it) => new BusinessMessageContext(client, it)) : [this]\n this.isMessageGroup = Array.isArray(message)\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 const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.answerText(this, send, 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 const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.answerMedia(this, send, 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 const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.answerMediaGroup(this, send, params_)\n }\n\n /** Send a text message in reply to this message */\n replyText(...params: ParametersSkip1<TelegramClient['replyText']>) {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.replyText(this, send, params_)\n }\n\n /** Send a media in reply to this message */\n replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>) {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.replyMedia(this, send, params_)\n }\n\n /** Send a media group in reply to this message */\n replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>) {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.replyMediaGroup(this, send, params_)\n }\n\n /** Send a text message in reply to this message */\n quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]) {\n params.businessConnectionId = this.update.connectionId\n\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 params.businessConnectionId = this.update.connectionId\n\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 params.businessConnectionId = this.update.connectionId\n\n return this.client.quoteWithMediaGroup(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"]}
@@ -1 +1,13 @@
1
+ import { ParsedUpdate } 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 { CallbackQueryContext } 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
+ /** @internal */
12
+ export declare function _parsedUpdateToContext(client: TelegramClient, update: ParsedUpdate): BusinessMessageContext | CallbackQueryContext | ChatJoinRequestUpdateContext | ChosenInlineResultContext | InlineQueryContext | MessageContext | PreCheckoutQueryContext | UpdateContextDistributed<import("@mtcute/core").DeleteMessageUpdate | import("@mtcute/core").ChatMemberUpdate | import("@mtcute/core").InlineCallbackQuery | import("@mtcute/core").PollUpdate | import("@mtcute/core").PollVoteUpdate | import("@mtcute/core").UserStatusUpdate | import("@mtcute/core").UserTypingUpdate | import("@mtcute/core").HistoryReadUpdate | import("@mtcute/core").BotStoppedUpdate | import("@mtcute/core").ChatJoinRequestUpdate | import("@mtcute/core").StoryUpdate | import("@mtcute/core").DeleteStoryUpdate | import("@mtcute/core").BotReactionUpdate | import("@mtcute/core").BotReactionCountUpdate | import("@mtcute/core").BusinessConnection | import("@mtcute/core").DeleteBusinessMessageUpdate>;
1
13
  export type UpdateContextType = ReturnType<typeof _parsedUpdateToContext>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports._parsedUpdateToContext = void 0;
4
+ const business_message_js_1 = require("./business-message.js");
4
5
  const callback_query_js_1 = require("./callback-query.js");
5
6
  const chat_join_request_js_1 = require("./chat-join-request.js");
6
7
  const chosen_inline_result_js_1 = require("./chosen-inline-result.js");
@@ -24,6 +25,10 @@ function _parsedUpdateToContext(client, update) {
24
25
  return new chat_join_request_js_1.ChatJoinRequestUpdateContext(client, update.data);
25
26
  case 'pre_checkout_query':
26
27
  return new pre_checkout_query_js_1.PreCheckoutQueryContext(client, update.data);
28
+ case 'new_business_message':
29
+ case 'edit_business_message':
30
+ case 'business_message_group':
31
+ return new business_message_js_1.BusinessMessageContext(client, update.data);
27
32
  }
28
33
  const _update = update.data;
29
34
  _update.client = client;
@@ -1 +1 @@
1
- {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/context/parse.ts"],"names":[],"mappings":";;;AAIA,2DAA0D;AAC1D,iEAAqE;AACrE,uEAAqE;AACrE,uDAAsD;AACtD,6CAA6C;AAC7C,mEAAiE;AAEjE,gBAAgB;AAChB,SAAgB,sBAAsB,CAAC,MAAsB,EAAE,MAAoB;IAC/E,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,aAAa,CAAC;QACnB,KAAK,cAAc,CAAC;QACpB,KAAK,eAAe;YAChB,OAAO,IAAI,2BAAc,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAClD,KAAK,cAAc;YACf,OAAO,IAAI,oCAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACtD,KAAK,sBAAsB;YACvB,OAAO,IAAI,mDAAyB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC7D,KAAK,gBAAgB;YACjB,OAAO,IAAI,wCAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,KAAK,uBAAuB;YACxB,OAAO,IAAI,mDAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAChE,KAAK,oBAAoB;YACrB,OAAO,IAAI,+CAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;IAC/D,CAAC;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;AAvBD,wDAuBC","sourcesContent":["import { ParsedUpdate } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\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"]}
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/context/parse.ts"],"names":[],"mappings":";;;AAIA,+DAA8D;AAC9D,2DAA0D;AAC1D,iEAAqE;AACrE,uEAAqE;AACrE,uDAAsD;AACtD,6CAA6C;AAC7C,mEAAiE;AAEjE,gBAAgB;AAChB,SAAgB,sBAAsB,CAAC,MAAsB,EAAE,MAAoB;IAC/E,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,aAAa,CAAC;QACnB,KAAK,cAAc,CAAC;QACpB,KAAK,eAAe;YAChB,OAAO,IAAI,2BAAc,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAClD,KAAK,cAAc;YACf,OAAO,IAAI,oCAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACtD,KAAK,sBAAsB;YACvB,OAAO,IAAI,mDAAyB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC7D,KAAK,gBAAgB;YACjB,OAAO,IAAI,wCAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,KAAK,uBAAuB;YACxB,OAAO,IAAI,mDAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAChE,KAAK,oBAAoB;YACrB,OAAO,IAAI,+CAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC3D,KAAK,sBAAsB,CAAC;QAC5B,KAAK,uBAAuB,CAAC;QAC7B,KAAK,wBAAwB;YACzB,OAAO,IAAI,4CAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;IAC9D,CAAC;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;AA3BD,wDA2BC","sourcesContent":["import { ParsedUpdate } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContextDistributed } from './base.js'\nimport { BusinessMessageContext } from './business-message.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 case 'new_business_message':\n case 'edit_business_message':\n case 'business_message_group':\n return new BusinessMessageContext(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"]}
@@ -1,9 +1,10 @@
1
- import { BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, MaybePromise, ParsedUpdate, PeersIndex, PollUpdate, PollVoteUpdate, StoryUpdate, tl, UserStatusUpdate, UserTypingUpdate } from '@mtcute/core';
1
+ import { BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, BusinessConnection, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteBusinessMessageUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, MaybePromise, ParsedUpdate, PeersIndex, PollUpdate, PollVoteUpdate, StoryUpdate, tl, UserStatusUpdate, UserTypingUpdate } from '@mtcute/core';
2
2
  import { TelegramClient } from '@mtcute/core/client.js';
3
3
  import { UpdateContext } from './context/base.js';
4
+ import { BusinessMessageContext } from './context/business-message.js';
4
5
  import { CallbackQueryContext, ChatJoinRequestUpdateContext, ChosenInlineResultContext, InlineCallbackQueryContext, InlineQueryContext, MessageContext, PreCheckoutQueryContext } from './context/index.js';
5
6
  import { filters, UpdateFilter } from './filters/index.js';
6
- import { BotChatJoinRequestHandler, BotReactionCountUpdateHandler, BotReactionUpdateHandler, BotStoppedHandler, CallbackQueryHandler, ChatJoinRequestHandler, ChatMemberUpdateHandler, ChosenInlineResultHandler, DeleteMessageHandler, DeleteStoryHandler, EditMessageHandler, HistoryReadHandler, InlineCallbackQueryHandler, InlineQueryHandler, MessageGroupHandler, NewMessageHandler, PollUpdateHandler, PollVoteHandler, PreCheckoutQueryHandler, RawUpdateHandler, StoryUpdateHandler, UpdateHandler, UserStatusUpdateHandler, UserTypingHandler } from './handler.js';
7
+ import { BotChatJoinRequestHandler, BotReactionCountUpdateHandler, BotReactionUpdateHandler, BotStoppedHandler, BusinessConnectionUpdateHandler, BusinessMessageGroupHandler, CallbackQueryHandler, ChatJoinRequestHandler, ChatMemberUpdateHandler, ChosenInlineResultHandler, DeleteBusinessMessageHandler, DeleteMessageHandler, DeleteStoryHandler, EditBusinessMessageHandler, EditMessageHandler, HistoryReadHandler, InlineCallbackQueryHandler, InlineQueryHandler, MessageGroupHandler, NewBusinessMessageHandler, NewMessageHandler, PollUpdateHandler, PollVoteHandler, PreCheckoutQueryHandler, RawUpdateHandler, StoryUpdateHandler, UpdateHandler, UserStatusUpdateHandler, UserTypingHandler } from './handler.js';
7
8
  import { PropagationAction } from './propagation.js';
8
9
  import { IStateStorageProvider, StateKeyDelegate, UpdateState } from './state/index.js';
9
10
  export interface DispatcherParams {
@@ -24,6 +25,8 @@ export interface DispatcherParams {
24
25
  */
25
26
  key?: StateKeyDelegate;
26
27
  }
28
+ export interface DispatcherDependencies {
29
+ }
27
30
  /**
28
31
  * Updates dispatcher
29
32
  */
@@ -40,6 +43,7 @@ export declare class Dispatcher<State extends object = never> {
40
43
  private _stateKeyDelegate?;
41
44
  private _customStateKeyDelegate?;
42
45
  private _customStorage?;
46
+ private _deps;
43
47
  private _errorHandler?;
44
48
  private _preUpdateHandler?;
45
49
  private _postUpdateHandler?;
@@ -58,6 +62,22 @@ export declare class Dispatcher<State extends object = never> {
58
62
  static scene<State extends object = Record<never, never>>(name: string, params?: Omit<DispatcherParams, 'sceneName'>): Dispatcher<State>;
59
63
  /** For scene dispatchers, name of the scene */
60
64
  get sceneName(): string | undefined;
65
+ /**
66
+ * Inject a dependency to be available in this dispatcher and all its children.
67
+ *
68
+ * **Note**: This is only available for the root dispatcher.
69
+ */
70
+ inject<Name extends keyof DispatcherDependencies>(name: Name, value: DispatcherDependencies[Name]): void;
71
+ /**
72
+ * Inject dependencies to be available in this dispatcher and all its children.
73
+ *
74
+ * **Note**: This is only available for the root dispatcher.
75
+ */
76
+ inject(deps: Partial<DispatcherDependencies>): void;
77
+ /**
78
+ * Get the dependencies injected into this dispatcher.
79
+ */
80
+ get deps(): DispatcherDependencies;
61
81
  /**
62
82
  * Bind the dispatcher to the client.
63
83
  * Called by the constructor automatically if
@@ -690,4 +710,103 @@ export declare class Dispatcher<State extends object = never> {
690
710
  * @param group Handler group index
691
711
  */
692
712
  onBotReactionCountUpdate<Mod>(filter: UpdateFilter<UpdateContext<BotReactionCountUpdate>, Mod>, handler: BotReactionCountUpdateHandler<filters.Modify<UpdateContext<BotReactionCountUpdate>, Mod>>['callback'], group?: number): void;
713
+ /**
714
+ * Register a business connection update handler without any filters
715
+ *
716
+ * @param handler Business connection update handler
717
+ * @param group Handler group index
718
+ */
719
+ onBusinessConnectionUpdate(handler: BusinessConnectionUpdateHandler['callback'], group?: number): void;
720
+ /**
721
+ * Register a business connection update handler with a filter
722
+ *
723
+ * @param filter Update filter
724
+ * @param handler Business connection update handler
725
+ * @param group Handler group index
726
+ */
727
+ onBusinessConnectionUpdate<Mod>(filter: UpdateFilter<UpdateContext<BusinessConnection>, Mod>, handler: BusinessConnectionUpdateHandler<filters.Modify<UpdateContext<BusinessConnection>, Mod>>['callback'], group?: number): void;
728
+ /**
729
+ * Register a new business message handler without any filters
730
+ *
731
+ * @param handler New business message handler
732
+ * @param group Handler group index
733
+ */
734
+ onNewBusinessMessage(handler: NewBusinessMessageHandler<BusinessMessageContext, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
735
+ /**
736
+ * Register a new business message handler with a filter
737
+ *
738
+ * @param filter Update filter
739
+ * @param handler New business message handler
740
+ * @param group Handler group index
741
+ */
742
+ onNewBusinessMessage<Mod>(filter: UpdateFilter<BusinessMessageContext, Mod, State>, handler: NewBusinessMessageHandler<filters.Modify<BusinessMessageContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
743
+ /**
744
+ * Register a new business message handler with a filter
745
+ *
746
+ * @param filter Update filter
747
+ * @param handler New business message handler
748
+ * @param group Handler group index
749
+ */
750
+ onNewBusinessMessage<Mod>(filter: UpdateFilter<BusinessMessageContext, Mod>, handler: NewBusinessMessageHandler<filters.Modify<BusinessMessageContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
751
+ /**
752
+ * Register an edit business message handler without any filters
753
+ *
754
+ * @param handler Edit business message handler
755
+ * @param group Handler group index
756
+ */
757
+ onEditBusinessMessage(handler: EditBusinessMessageHandler<BusinessMessageContext, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
758
+ /**
759
+ * Register an edit business message handler with a filter
760
+ *
761
+ * @param filter Update filter
762
+ * @param handler Edit business message handler
763
+ * @param group Handler group index
764
+ */
765
+ onEditBusinessMessage<Mod>(filter: UpdateFilter<BusinessMessageContext, Mod, State>, handler: EditBusinessMessageHandler<filters.Modify<BusinessMessageContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
766
+ /**
767
+ * Register an edit business message handler with a filter
768
+ *
769
+ * @param filter Update filter
770
+ * @param handler Edit business message handler
771
+ * @param group Handler group index
772
+ */
773
+ onEditBusinessMessage<Mod>(filter: UpdateFilter<BusinessMessageContext, Mod>, handler: EditBusinessMessageHandler<filters.Modify<BusinessMessageContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
774
+ /**
775
+ * Register a business message group handler without any filters
776
+ *
777
+ * @param handler Business message group handler
778
+ * @param group Handler group index
779
+ */
780
+ onBusinessMessageGroup(handler: BusinessMessageGroupHandler<BusinessMessageContext, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
781
+ /**
782
+ * Register a business message group handler with a filter
783
+ *
784
+ * @param filter Update filter
785
+ * @param handler Business message group handler
786
+ * @param group Handler group index
787
+ */
788
+ onBusinessMessageGroup<Mod>(filter: UpdateFilter<BusinessMessageContext, Mod, State>, handler: BusinessMessageGroupHandler<filters.Modify<BusinessMessageContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
789
+ /**
790
+ * Register a business message group handler with a filter
791
+ *
792
+ * @param filter Update filter
793
+ * @param handler Business message group handler
794
+ * @param group Handler group index
795
+ */
796
+ onBusinessMessageGroup<Mod>(filter: UpdateFilter<BusinessMessageContext, Mod>, handler: BusinessMessageGroupHandler<filters.Modify<BusinessMessageContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
797
+ /**
798
+ * Register a delete business message handler without any filters
799
+ *
800
+ * @param handler Delete business message handler
801
+ * @param group Handler group index
802
+ */
803
+ onDeleteBusinessMessage(handler: DeleteBusinessMessageHandler['callback'], group?: number): void;
804
+ /**
805
+ * Register a delete business message handler with a filter
806
+ *
807
+ * @param filter Update filter
808
+ * @param handler Delete business message handler
809
+ * @param group Handler group index
810
+ */
811
+ onDeleteBusinessMessage<Mod>(filter: UpdateFilter<UpdateContext<DeleteBusinessMessageUpdate>, Mod>, handler: DeleteBusinessMessageHandler<filters.Modify<UpdateContext<DeleteBusinessMessageUpdate>, Mod>>['callback'], group?: number): void;
693
812
  }
package/cjs/dispatcher.js CHANGED
@@ -25,6 +25,7 @@ class Dispatcher {
25
25
  _stateKeyDelegate;
26
26
  _customStateKeyDelegate;
27
27
  _customStorage;
28
+ _deps = {};
28
29
  _errorHandler;
29
30
  _preUpdateHandler;
30
31
  _postUpdateHandler;
@@ -78,6 +79,25 @@ class Dispatcher {
78
79
  get sceneName() {
79
80
  return this._scene;
80
81
  }
82
+ inject(name, value) {
83
+ if (this._parent) {
84
+ throw new core_1.MtArgumentError('Cannot inject dependencies to child dispatchers');
85
+ }
86
+ if (typeof name === 'object') {
87
+ for (const [k, v] of Object.entries(name)) {
88
+ this._deps[k] = v;
89
+ }
90
+ }
91
+ else {
92
+ this._deps[name] = value;
93
+ }
94
+ }
95
+ /**
96
+ * Get the dependencies injected into this dispatcher.
97
+ */
98
+ get deps() {
99
+ return this._deps;
100
+ }
81
101
  /**
82
102
  * Bind the dispatcher to the client.
83
103
  * Called by the constructor automatically if
@@ -492,6 +512,7 @@ class Dispatcher {
492
512
  child._parent = this;
493
513
  child._client = this._client;
494
514
  child._storage = this._storage;
515
+ child._deps = this._deps;
495
516
  child._stateKeyDelegate = this._stateKeyDelegate;
496
517
  child._customStorage ??= this._customStorage;
497
518
  child._customStateKeyDelegate ??= this._customStateKeyDelegate;
@@ -550,6 +571,7 @@ class Dispatcher {
550
571
  }
551
572
  _unparent() {
552
573
  this._parent = this._client = undefined;
574
+ this._deps = {}; // to avoid dangling references
553
575
  this._stateKeyDelegate = undefined;
554
576
  this._storage = undefined;
555
577
  }
@@ -692,7 +714,7 @@ class Dispatcher {
692
714
  _addKnownHandler(name, filter, handler, group) {
693
715
  if (typeof handler === 'number' || typeof handler === 'undefined') {
694
716
  this.addUpdateHandler({
695
- name,
717
+ name: name,
696
718
  callback: filter,
697
719
  }, handler);
698
720
  }
@@ -796,6 +818,26 @@ class Dispatcher {
796
818
  onBotReactionCountUpdate(filter, handler, group) {
797
819
  this._addKnownHandler('bot_reaction_count', filter, handler, group);
798
820
  }
821
+ /** @internal */
822
+ onBusinessConnectionUpdate(filter, handler, group) {
823
+ this._addKnownHandler('business_connection', filter, handler, group);
824
+ }
825
+ /** @internal */
826
+ onNewBusinessMessage(filter, handler, group) {
827
+ this._addKnownHandler('new_business_message', filter, handler, group);
828
+ }
829
+ /** @internal */
830
+ onEditBusinessMessage(filter, handler, group) {
831
+ this._addKnownHandler('edit_business_message', filter, handler, group);
832
+ }
833
+ /** @internal */
834
+ onBusinessMessageGroup(filter, handler, group) {
835
+ this._addKnownHandler('business_message_group', filter, handler, group);
836
+ }
837
+ /** @internal */
838
+ onDeleteBusinessMessage(filter, handler, group) {
839
+ this._addKnownHandler('delete_business_message', filter, handler, group);
840
+ }
799
841
  }
800
842
  exports.Dispatcher = Dispatcher;
801
843
  //# sourceMappingURL=dispatcher.js.map