@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
@@ -1,4 +1,5 @@
1
1
  import { _RepliedMessageAssertionsByOrigin, MaybeArray, Message, MessageAction, Peer, RawDocument, RepliedMessageInfo, RepliedMessageOrigin, Sticker, StickerSourceType, StickerType, User, Video } from '@mtcute/core';
2
+ import { BusinessMessageContext } from '../context/business-message.js';
2
3
  import { MessageContext } from '../index.js';
3
4
  import { Modify, UpdateFilter } from './types.js';
4
5
  /**
@@ -17,6 +18,12 @@ export declare const incoming: UpdateFilter<Message, {
17
18
  export declare const outgoing: UpdateFilter<Message, {
18
19
  isOutgoing: true;
19
20
  }>;
21
+ /**
22
+ * Filter for scheduled messages
23
+ */
24
+ export declare const scheduled: UpdateFilter<Message, {
25
+ isScheduled: true;
26
+ }>;
20
27
  /**
21
28
  * Filter messages that are replies to some other message
22
29
  */
@@ -40,39 +47,39 @@ export declare const media: UpdateFilter<Message, {
40
47
  /**
41
48
  * Filter messages containing media of given type
42
49
  */
43
- export declare const mediaOf: <T extends "photo" | "location" | "contact" | "document" | "game" | "invoice" | "poll" | "video" | "voice" | "webpage" | "story" | "sticker" | "live_location" | "audio" | "dice" | "venue">(type: T) => UpdateFilter<Message, {
44
- media: Extract<import("@mtcute/core").Photo, {
50
+ export declare const mediaOf: <T extends "photo" | "location" | "poll" | "story" | "contact" | "game" | "sticker" | "dice" | "audio" | "voice" | "document" | "video" | "live_location" | "webpage" | "venue" | "invoice">(type: T) => UpdateFilter<Message, {
51
+ media: Extract<Sticker, {
45
52
  type: T;
46
- }> | Extract<import("@mtcute/core").Location, {
53
+ }> | Extract<import("@mtcute/core").Photo, {
47
54
  type: T;
48
- }> | Extract<import("@mtcute/core").LiveLocation, {
55
+ }> | Extract<import("@mtcute/core").Dice, {
49
56
  type: T;
50
- }> | Extract<import("@mtcute/core").Document, {
57
+ }> | Extract<import("@mtcute/core").Contact, {
51
58
  type: T;
52
59
  }> | Extract<import("@mtcute/core").Audio, {
53
60
  type: T;
54
- }> | Extract<Sticker, {
61
+ }> | Extract<import("@mtcute/core").Voice, {
55
62
  type: T;
56
- }> | Extract<Video, {
63
+ }> | Extract<import("@mtcute/core").Document, {
57
64
  type: T;
58
- }> | Extract<import("@mtcute/core").Voice, {
65
+ }> | Extract<Video, {
59
66
  type: T;
60
- }> | Extract<import("@mtcute/core").Contact, {
67
+ }> | Extract<import("@mtcute/core").Location, {
61
68
  type: T;
62
- }> | Extract<import("@mtcute/core").Dice, {
69
+ }> | Extract<import("@mtcute/core").LiveLocation, {
63
70
  type: T;
64
71
  }> | Extract<import("@mtcute/core").Game, {
65
72
  type: T;
73
+ }> | Extract<import("@mtcute/core").WebPage, {
74
+ type: T;
66
75
  }> | Extract<import("@mtcute/core").Venue, {
67
76
  type: T;
68
77
  }> | Extract<import("@mtcute/core").Poll, {
69
78
  type: T;
70
- }> | Extract<import("@mtcute/core").MediaStory, {
71
- type: T;
72
- }> | Extract<import("@mtcute/core").WebPage, {
73
- type: T;
74
79
  }> | Extract<import("@mtcute/core").Invoice, {
75
80
  type: T;
81
+ }> | Extract<import("@mtcute/core").MediaStory, {
82
+ type: T;
76
83
  }>;
77
84
  }>;
78
85
  /** Filter messages containing a photo */
@@ -210,7 +217,7 @@ export declare const service: UpdateFilter<Message, {
210
217
  /**
211
218
  * Filter service messages by action type
212
219
  */
213
- export declare const action: <T extends "call" | "chat_created" | "channel_created" | "chat_migrate_to" | "channel_migrate_from" | "message_pinned" | "history_cleared" | "game_score" | "contact_joined" | "title_changed" | "photo_changed" | "photo_deleted" | "users_added" | "user_left" | "user_removed" | "user_joined_link" | "user_joined_approved" | "payment_received" | "payment_sent" | "screenshot_taken" | "bot_allowed" | "geo_proximity" | "group_call_started" | "group_call_ended" | "group_call_scheduled" | "group_call_invite" | "ttl_changed" | "topic_created" | "topic_edited" | "custom" | "theme_changed" | "webview_sent" | "webview_received" | "premium_gifted" | "photo_suggested" | "peer_chosen" | "wallpaper_changed" | "gift_code" | "giveaway_started" | "giveaway_ended" | "boost_apply">(type: MaybeArray<T>) => UpdateFilter<Message, {
220
+ export declare const action: <T extends "chat_created" | "channel_created" | "chat_migrate_to" | "channel_migrate_from" | "message_pinned" | "history_cleared" | "game_score" | "contact_joined" | "title_changed" | "photo_changed" | "photo_deleted" | "users_added" | "user_left" | "user_removed" | "user_joined_link" | "payment_received" | "payment_sent" | "call" | "screenshot_taken" | "bot_allowed" | "geo_proximity" | "group_call_started" | "group_call_ended" | "group_call_scheduled" | "group_call_invite" | "ttl_changed" | "topic_created" | "topic_edited" | "custom" | "theme_changed" | "user_joined_approved" | "webview_sent" | "webview_received" | "premium_gifted" | "photo_suggested" | "peer_sent" | "peer_chosen" | "wallpaper_changed" | "gift_code" | "giveaway_started" | "giveaway_ended" | "boost_apply">(type: MaybeArray<T>) => UpdateFilter<Message, {
214
221
  action: Extract<import("@mtcute/core").ActionChatCreated, {
215
222
  type: T;
216
223
  }> | Extract<import("@mtcute/core").ActionChannelCreated, {
@@ -241,8 +248,6 @@ export declare const action: <T extends "call" | "chat_created" | "channel_creat
241
248
  type: T;
242
249
  }> | Extract<import("@mtcute/core").ActionUserJoinedLink, {
243
250
  type: T;
244
- }> | Extract<import("@mtcute/core").ActionUserJoinedApproved, {
245
- type: T;
246
251
  }> | Extract<import("@mtcute/core").ActionPaymentReceived, {
247
252
  type: T;
248
253
  }> | Extract<import("@mtcute/core").ActionPaymentSent, {
@@ -273,6 +278,8 @@ export declare const action: <T extends "call" | "chat_created" | "channel_creat
273
278
  type: T;
274
279
  }> | Extract<import("@mtcute/core").ActionThemeChanged, {
275
280
  type: T;
281
+ }> | Extract<import("@mtcute/core").ActionUserJoinedApproved, {
282
+ type: T;
276
283
  }> | Extract<import("@mtcute/core").ActionWebviewDataSent, {
277
284
  type: T;
278
285
  }> | Extract<import("@mtcute/core").ActionWebviewDataReceived, {
@@ -281,6 +288,8 @@ export declare const action: <T extends "call" | "chat_created" | "channel_creat
281
288
  type: T;
282
289
  }> | Extract<import("@mtcute/core").ActionPhotoSuggested, {
283
290
  type: T;
291
+ }> | Extract<import("@mtcute/core").ActionPeerSent, {
292
+ type: T;
284
293
  }> | Extract<import("@mtcute/core").ActionPeerChosen, {
285
294
  type: T;
286
295
  }> | Extract<import("@mtcute/core").ActionWallpaperChanged, {
@@ -309,7 +318,7 @@ export declare const sender: <T extends "user" | "chat">(type: T) => UpdateFilte
309
318
  *
310
319
  * Optionally, you can pass a filter that will be applied to the replied message.
311
320
  */
312
- export declare const replyTo: <Mod, State extends object>(filter?: UpdateFilter<Message, Mod, State>) => UpdateFilter<MessageContext, {
321
+ export declare const replyTo: <Mod, State extends object>(filter?: UpdateFilter<Message, Mod, State>) => UpdateFilter<MessageContext | BusinessMessageContext, {
313
322
  getReplyTo: () => Promise<Message & Mod>;
314
323
  }, State>;
315
324
  /**
@@ -13,6 +13,10 @@ export const incoming = (msg) => !msg.isOutgoing;
13
13
  * Messages sent to yourself (i.e. Saved Messages) are **not** "outgoing"
14
14
  */
15
15
  export const outgoing = (msg) => msg.isOutgoing;
16
+ /**
17
+ * Filter for scheduled messages
18
+ */
19
+ export const scheduled = (msg) => msg.isScheduled;
16
20
  /**
17
21
  * Filter messages that are replies to some other message
18
22
  */
@@ -124,10 +128,12 @@ export const sender = (type) => (msg) => msg.sender.type === type;
124
128
  export const replyTo = (filter) => async (msg, state) => {
125
129
  if (!msg.replyToMessage?.id)
126
130
  return false;
127
- const reply = await msg.getReplyTo();
131
+ const reply = msg._name === 'new_message' ? await msg.getReplyTo() : msg.replyTo;
128
132
  if (!reply)
129
133
  return false;
130
- msg.getReplyTo = () => Promise.resolve(reply);
134
+ if (msg._name === 'new_message') {
135
+ msg.getReplyTo = () => Promise.resolve(reply);
136
+ }
131
137
  if (!filter)
132
138
  return true;
133
139
  return filter(reply, state);
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/filters/message.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,mCAAmC;AACnC,OAAO,EAOH,WAAW,EACX,WAAW,GAQd,MAAM,cAAc,CAAA;AAKrB;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAiD,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAA;AAE9F;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAgD,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAA;AAE5F;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAkE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,cAAc,KAAK,IAAI,CAAA;AAExH;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GACpB,CACI,MAAS,EAMX,EAAE,CACA,CAAC,GAAG,EAAE,EAAE,CACJ,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,CAAA,CAAC,kCAAkC;AAE5F;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAsE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,IAAI,CAAA;AAEnH;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAChB,CAA6B,IAAO,EAA4E,EAAE,CAC9G,CAAC,GAAG,EAAE,EAAE,CACJ,GAAG,CA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AE,CAAA;IACpC,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IAExB,GAAG,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAE7C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,OAAO,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAC/B,CAAC,CAAA;AAET;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC3B,CACI,MAAiD,EACT,EAAE,CAC1C,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;IACjB,IAAI,CAAC;QACD,MAAM,GAAG,CAAC,iBAAiB,EAAE,CAAA;IACjC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,OAAO,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AAC7B,CAAC,CAAA","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// ^^ will be looked into in MTQ-29\nimport {\n _RepliedMessageAssertionsByOrigin,\n MaybeArray,\n Message,\n MessageAction,\n MessageMediaType,\n Peer,\n RawDocument,\n RawLocation,\n RepliedMessageInfo,\n RepliedMessageOrigin,\n Sticker,\n StickerSourceType,\n StickerType,\n User,\n Video,\n} from '@mtcute/core'\n\nimport { MessageContext } from '../index.js'\nimport { Modify, UpdateFilter } from './types.js'\n\n/**\n * Filter incoming messages.\n *\n * Messages sent to yourself (i.e. Saved Messages) are also \"incoming\"\n */\nexport const incoming: UpdateFilter<Message, { isOutgoing: false }> = (msg) => !msg.isOutgoing\n\n/**\n * Filter outgoing messages.\n *\n * Messages sent to yourself (i.e. Saved Messages) are **not** \"outgoing\"\n */\nexport const outgoing: UpdateFilter<Message, { isOutgoing: true }> = (msg) => msg.isOutgoing\n\n/**\n * Filter messages that are replies to some other message\n */\nexport const reply: UpdateFilter<Message, { replyToMessage: RepliedMessageInfo }> = (msg) => msg.replyToMessage !== null\n\n/**\n * Filter messages that are replies with the given origin type\n */\nexport const replyOrigin =\n <T extends RepliedMessageOrigin>(\n origin: T,\n ): UpdateFilter<\n Message,\n {\n replyToMessage: Modify<RepliedMessageInfo, _RepliedMessageAssertionsByOrigin[T] & { origin: T }>\n }\n > =>\n (msg) =>\n msg.replyToMessage?.originIs(origin) ?? false // originIs does additional checks\n\n/**\n * Filter messages containing some media\n */\nexport const media: UpdateFilter<Message, { media: Exclude<Message['media'], null> }> = (msg) => msg.media !== null\n\n/**\n * Filter messages containing media of given type\n */\nexport const mediaOf =\n <T extends MessageMediaType>(type: T): UpdateFilter<Message, { media: Extract<Message['media'], { type: T }> }> =>\n (msg) =>\n msg.media?.type === type\n\n/** Filter messages containing a photo */\nexport const photo = mediaOf('photo')\n/** Filter messages containing a dice */\nexport const dice = mediaOf('dice')\n/** Filter messages containing a contact */\nexport const contact = mediaOf('contact')\n/** Filter messages containing an audio file */\nexport const audio = mediaOf('audio')\n/** Filter messages containing a voice message (audio-only) */\nexport const voice = mediaOf('voice')\n/** Filter messages containing a sticker */\nexport const sticker = mediaOf('sticker')\n/** Filter messages containing a document (a file) */\nexport const document = mediaOf('document')\n/** Filter messages containing any video (videos, round messages and animations) */\nexport const anyVideo = mediaOf('video')\n/** Filter messages containing a static location */\nexport const location = mediaOf('location')\n/** Filter messages containing a live location */\nexport const liveLocation = mediaOf('live_location')\n/** Filter messages containing a game */\nexport const game = mediaOf('game')\n/** Filter messages containing a web page */\nexport const webpage = mediaOf('webpage')\n/** Filter messages containing a venue */\nexport const venue = mediaOf('venue')\n/** Filter messages containing a poll */\nexport const poll = mediaOf('poll')\n/** Filter messages containing an invoice */\nexport const invoice = mediaOf('invoice')\n\n/**\n * Filter messages containing any location (live or static).\n */\nexport const anyLocation: UpdateFilter<Message, { media: Location }> = (msg) => msg.media instanceof RawLocation\n\n/**\n * Filter messages containing a document\n *\n * This will also match media like audio, video, voice\n * that also use Documents\n */\nexport const anyDocument: UpdateFilter<Message, { media: RawDocument }> = (msg) => msg.media instanceof RawDocument\n\n/**\n * Filter messages containing a simple video.\n *\n * This does not include round messages and animations\n */\nexport const video: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: false\n isAnimation: false\n }\n >\n }\n> = (msg) => msg.media?.type === 'video' && !msg.media.isAnimation && !msg.media.isRound\n\n/**\n * Filter messages containing an animation.\n *\n * > **Note**: Legacy GIFs (i.e. documents with `image/gif` MIME)\n * > are also considered animations.\n */\nexport const animation: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: false\n isAnimation: true\n }\n >\n }\n> = (msg) => msg.media?.type === 'video' && msg.media.isAnimation && !msg.media.isRound\n\n/**\n * Filter messages containing a round message (aka video note).\n */\nexport const roundMessage: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: true\n isAnimation: false\n }\n >\n }\n> = (msg) => msg.media?.type === 'video' && !msg.media.isAnimation && msg.media.isRound\n\n/**\n * Filter messages containing a sticker by its type\n */\nexport const stickerByType =\n (type: StickerType): UpdateFilter<Message, { media: Sticker }> =>\n (msg) =>\n msg.media?.type === 'sticker' && msg.media.stickerType === type\n\n/**\n * Filter messages containing a sticker by its source file type\n */\nexport const stickerBySourceType =\n (type: StickerSourceType): UpdateFilter<Message, { media: Sticker }> =>\n (msg) =>\n msg.media?.type === 'sticker' && msg.media.sourceType === type\n\n/**\n * Filter text-only messages non-service messages\n */\nexport const text: UpdateFilter<\n Message,\n {\n media: null\n isService: false\n }\n> = (msg) => msg.media === null && !msg.isService\n\n/**\n * Filter service messages\n */\nexport const service: UpdateFilter<Message, { isService: true }> = (msg) => msg.isService\n\n/**\n * Filter service messages by action type\n */\nexport const action = <T extends Exclude<MessageAction, null>['type']>(\n type: MaybeArray<T>,\n): UpdateFilter<\n Message,\n {\n action: Extract<MessageAction, { type: T }>\n sender: T extends 'user_joined_link' | 'user_removed' | 'history_cleared' | 'contact_joined' | 'bot_allowed'\n ? User\n : Peer\n }\n> => {\n if (Array.isArray(type)) {\n const index: Partial<Record<T, true>> = {}\n type.forEach((it) => (index[it] = true))\n\n return (msg) => (msg.action?.type as any) in index\n }\n\n return (msg) => msg.action?.type === type\n}\n\nexport const sender =\n <T extends Message['sender']['type']>(\n type: T,\n ): UpdateFilter<Message, { sender: Extract<Message['sender'], { type: T }> }> =>\n (msg) =>\n msg.sender.type === type\n\n/**\n * Filter that matches messages that are replies to some other message that can be fetched\n * (i.e. not `private` origin, and has not been deleted)\n *\n * Optionally, you can pass a filter that will be applied to the replied message.\n */\nexport const replyTo =\n <Mod, State extends object>(\n filter?: UpdateFilter<Message, Mod, State>,\n ): UpdateFilter<MessageContext, { getReplyTo: () => Promise<Message & Mod> }, State> =>\n async (msg, state) => {\n if (!msg.replyToMessage?.id) return false\n\n const reply = await msg.getReplyTo()\n if (!reply) return false\n\n msg.getReplyTo = () => Promise.resolve(reply)\n\n if (!filter) return true\n\n return filter(reply, state)\n }\n\n/**\n * Middleware-like filter that will fetch the sender of the message\n * and make it available to further filters, as well as the handler itself.\n */\nexport const withCompleteSender =\n <Mod, State extends object>(\n filter?: UpdateFilter<MessageContext, Mod, State>,\n ): UpdateFilter<MessageContext, Mod, State> =>\n async (msg, state) => {\n try {\n await msg.getCompleteSender()\n } catch (e) {\n return false\n }\n\n if (!filter) return true\n\n return filter(msg, state)\n }\n"]}
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/filters/message.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,mCAAmC;AACnC,OAAO,EAOH,WAAW,EACX,WAAW,GAQd,MAAM,cAAc,CAAA;AAMrB;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAiD,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAA;AAE9F;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAgD,CAA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AAE,EAAE;IACjB,IAAI,CAAC;QACD,MAAM,GAAG,CAAC,iBAAiB,EAAE,CAAA;IACjC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,OAAO,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AAC7B,CAAC,CAAA","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// ^^ will be looked into in MTQ-29\nimport {\n _RepliedMessageAssertionsByOrigin,\n MaybeArray,\n Message,\n MessageAction,\n MessageMediaType,\n Peer,\n RawDocument,\n RawLocation,\n RepliedMessageInfo,\n RepliedMessageOrigin,\n Sticker,\n StickerSourceType,\n StickerType,\n User,\n Video,\n} from '@mtcute/core'\n\nimport { BusinessMessageContext } from '../context/business-message.js'\nimport { MessageContext } from '../index.js'\nimport { Modify, UpdateFilter } from './types.js'\n\n/**\n * Filter incoming messages.\n *\n * Messages sent to yourself (i.e. Saved Messages) are also \"incoming\"\n */\nexport const incoming: UpdateFilter<Message, { isOutgoing: false }> = (msg) => !msg.isOutgoing\n\n/**\n * Filter outgoing messages.\n *\n * Messages sent to yourself (i.e. Saved Messages) are **not** \"outgoing\"\n */\nexport const outgoing: UpdateFilter<Message, { isOutgoing: true }> = (msg) => msg.isOutgoing\n\n/**\n * Filter for scheduled messages\n */\nexport const scheduled: UpdateFilter<Message, { isScheduled: true }> = (msg) => msg.isScheduled\n\n/**\n * Filter messages that are replies to some other message\n */\nexport const reply: UpdateFilter<Message, { replyToMessage: RepliedMessageInfo }> = (msg) => msg.replyToMessage !== null\n\n/**\n * Filter messages that are replies with the given origin type\n */\nexport const replyOrigin =\n <T extends RepliedMessageOrigin>(\n origin: T,\n ): UpdateFilter<\n Message,\n {\n replyToMessage: Modify<RepliedMessageInfo, _RepliedMessageAssertionsByOrigin[T] & { origin: T }>\n }\n > =>\n (msg) =>\n msg.replyToMessage?.originIs(origin) ?? false // originIs does additional checks\n\n/**\n * Filter messages containing some media\n */\nexport const media: UpdateFilter<Message, { media: Exclude<Message['media'], null> }> = (msg) => msg.media !== null\n\n/**\n * Filter messages containing media of given type\n */\nexport const mediaOf =\n <T extends MessageMediaType>(type: T): UpdateFilter<Message, { media: Extract<Message['media'], { type: T }> }> =>\n (msg) =>\n msg.media?.type === type\n\n/** Filter messages containing a photo */\nexport const photo = mediaOf('photo')\n/** Filter messages containing a dice */\nexport const dice = mediaOf('dice')\n/** Filter messages containing a contact */\nexport const contact = mediaOf('contact')\n/** Filter messages containing an audio file */\nexport const audio = mediaOf('audio')\n/** Filter messages containing a voice message (audio-only) */\nexport const voice = mediaOf('voice')\n/** Filter messages containing a sticker */\nexport const sticker = mediaOf('sticker')\n/** Filter messages containing a document (a file) */\nexport const document = mediaOf('document')\n/** Filter messages containing any video (videos, round messages and animations) */\nexport const anyVideo = mediaOf('video')\n/** Filter messages containing a static location */\nexport const location = mediaOf('location')\n/** Filter messages containing a live location */\nexport const liveLocation = mediaOf('live_location')\n/** Filter messages containing a game */\nexport const game = mediaOf('game')\n/** Filter messages containing a web page */\nexport const webpage = mediaOf('webpage')\n/** Filter messages containing a venue */\nexport const venue = mediaOf('venue')\n/** Filter messages containing a poll */\nexport const poll = mediaOf('poll')\n/** Filter messages containing an invoice */\nexport const invoice = mediaOf('invoice')\n\n/**\n * Filter messages containing any location (live or static).\n */\nexport const anyLocation: UpdateFilter<Message, { media: Location }> = (msg) => msg.media instanceof RawLocation\n\n/**\n * Filter messages containing a document\n *\n * This will also match media like audio, video, voice\n * that also use Documents\n */\nexport const anyDocument: UpdateFilter<Message, { media: RawDocument }> = (msg) => msg.media instanceof RawDocument\n\n/**\n * Filter messages containing a simple video.\n *\n * This does not include round messages and animations\n */\nexport const video: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: false\n isAnimation: false\n }\n >\n }\n> = (msg) => msg.media?.type === 'video' && !msg.media.isAnimation && !msg.media.isRound\n\n/**\n * Filter messages containing an animation.\n *\n * > **Note**: Legacy GIFs (i.e. documents with `image/gif` MIME)\n * > are also considered animations.\n */\nexport const animation: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: false\n isAnimation: true\n }\n >\n }\n> = (msg) => msg.media?.type === 'video' && msg.media.isAnimation && !msg.media.isRound\n\n/**\n * Filter messages containing a round message (aka video note).\n */\nexport const roundMessage: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: true\n isAnimation: false\n }\n >\n }\n> = (msg) => msg.media?.type === 'video' && !msg.media.isAnimation && msg.media.isRound\n\n/**\n * Filter messages containing a sticker by its type\n */\nexport const stickerByType =\n (type: StickerType): UpdateFilter<Message, { media: Sticker }> =>\n (msg) =>\n msg.media?.type === 'sticker' && msg.media.stickerType === type\n\n/**\n * Filter messages containing a sticker by its source file type\n */\nexport const stickerBySourceType =\n (type: StickerSourceType): UpdateFilter<Message, { media: Sticker }> =>\n (msg) =>\n msg.media?.type === 'sticker' && msg.media.sourceType === type\n\n/**\n * Filter text-only messages non-service messages\n */\nexport const text: UpdateFilter<\n Message,\n {\n media: null\n isService: false\n }\n> = (msg) => msg.media === null && !msg.isService\n\n/**\n * Filter service messages\n */\nexport const service: UpdateFilter<Message, { isService: true }> = (msg) => msg.isService\n\n/**\n * Filter service messages by action type\n */\nexport const action = <T extends Exclude<MessageAction, null>['type']>(\n type: MaybeArray<T>,\n): UpdateFilter<\n Message,\n {\n action: Extract<MessageAction, { type: T }>\n sender: T extends 'user_joined_link' | 'user_removed' | 'history_cleared' | 'contact_joined' | 'bot_allowed'\n ? User\n : Peer\n }\n> => {\n if (Array.isArray(type)) {\n const index: Partial<Record<T, true>> = {}\n type.forEach((it) => (index[it] = true))\n\n return (msg) => (msg.action?.type as any) in index\n }\n\n return (msg) => msg.action?.type === type\n}\n\nexport const sender =\n <T extends Message['sender']['type']>(\n type: T,\n ): UpdateFilter<Message, { sender: Extract<Message['sender'], { type: T }> }> =>\n (msg) =>\n msg.sender.type === type\n\n/**\n * Filter that matches messages that are replies to some other message that can be fetched\n * (i.e. not `private` origin, and has not been deleted)\n *\n * Optionally, you can pass a filter that will be applied to the replied message.\n */\nexport const replyTo =\n <Mod, State extends object>(\n filter?: UpdateFilter<Message, Mod, State>,\n ): UpdateFilter<MessageContext | BusinessMessageContext, { getReplyTo: () => Promise<Message & Mod> }, State> =>\n async (msg, state) => {\n if (!msg.replyToMessage?.id) return false\n\n const reply = msg._name === 'new_message' ? await msg.getReplyTo() : msg.replyTo\n if (!reply) return false\n\n if (msg._name === 'new_message') {\n msg.getReplyTo = () => Promise.resolve(reply)\n }\n\n if (!filter) return true\n\n return filter(reply, state)\n }\n\n/**\n * Middleware-like filter that will fetch the sender of the message\n * and make it available to further filters, as well as the handler itself.\n */\nexport const withCompleteSender =\n <Mod, State extends object>(\n filter?: UpdateFilter<MessageContext, Mod, State>,\n ): UpdateFilter<MessageContext, Mod, State> =>\n async (msg, state) => {\n try {\n await msg.getCompleteSender()\n } catch (e) {\n return false\n }\n\n if (!filter) return true\n\n return filter(msg, state)\n }\n"]}
@@ -33,7 +33,9 @@ export const userId = (id) => {
33
33
  return (upd) => {
34
34
  switch (upd._name) {
35
35
  case 'new_message':
36
- case 'edit_message': {
36
+ case 'edit_message':
37
+ case 'new_business_message':
38
+ case 'edit_business_message': {
37
39
  const sender = upd.sender;
38
40
  return (matchSelf && sender.isSelf) ||
39
41
  indexId.has(sender.id) ||
@@ -1 +1 @@
1
- {"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/filters/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAaH,IAAI,GAGP,MAAM,cAAc,CAAA;AAKrB;;GAEG;AACH,MAAM,CAAC,MAAM,EAAE,GAA4C,CAAC,GAAG,EAAE,EAAE,CAC/D,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,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,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CACtE,CAAA;IACL,CAAC,CAAA;AACL,CAAC,CAAA","sourcesContent":["import {\n BotChatJoinRequestUpdate,\n CallbackQuery,\n ChatMemberUpdate,\n ChosenInlineResult,\n DeleteStoryUpdate,\n HistoryReadUpdate,\n InlineCallbackQuery,\n InlineQuery,\n MaybeArray,\n Message,\n PollVoteUpdate,\n StoryUpdate,\n User,\n UserStatusUpdate,\n UserTypingUpdate,\n} from '@mtcute/core'\n\nimport { UpdateContextDistributed } from '../context/base.js'\nimport { UpdateFilter } from './types.js'\n\n/**\n * Filter messages generated by yourself (including Saved Messages)\n */\nexport const me: UpdateFilter<Message, { sender: User }> = (msg) =>\n (msg.sender.type === 'user' && msg.sender.isSelf) || msg.isOutgoing\n\n/**\n * Filter messages sent by bots\n */\nexport const bot: UpdateFilter<Message, { sender: User }> = (msg) => msg.sender.constructor === User && msg.sender.isBot\n\n// prettier-ignore\n/**\n * Filter updates by user ID(s) or username(s)\n *\n * Note that only some updates support filtering by username.\n */\nexport const userId: {\n (id: MaybeArray<number>): UpdateFilter<UpdateContextDistributed<\n | Message\n | StoryUpdate\n | DeleteStoryUpdate\n | InlineQuery\n | ChatMemberUpdate\n | ChosenInlineResult\n | CallbackQuery\n | InlineCallbackQuery\n | PollVoteUpdate\n | BotChatJoinRequestUpdate\n >>\n (id: MaybeArray<number | string>): UpdateFilter<UpdateContextDistributed<\n | Message\n | UserStatusUpdate\n | UserTypingUpdate\n | StoryUpdate\n | HistoryReadUpdate\n | DeleteStoryUpdate\n | InlineQuery\n | ChatMemberUpdate\n | ChosenInlineResult\n | CallbackQuery\n | InlineCallbackQuery\n | PollVoteUpdate\n | BotChatJoinRequestUpdate\n >>\n} = (id) => {\n const indexId = new Set<number>()\n const indexUsername = new Set<string>()\n let matchSelf = false\n\n if (!Array.isArray(id)) id = [id]\n id.forEach((id) => {\n if (id === 'me' || id === 'self') {\n matchSelf = true\n } else if (typeof id === 'string') {\n indexUsername.add(id)\n } else {\n indexId.add(id)\n }\n })\n\n return (upd) => {\n switch (upd._name) {\n case 'new_message':\n case 'edit_message': {\n const sender = upd.sender\n\n return (matchSelf && sender.isSelf) ||\n indexId.has(sender.id) ||\n indexUsername.has(sender.username!)\n }\n case 'user_status':\n case 'user_typing': {\n const id = upd.userId\n\n return (matchSelf && id === upd.client.storage.self.getCached()?.userId) ||\n indexId.has(id)\n }\n case 'poll_vote':\n case 'story':\n case 'delete_story': {\n const peer = upd.peer\n if (peer.type !== 'user') return false\n\n return (matchSelf && peer.isSelf) ||\n indexId.has(peer.id) ||\n Boolean(peer.usernames?.some((u) => indexUsername.has(u.username)))\n }\n case 'history_read': {\n const id = upd.chatId\n\n return (matchSelf && id === upd.client.storage.self.getCached()?.userId) ||\n indexId.has(id)\n }\n }\n\n const user = upd.user\n\n return (\n (matchSelf && user.isSelf) ||\n indexId.has(user.id) ||\n Boolean(user.usernames?.some((u) => indexUsername.has(u.username)))\n )\n }\n}\n"]}
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/filters/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAaH,IAAI,GAGP,MAAM,cAAc,CAAA;AAKrB;;GAEG;AACH,MAAM,CAAC,MAAM,EAAE,GAA4C,CAAC,GAAG,EAAE,EAAE,CAC/D,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,UAAU,CAAA;AAEvE;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAA4C,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,KAAK,IAAI,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAA;AAExH,kBAAkB;AAClB;;;;GAIG;AACH,MAAM,CA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AC,CAAA","sourcesContent":["import {\n BotChatJoinRequestUpdate,\n CallbackQuery,\n ChatMemberUpdate,\n ChosenInlineResult,\n DeleteStoryUpdate,\n HistoryReadUpdate,\n InlineCallbackQuery,\n InlineQuery,\n MaybeArray,\n Message,\n PollVoteUpdate,\n StoryUpdate,\n User,\n UserStatusUpdate,\n UserTypingUpdate,\n} from '@mtcute/core'\n\nimport { UpdateContextDistributed } from '../context/base.js'\nimport { UpdateFilter } from './types.js'\n\n/**\n * Filter messages generated by yourself (including Saved Messages)\n */\nexport const me: UpdateFilter<Message, { sender: User }> = (msg) =>\n (msg.sender.type === 'user' && msg.sender.isSelf) || msg.isOutgoing\n\n/**\n * Filter messages sent by bots\n */\nexport const bot: UpdateFilter<Message, { sender: User }> = (msg) => msg.sender.constructor === User && msg.sender.isBot\n\n// prettier-ignore\n/**\n * Filter updates by user ID(s) or username(s)\n *\n * Note that only some updates support filtering by username.\n */\nexport const userId: {\n (id: MaybeArray<number>): UpdateFilter<UpdateContextDistributed<\n | Message\n | StoryUpdate\n | DeleteStoryUpdate\n | InlineQuery\n | ChatMemberUpdate\n | ChosenInlineResult\n | CallbackQuery\n | InlineCallbackQuery\n | PollVoteUpdate\n | BotChatJoinRequestUpdate\n >>\n (id: MaybeArray<number | string>): UpdateFilter<UpdateContextDistributed<\n | Message\n | UserStatusUpdate\n | UserTypingUpdate\n | StoryUpdate\n | HistoryReadUpdate\n | DeleteStoryUpdate\n | InlineQuery\n | ChatMemberUpdate\n | ChosenInlineResult\n | CallbackQuery\n | InlineCallbackQuery\n | PollVoteUpdate\n | BotChatJoinRequestUpdate\n >>\n} = (id) => {\n const indexId = new Set<number>()\n const indexUsername = new Set<string>()\n let matchSelf = false\n\n if (!Array.isArray(id)) id = [id]\n id.forEach((id) => {\n if (id === 'me' || id === 'self') {\n matchSelf = true\n } else if (typeof id === 'string') {\n indexUsername.add(id)\n } else {\n indexId.add(id)\n }\n })\n\n return (upd) => {\n switch (upd._name) {\n case 'new_message':\n case 'edit_message':\n case 'new_business_message':\n case 'edit_business_message': {\n const sender = upd.sender\n\n return (matchSelf && sender.isSelf) ||\n indexId.has(sender.id) ||\n indexUsername.has(sender.username!)\n }\n case 'user_status':\n case 'user_typing': {\n const id = upd.userId\n\n return (matchSelf && id === upd.client.storage.self.getCached()?.userId) ||\n indexId.has(id)\n }\n case 'poll_vote':\n case 'story':\n case 'delete_story': {\n const peer = upd.peer\n if (peer.type !== 'user') return false\n\n return (matchSelf && peer.isSelf) ||\n indexId.has(peer.id) ||\n Boolean(peer.usernames?.some((u) => indexUsername.has(u.username)))\n }\n case 'history_read': {\n const id = upd.chatId\n\n return (matchSelf && id === upd.client.storage.self.getCached()?.userId) ||\n indexId.has(id)\n }\n }\n\n const user = upd.user\n\n return (\n (matchSelf && user.isSelf) ||\n indexId.has(user.id) ||\n Boolean(user.usernames?.some((u) => indexUsername.has(u.username)))\n )\n }\n}\n"]}
package/esm/handler.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, MaybePromise, PeersIndex, PollUpdate, PollVoteUpdate, StoryUpdate, tl, UserStatusUpdate, UserTypingUpdate } from '@mtcute/core';
1
+ import { BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, BusinessConnection, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteBusinessMessageUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, MaybePromise, 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 { PropagationAction } from './propagation.js';
6
7
  export interface BaseUpdateHandler<Name, Handler, Checker> {
@@ -32,4 +33,9 @@ export type StoryUpdateHandler<T = UpdateContext<StoryUpdate>> = ParsedUpdateHan
32
33
  export type DeleteStoryHandler<T = UpdateContext<DeleteStoryUpdate>> = ParsedUpdateHandler<'delete_story', T>;
33
34
  export type BotReactionUpdateHandler<T = UpdateContext<BotReactionUpdate>> = ParsedUpdateHandler<'bot_reaction', T>;
34
35
  export type BotReactionCountUpdateHandler<T = UpdateContext<BotReactionCountUpdate>> = ParsedUpdateHandler<'bot_reaction_count', T>;
35
- export type UpdateHandler = RawUpdateHandler | NewMessageHandler | EditMessageHandler | MessageGroupHandler | DeleteMessageHandler | ChatMemberUpdateHandler | InlineQueryHandler | ChosenInlineResultHandler | CallbackQueryHandler | InlineCallbackQueryHandler | PollUpdateHandler | PollVoteHandler | UserStatusUpdateHandler | UserTypingHandler | HistoryReadHandler | BotStoppedHandler | BotChatJoinRequestHandler | ChatJoinRequestHandler | PreCheckoutQueryHandler | StoryUpdateHandler | DeleteStoryHandler | BotReactionUpdateHandler | BotReactionCountUpdateHandler;
36
+ export type BusinessConnectionUpdateHandler<T = UpdateContext<BusinessConnection>> = ParsedUpdateHandler<'business_connection', T>;
37
+ export type NewBusinessMessageHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<'new_business_message', T, S>;
38
+ export type EditBusinessMessageHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<'edit_business_message', T, S>;
39
+ export type BusinessMessageGroupHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<'business_message_group', T, S>;
40
+ export type DeleteBusinessMessageHandler<T = UpdateContext<DeleteBusinessMessageUpdate>> = ParsedUpdateHandler<'delete_business_message', T>;
41
+ export type UpdateHandler = RawUpdateHandler | NewMessageHandler | EditMessageHandler | MessageGroupHandler | DeleteMessageHandler | ChatMemberUpdateHandler | InlineQueryHandler | ChosenInlineResultHandler | CallbackQueryHandler | InlineCallbackQueryHandler | PollUpdateHandler | PollVoteHandler | UserStatusUpdateHandler | UserTypingHandler | HistoryReadHandler | BotStoppedHandler | BotChatJoinRequestHandler | ChatJoinRequestHandler | PreCheckoutQueryHandler | StoryUpdateHandler | DeleteStoryHandler | BotReactionUpdateHandler | BotReactionCountUpdateHandler | BusinessConnectionUpdateHandler | NewBusinessMessageHandler | EditBusinessMessageHandler | BusinessMessageGroupHandler | DeleteBusinessMessageHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/handler.ts"],"names":[],"mappings":";AAqHA,cAAc","sourcesContent":["import {\n BotReactionCountUpdate,\n BotReactionUpdate,\n BotStoppedUpdate,\n ChatJoinRequestUpdate,\n ChatMemberUpdate,\n DeleteMessageUpdate,\n DeleteStoryUpdate,\n HistoryReadUpdate,\n MaybePromise,\n PeersIndex,\n PollUpdate,\n PollVoteUpdate,\n StoryUpdate,\n tl,\n UserStatusUpdate,\n UserTypingUpdate,\n} from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContext } from './context/base.js'\nimport {\n CallbackQueryContext,\n ChatJoinRequestUpdateContext,\n ChosenInlineResultContext,\n InlineCallbackQueryContext,\n InlineQueryContext,\n MessageContext,\n PreCheckoutQueryContext,\n} from './context/index.js'\nimport { PropagationAction } from './propagation.js'\n\nexport interface BaseUpdateHandler<Name, Handler, Checker> {\n name: Name\n callback: Handler\n\n check?: Checker\n}\n\nexport type ParsedUpdateHandler<Name, Update, State = never> = BaseUpdateHandler<\n Name,\n (update: Update, state: State) => MaybePromise<void | PropagationAction>,\n (update: Update, state: State) => MaybePromise<boolean>\n>\n\nexport type RawUpdateHandler = BaseUpdateHandler<\n 'raw',\n (\n client: TelegramClient,\n update: tl.TypeUpdate | tl.TypeMessage,\n peers: PeersIndex,\n ) => MaybePromise<void | PropagationAction>,\n (client: TelegramClient, update: tl.TypeUpdate | tl.TypeMessage, peers: PeersIndex) => MaybePromise<boolean>\n>\n\n// begin-codegen\nexport type NewMessageHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'new_message', T, S>\nexport type EditMessageHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'edit_message', T, S>\nexport type MessageGroupHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'message_group', T, S>\nexport type DeleteMessageHandler<T = UpdateContext<DeleteMessageUpdate>> = ParsedUpdateHandler<'delete_message', T>\nexport type ChatMemberUpdateHandler<T = UpdateContext<ChatMemberUpdate>> = ParsedUpdateHandler<'chat_member', T>\nexport type InlineQueryHandler<T = InlineQueryContext> = ParsedUpdateHandler<'inline_query', T>\nexport type ChosenInlineResultHandler<T = ChosenInlineResultContext> = ParsedUpdateHandler<'chosen_inline_result', T>\nexport type CallbackQueryHandler<T = CallbackQueryContext, S = never> = ParsedUpdateHandler<'callback_query', T, S>\nexport type InlineCallbackQueryHandler<T = InlineCallbackQueryContext, S = never> = ParsedUpdateHandler<\n 'inline_callback_query',\n T,\n S\n>\nexport type PollUpdateHandler<T = UpdateContext<PollUpdate>> = ParsedUpdateHandler<'poll', T>\nexport type PollVoteHandler<T = UpdateContext<PollVoteUpdate>> = ParsedUpdateHandler<'poll_vote', T>\nexport type UserStatusUpdateHandler<T = UpdateContext<UserStatusUpdate>> = ParsedUpdateHandler<'user_status', T>\nexport type UserTypingHandler<T = UpdateContext<UserTypingUpdate>> = ParsedUpdateHandler<'user_typing', T>\nexport type HistoryReadHandler<T = UpdateContext<HistoryReadUpdate>> = ParsedUpdateHandler<'history_read', T>\nexport type BotStoppedHandler<T = UpdateContext<BotStoppedUpdate>> = ParsedUpdateHandler<'bot_stopped', T>\nexport type BotChatJoinRequestHandler<T = ChatJoinRequestUpdateContext> = ParsedUpdateHandler<\n 'bot_chat_join_request',\n T\n>\nexport type ChatJoinRequestHandler<T = UpdateContext<ChatJoinRequestUpdate>> = ParsedUpdateHandler<\n 'chat_join_request',\n T\n>\nexport type PreCheckoutQueryHandler<T = PreCheckoutQueryContext> = ParsedUpdateHandler<'pre_checkout_query', T>\nexport type StoryUpdateHandler<T = UpdateContext<StoryUpdate>> = ParsedUpdateHandler<'story', T>\nexport type DeleteStoryHandler<T = UpdateContext<DeleteStoryUpdate>> = ParsedUpdateHandler<'delete_story', T>\nexport type BotReactionUpdateHandler<T = UpdateContext<BotReactionUpdate>> = ParsedUpdateHandler<'bot_reaction', T>\nexport type BotReactionCountUpdateHandler<T = UpdateContext<BotReactionCountUpdate>> = ParsedUpdateHandler<\n 'bot_reaction_count',\n T\n>\n\nexport type UpdateHandler =\n | RawUpdateHandler\n | NewMessageHandler\n | EditMessageHandler\n | MessageGroupHandler\n | DeleteMessageHandler\n | ChatMemberUpdateHandler\n | InlineQueryHandler\n | ChosenInlineResultHandler\n | CallbackQueryHandler\n | InlineCallbackQueryHandler\n | PollUpdateHandler\n | PollVoteHandler\n | UserStatusUpdateHandler\n | UserTypingHandler\n | HistoryReadHandler\n | BotStoppedHandler\n | BotChatJoinRequestHandler\n | ChatJoinRequestHandler\n | PreCheckoutQueryHandler\n | StoryUpdateHandler\n | DeleteStoryHandler\n | BotReactionUpdateHandler\n | BotReactionCountUpdateHandler\n\n// end-codegen\n"]}
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/handler.ts"],"names":[],"mappings":";AAoJA,cAAc","sourcesContent":["import {\n BotReactionCountUpdate,\n BotReactionUpdate,\n BotStoppedUpdate,\n BusinessConnection,\n ChatJoinRequestUpdate,\n ChatMemberUpdate,\n DeleteBusinessMessageUpdate,\n DeleteMessageUpdate,\n DeleteStoryUpdate,\n HistoryReadUpdate,\n MaybePromise,\n PeersIndex,\n PollUpdate,\n PollVoteUpdate,\n StoryUpdate,\n tl,\n UserStatusUpdate,\n UserTypingUpdate,\n} from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContext } from './context/base.js'\nimport { BusinessMessageContext } from './context/business-message.js'\nimport {\n CallbackQueryContext,\n ChatJoinRequestUpdateContext,\n ChosenInlineResultContext,\n InlineCallbackQueryContext,\n InlineQueryContext,\n MessageContext,\n PreCheckoutQueryContext,\n} from './context/index.js'\nimport { PropagationAction } from './propagation.js'\n\nexport interface BaseUpdateHandler<Name, Handler, Checker> {\n name: Name\n callback: Handler\n\n check?: Checker\n}\n\nexport type ParsedUpdateHandler<Name, Update, State = never> = BaseUpdateHandler<\n Name,\n (update: Update, state: State) => MaybePromise<void | PropagationAction>,\n (update: Update, state: State) => MaybePromise<boolean>\n>\n\nexport type RawUpdateHandler = BaseUpdateHandler<\n 'raw',\n (\n client: TelegramClient,\n update: tl.TypeUpdate | tl.TypeMessage,\n peers: PeersIndex,\n ) => MaybePromise<void | PropagationAction>,\n (client: TelegramClient, update: tl.TypeUpdate | tl.TypeMessage, peers: PeersIndex) => MaybePromise<boolean>\n>\n\n// begin-codegen\nexport type NewMessageHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'new_message', T, S>\nexport type EditMessageHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'edit_message', T, S>\nexport type MessageGroupHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'message_group', T, S>\nexport type DeleteMessageHandler<T = UpdateContext<DeleteMessageUpdate>> = ParsedUpdateHandler<'delete_message', T>\nexport type ChatMemberUpdateHandler<T = UpdateContext<ChatMemberUpdate>> = ParsedUpdateHandler<'chat_member', T>\nexport type InlineQueryHandler<T = InlineQueryContext> = ParsedUpdateHandler<'inline_query', T>\nexport type ChosenInlineResultHandler<T = ChosenInlineResultContext> = ParsedUpdateHandler<'chosen_inline_result', T>\nexport type CallbackQueryHandler<T = CallbackQueryContext, S = never> = ParsedUpdateHandler<'callback_query', T, S>\nexport type InlineCallbackQueryHandler<T = InlineCallbackQueryContext, S = never> = ParsedUpdateHandler<\n 'inline_callback_query',\n T,\n S\n>\nexport type PollUpdateHandler<T = UpdateContext<PollUpdate>> = ParsedUpdateHandler<'poll', T>\nexport type PollVoteHandler<T = UpdateContext<PollVoteUpdate>> = ParsedUpdateHandler<'poll_vote', T>\nexport type UserStatusUpdateHandler<T = UpdateContext<UserStatusUpdate>> = ParsedUpdateHandler<'user_status', T>\nexport type UserTypingHandler<T = UpdateContext<UserTypingUpdate>> = ParsedUpdateHandler<'user_typing', T>\nexport type HistoryReadHandler<T = UpdateContext<HistoryReadUpdate>> = ParsedUpdateHandler<'history_read', T>\nexport type BotStoppedHandler<T = UpdateContext<BotStoppedUpdate>> = ParsedUpdateHandler<'bot_stopped', T>\nexport type BotChatJoinRequestHandler<T = ChatJoinRequestUpdateContext> = ParsedUpdateHandler<\n 'bot_chat_join_request',\n T\n>\nexport type ChatJoinRequestHandler<T = UpdateContext<ChatJoinRequestUpdate>> = ParsedUpdateHandler<\n 'chat_join_request',\n T\n>\nexport type PreCheckoutQueryHandler<T = PreCheckoutQueryContext> = ParsedUpdateHandler<'pre_checkout_query', T>\nexport type StoryUpdateHandler<T = UpdateContext<StoryUpdate>> = ParsedUpdateHandler<'story', T>\nexport type DeleteStoryHandler<T = UpdateContext<DeleteStoryUpdate>> = ParsedUpdateHandler<'delete_story', T>\nexport type BotReactionUpdateHandler<T = UpdateContext<BotReactionUpdate>> = ParsedUpdateHandler<'bot_reaction', T>\nexport type BotReactionCountUpdateHandler<T = UpdateContext<BotReactionCountUpdate>> = ParsedUpdateHandler<\n 'bot_reaction_count',\n T\n>\nexport type BusinessConnectionUpdateHandler<T = UpdateContext<BusinessConnection>> = ParsedUpdateHandler<\n 'business_connection',\n T\n>\nexport type NewBusinessMessageHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<\n 'new_business_message',\n T,\n S\n>\nexport type EditBusinessMessageHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<\n 'edit_business_message',\n T,\n S\n>\nexport type BusinessMessageGroupHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<\n 'business_message_group',\n T,\n S\n>\nexport type DeleteBusinessMessageHandler<T = UpdateContext<DeleteBusinessMessageUpdate>> = ParsedUpdateHandler<\n 'delete_business_message',\n T\n>\n\nexport type UpdateHandler =\n | RawUpdateHandler\n | NewMessageHandler\n | EditMessageHandler\n | MessageGroupHandler\n | DeleteMessageHandler\n | ChatMemberUpdateHandler\n | InlineQueryHandler\n | ChosenInlineResultHandler\n | CallbackQueryHandler\n | InlineCallbackQueryHandler\n | PollUpdateHandler\n | PollVoteHandler\n | UserStatusUpdateHandler\n | UserTypingHandler\n | HistoryReadHandler\n | BotStoppedHandler\n | BotChatJoinRequestHandler\n | ChatJoinRequestHandler\n | PreCheckoutQueryHandler\n | StoryUpdateHandler\n | DeleteStoryHandler\n | BotReactionUpdateHandler\n | BotReactionCountUpdateHandler\n | BusinessConnectionUpdateHandler\n | NewBusinessMessageHandler\n | EditBusinessMessageHandler\n | BusinessMessageGroupHandler\n | DeleteBusinessMessageHandler\n\n// end-codegen\n"]}
@@ -1,4 +1,5 @@
1
1
  import { MaybePromise, Peer } from '@mtcute/core';
2
+ import { BusinessMessageContext } from '../context/business-message.js';
2
3
  import { CallbackQueryContext, MessageContext } from '../context/index.js';
3
4
  /**
4
5
  * Function that determines how the state key is derived.
@@ -8,7 +9,7 @@ import { CallbackQueryContext, MessageContext } from '../context/index.js';
8
9
  * @param msg Message or callback from which to derive the key
9
10
  * @param scene Current scene UID, or `null` if none
10
11
  */
11
- export type StateKeyDelegate = (upd: MessageContext | CallbackQueryContext | Peer) => MaybePromise<string | null>;
12
+ export type StateKeyDelegate = (upd: MessageContext | BusinessMessageContext | CallbackQueryContext | Peer) => MaybePromise<string | null>;
12
13
  /**
13
14
  * Default state key delegate.
14
15
  *
package/esm/state/key.js CHANGED
@@ -15,7 +15,7 @@ export const defaultStateKeyDelegate = (upd) => {
15
15
  // User | Chat
16
16
  return String(upd.id);
17
17
  }
18
- if (upd._name === 'new_message') {
18
+ if (upd._name === 'new_message' || upd._name === 'new_business_message') {
19
19
  switch (upd.chat.chatType) {
20
20
  case 'private':
21
21
  case 'bot':
@@ -1 +1 @@
1
- {"version":3,"file":"key.js","sourceRoot":"","sources":["../../../src/state/key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAsB,MAAM,cAAc,CAAA;AAc9D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAqB,CAAC,GAAG,EAAiB,EAAE;IAC5E,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QAChB,cAAc;QACd,OAAO,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACzB,CAAC;IAED,IAAI,GAAG,CAAC,KAAK,KAAK,aAAa,EAAE,CAAC;QAC9B,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACxB,KAAK,SAAS,CAAC;YACf,KAAK,KAAK,CAAC;YACX,KAAK,SAAS;gBACV,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAC9B,KAAK,OAAO,CAAC;YACb,KAAK,YAAY,CAAC;YAClB,KAAK,WAAW;gBACZ,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;YAC5C;gBACI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACtC,CAAC;IACL,CAAC;IAED,IAAI,GAAG,CAAC,KAAK,KAAK,gBAAgB,EAAE,CAAC;QACjC,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS;YAAE,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,CAAA;QAE5D,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,CAAA;IAC1C,CAAC;IAED,OAAO,IAAI,CAAA;AACf,CAAC,CAAA","sourcesContent":["import { assertNever, MaybePromise, Peer } from '@mtcute/core'\n\nimport { CallbackQueryContext, MessageContext } from '../context/index.js'\n\n/**\n * Function that determines how the state key is derived.\n *\n * The key is additionally prefixed with current scene, if any.\n *\n * @param msg Message or callback from which to derive the key\n * @param scene Current scene UID, or `null` if none\n */\nexport type StateKeyDelegate = (upd: MessageContext | CallbackQueryContext | Peer) => MaybePromise<string | null>\n\n/**\n * Default state key delegate.\n *\n * Derives key as follows:\n * - If private chat, `msg.chat.id`\n * - If group chat, `msg.chat.id + '_' + msg.sender.id`\n * - If channel, `msg.chat.id`\n * - If non-inline callback query:\n * - If in private chat (i.e. `upd.chatType === 'user'`), `upd.user.id`\n * - If in group/channel/supergroup (i.e. `upd.chatType !== 'user'`), `upd.chatId + '_' + upd.user.id`\n */\nexport const defaultStateKeyDelegate: StateKeyDelegate = (upd): string | null => {\n if ('type' in upd) {\n // User | Chat\n return String(upd.id)\n }\n\n if (upd._name === 'new_message') {\n switch (upd.chat.chatType) {\n case 'private':\n case 'bot':\n case 'channel':\n return String(upd.chat.id)\n case 'group':\n case 'supergroup':\n case 'gigagroup':\n return `${upd.chat.id}_${upd.sender.id}`\n default:\n assertNever(upd.chat.chatType)\n }\n }\n\n if (upd._name === 'callback_query') {\n if (upd.chat.chatType === 'private') return `${upd.user.id}`\n\n return `${upd.chat.id}_${upd.user.id}`\n }\n\n return null\n}\n"]}
1
+ {"version":3,"file":"key.js","sourceRoot":"","sources":["../../../src/state/key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAsB,MAAM,cAAc,CAAA;AAiB9D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAqB,CAAC,GAAG,EAAiB,EAAE;IAC5E,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QAChB,cAAc;QACd,OAAO,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACzB,CAAC;IAED,IAAI,GAAG,CAAC,KAAK,KAAK,aAAa,IAAI,GAAG,CAAC,KAAK,KAAK,sBAAsB,EAAE,CAAC;QACtE,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACxB,KAAK,SAAS,CAAC;YACf,KAAK,KAAK,CAAC;YACX,KAAK,SAAS;gBACV,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAC9B,KAAK,OAAO,CAAC;YACb,KAAK,YAAY,CAAC;YAClB,KAAK,WAAW;gBACZ,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;YAC5C;gBACI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACtC,CAAC;IACL,CAAC;IAED,IAAI,GAAG,CAAC,KAAK,KAAK,gBAAgB,EAAE,CAAC;QACjC,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS;YAAE,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,CAAA;QAE5D,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,CAAA;IAC1C,CAAC;IAED,OAAO,IAAI,CAAA;AACf,CAAC,CAAA","sourcesContent":["import { assertNever, MaybePromise, Peer } from '@mtcute/core'\n\nimport { BusinessMessageContext } from '../context/business-message.js'\nimport { CallbackQueryContext, MessageContext } from '../context/index.js'\n\n/**\n * Function that determines how the state key is derived.\n *\n * The key is additionally prefixed with current scene, if any.\n *\n * @param msg Message or callback from which to derive the key\n * @param scene Current scene UID, or `null` if none\n */\nexport type StateKeyDelegate = (\n upd: MessageContext | BusinessMessageContext | CallbackQueryContext | Peer,\n) => MaybePromise<string | null>\n\n/**\n * Default state key delegate.\n *\n * Derives key as follows:\n * - If private chat, `msg.chat.id`\n * - If group chat, `msg.chat.id + '_' + msg.sender.id`\n * - If channel, `msg.chat.id`\n * - If non-inline callback query:\n * - If in private chat (i.e. `upd.chatType === 'user'`), `upd.user.id`\n * - If in group/channel/supergroup (i.e. `upd.chatType !== 'user'`), `upd.chatId + '_' + upd.user.id`\n */\nexport const defaultStateKeyDelegate: StateKeyDelegate = (upd): string | null => {\n if ('type' in upd) {\n // User | Chat\n return String(upd.id)\n }\n\n if (upd._name === 'new_message' || upd._name === 'new_business_message') {\n switch (upd.chat.chatType) {\n case 'private':\n case 'bot':\n case 'channel':\n return String(upd.chat.id)\n case 'group':\n case 'supergroup':\n case 'gigagroup':\n return `${upd.chat.id}_${upd.sender.id}`\n default:\n assertNever(upd.chat.chatType)\n }\n }\n\n if (upd._name === 'callback_query') {\n if (upd.chat.chatType === 'private') return `${upd.user.id}`\n\n return `${upd.chat.id}_${upd.user.id}`\n }\n\n return null\n}\n"]}
package/esm/wizard.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { MaybePromise } from '@mtcute/core';
2
2
  import { MessageContext } from './context/message.js';
3
- import { Dispatcher } from './dispatcher.js';
3
+ import { Dispatcher, DispatcherParams } from './dispatcher.js';
4
4
  import { filters } from './filters/index.js';
5
5
  import { UpdateState } from './state/update-state.js';
6
6
  /**
@@ -31,6 +31,10 @@ interface WizardInternalState {
31
31
  export declare class WizardScene<State extends object> extends Dispatcher<State & WizardInternalState> {
32
32
  private _steps;
33
33
  private _defaultState;
34
+ constructor(name: string, params?: Omit<DispatcherParams, 'sceneName'>);
35
+ static for: never;
36
+ static child: never;
37
+ static scene: never;
34
38
  setDefaultState(defaultState: State): void;
35
39
  /**
36
40
  * Get the total number of registered steps
package/esm/wizard.js CHANGED
@@ -26,6 +26,9 @@ export var WizardSceneAction;
26
26
  export class WizardScene extends Dispatcher {
27
27
  _steps = 0;
28
28
  _defaultState = {};
29
+ constructor(name, params) {
30
+ super(undefined, { sceneName: name, ...params });
31
+ }
29
32
  setDefaultState(defaultState) {
30
33
  this._defaultState = defaultState;
31
34
  }
package/esm/wizard.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"wizard.js","sourceRoot":"","sources":["../../src/wizard.ts"],"names":[],"mappings":"AAGA,OA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AAS,CAAC,IAAY;QACzB,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAsB,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAA;QAE5E,IAAI,IAAI,KAAK,CAAC;YAAE,OAAO,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;QAE7D,OAAO,MAAM,CAAA;IACjB,CAAC;IAED;;OAEG;IACH,aAAa;QACT,OAAO,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC7C,CAAC;IAED;;OAEG;IACH,OAAO,CACH,OAG6C;QAE7C,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;QAE1B,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;YAChE,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YAExC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;gBAC7B,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;gBAElC,OAAM;YACV,CAAC;YAED,QAAQ,MAAM,EAAE,CAAC;gBACb,KAAK,MAAM,CAAC,CAAC,CAAC;oBACV,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,CAAA;oBACpC,MAAK;gBACT,CAAC;gBACD,KAAK,MAAM;oBACP,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;oBAClB,MAAK;YACb,CAAC;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import { MaybePromise } from '@mtcute/core'\n\nimport { MessageContext } from './context/message.js'\nimport { Dispatcher } from './dispatcher.js'\nimport { filters } from './filters/index.js'\nimport { UpdateState } from './state/update-state.js'\n\n/**\n * Action for the wizard scene.\n *\n * `Next`: Continue to the next registered step\n * (or exit, if this is the last step)\n *\n * `Stay`: Stay on the same step\n *\n * `Exit`: Exit from the wizard scene\n *\n * You can also return a `number` to jump to that step\n */\nexport enum WizardSceneAction {\n Next = 'next',\n Stay = 'stay',\n Exit = 'exit',\n}\n\ninterface WizardInternalState {\n $step?: number\n}\n\n/**\n * Wizard is a special type of Dispatcher\n * that can be used to simplify implementing\n * step-by-step scenes.\n */\nexport class WizardScene<State extends object> extends Dispatcher<State & WizardInternalState> {\n private _steps = 0\n\n private _defaultState: State & WizardInternalState = {} as State & WizardInternalState\n\n setDefaultState(defaultState: State): void {\n this._defaultState = defaultState as State & WizardInternalState\n }\n\n /**\n * Get the total number of registered steps\n */\n get totalSteps(): number {\n return this._steps\n }\n\n /**\n * Go to the Nth step\n */\n async goToStep(state: UpdateState<WizardInternalState>, step: number) {\n if (step >= this._steps) {\n await state.exit()\n } else {\n await state.merge({ $step: step }, this._defaultState)\n }\n }\n\n /**\n * Skip N steps\n */\n async skip(state: UpdateState<WizardInternalState>, count = 1) {\n const { $step } = (await state.get()) || {}\n if ($step === undefined) throw new Error('Wizard state is not initialized')\n\n return this.goToStep(state, $step + count)\n }\n\n /**\n * Filter that will only pass if the current step is `step`\n */\n static onNthStep(step: number) {\n const filter = filters.state<WizardInternalState>((it) => it.$step === step)\n\n if (step === 0) return filters.or(filters.stateEmpty, filter)\n\n return filter\n }\n\n /**\n * Filter that will only pass if the current step is the one after last one added\n */\n onCurrentStep() {\n return WizardScene.onNthStep(this._steps)\n }\n\n /**\n * Add a step to the wizard\n */\n addStep(\n handler: (\n msg: MessageContext,\n state: UpdateState<State & WizardInternalState>,\n ) => MaybePromise<WizardSceneAction | number>,\n ): void {\n const step = this._steps++\n\n this.onNewMessage(WizardScene.onNthStep(step), async (msg, state) => {\n const result = await handler(msg, state)\n\n if (typeof result === 'number') {\n await this.goToStep(state, result)\n\n return\n }\n\n switch (result) {\n case 'next': {\n await this.goToStep(state, step + 1)\n break\n }\n case 'exit':\n await state.exit()\n break\n }\n })\n }\n}\n"]}
1
+ {"version":3,"file":"wizard.js","sourceRoot":"","sources":["../../src/wizard.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAoB,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAG5C;;;;;;;;;;;GAWG;AACH,MAAM,CAAN,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IACzB,kCAAa,CAAA;IACb,kCAAa,CAAA;IACb,kCAAa,CAAA;AACjB,CAAC,EAJW,iBAAiB,KAAjB,iBAAiB,QAI5B;AAMD;;;;GAIG;AACH,MAAM,OAAO,WAAkC,SAAQ,UAAuC;IAClF,MAAM,GAAG,CAAC,CAAA;IAEV,aAAa,GAAgC,EAAiC,CAAA;IAEtF,YAAY,IAAY,EAAE,MAA4C;QAClE,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;IACpD,CAAC;IAOD,eAAe,CAAC,YAAmB;QAC/B,IAAI,CAAC,aAAa,GAAG,YAA2C,CAAA;IACpE,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,MAAM,CAAA;IACtB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,KAAuC,EAAE,IAAY;QAChE,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACtB,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;QACtB,CAAC;aAAM,CAAC;YACJ,MAAM,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;QAC1D,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,KAAuC,EAAE,KAAK,GAAG,CAAC;QACzD,MAAM,EAAE,KAAK,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BACpC,MAAK;gBACT,CAAC;gBACD,KAAK,MAAM;oBACP,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;oBAClB,MAAK;YACb,CAAC;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import { MaybePromise } from '@mtcute/core'\n\nimport { MessageContext } from './context/message.js'\nimport { Dispatcher, DispatcherParams } from './dispatcher.js'\nimport { filters } from './filters/index.js'\nimport { UpdateState } from './state/update-state.js'\n\n/**\n * Action for the wizard scene.\n *\n * `Next`: Continue to the next registered step\n * (or exit, if this is the last step)\n *\n * `Stay`: Stay on the same step\n *\n * `Exit`: Exit from the wizard scene\n *\n * You can also return a `number` to jump to that step\n */\nexport enum WizardSceneAction {\n Next = 'next',\n Stay = 'stay',\n Exit = 'exit',\n}\n\ninterface WizardInternalState {\n $step?: number\n}\n\n/**\n * Wizard is a special type of Dispatcher\n * that can be used to simplify implementing\n * step-by-step scenes.\n */\nexport class WizardScene<State extends object> extends Dispatcher<State & WizardInternalState> {\n private _steps = 0\n\n private _defaultState: State & WizardInternalState = {} as State & WizardInternalState\n\n constructor(name: string, params?: Omit<DispatcherParams, 'sceneName'>) {\n super(undefined, { sceneName: name, ...params })\n }\n\n // remove inherited statics from Dispatcher\n declare static for: never\n declare static child: never\n declare static scene: never\n\n setDefaultState(defaultState: State): void {\n this._defaultState = defaultState as State & WizardInternalState\n }\n\n /**\n * Get the total number of registered steps\n */\n get totalSteps(): number {\n return this._steps\n }\n\n /**\n * Go to the Nth step\n */\n async goToStep(state: UpdateState<WizardInternalState>, step: number) {\n if (step >= this._steps) {\n await state.exit()\n } else {\n await state.merge({ $step: step }, this._defaultState)\n }\n }\n\n /**\n * Skip N steps\n */\n async skip(state: UpdateState<WizardInternalState>, count = 1) {\n const { $step } = (await state.get()) || {}\n if ($step === undefined) throw new Error('Wizard state is not initialized')\n\n return this.goToStep(state, $step + count)\n }\n\n /**\n * Filter that will only pass if the current step is `step`\n */\n static onNthStep(step: number) {\n const filter = filters.state<WizardInternalState>((it) => it.$step === step)\n\n if (step === 0) return filters.or(filters.stateEmpty, filter)\n\n return filter\n }\n\n /**\n * Filter that will only pass if the current step is the one after last one added\n */\n onCurrentStep() {\n return WizardScene.onNthStep(this._steps)\n }\n\n /**\n * Add a step to the wizard\n */\n addStep(\n handler: (\n msg: MessageContext,\n state: UpdateState<State & WizardInternalState>,\n ) => MaybePromise<WizardSceneAction | number>,\n ): void {\n const step = this._steps++\n\n this.onNewMessage(WizardScene.onNthStep(step), async (msg, state) => {\n const result = await handler(msg, state)\n\n if (typeof result === 'number') {\n await this.goToStep(state, result)\n\n return\n }\n\n switch (result) {\n case 'next': {\n await this.goToStep(state, step + 1)\n break\n }\n case 'exit':\n await state.exit()\n break\n }\n })\n }\n}\n"]}
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './esm/index.js'
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './esm/index.js'
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@mtcute/dispatcher",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Updates dispatcher and bot framework for @mtcute/client",
5
5
  "author": "alina sireneva <alina@tei.su>",
6
6
  "license": "MIT",
7
- "main": "cjs/index.js",
8
7
  "type": "module",
9
8
  "sideEffects": false,
10
9
  "exports": {
@@ -15,8 +14,9 @@
15
14
  },
16
15
  "scripts": {},
17
16
  "dependencies": {
18
- "@mtcute/core": "^0.11.0",
17
+ "@mtcute/core": "^0.12.0",
19
18
  "events": "3.2.0"
20
19
  },
20
+ "main": "cjs/index.js",
21
21
  "module": "esm/index.js"
22
22
  }