@mtcute/dispatcher 0.2.1 → 0.3.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.
- package/cjs/context/callback-query.d.ts +22 -8
- package/cjs/context/callback-query.js +30 -19
- package/cjs/context/callback-query.js.map +1 -1
- package/cjs/dispatcher.d.ts +25 -2
- package/cjs/dispatcher.js +4 -0
- package/cjs/dispatcher.js.map +1 -1
- package/cjs/filters/text.d.ts +2 -2
- package/cjs/filters/text.js +1 -0
- package/cjs/filters/text.js.map +1 -1
- package/cjs/filters/updates.d.ts +1 -8
- package/cjs/filters/updates.js +1 -7
- package/cjs/filters/updates.js.map +1 -1
- package/cjs/filters/user.d.ts +3 -3
- package/cjs/filters/user.js.map +1 -1
- package/cjs/handler.d.ts +3 -2
- package/cjs/handler.js.map +1 -1
- package/cjs/state/key.js +2 -4
- package/cjs/state/key.js.map +1 -1
- package/esm/context/callback-query.d.ts +22 -8
- package/esm/context/callback-query.js +29 -19
- package/esm/context/callback-query.js.map +1 -1
- package/esm/dispatcher.d.ts +25 -2
- package/esm/dispatcher.js +4 -0
- package/esm/dispatcher.js.map +1 -1
- package/esm/filters/text.d.ts +2 -2
- package/esm/filters/text.js +1 -0
- package/esm/filters/text.js.map +1 -1
- package/esm/filters/updates.d.ts +1 -8
- package/esm/filters/updates.js +0 -5
- package/esm/filters/updates.js.map +1 -1
- package/esm/filters/user.d.ts +3 -3
- package/esm/filters/user.js.map +1 -1
- package/esm/handler.d.ts +3 -2
- package/esm/handler.js.map +1 -1
- package/esm/state/key.js +2 -4
- package/esm/state/key.js.map +1 -1
- package/package.json +3 -3
package/cjs/filters/text.js
CHANGED
package/cjs/filters/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/filters/text.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/filters/text.ts"],"names":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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;QACZ,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;KACJ;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 { CallbackQuery, ChosenInlineResult, InlineCallbackQuery, InlineQuery, Message } from '@mtcute/client'\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"]}
|
package/cjs/filters/updates.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChatMemberUpdate, ChatMemberUpdateType, UserStatus, UserStatusUpdate } from '@mtcute/client';
|
|
2
2
|
import { UpdateFilter } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Create a filter for {@link ChatMemberUpdate} by update type
|
|
@@ -37,10 +37,3 @@ export declare const userStatus: {
|
|
|
37
37
|
export declare const chatMemberSelf: UpdateFilter<ChatMemberUpdate, {
|
|
38
38
|
isSelf: true;
|
|
39
39
|
}>;
|
|
40
|
-
/**
|
|
41
|
-
* Create a filter for callback queries that
|
|
42
|
-
* originated from an inline message
|
|
43
|
-
*/
|
|
44
|
-
export declare const callbackInline: UpdateFilter<CallbackQuery, {
|
|
45
|
-
isInline: true;
|
|
46
|
-
}>;
|
package/cjs/filters/updates.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.chatMemberSelf = exports.userStatus = exports.chatMember = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Create a filter for {@link ChatMemberUpdate} by update type
|
|
6
6
|
*
|
|
@@ -37,10 +37,4 @@ exports.userStatus = userStatus;
|
|
|
37
37
|
*/
|
|
38
38
|
const chatMemberSelf = (upd) => upd.isSelf;
|
|
39
39
|
exports.chatMemberSelf = chatMemberSelf;
|
|
40
|
-
/**
|
|
41
|
-
* Create a filter for callback queries that
|
|
42
|
-
* originated from an inline message
|
|
43
|
-
*/
|
|
44
|
-
const callbackInline = (q) => q.isInline;
|
|
45
|
-
exports.callbackInline = callbackInline;
|
|
46
40
|
//# sourceMappingURL=updates.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updates.js","sourceRoot":"","sources":["../../../src/filters/updates.ts"],"names":[],"mappings":";;;AAIA;;;;;GAKG;AACI,MAAM,UAAU,GAGnB,CAAC,KAAuC,EAAkC,EAAE;IAC5E,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACtB,MAAM,KAAK,GAAgD,EAAE,CAAA;QAC7D,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;QAE3C,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,KAAK,CAAA;KACpC;IAED,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,CAAA;AACtC,CAAC,CAAA;AAZY,QAAA,UAAU,cAYtB;AAED;;;;;GAKG;AACI,MAAM,UAAU,GAYnB,CAAC,QAA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Q,CAAC,EAAE;QACzB,MAAM,KAAK,GAAsC,EAAE,CAAA;QACnD,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;QAE9C,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,IAAI,KAAK,CAAA;KACtC;IAED,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,QAAQ,CAAA;AAC3C,CAAC,CAAA;AArBY,QAAA,UAAU,cAqBtB;AAED;;;GAGG;AACI,MAAM,cAAc,GAAqD,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAA;AAAtF,QAAA,cAAc,kBAAwE","sourcesContent":["import { ChatMemberUpdate, ChatMemberUpdateType, MaybeArray, UserStatus, UserStatusUpdate } from '@mtcute/client'\n\nimport { UpdateFilter } from './types.js'\n\n/**\n * Create a filter for {@link ChatMemberUpdate} by update type\n *\n * @param types Update type(s)\n * @link ChatMemberUpdate.Type\n */\nexport const chatMember: {\n <T extends ChatMemberUpdateType>(type: T): UpdateFilter<ChatMemberUpdate, { type: T }>\n <T extends ChatMemberUpdateType[]>(types: T): UpdateFilter<ChatMemberUpdate, { type: T[number] }>\n} = (types: MaybeArray<ChatMemberUpdateType>): UpdateFilter<ChatMemberUpdate> => {\n if (Array.isArray(types)) {\n const index: Partial<Record<ChatMemberUpdateType, true>> = {}\n types.forEach((typ) => (index[typ] = true))\n\n return (upd) => upd.type in index\n }\n\n return (upd) => upd.type === types\n}\n\n/**\n * Create a filter for {@link UserStatusUpdate} by new user status\n *\n * @param statuses Update type(s)\n * @link User.Status\n */\nexport const userStatus: {\n <T extends UserStatus>(\n status: T,\n ): UpdateFilter<\n UserStatusUpdate,\n {\n type: T\n lastOnline: T extends 'offline' ? Date : null\n nextOffline: T extends 'online' ? Date : null\n }\n >\n <T extends UserStatus[]>(statuses: T): UpdateFilter<UserStatusUpdate, { type: T[number] }>\n} = (statuses: MaybeArray<UserStatus>): UpdateFilter<UserStatusUpdate> => {\n if (Array.isArray(statuses)) {\n const index: Partial<Record<UserStatus, true>> = {}\n statuses.forEach((typ) => (index[typ] = true))\n\n return (upd) => upd.status in index\n }\n\n return (upd) => upd.status === statuses\n}\n\n/**\n * Create a filter for {@link ChatMemberUpdate} for updates\n * regarding current user\n */\nexport const chatMemberSelf: UpdateFilter<ChatMemberUpdate, { isSelf: true }> = (upd) => upd.isSelf\n"]}
|
package/cjs/filters/user.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BotChatJoinRequestUpdate, CallbackQuery, ChatMemberUpdate, ChosenInlineResult, DeleteStoryUpdate, HistoryReadUpdate, InlineQuery, MaybeArray, Message, PollVoteUpdate, StoryUpdate, User, UserStatusUpdate, UserTypingUpdate } from '@mtcute/client';
|
|
1
|
+
import { BotChatJoinRequestUpdate, CallbackQuery, ChatMemberUpdate, ChosenInlineResult, DeleteStoryUpdate, HistoryReadUpdate, InlineCallbackQuery, InlineQuery, MaybeArray, Message, PollVoteUpdate, StoryUpdate, User, UserStatusUpdate, UserTypingUpdate } from '@mtcute/client';
|
|
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 | PollVoteUpdate | BotChatJoinRequestUpdate>>;
|
|
23
|
-
(id: MaybeArray<number | string>): UpdateFilter<UpdateContextDistributed<Message | UserStatusUpdate | UserTypingUpdate | StoryUpdate | HistoryReadUpdate | DeleteStoryUpdate | InlineQuery | ChatMemberUpdate | ChosenInlineResult | CallbackQuery | PollVoteUpdate | BotChatJoinRequestUpdate>>;
|
|
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>>;
|
|
24
24
|
};
|
package/cjs/filters/user.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/filters/user.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/filters/user.ts"],"names":[],"mappings":";;;AAAA,2CAgBuB;AAKvB;;GAEG;AACI,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;AAD1D,QAAA,EAAE,MACwD;AAEvE;;GAEG;AACI,MAAM,GAAG,GAA4C,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,KAAK,aAAI,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAA;AAA3G,QAAA,GAAG,OAAwG;AAExH,kBAAkB;AAClB;;;;GAIG;AACI,MAAM,MAAM,GA4Bf,CAAC,EAAE,EAAE,EAAE;IACP,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IACjC,MA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,CAAA;gBACrB,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;oBAAE,OAAO,KAAK,CAAA;gBAEtC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC;oBAC7B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBACpB,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;aAC1E;YACD,KAAK,cAAc,CAAC,CAAC;gBACjB,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAA;gBAErB,OAAO,CAAC,SAAS,IAAI,EAAE,KAAK,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC;oBACzD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;aACtB;SACJ;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;AAvFY,QAAA,MAAM,UAuFlB","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/client'\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.getAuthState().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.getAuthState().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,6 +1,6 @@
|
|
|
1
1
|
import { BotStoppedUpdate, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, MaybeAsync, PeersIndex, PollUpdate, PollVoteUpdate, StoryUpdate, TelegramClient, tl, UserStatusUpdate, UserTypingUpdate } from '@mtcute/client';
|
|
2
2
|
import { UpdateContext } from './context/base.js';
|
|
3
|
-
import { CallbackQueryContext, ChatJoinRequestUpdateContext, ChosenInlineResultContext, InlineQueryContext, MessageContext, PreCheckoutQueryContext } from './context/index.js';
|
|
3
|
+
import { CallbackQueryContext, ChatJoinRequestUpdateContext, ChosenInlineResultContext, InlineCallbackQueryContext, InlineQueryContext, MessageContext, PreCheckoutQueryContext } from './context/index.js';
|
|
4
4
|
import { PropagationAction } from './propagation.js';
|
|
5
5
|
export interface BaseUpdateHandler<Name, Handler, Checker> {
|
|
6
6
|
name: Name;
|
|
@@ -17,6 +17,7 @@ export type ChatMemberUpdateHandler<T = UpdateContext<ChatMemberUpdate>> = Parse
|
|
|
17
17
|
export type InlineQueryHandler<T = InlineQueryContext> = ParsedUpdateHandler<'inline_query', T>;
|
|
18
18
|
export type ChosenInlineResultHandler<T = ChosenInlineResultContext> = ParsedUpdateHandler<'chosen_inline_result', T>;
|
|
19
19
|
export type CallbackQueryHandler<T = CallbackQueryContext, S = never> = ParsedUpdateHandler<'callback_query', T, S>;
|
|
20
|
+
export type InlineCallbackQueryHandler<T = InlineCallbackQueryContext, S = never> = ParsedUpdateHandler<'inline_callback_query', T, S>;
|
|
20
21
|
export type PollUpdateHandler<T = UpdateContext<PollUpdate>> = ParsedUpdateHandler<'poll', T>;
|
|
21
22
|
export type PollVoteHandler<T = UpdateContext<PollVoteUpdate>> = ParsedUpdateHandler<'poll_vote', T>;
|
|
22
23
|
export type UserStatusUpdateHandler<T = UpdateContext<UserStatusUpdate>> = ParsedUpdateHandler<'user_status', T>;
|
|
@@ -28,4 +29,4 @@ export type ChatJoinRequestHandler<T = UpdateContext<ChatJoinRequestUpdate>> = P
|
|
|
28
29
|
export type PreCheckoutQueryHandler<T = PreCheckoutQueryContext> = ParsedUpdateHandler<'pre_checkout_query', T>;
|
|
29
30
|
export type StoryUpdateHandler<T = UpdateContext<StoryUpdate>> = ParsedUpdateHandler<'story', T>;
|
|
30
31
|
export type DeleteStoryHandler<T = UpdateContext<DeleteStoryUpdate>> = ParsedUpdateHandler<'delete_story', T>;
|
|
31
|
-
export type UpdateHandler = RawUpdateHandler | NewMessageHandler | EditMessageHandler | MessageGroupHandler | DeleteMessageHandler | ChatMemberUpdateHandler | InlineQueryHandler | ChosenInlineResultHandler | CallbackQueryHandler | PollUpdateHandler | PollVoteHandler | UserStatusUpdateHandler | UserTypingHandler | HistoryReadHandler | BotStoppedHandler | BotChatJoinRequestHandler | ChatJoinRequestHandler | PreCheckoutQueryHandler | StoryUpdateHandler | DeleteStoryHandler;
|
|
32
|
+
export type UpdateHandler = RawUpdateHandler | NewMessageHandler | EditMessageHandler | MessageGroupHandler | DeleteMessageHandler | ChatMemberUpdateHandler | InlineQueryHandler | ChosenInlineResultHandler | CallbackQueryHandler | InlineCallbackQueryHandler | PollUpdateHandler | PollVoteHandler | UserStatusUpdateHandler | UserTypingHandler | HistoryReadHandler | BotStoppedHandler | BotChatJoinRequestHandler | ChatJoinRequestHandler | PreCheckoutQueryHandler | StoryUpdateHandler | DeleteStoryHandler;
|
package/cjs/handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/handler.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/handler.ts"],"names":[],"mappings":";;AA4GA,cAAc","sourcesContent":["import {\n BotStoppedUpdate,\n ChatJoinRequestUpdate,\n ChatMemberUpdate,\n DeleteMessageUpdate,\n DeleteStoryUpdate,\n HistoryReadUpdate,\n MaybeAsync,\n PeersIndex,\n PollUpdate,\n PollVoteUpdate,\n StoryUpdate,\n TelegramClient,\n tl,\n UserStatusUpdate,\n UserTypingUpdate,\n} from '@mtcute/client'\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) => MaybeAsync<void | PropagationAction>,\n (update: Update, state: State) => MaybeAsync<boolean>\n>\n\nexport type RawUpdateHandler = BaseUpdateHandler<\n 'raw',\n (\n client: TelegramClient,\n update: tl.TypeUpdate | tl.TypeMessage,\n peers: PeersIndex,\n ) => MaybeAsync<void | PropagationAction>,\n (client: TelegramClient, update: tl.TypeUpdate | tl.TypeMessage, peers: PeersIndex) => MaybeAsync<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>\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\n// end-codegen\n"]}
|
package/cjs/state/key.js
CHANGED
|
@@ -33,11 +33,9 @@ const defaultStateKeyDelegate = (upd) => {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
if (upd._name === 'callback_query') {
|
|
36
|
-
if (upd.
|
|
37
|
-
return null;
|
|
38
|
-
if (upd.chatType === 'user')
|
|
36
|
+
if (upd.chat.chatType === 'private')
|
|
39
37
|
return `${upd.user.id}`;
|
|
40
|
-
return `${upd.
|
|
38
|
+
return `${upd.chat.id}_${upd.user.id}`;
|
|
41
39
|
}
|
|
42
40
|
return null;
|
|
43
41
|
};
|
package/cjs/state/key.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../../src/state/key.ts"],"names":[],"mappings":";;;AAAA,2CAA8D;AAc9D;;;;;;;;;;GAUG;AACI,MAAM,uBAAuB,GAAqB,CAAC,GAAG,EAAiB,EAAE;IAC5E,IAAI,MAAM,IAAI,GAAG,EAAE;QACf,cAAc;QACd,OAAO,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;KACxB;IAED,IAAI,GAAG,CAAC,KAAK,KAAK,aAAa,EAAE;QAC7B,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE;YACvB,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,O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AAC,IAAI,CAAC,EAAE,EAAE,CAAA;KACzC;IAED,OAAO,IAAI,CAAA;AACf,CAAC,CAAA;AA5BY,QAAA,uBAAuB,2BA4BnC","sourcesContent":["import { assertNever, MaybeAsync, Peer } from '@mtcute/client'\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) => MaybeAsync<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,4 +1,4 @@
|
|
|
1
|
-
import { CallbackQuery, MaybeAsync, Message, TelegramClient } from '@mtcute/client';
|
|
1
|
+
import { CallbackQuery, InlineCallbackQuery, MaybeAsync, Message, TelegramClient } from '@mtcute/client';
|
|
2
2
|
import { UpdateContext } from './base.js';
|
|
3
3
|
/**
|
|
4
4
|
* Context of a callback query update.
|
|
@@ -12,20 +12,34 @@ export declare class CallbackQueryContext extends CallbackQuery implements Updat
|
|
|
12
12
|
/** Answer to this callback query */
|
|
13
13
|
answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]): Promise<void>;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Get the message containing the callback button being clicked.
|
|
16
16
|
*
|
|
17
17
|
* Note that the message may have been deleted, in which case
|
|
18
|
-
* `
|
|
19
|
-
*
|
|
20
|
-
* Can only be used if `isInline = false`
|
|
18
|
+
* `null` will be returned.
|
|
21
19
|
*/
|
|
22
|
-
getMessage(): Promise<Message>;
|
|
20
|
+
getMessage(): Promise<Message | null>;
|
|
23
21
|
/**
|
|
24
22
|
* Edit the message that contained the callback button that was clicked.
|
|
25
23
|
*/
|
|
26
|
-
editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>): Promise<
|
|
24
|
+
editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>): Promise<Message>;
|
|
27
25
|
/**
|
|
28
26
|
* Shortcut for getting the message and editing it.
|
|
29
27
|
*/
|
|
30
|
-
editMessageWith(handler: (msg: Message) => MaybeAsync<Parameters<CallbackQueryContext['editMessage']>[0]>): Promise<
|
|
28
|
+
editMessageWith(handler: (msg: Message) => MaybeAsync<Parameters<CallbackQueryContext['editMessage']>[0]>): Promise<Message | undefined>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Context of an inline-originated callback query update.
|
|
32
|
+
*
|
|
33
|
+
* This is a subclass of {@link InlineCallbackQuery}, so all its fields are also available.
|
|
34
|
+
*/
|
|
35
|
+
export declare class InlineCallbackQueryContext extends InlineCallbackQuery implements UpdateContext<InlineCallbackQuery> {
|
|
36
|
+
readonly client: TelegramClient;
|
|
37
|
+
readonly _name = "inline_callback_query";
|
|
38
|
+
constructor(client: TelegramClient, query: InlineCallbackQuery);
|
|
39
|
+
/** Answer to this callback query */
|
|
40
|
+
answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Edit the message that contained the callback button that was clicked.
|
|
43
|
+
*/
|
|
44
|
+
editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>): Promise<void>;
|
|
31
45
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CallbackQuery,
|
|
1
|
+
import { CallbackQuery, InlineCallbackQuery } from '@mtcute/client';
|
|
2
2
|
/**
|
|
3
3
|
* Context of a callback query update.
|
|
4
4
|
*
|
|
@@ -15,33 +15,18 @@ export class CallbackQueryContext extends CallbackQuery {
|
|
|
15
15
|
return this.client.answerCallbackQuery(this.id, params);
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Get the message containing the callback button being clicked.
|
|
19
19
|
*
|
|
20
20
|
* Note that the message may have been deleted, in which case
|
|
21
|
-
* `
|
|
22
|
-
*
|
|
23
|
-
* Can only be used if `isInline = false`
|
|
21
|
+
* `null` will be returned.
|
|
24
22
|
*/
|
|
25
23
|
async getMessage() {
|
|
26
|
-
|
|
27
|
-
throw new MtArgumentError('Cannot get message for inline callback query');
|
|
28
|
-
}
|
|
29
|
-
const [msg] = await this.client.getMessages(this.raw.peer, this.raw.msgId);
|
|
30
|
-
if (!msg) {
|
|
31
|
-
throw new MtMessageNotFoundError(getMarkedPeerId(this.raw.peer), this.raw.msgId, 'Message not found');
|
|
32
|
-
}
|
|
33
|
-
return msg;
|
|
24
|
+
return this.client.getCallbackQueryMessage(this);
|
|
34
25
|
}
|
|
35
26
|
/**
|
|
36
27
|
* Edit the message that contained the callback button that was clicked.
|
|
37
28
|
*/
|
|
38
29
|
async editMessage(params) {
|
|
39
|
-
if (this.raw._ === 'updateInlineBotCallbackQuery') {
|
|
40
|
-
return this.client.editInlineMessage({
|
|
41
|
-
messageId: this.raw.msgId,
|
|
42
|
-
...params,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
30
|
return this.client.editMessage({
|
|
46
31
|
chatId: this.raw.peer,
|
|
47
32
|
message: this.raw.msgId,
|
|
@@ -61,4 +46,29 @@ export class CallbackQueryContext extends CallbackQuery {
|
|
|
61
46
|
return this.editMessage(res);
|
|
62
47
|
}
|
|
63
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Context of an inline-originated callback query update.
|
|
51
|
+
*
|
|
52
|
+
* This is a subclass of {@link InlineCallbackQuery}, so all its fields are also available.
|
|
53
|
+
*/
|
|
54
|
+
export class InlineCallbackQueryContext extends InlineCallbackQuery {
|
|
55
|
+
constructor(client, query) {
|
|
56
|
+
super(query.raw, query._peers);
|
|
57
|
+
this.client = client;
|
|
58
|
+
this._name = 'inline_callback_query';
|
|
59
|
+
}
|
|
60
|
+
/** Answer to this callback query */
|
|
61
|
+
answer(params) {
|
|
62
|
+
return this.client.answerCallbackQuery(this.id, params);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Edit the message that contained the callback button that was clicked.
|
|
66
|
+
*/
|
|
67
|
+
async editMessage(params) {
|
|
68
|
+
return this.client.editInlineMessage({
|
|
69
|
+
messageId: this.raw.msgId,
|
|
70
|
+
...params,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
64
74
|
//# 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,
|
|
1
|
+
{"version":3,"file":"callback-query.js","sourceRoot":"","sources":["../../../src/context/callback-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAuC,MAAM,gBAAgB,CAAA;AAIxG;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IAGnD,YACa,MAAsB,EAC/B,KAAoB;QAEpB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,W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,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, MaybeAsync, Message, TelegramClient } from '@mtcute/client'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a callback query update.\n *\n * This is a subclass of {@link CallbackQuery}, so all its fields are also available.\n */\nexport class CallbackQueryContext extends CallbackQuery implements UpdateContext<CallbackQuery> {\n readonly _name = 'callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: CallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * 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) => MaybeAsync<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"]}
|
package/esm/dispatcher.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BotStoppedUpdate, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, MaybeAsync, ParsedUpdate, PeersIndex, PollUpdate, PollVoteUpdate, StoryUpdate, TelegramClient, tl, UserStatusUpdate, UserTypingUpdate } from '@mtcute/client';
|
|
2
2
|
import { UpdateContext } from './context/base.js';
|
|
3
|
-
import { CallbackQueryContext, ChatJoinRequestUpdateContext, ChosenInlineResultContext, InlineQueryContext, MessageContext, PreCheckoutQueryContext } from './context/index.js';
|
|
3
|
+
import { CallbackQueryContext, ChatJoinRequestUpdateContext, ChosenInlineResultContext, InlineCallbackQueryContext, InlineQueryContext, MessageContext, PreCheckoutQueryContext } from './context/index.js';
|
|
4
4
|
import { filters, UpdateFilter } from './filters/index.js';
|
|
5
|
-
import { BotChatJoinRequestHandler, BotStoppedHandler, CallbackQueryHandler, ChatJoinRequestHandler, ChatMemberUpdateHandler, ChosenInlineResultHandler, DeleteMessageHandler, DeleteStoryHandler, EditMessageHandler, HistoryReadHandler, InlineQueryHandler, MessageGroupHandler, NewMessageHandler, PollUpdateHandler, PollVoteHandler, PreCheckoutQueryHandler, RawUpdateHandler, StoryUpdateHandler, UpdateHandler, UserStatusUpdateHandler, UserTypingHandler } from './handler.js';
|
|
5
|
+
import { BotChatJoinRequestHandler, BotStoppedHandler, CallbackQueryHandler, ChatJoinRequestHandler, ChatMemberUpdateHandler, ChosenInlineResultHandler, DeleteMessageHandler, DeleteStoryHandler, EditMessageHandler, HistoryReadHandler, InlineCallbackQueryHandler, InlineQueryHandler, MessageGroupHandler, NewMessageHandler, PollUpdateHandler, PollVoteHandler, PreCheckoutQueryHandler, RawUpdateHandler, StoryUpdateHandler, UpdateHandler, UserStatusUpdateHandler, UserTypingHandler } from './handler.js';
|
|
6
6
|
import { PropagationAction } from './propagation.js';
|
|
7
7
|
import { IStateStorage, StateKeyDelegate, UpdateState } from './state/index.js';
|
|
8
8
|
export interface DispatcherParams {
|
|
@@ -466,6 +466,29 @@ export declare class Dispatcher<State extends object = never> {
|
|
|
466
466
|
* @param group Handler group index
|
|
467
467
|
*/
|
|
468
468
|
onCallbackQuery<Mod>(filter: UpdateFilter<CallbackQueryContext, Mod>, handler: CallbackQueryHandler<filters.Modify<CallbackQueryContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
|
|
469
|
+
/**
|
|
470
|
+
* Register an inline callback query handler without any filters
|
|
471
|
+
*
|
|
472
|
+
* @param handler Inline callback query handler
|
|
473
|
+
* @param group Handler group index
|
|
474
|
+
*/
|
|
475
|
+
onInlineCallbackQuery(handler: InlineCallbackQueryHandler<InlineCallbackQueryContext, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
|
|
476
|
+
/**
|
|
477
|
+
* Register an inline callback query handler with a filter
|
|
478
|
+
*
|
|
479
|
+
* @param filter Update filter
|
|
480
|
+
* @param handler Inline callback query handler
|
|
481
|
+
* @param group Handler group index
|
|
482
|
+
*/
|
|
483
|
+
onInlineCallbackQuery<Mod>(filter: UpdateFilter<InlineCallbackQueryContext, Mod, State>, handler: InlineCallbackQueryHandler<filters.Modify<InlineCallbackQueryContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
|
|
484
|
+
/**
|
|
485
|
+
* Register an inline callback query handler with a filter
|
|
486
|
+
*
|
|
487
|
+
* @param filter Update filter
|
|
488
|
+
* @param handler Inline callback query handler
|
|
489
|
+
* @param group Handler group index
|
|
490
|
+
*/
|
|
491
|
+
onInlineCallbackQuery<Mod>(filter: UpdateFilter<InlineCallbackQueryContext, Mod>, handler: InlineCallbackQueryHandler<filters.Modify<InlineCallbackQueryContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
|
|
469
492
|
/**
|
|
470
493
|
* Register a poll update handler without any filters
|
|
471
494
|
*
|
package/esm/dispatcher.js
CHANGED
|
@@ -763,6 +763,10 @@ export class Dispatcher {
|
|
|
763
763
|
this._addKnownHandler('callback_query', filter, handler, group);
|
|
764
764
|
}
|
|
765
765
|
/** @internal */
|
|
766
|
+
onInlineCallbackQuery(filter, handler, group) {
|
|
767
|
+
this._addKnownHandler('inline_callback_query', filter, handler, group);
|
|
768
|
+
}
|
|
769
|
+
/** @internal */
|
|
766
770
|
onPollUpdate(filter, handler, group) {
|
|
767
771
|
this._addKnownHandler('poll', filter, handler, group);
|
|
768
772
|
}
|