@mtcute/dispatcher 0.13.4 → 0.14.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 (43) hide show
  1. package/cjs/context/callback-query.d.ts +17 -1
  2. package/cjs/context/callback-query.js +29 -1
  3. package/cjs/context/callback-query.js.map +1 -1
  4. package/cjs/context/index.d.ts +1 -0
  5. package/cjs/context/index.js +1 -0
  6. package/cjs/context/index.js.map +1 -1
  7. package/cjs/context/parse.d.ts +2 -2
  8. package/cjs/context/parse.js +2 -0
  9. package/cjs/context/parse.js.map +1 -1
  10. package/cjs/dispatcher.d.ts +28 -5
  11. package/cjs/dispatcher.js +5 -0
  12. package/cjs/dispatcher.js.map +1 -1
  13. package/cjs/filters/chat.d.ts +3 -3
  14. package/cjs/filters/chat.js.map +1 -1
  15. package/cjs/filters/text.d.ts +7 -7
  16. package/cjs/filters/text.js +7 -5
  17. package/cjs/filters/text.js.map +1 -1
  18. package/cjs/filters/user.d.ts +3 -3
  19. package/cjs/filters/user.js.map +1 -1
  20. package/cjs/handler.d.ts +3 -3
  21. package/cjs/handler.js.map +1 -1
  22. package/esm/context/callback-query.d.ts +17 -1
  23. package/esm/context/callback-query.js +28 -1
  24. package/esm/context/callback-query.js.map +1 -1
  25. package/esm/context/index.d.ts +1 -0
  26. package/esm/context/index.js +1 -0
  27. package/esm/context/index.js.map +1 -1
  28. package/esm/context/parse.d.ts +2 -2
  29. package/esm/context/parse.js +3 -1
  30. package/esm/context/parse.js.map +1 -1
  31. package/esm/dispatcher.d.ts +28 -5
  32. package/esm/dispatcher.js +5 -0
  33. package/esm/dispatcher.js.map +1 -1
  34. package/esm/filters/chat.d.ts +3 -3
  35. package/esm/filters/chat.js.map +1 -1
  36. package/esm/filters/text.d.ts +7 -7
  37. package/esm/filters/text.js +7 -5
  38. package/esm/filters/text.js.map +1 -1
  39. package/esm/filters/user.d.ts +3 -3
  40. package/esm/filters/user.js.map +1 -1
  41. package/esm/handler.d.ts +3 -3
  42. package/esm/handler.js.map +1 -1
  43. package/package.json +2 -2
@@ -4,6 +4,7 @@ exports.endsWith = exports.startsWith = exports.contains = exports.equals = expo
4
4
  function extractText(obj) {
5
5
  switch (obj._name) {
6
6
  case 'new_message':
7
+ case 'new_business_message':
7
8
  return obj.text;
8
9
  case 'inline_query':
9
10
  return obj.query;
@@ -11,6 +12,7 @@ function extractText(obj) {
11
12
  return obj.id;
12
13
  case 'callback_query':
13
14
  case 'inline_callback_query':
15
+ case 'business_callback_query':
14
16
  if (obj.raw.data)
15
17
  return obj.dataStr;
16
18
  }
@@ -21,7 +23,7 @@ function extractText(obj) {
21
23
  * - for `Message`, `Message.text` is used
22
24
  * - for `InlineQuery`, `InlineQuery.query` is used
23
25
  * - for {@link ChosenInlineResult}, {@link ChosenInlineResult#id} is used
24
- * - for `CallbackQuery`, `CallbackQuery.dataStr` is used
26
+ * - for callback queries, `dataStr` is used
25
27
  *
26
28
  * When a regex matches, the match array is stored in a
27
29
  * type-safe extension field `.match` of the object
@@ -45,7 +47,7 @@ exports.regex = regex;
45
47
  * - for `Message`, `Message.text` is used
46
48
  * - for `InlineQuery`, `InlineQuery.query` is used
47
49
  * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
48
- * - for `CallbackQuery`, `CallbackQuery.dataStr` is used
50
+ * - for callback queries, `dataStr` is used
49
51
  *
50
52
  * @param str String to be matched
51
53
  * @param ignoreCase Whether string case should be ignored
@@ -63,7 +65,7 @@ exports.equals = equals;
63
65
  * - for `Message`, `Message.text` is used
64
66
  * - for `InlineQuery`, `InlineQuery.query` is used
65
67
  * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
66
- * - for `CallbackQuery`, `CallbackQuery.dataStr` is used
68
+ * - for callback queries, `dataStr` is used
67
69
  *
68
70
  * @param str Substring to be matched
69
71
  * @param ignoreCase Whether string case should be ignored
@@ -87,7 +89,7 @@ exports.contains = contains;
87
89
  * - for `Message`, `Message.text` is used
88
90
  * - for `InlineQuery`, `InlineQuery.query` is used
89
91
  * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
90
- * - for `CallbackQuery`, `CallbackQuery.dataStr` is used
92
+ * - for callback queries, `dataStr` is used
91
93
  *
92
94
  * @param str Substring to be matched
93
95
  * @param ignoreCase Whether string case should be ignored
@@ -111,7 +113,7 @@ exports.startsWith = startsWith;
111
113
  * - for `Message`, `Message.text` is used
112
114
  * - for `InlineQuery`, `InlineQuery.query` is used
113
115
  * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
114
- * - for `CallbackQuery`, `CallbackQuery.dataStr` is used
116
+ * - for callback queries, `dataStr` is used
115
117
  *
116
118
  * @param str Substring to be matched
117
119
  * @param ignoreCase Whether string case should be ignored
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/filters/text.ts"],"names":[],"mappings":";;;AASA,SAAS,WAAW,CAAC,GAAoB;IACrC,QAAQ,GAAG,CAAC,KAAK,EAAE,CAAC;QAChB,KAAK,aAAa;YACd,OAAO,GAAG,CAAC,IAAI,CAAA;QACnB,KAAK,cAAc;YACf,OAAO,GAAG,CAAC,KAAK,CAAA;QACpB,KAAK,sBAAsB;YACvB,OAAO,GAAG,CAAC,EAAE,CAAA;QACjB,KAAK,gBAAgB,CAAC;QACtB,KAAK,uBAAuB;YACxB,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI;gBAAE,OAAO,GAAG,CAAC,OAAO,CAAA;IAC5C,CAAC;IAED,OAAO,IAAI,CAAA;AACf,CAAC;AAED;;;;;;;;;;;GAWG;AACI,MAAM,KAAK,GACd,CAAC,KAAa,EAA8D,EAAE,CAC1E,CAAC,GAAG,EAAE,EAAE;IACJ,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;IAC5B,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAA;IAEtB,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,C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AS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA;IAC9D,CAAC,CAAA;AACL,CAAC,CAAA;AAhBY,QAAA,QAAQ,YAgBpB","sourcesContent":["import { CallbackQuery, ChosenInlineResult, InlineCallbackQuery, InlineQuery, Message } from '@mtcute/core'\n\nimport { UpdateContextDistributed } from '../context/base.js'\nimport { UpdateFilter } from './types.js'\n\ntype UpdatesWithText = UpdateContextDistributed<\n Message | InlineQuery | ChosenInlineResult | CallbackQuery | InlineCallbackQuery\n>\n\nfunction extractText(obj: UpdatesWithText): string | null {\n switch (obj._name) {\n case 'new_message':\n return obj.text\n case 'inline_query':\n return obj.query\n case 'chosen_inline_result':\n return obj.id\n case 'callback_query':\n case 'inline_callback_query':\n if (obj.raw.data) return obj.dataStr\n }\n\n return null\n}\n\n/**\n * Filter objects that match a given regular expression\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult#id} is used\n * - for `CallbackQuery`, `CallbackQuery.dataStr` is used\n *\n * When a regex matches, the match array is stored in a\n * type-safe extension field `.match` of the object\n *\n * @param regex Regex to be matched\n */\nexport const regex =\n (regex: RegExp): UpdateFilter<UpdatesWithText, { match: RegExpMatchArray }> =>\n (obj) => {\n const txt = extractText(obj)\n if (!txt) return false\n\n const m = txt.match(regex)\n\n if (m) {\n (obj as typeof obj & { match: RegExpMatchArray }).match = m\n\n return true\n }\n\n return false\n }\n\n/**\n * Filter objects which contain the exact text given\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for `CallbackQuery`, `CallbackQuery.dataStr` is used\n *\n * @param str String to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport const equals = (str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> => {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => extractText(obj)?.toLowerCase() === str\n }\n\n return (obj) => extractText(obj) === str\n}\n\n/**\n * Filter objects which contain the text given (as a substring)\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for `CallbackQuery`, `CallbackQuery.dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport const contains = (str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> => {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().includes(str)\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.includes(str)\n }\n}\n\n/**\n * Filter objects which contain the text starting with a given string\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for `CallbackQuery`, `CallbackQuery.dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport const startsWith = (str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> => {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().substring(0, str.length) === str\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.substring(0, str.length) === str\n }\n}\n\n/**\n * Filter objects which contain the text ending with a given string\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for `CallbackQuery`, `CallbackQuery.dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport const endsWith = (str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> => {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().substring(0, str.length) === str\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.substring(0, str.length) === str\n }\n}\n"]}
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/filters/text.ts"],"names":[],"mappings":";;;AAuBA,SAAS,WAAW,CAAC,GAAoB;IACrC,QAAQ,GAAG,CAAC,KAAK,EAAE,CAAC;QAChB,KAAK,aAAa,CAAC;QACnB,KAAK,sBAAsB;YACvB,OAAO,GAAG,CAAC,IAAI,CAAA;QACnB,KAAK,cAAc;YACf,OAAO,GAAG,CAAC,KAAK,CAAA;QACpB,KAAK,sBAAsB;YACvB,OAAO,GAAG,CAAC,EAAE,CAAA;QACjB,KAAK,gBAAgB,CAAC;QACtB,KAAK,uBAAuB,CAAC;QAC7B,KAAK,yBAAyB;YAC1B,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI;gBAAE,OAAO,GAAG,CAAC,OAAO,CAAA;IAC5C,CAAC;IAED,OAAO,IAAI,CAAA;AACf,CAAC;AAED;;;;;;;;;;;GAWG;AACI,MAAM,KAAK,GACd,CAAC,KAAa,EAA8D,EAAE,CAC1E,CAAC,GAAG,EAAE,EAAE;IACJ,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;IAC5B,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAA;IAEtB,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAE1B,IAAI,CAAC,EAAE,CAAC;QACH,GAAgD,CAAC,KAAK,GAAG,CAAC,CAAA;QAE3D,OAAO,IAAI,CAAA;IACf,CAAC;IAED,OAAO,KAAK,CAAA;AAChB,CAAC,CAAA;AAfI,QAAA,KAAK,SAeT;AAET;;;;;;;;;GASG;AACI,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,UAAU,GAAG,KAAK,EAAiC,EAAE;IACrF,IAAI,UAAU,EAAE,CAAC;QACb,GAAG,GAAG,GAAG,C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AAE,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA;QAC5E,CAAC,CAAA;IACL,CAAC;IAED,OAAO,CAAC,GAAG,EAAE,EAAE;QACX,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;QAE5B,OAAO,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA;IAC9D,CAAC,CAAA;AACL,CAAC,CAAA;AAhBY,QAAA,UAAU,cAgBtB;AAED;;;;;;;;;GASG;AACI,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,UAAU,GAAG,KAAK,EAAiC,EAAE;IACvF,IAAI,UAAU,EAAE,CAAC;QACb,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;QAEvB,OAAO,CAAC,GAAG,EAAE,EAAE;YACX,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;YAE5B,OAAO,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA;QAC5E,CAAC,CAAA;IACL,CAAC;IAED,OAAO,CAAC,GAAG,EAAE,EAAE;QACX,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;QAE5B,OAAO,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA;IAC9D,CAAC,CAAA;AACL,CAAC,CAAA;AAhBY,QAAA,QAAQ,YAgBpB","sourcesContent":["import {\n BusinessCallbackQuery,\n BusinessMessage,\n CallbackQuery,\n ChosenInlineResult,\n InlineCallbackQuery,\n InlineQuery,\n Message,\n} from '@mtcute/core'\n\nimport { UpdateContextDistributed } from '../context/base.js'\nimport { UpdateFilter } from './types.js'\n\ntype UpdatesWithText = UpdateContextDistributed<\n | Message\n | BusinessMessage\n | InlineQuery\n | ChosenInlineResult\n | CallbackQuery\n | InlineCallbackQuery\n | BusinessCallbackQuery\n>\n\nfunction extractText(obj: UpdatesWithText): string | null {\n switch (obj._name) {\n case 'new_message':\n case 'new_business_message':\n return obj.text\n case 'inline_query':\n return obj.query\n case 'chosen_inline_result':\n return obj.id\n case 'callback_query':\n case 'inline_callback_query':\n case 'business_callback_query':\n if (obj.raw.data) return obj.dataStr\n }\n\n return null\n}\n\n/**\n * Filter objects that match a given regular expression\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult#id} is used\n * - for callback queries, `dataStr` is used\n *\n * When a regex matches, the match array is stored in a\n * type-safe extension field `.match` of the object\n *\n * @param regex Regex to be matched\n */\nexport const regex =\n (regex: RegExp): UpdateFilter<UpdatesWithText, { match: RegExpMatchArray }> =>\n (obj) => {\n const txt = extractText(obj)\n if (!txt) return false\n\n const m = txt.match(regex)\n\n if (m) {\n (obj as typeof obj & { match: RegExpMatchArray }).match = m\n\n return true\n }\n\n return false\n }\n\n/**\n * Filter objects which contain the exact text given\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for callback queries, `dataStr` is used\n *\n * @param str String to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport const equals = (str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> => {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => extractText(obj)?.toLowerCase() === str\n }\n\n return (obj) => extractText(obj) === str\n}\n\n/**\n * Filter objects which contain the text given (as a substring)\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for callback queries, `dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport const contains = (str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> => {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().includes(str)\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.includes(str)\n }\n}\n\n/**\n * Filter objects which contain the text starting with a given string\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for callback queries, `dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport const startsWith = (str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> => {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().substring(0, str.length) === str\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.substring(0, str.length) === str\n }\n}\n\n/**\n * Filter objects which contain the text ending with a given string\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for callback queries, `dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport const endsWith = (str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> => {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().substring(0, str.length) === str\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.substring(0, str.length) === str\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { BotChatJoinRequestUpdate, CallbackQuery, ChatMemberUpdate, ChosenInlineResult, DeleteStoryUpdate, HistoryReadUpdate, InlineCallbackQuery, InlineQuery, MaybeArray, Message, PollVoteUpdate, StoryUpdate, User, UserStatusUpdate, UserTypingUpdate } from '@mtcute/core';
1
+ import { BotChatJoinRequestUpdate, BusinessCallbackQuery, BusinessMessage, CallbackQuery, ChatMemberUpdate, ChosenInlineResult, DeleteStoryUpdate, HistoryReadUpdate, InlineCallbackQuery, InlineQuery, MaybeArray, Message, PollVoteUpdate, StoryUpdate, User, UserStatusUpdate, UserTypingUpdate } from '@mtcute/core';
2
2
  import { UpdateContextDistributed } from '../context/base.js';
3
3
  import { UpdateFilter } from './types.js';
4
4
  /**
@@ -19,6 +19,6 @@ export declare const bot: UpdateFilter<Message, {
19
19
  * Note that only some updates support filtering by username.
20
20
  */
21
21
  export declare const userId: {
22
- (id: MaybeArray<number>): UpdateFilter<UpdateContextDistributed<Message | StoryUpdate | DeleteStoryUpdate | InlineQuery | ChatMemberUpdate | ChosenInlineResult | CallbackQuery | InlineCallbackQuery | PollVoteUpdate | BotChatJoinRequestUpdate>>;
23
- (id: MaybeArray<number | string>): UpdateFilter<UpdateContextDistributed<Message | UserStatusUpdate | UserTypingUpdate | StoryUpdate | HistoryReadUpdate | DeleteStoryUpdate | InlineQuery | ChatMemberUpdate | ChosenInlineResult | CallbackQuery | InlineCallbackQuery | PollVoteUpdate | BotChatJoinRequestUpdate>>;
22
+ (id: MaybeArray<number>): UpdateFilter<UpdateContextDistributed<Message | BusinessMessage | StoryUpdate | DeleteStoryUpdate | InlineQuery | ChatMemberUpdate | ChosenInlineResult | CallbackQuery | InlineCallbackQuery | BusinessCallbackQuery | PollVoteUpdate | BotChatJoinRequestUpdate>>;
23
+ (id: MaybeArray<number | string>): UpdateFilter<UpdateContextDistributed<Message | BusinessMessage | UserStatusUpdate | UserTypingUpdate | StoryUpdate | HistoryReadUpdate | DeleteStoryUpdate | InlineQuery | ChatMemberUpdate | ChosenInlineResult | CallbackQuery | InlineCallbackQuery | BusinessCallbackQuery | PollVoteUpdate | BotChatJoinRequestUpdate>>;
24
24
  };
@@ -1 +1 @@
1
- {"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/filters/user.ts"],"names":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I,CAAC,SAAS,EAAE,EAAE,MAAM,CAAC;oBACpE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;YACvB,CAAC;QACL,CAAC;QAED,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAA;QAErB,OAAO,CACH,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC;YAC1B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACpB,OAAO,CAAC,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;AAzFY,QAAA,MAAM,UAyFlB","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"]}
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/filters/user.ts"],"names":[],"mappings":";;;AAAA,uCAkBqB;AAKrB;;GAEG;AACI,MAAM,EAAE,GAA4C,CAAC,GAAG,EAAE,EAAE,CAC/D,CAAC,GAAG,CAAC,MAAM,CA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I,GAAG,GAAG,CAAC,IAAI,CAAA;QAErB,OAAO,CACH,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC;YAC1B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACpB,OAAO,CAAC,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;AA7FY,QAAA,MAAM,UA6FlB","sourcesContent":["import {\n BotChatJoinRequestUpdate,\n BusinessCallbackQuery,\n BusinessMessage,\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 | BusinessMessage\n | StoryUpdate\n | DeleteStoryUpdate\n | InlineQuery\n | ChatMemberUpdate\n | ChosenInlineResult\n | CallbackQuery\n | InlineCallbackQuery\n | BusinessCallbackQuery\n | PollVoteUpdate\n | BotChatJoinRequestUpdate\n >>\n (id: MaybeArray<number | string>): UpdateFilter<UpdateContextDistributed<\n | Message\n | BusinessMessage\n | UserStatusUpdate\n | UserTypingUpdate\n | StoryUpdate\n | HistoryReadUpdate\n | DeleteStoryUpdate\n | InlineQuery\n | ChatMemberUpdate\n | ChosenInlineResult\n | CallbackQuery\n | InlineCallbackQuery\n | BusinessCallbackQuery\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/cjs/handler.d.ts CHANGED
@@ -1,8 +1,7 @@
1
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';
5
- import { CallbackQueryContext, ChatJoinRequestUpdateContext, ChosenInlineResultContext, InlineCallbackQueryContext, InlineQueryContext, MessageContext, PreCheckoutQueryContext } from './context/index.js';
4
+ import { BusinessCallbackQueryContext, BusinessMessageContext, CallbackQueryContext, ChatJoinRequestUpdateContext, ChosenInlineResultContext, InlineCallbackQueryContext, InlineQueryContext, MessageContext, PreCheckoutQueryContext } from './context/index.js';
6
5
  import { PropagationAction } from './propagation.js';
7
6
  export interface BaseUpdateHandler<Name, Handler, Checker> {
8
7
  name: Name;
@@ -20,6 +19,7 @@ export type InlineQueryHandler<T = InlineQueryContext> = ParsedUpdateHandler<'in
20
19
  export type ChosenInlineResultHandler<T = ChosenInlineResultContext> = ParsedUpdateHandler<'chosen_inline_result', T>;
21
20
  export type CallbackQueryHandler<T = CallbackQueryContext, S = never> = ParsedUpdateHandler<'callback_query', T, S>;
22
21
  export type InlineCallbackQueryHandler<T = InlineCallbackQueryContext, S = never> = ParsedUpdateHandler<'inline_callback_query', T, S>;
22
+ export type BusinessCallbackQueryHandler<T = BusinessCallbackQueryContext, S = never> = ParsedUpdateHandler<'business_callback_query', T, S>;
23
23
  export type PollUpdateHandler<T = UpdateContext<PollUpdate>> = ParsedUpdateHandler<'poll', T>;
24
24
  export type PollVoteHandler<T = UpdateContext<PollVoteUpdate>> = ParsedUpdateHandler<'poll_vote', T>;
25
25
  export type UserStatusUpdateHandler<T = UpdateContext<UserStatusUpdate>> = ParsedUpdateHandler<'user_status', T>;
@@ -38,4 +38,4 @@ export type NewBusinessMessageHandler<T = BusinessMessageContext, S = never> = P
38
38
  export type EditBusinessMessageHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<'edit_business_message', T, S>;
39
39
  export type BusinessMessageGroupHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<'business_message_group', T, S>;
40
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;
41
+ export type UpdateHandler = RawUpdateHandler | NewMessageHandler | EditMessageHandler | MessageGroupHandler | DeleteMessageHandler | ChatMemberUpdateHandler | InlineQueryHandler | ChosenInlineResultHandler | CallbackQueryHandler | InlineCallbackQueryHandler | BusinessCallbackQueryHandler | 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":";;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
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/handler.ts"],"names":[],"mappings":";;AA2JA,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 {\n BusinessCallbackQueryContext,\n BusinessMessageContext,\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 BusinessCallbackQueryHandler<T = BusinessCallbackQueryContext, S = never> = ParsedUpdateHandler<\n 'business_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 | BusinessCallbackQueryHandler\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,4 @@
1
- import { CallbackQuery, InlineCallbackQuery, MaybePromise, Message } from '@mtcute/core';
1
+ import { BusinessCallbackQuery, CallbackQuery, InlineCallbackQuery, MaybePromise, Message } from '@mtcute/core';
2
2
  import { TelegramClient } from '@mtcute/core/client.js';
3
3
  import { UpdateContext } from './base.js';
4
4
  /**
@@ -44,3 +44,19 @@ export declare class InlineCallbackQueryContext extends InlineCallbackQuery impl
44
44
  */
45
45
  editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>): Promise<void>;
46
46
  }
47
+ /**
48
+ * Context of an callback query update originated from a business connection message
49
+ *
50
+ * This is a subclass of {@link BusinessCallbackQuery}, so all its fields are also available.
51
+ */
52
+ export declare class BusinessCallbackQueryContext extends BusinessCallbackQuery implements UpdateContext<BusinessCallbackQuery> {
53
+ readonly client: TelegramClient;
54
+ readonly _name = "business_callback_query";
55
+ constructor(client: TelegramClient, query: BusinessCallbackQuery);
56
+ /** Answer to this callback query */
57
+ answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]): Promise<void>;
58
+ /**
59
+ * Edit the message that contained the callback button that was clicked.
60
+ */
61
+ editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>): Promise<Message>;
62
+ }
@@ -1,4 +1,4 @@
1
- import { CallbackQuery, InlineCallbackQuery } from '@mtcute/core';
1
+ import { BusinessCallbackQuery, CallbackQuery, InlineCallbackQuery } from '@mtcute/core';
2
2
  /**
3
3
  * Context of a callback query update.
4
4
  *
@@ -73,4 +73,31 @@ export class InlineCallbackQueryContext extends InlineCallbackQuery {
73
73
  });
74
74
  }
75
75
  }
76
+ /**
77
+ * Context of an callback query update originated from a business connection message
78
+ *
79
+ * This is a subclass of {@link BusinessCallbackQuery}, so all its fields are also available.
80
+ */
81
+ export class BusinessCallbackQueryContext extends BusinessCallbackQuery {
82
+ client;
83
+ _name = 'business_callback_query';
84
+ constructor(client, query) {
85
+ super(query.raw, query._peers);
86
+ this.client = client;
87
+ }
88
+ /** Answer to this callback query */
89
+ answer(params) {
90
+ return this.client.answerCallbackQuery(this.id, params);
91
+ }
92
+ /**
93
+ * Edit the message that contained the callback button that was clicked.
94
+ */
95
+ async editMessage(params) {
96
+ return this.client.editMessage({
97
+ message: this.message,
98
+ businessConnectionId: this.connectionId,
99
+ ...params,
100
+ });
101
+ }
102
+ }
76
103
  //# sourceMappingURL=callback-query.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"callback-query.js","sourceRoot":"","sources":["../../../src/context/callback-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAyB,MAAM,cAAc,CAAA;AAKxF;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IAItC;IAHJ,KAAK,GAAG,gBAAgB,CAAA;IAEjC,YACa,MAAsB,EAC/B,K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;QAC/D,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,MAA6E;QAC3F,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;YACjC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK;YACzB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import { CallbackQuery, InlineCallbackQuery, MaybePromise, Message } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a callback query update.\n *\n * This is a subclass of {@link CallbackQuery}, so all its fields are also available.\n */\nexport class CallbackQueryContext extends CallbackQuery implements UpdateContext<CallbackQuery> {\n readonly _name = 'callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: CallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * Get the message containing the callback button being clicked.\n *\n * Note that the message may have been deleted, in which case\n * `null` will be returned.\n */\n async getMessage(): Promise<Message | null> {\n return this.client.getCallbackQueryMessage(this)\n }\n\n /**\n * Edit the message that contained the callback button that was clicked.\n */\n async editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>) {\n return this.client.editMessage({\n chatId: this.raw.peer,\n message: this.raw.msgId,\n ...params,\n })\n }\n\n /**\n * Shortcut for getting the message and editing it.\n */\n async editMessageWith(handler: (msg: Message) => MaybePromise<Parameters<CallbackQueryContext['editMessage']>[0]>) {\n const msg = await this.getMessage()\n if (!msg) return\n\n const res = await handler(msg)\n if (!res) return\n\n return this.editMessage(res)\n }\n}\n\n/**\n * Context of an inline-originated callback query update.\n *\n * This is a subclass of {@link InlineCallbackQuery}, so all its fields are also available.\n */\nexport class InlineCallbackQueryContext extends InlineCallbackQuery implements UpdateContext<InlineCallbackQuery> {\n readonly _name = 'inline_callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: InlineCallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * Edit the message that contained the callback button that was clicked.\n */\n async editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>) {\n return this.client.editInlineMessage({\n messageId: this.raw.msgId,\n ...params,\n })\n }\n}\n"]}
1
+ {"version":3,"file":"callback-query.js","sourceRoot":"","sources":["../../../src/context/callback-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,mBAAmB,EAAyB,MAAM,cAAc,CAAA;AAK/G;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IAItC;IAHJ,KAAK,GAAG,gBAAgB,CAAA;IAEjC,YACa,MAAsB,EAC/B,KAAoB;QAEpB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;IAInC,CAAC;IAED,oCAAoC;IACpC,MAAM,CAAC,MAA4D;QAC/D,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAA;IACpD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,MAA6E;QAC3F,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;YAC3B,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI;YACrB,OAAO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C,CAAC;IAED,oCAAoC;IACpC,MAAM,CAAC,MAA4D;QAC/D,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,MAA6E;QAC3F,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;YAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,oBAAoB,EAAE,IAAI,CAAC,YAAY;YACvC,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import { BusinessCallbackQuery, CallbackQuery, InlineCallbackQuery, MaybePromise, Message } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a callback query update.\n *\n * This is a subclass of {@link CallbackQuery}, so all its fields are also available.\n */\nexport class CallbackQueryContext extends CallbackQuery implements UpdateContext<CallbackQuery> {\n readonly _name = 'callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: CallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * Get the message containing the callback button being clicked.\n *\n * Note that the message may have been deleted, in which case\n * `null` will be returned.\n */\n async getMessage(): Promise<Message | null> {\n return this.client.getCallbackQueryMessage(this)\n }\n\n /**\n * Edit the message that contained the callback button that was clicked.\n */\n async editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>) {\n return this.client.editMessage({\n chatId: this.raw.peer,\n message: this.raw.msgId,\n ...params,\n })\n }\n\n /**\n * Shortcut for getting the message and editing it.\n */\n async editMessageWith(handler: (msg: Message) => MaybePromise<Parameters<CallbackQueryContext['editMessage']>[0]>) {\n const msg = await this.getMessage()\n if (!msg) return\n\n const res = await handler(msg)\n if (!res) return\n\n return this.editMessage(res)\n }\n}\n\n/**\n * Context of an inline-originated callback query update.\n *\n * This is a subclass of {@link InlineCallbackQuery}, so all its fields are also available.\n */\nexport class InlineCallbackQueryContext extends InlineCallbackQuery implements UpdateContext<InlineCallbackQuery> {\n readonly _name = 'inline_callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: InlineCallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * Edit the message that contained the callback button that was clicked.\n */\n async editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>) {\n return this.client.editInlineMessage({\n messageId: this.raw.msgId,\n ...params,\n })\n }\n}\n\n/**\n * Context of an callback query update originated from a business connection message\n *\n * This is a subclass of {@link BusinessCallbackQuery}, so all its fields are also available.\n */\nexport class BusinessCallbackQueryContext\n extends BusinessCallbackQuery\n implements UpdateContext<BusinessCallbackQuery> {\n readonly _name = 'business_callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: BusinessCallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * Edit the message that contained the callback button that was clicked.\n */\n async editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>) {\n return this.client.editMessage({\n message: this.message,\n businessConnectionId: this.connectionId,\n ...params,\n })\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  export * from './base.js';
2
+ export * from './business-message.js';
2
3
  export * from './callback-query.js';
3
4
  export * from './chat-join-request.js';
4
5
  export * from './chosen-inline-result.js';
@@ -1,4 +1,5 @@
1
1
  export * from './base.js';
2
+ export * from './business-message.js';
2
3
  export * from './callback-query.js';
3
4
  export * from './chat-join-request.js';
4
5
  export * from './chosen-inline-result.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAE5B,cAAc,yBAAyB,CAAA","sourcesContent":["export * from './base.js'\nexport * from './callback-query.js'\nexport * from './chat-join-request.js'\nexport * from './chosen-inline-result.js'\nexport * from './inline-query.js'\nexport * from './message.js'\nexport type { UpdateContextType } from './parse.js'\nexport * from './pre-checkout-query.js'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAE5B,cAAc,yBAAyB,CAAA","sourcesContent":["export * from './base.js'\nexport * from './business-message.js'\nexport * from './callback-query.js'\nexport * from './chat-join-request.js'\nexport * from './chosen-inline-result.js'\nexport * from './inline-query.js'\nexport * from './message.js'\nexport type { UpdateContextType } from './parse.js'\nexport * from './pre-checkout-query.js'\n"]}
@@ -2,12 +2,12 @@ import { ParsedUpdate } from '@mtcute/core';
2
2
  import { TelegramClient } from '@mtcute/core/client.js';
3
3
  import { UpdateContextDistributed } from './base.js';
4
4
  import { BusinessMessageContext } from './business-message.js';
5
- import { CallbackQueryContext, InlineCallbackQueryContext } from './callback-query.js';
5
+ import { BusinessCallbackQueryContext, CallbackQueryContext, InlineCallbackQueryContext } from './callback-query.js';
6
6
  import { ChatJoinRequestUpdateContext } from './chat-join-request.js';
7
7
  import { ChosenInlineResultContext } from './chosen-inline-result.js';
8
8
  import { InlineQueryContext } from './inline-query.js';
9
9
  import { MessageContext } from './message.js';
10
10
  import { PreCheckoutQueryContext } from './pre-checkout-query.js';
11
11
  /** @internal */
12
- export declare function _parsedUpdateToContext(client: TelegramClient, update: ParsedUpdate): BusinessMessageContext | CallbackQueryContext | InlineCallbackQueryContext | ChatJoinRequestUpdateContext | ChosenInlineResultContext | InlineQueryContext | MessageContext | PreCheckoutQueryContext | UpdateContextDistributed<import("@mtcute/core").DeleteMessageUpdate | import("@mtcute/core").ChatMemberUpdate | 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>;
12
+ export declare function _parsedUpdateToContext(client: TelegramClient, update: ParsedUpdate): BusinessMessageContext | CallbackQueryContext | InlineCallbackQueryContext | BusinessCallbackQueryContext | ChatJoinRequestUpdateContext | ChosenInlineResultContext | InlineQueryContext | MessageContext | PreCheckoutQueryContext | UpdateContextDistributed<import("@mtcute/core").DeleteMessageUpdate | import("@mtcute/core").ChatMemberUpdate | 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>;
13
13
  export type UpdateContextType = ReturnType<typeof _parsedUpdateToContext>;
@@ -1,5 +1,5 @@
1
1
  import { BusinessMessageContext } from './business-message.js';
2
- import { CallbackQueryContext, InlineCallbackQueryContext } from './callback-query.js';
2
+ import { BusinessCallbackQueryContext, CallbackQueryContext, InlineCallbackQueryContext } from './callback-query.js';
3
3
  import { ChatJoinRequestUpdateContext } from './chat-join-request.js';
4
4
  import { ChosenInlineResultContext } from './chosen-inline-result.js';
5
5
  import { InlineQueryContext } from './inline-query.js';
@@ -20,6 +20,8 @@ export function _parsedUpdateToContext(client, update) {
20
20
  return new CallbackQueryContext(client, update.data);
21
21
  case 'inline_callback_query':
22
22
  return new InlineCallbackQueryContext(client, update.data);
23
+ case 'business_callback_query':
24
+ return new BusinessCallbackQueryContext(client, update.data);
23
25
  case 'bot_chat_join_request':
24
26
  return new ChatJoinRequestUpdateContext(client, update.data);
25
27
  case 'pre_checkout_query':
@@ -1 +1 @@
1
- {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/context/parse.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAC9D,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAA;AACtF,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AAEjE,gBAAgB;AAChB,MAAM,UAAU,sBAAsB,CAAC,MAAsB,EAAE,MAAoB;IAC/E,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,aAAa,CAAC;QACnB,KAAK,cAAc,CAAC;QACpB,KAAK,eAAe;YAChB,OAAO,IAAI,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAClD,KAAK,cAAc;YACf,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACtD,KAAK,sBAAsB;YACvB,OAAO,IAAI,yBAAyB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC7D,KAAK,gBAAgB;YACjB,OAAO,IAAI,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,KAAK,uBAAuB;YACxB,OAAO,IAAI,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC9D,KAAK,uBAAuB;YACxB,OAAO,IAAI,4BAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAChE,KAAK,oBAAoB;YACrB,OAAO,IAAI,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC3D,KAAK,sBAAsB,CAAC;QAC5B,KAAK,uBAAuB,CAAC;QAC7B,KAAK,wBAAwB;YACzB,OAAO,IAAI,sBAAsB,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","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, InlineCallbackQueryContext } 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 'inline_callback_query':\n return new InlineCallbackQueryContext(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
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/context/parse.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAC9D,OAAO,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAA;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AAEjE,gBAAgB;AAChB,MAAM,UAAU,sBAAsB,CAAC,MAAsB,EAAE,MAAoB;IAC/E,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,aAAa,CAAC;QACnB,KAAK,cAAc,CAAC;QACpB,KAAK,eAAe;YAChB,OAAO,IAAI,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAClD,KAAK,cAAc;YACf,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACtD,KAAK,sBAAsB;YACvB,OAAO,IAAI,yBAAyB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC7D,KAAK,gBAAgB;YACjB,OAAO,IAAI,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,KAAK,uBAAuB;YACxB,OAAO,IAAI,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC9D,KAAK,yBAAyB;YAC1B,OAAO,IAAI,4BAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAChE,KAAK,uBAAuB;YACxB,OAAO,IAAI,4BAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAChE,KAAK,oBAAoB;YACrB,OAAO,IAAI,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC3D,KAAK,sBAAsB,CAAC;QAC5B,KAAK,uBAAuB,CAAC;QAC7B,KAAK,wBAAwB;YACzB,OAAO,IAAI,sBAAsB,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","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 { BusinessCallbackQueryContext, CallbackQueryContext, InlineCallbackQueryContext } 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 'inline_callback_query':\n return new InlineCallbackQueryContext(client, update.data)\n case 'business_callback_query':\n return new BusinessCallbackQueryContext(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"]}
@@ -2,10 +2,10 @@ import { BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, BusinessCo
2
2
  import { TelegramClient } from '@mtcute/core/client.js';
3
3
  import { UpdateContext } from './context/base.js';
4
4
  import { BusinessMessageContext } from './context/business-message.js';
5
- import { CallbackQueryContext, ChatJoinRequestUpdateContext, ChosenInlineResultContext, InlineCallbackQueryContext, InlineQueryContext, MessageContext, PreCheckoutQueryContext } from './context/index.js';
5
+ import { BusinessCallbackQueryContext, CallbackQueryContext, ChatJoinRequestUpdateContext, ChosenInlineResultContext, InlineCallbackQueryContext, InlineQueryContext, MessageContext, PreCheckoutQueryContext } from './context/index.js';
6
6
  import { SceneTransitionContext } from './context/scene-transition.js';
7
7
  import { filters, UpdateFilter } from './filters/index.js';
8
- 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';
8
+ import { BotChatJoinRequestHandler, BotReactionCountUpdateHandler, BotReactionUpdateHandler, BotStoppedHandler, BusinessCallbackQueryHandler, 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';
9
9
  import { PropagationAction } from './propagation.js';
10
10
  import { IStateStorageProvider, StateKeyDelegate, UpdateState } from './state/index.js';
11
11
  export interface DispatcherParams {
@@ -368,7 +368,7 @@ export declare class Dispatcher<State extends object = never> {
368
368
  * @param handler Callback query handler
369
369
  * @param group Handler group index
370
370
  */
371
- onAnyCallbackQuery(handler: CallbackQueryHandler<CallbackQueryContext | InlineCallbackQueryContext, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
371
+ onAnyCallbackQuery(handler: CallbackQueryHandler<CallbackQueryContext | InlineCallbackQueryContext | BusinessCallbackQueryContext, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
372
372
  /**
373
373
  * Register a callback query (both inline and non-inline) handler with a filter
374
374
  *
@@ -376,7 +376,7 @@ export declare class Dispatcher<State extends object = never> {
376
376
  * @param handler Callback query handler
377
377
  * @param group Handler group index
378
378
  */
379
- onAnyCallbackQuery<Mod>(filter: UpdateFilter<CallbackQueryContext | InlineCallbackQueryContext, Mod, State>, handler: CallbackQueryHandler<filters.Modify<CallbackQueryContext | InlineCallbackQueryContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
379
+ onAnyCallbackQuery<Mod>(filter: UpdateFilter<CallbackQueryContext | InlineCallbackQueryContext | BusinessCallbackQueryContext, Mod, State>, handler: CallbackQueryHandler<filters.Modify<CallbackQueryContext | InlineCallbackQueryContext | BusinessCallbackQueryContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
380
380
  /**
381
381
  * Register a callback query (both inline and non-inline) handler with a filter
382
382
  *
@@ -384,7 +384,7 @@ export declare class Dispatcher<State extends object = never> {
384
384
  * @param handler Callback query handler
385
385
  * @param group Handler group index
386
386
  */
387
- onAnyCallbackQuery<Mod>(filter: UpdateFilter<CallbackQueryContext | InlineCallbackQueryContext, Mod>, handler: CallbackQueryHandler<filters.Modify<CallbackQueryContext | InlineCallbackQueryContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
387
+ onAnyCallbackQuery<Mod>(filter: UpdateFilter<CallbackQueryContext | InlineCallbackQueryContext | BusinessCallbackQueryContext, Mod>, handler: CallbackQueryHandler<filters.Modify<CallbackQueryContext | InlineCallbackQueryContext | BusinessCallbackQueryContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
388
388
  /**
389
389
  * Register a new message handler without any filters
390
390
  *
@@ -560,6 +560,29 @@ export declare class Dispatcher<State extends object = never> {
560
560
  * @param group Handler group index
561
561
  */
562
562
  onInlineCallbackQuery<Mod>(filter: UpdateFilter<InlineCallbackQueryContext, Mod>, handler: InlineCallbackQueryHandler<filters.Modify<InlineCallbackQueryContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
563
+ /**
564
+ * Register a business callback query handler without any filters
565
+ *
566
+ * @param handler Business callback query handler
567
+ * @param group Handler group index
568
+ */
569
+ onBusinessCallbackQuery(handler: BusinessCallbackQueryHandler<BusinessCallbackQueryContext, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
570
+ /**
571
+ * Register a business callback query handler with a filter
572
+ *
573
+ * @param filter Update filter
574
+ * @param handler Business callback query handler
575
+ * @param group Handler group index
576
+ */
577
+ onBusinessCallbackQuery<Mod>(filter: UpdateFilter<BusinessCallbackQueryContext, Mod, State>, handler: BusinessCallbackQueryHandler<filters.Modify<BusinessCallbackQueryContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
578
+ /**
579
+ * Register a business callback query handler with a filter
580
+ *
581
+ * @param filter Update filter
582
+ * @param handler Business callback query handler
583
+ * @param group Handler group index
584
+ */
585
+ onBusinessCallbackQuery<Mod>(filter: UpdateFilter<BusinessCallbackQueryContext, Mod>, handler: BusinessCallbackQueryHandler<filters.Modify<BusinessCallbackQueryContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
563
586
  /**
564
587
  * Register a poll update handler without any filters
565
588
  *
package/esm/dispatcher.js CHANGED
@@ -783,6 +783,7 @@ export class Dispatcher {
783
783
  onAnyCallbackQuery(filter, handler, group) {
784
784
  this._addKnownHandler('callback_query', filter, handler, group);
785
785
  this._addKnownHandler('inline_callback_query', filter, handler, group);
786
+ this._addKnownHandler('business_callback_query', filter, handler, group);
786
787
  }
787
788
  /** @internal */
788
789
  onNewMessage(filter, handler, group) {
@@ -821,6 +822,10 @@ export class Dispatcher {
821
822
  this._addKnownHandler('inline_callback_query', filter, handler, group);
822
823
  }
823
824
  /** @internal */
825
+ onBusinessCallbackQuery(filter, handler, group) {
826
+ this._addKnownHandler('business_callback_query', filter, handler, group);
827
+ }
828
+ /** @internal */
824
829
  onPollUpdate(filter, handler, group) {
825
830
  this._addKnownHandler('poll', filter, handler, group);
826
831
  }