@mtcute/dispatcher 0.11.1 → 0.12.3
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/callback-data-builder.d.ts +9 -5
- package/cjs/callback-data-builder.js +38 -3
- package/cjs/callback-data-builder.js.map +1 -1
- package/cjs/context/business-message.d.ts +60 -0
- package/cjs/context/business-message.js +146 -0
- package/cjs/context/business-message.js.map +1 -0
- package/cjs/context/parse.d.ts +12 -0
- package/cjs/context/parse.js +5 -0
- package/cjs/context/parse.js.map +1 -1
- package/cjs/dispatcher.d.ts +121 -2
- package/cjs/dispatcher.js +43 -1
- package/cjs/dispatcher.js.map +1 -1
- package/cjs/filters/bots.d.ts +6 -5
- package/cjs/filters/bots.js.map +1 -1
- package/cjs/filters/chat.d.ts +2 -2
- package/cjs/filters/chat.js.map +1 -1
- package/cjs/filters/group.d.ts +4 -3
- package/cjs/filters/group.js.map +1 -1
- package/cjs/filters/message.d.ts +27 -18
- package/cjs/filters/message.js +10 -3
- package/cjs/filters/message.js.map +1 -1
- package/cjs/filters/user.js +3 -1
- package/cjs/filters/user.js.map +1 -1
- package/cjs/handler.d.ts +8 -2
- package/cjs/handler.js.map +1 -1
- package/cjs/index.js +6 -0
- package/cjs/state/key.d.ts +2 -1
- package/cjs/state/key.js +1 -1
- package/cjs/state/key.js.map +1 -1
- package/esm/callback-data-builder.d.ts +9 -5
- package/esm/callback-data-builder.js +38 -3
- package/esm/callback-data-builder.js.map +1 -1
- package/esm/context/business-message.d.ts +60 -0
- package/esm/context/business-message.js +142 -0
- package/esm/context/business-message.js.map +1 -0
- package/esm/context/parse.d.ts +12 -0
- package/esm/context/parse.js +5 -0
- package/esm/context/parse.js.map +1 -1
- package/esm/dispatcher.d.ts +121 -2
- package/esm/dispatcher.js +43 -1
- package/esm/dispatcher.js.map +1 -1
- package/esm/filters/bots.d.ts +6 -5
- package/esm/filters/bots.js.map +1 -1
- package/esm/filters/chat.d.ts +2 -2
- package/esm/filters/chat.js.map +1 -1
- package/esm/filters/group.d.ts +4 -3
- package/esm/filters/group.js.map +1 -1
- package/esm/filters/message.d.ts +27 -18
- package/esm/filters/message.js +8 -2
- package/esm/filters/message.js.map +1 -1
- package/esm/filters/user.js +3 -1
- package/esm/filters/user.js.map +1 -1
- package/esm/handler.d.ts +8 -2
- package/esm/handler.js.map +1 -1
- package/esm/state/key.d.ts +2 -1
- package/esm/state/key.js +1 -1
- package/esm/state/key.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CallbackQuery, MaybeArray } from '@mtcute/core';
|
|
1
|
+
import { CallbackQuery, MaybeArray, MaybePromise } from '@mtcute/core';
|
|
2
2
|
import { UpdateFilter } from './filters/types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Callback data builder, inspired by [aiogram](https://github.com/aiogram/aiogram).
|
|
@@ -31,13 +31,17 @@ export declare class CallbackDataBuilder<T extends string> {
|
|
|
31
31
|
/**
|
|
32
32
|
* Create a filter for this callback data.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
34
|
+
* You can either pass an object with field names as keys and values as strings or regexes,
|
|
35
|
+
* which will be compiled to a RegExp, or a function that will be called with the parsed data.
|
|
36
|
+
* Note that the strings will be passed to `RegExp` **directly**, so you may want to escape them.
|
|
37
|
+
*
|
|
38
|
+
* When using a function, you can either return a boolean, or an object with field names as keys
|
|
39
|
+
* and values as strings or regexes. In the latter case, the resulting object will be matched
|
|
40
|
+
* against the parsed data the same way as if you passed it directly.
|
|
37
41
|
*
|
|
38
42
|
* @param params
|
|
39
43
|
*/
|
|
40
|
-
filter(params?: Partial<Record<T, MaybeArray<string | RegExp>>>): UpdateFilter<CallbackQuery, {
|
|
44
|
+
filter(params?: ((upd: CallbackQuery, parsed: Record<T, string>) => MaybePromise<Partial<Record<T, MaybeArray<string | RegExp>>> | boolean>) | Partial<Record<T, MaybeArray<string | RegExp>>>): UpdateFilter<CallbackQuery, {
|
|
41
45
|
match: Record<T, string>;
|
|
42
46
|
}>;
|
|
43
47
|
}
|
|
@@ -67,13 +67,48 @@ class CallbackDataBuilder {
|
|
|
67
67
|
/**
|
|
68
68
|
* Create a filter for this callback data.
|
|
69
69
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
70
|
+
* You can either pass an object with field names as keys and values as strings or regexes,
|
|
71
|
+
* which will be compiled to a RegExp, or a function that will be called with the parsed data.
|
|
72
|
+
* Note that the strings will be passed to `RegExp` **directly**, so you may want to escape them.
|
|
73
|
+
*
|
|
74
|
+
* When using a function, you can either return a boolean, or an object with field names as keys
|
|
75
|
+
* and values as strings or regexes. In the latter case, the resulting object will be matched
|
|
76
|
+
* against the parsed data the same way as if you passed it directly.
|
|
73
77
|
*
|
|
74
78
|
* @param params
|
|
75
79
|
*/
|
|
76
80
|
filter(params = {}) {
|
|
81
|
+
if (typeof params === 'function') {
|
|
82
|
+
return async (query) => {
|
|
83
|
+
if (!query.dataStr)
|
|
84
|
+
return false;
|
|
85
|
+
const data = this.parse(query.dataStr);
|
|
86
|
+
const fnResult = await params(query, data);
|
|
87
|
+
if (typeof fnResult === 'boolean') {
|
|
88
|
+
query.match = data;
|
|
89
|
+
return fnResult;
|
|
90
|
+
}
|
|
91
|
+
// validate result
|
|
92
|
+
for (const key in fnResult) {
|
|
93
|
+
const value = data[key];
|
|
94
|
+
if (value === undefined)
|
|
95
|
+
return false;
|
|
96
|
+
let matchers = fnResult[key];
|
|
97
|
+
if (!Array.isArray(matchers))
|
|
98
|
+
matchers = [matchers];
|
|
99
|
+
for (const matcher of matchers) {
|
|
100
|
+
if (typeof matcher === 'string') {
|
|
101
|
+
if (value !== matcher)
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
else if (!matcher.test(value))
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
query.match = data;
|
|
109
|
+
return true;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
77
112
|
const parts = [];
|
|
78
113
|
this._fields.forEach((field) => {
|
|
79
114
|
if (!(field in params)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callback-data-builder.js","sourceRoot":"","sources":["../../src/callback-data-builder.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"callback-data-builder.js","sourceRoot":"","sources":["../../src/callback-data-builder.ts"],"names":[],"mappings":";;;AAAA,uCAAuF;AAIvF;;;;;;GAMG;AACH,MAAa,mBAAmB;IAUjB;IATM,OAAO,CAAK;IAE7B,GAAG,GAAG,GAAG,CAAA;IAET;;;OAGG;IACH,YACW,MAAc,EACrB,GAAG,MAAW;QADP,WAAM,GAAN,MAAM,CAAQ;QAGrB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACzB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,GAAsB;QACxB,MAAM,GAAG,GACL,IAAI,CAAC,MAAM;YACX,IAAI,CAAC,GAAG;YACR,IAAI,CAAC,OAAO;iBACP,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;gBACP,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;gBAElB,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;oBACzB,MAAM,IAAI,sBAAe,CACrB,aAAa,CAAC,IAAI,GAAG,uBAAuB,IAAI,CAAC,GAAG,sBAAsB,CAC7E,CAAA;gBACL,CAAC;gBAED,OAAO,GAAG,CAAA;YACd,CAAC,CAAC;iBACD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAEvB,IAAI,GAAG,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;YAClB,MAAM,IAAI,sBAAe,CAAC,sCAAsC,CAAC,CAAA;QACrE,CAAC;QAED,OAAO,GAAG,CAAA;IACd,CAAC;IAED;;;;OAI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CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACzF,CAAC;iBAAM,CAAC;gBACJ,qCAAqC;gBACrC,KAAK,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,KAAgB,CAAC,MAAM,CAAC,CAAA;YAC5E,CAAC;QACL,CAAC,CAAC,CAAA;QAEF,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAE9E,OAAO,CAAC,KAAK,EAAE,EAAE;YACb,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;YACrC,IAAI,CAAC,CAAC;gBAAE,OAAO,KAAK,CACnB;YACG,KAGH,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YAE1B,OAAO,IAAI,CAAA;QACf,CAAC,CAAA;IACL,CAAC;CACJ;AA7KD,kDA6KC","sourcesContent":["import { CallbackQuery, MaybeArray, MaybePromise, MtArgumentError } from '@mtcute/core'\n\nimport { UpdateFilter } from './filters/types.js'\n\n/**\n * Callback data builder, inspired by [aiogram](https://github.com/aiogram/aiogram).\n *\n * This can be used to simplify management of different callbacks.\n *\n * [Learn more in the docs](/guide/topics/keyboards.html#callback-data-builders)\n */\nexport class CallbackDataBuilder<T extends string> {\n private readonly _fields: T[]\n\n sep = ':'\n\n /**\n * @param prefix Prefix for the data. Use something unique across your bot.\n * @param fields Field names in the order they will be serialized.\n */\n constructor(\n public prefix: string,\n ...fields: T[]\n ) {\n this._fields = fields\n }\n\n /**\n * Build a callback data string\n *\n * @param obj Object containing the data\n */\n build(obj: Record<T, string>): string {\n const ret =\n this.prefix +\n this.sep +\n this._fields\n .map((f) => {\n const val = obj[f]\n\n if (val.includes(this.sep)) {\n throw new MtArgumentError(\n `Value for ${f} ${val} contains separator ${this.sep} and cannot be used.`,\n )\n }\n\n return val\n })\n .join(this.sep)\n\n if (ret.length > 64) {\n throw new MtArgumentError('Resulting callback data is too long.')\n }\n\n return ret\n }\n\n /**\n * Parse callback data to object\n *\n * @param data Callback data as string\n */\n parse(data: string): Record<T, string> {\n const parts = data.split(this.sep)\n\n if (parts[0] !== this.prefix) {\n throw new MtArgumentError('Invalid data passed')\n }\n\n if (parts.length !== this._fields.length + 1) {\n throw new MtArgumentError('Invalid data passed')\n }\n\n const ret = {} as Record<T, string>\n parts.forEach((it, idx) => {\n if (idx === 0) return // skip prefix\n\n ret[this._fields[idx - 1]] = it\n })\n\n return ret\n }\n\n /**\n * Create a filter for this callback data.\n *\n * You can either pass an object with field names as keys and values as strings or regexes,\n * which will be compiled to a RegExp, or a function that will be called with the parsed data.\n * Note that the strings will be passed to `RegExp` **directly**, so you may want to escape them.\n *\n * When using a function, you can either return a boolean, or an object with field names as keys\n * and values as strings or regexes. In the latter case, the resulting object will be matched\n * against the parsed data the same way as if you passed it directly.\n *\n * @param params\n */\n filter(\n params:\n | ((\n upd: CallbackQuery,\n parsed: Record<T, string>,\n ) => MaybePromise<Partial<Record<T, MaybeArray<string | RegExp>>> | boolean>)\n | Partial<Record<T, MaybeArray<string | RegExp>>> = {},\n ): UpdateFilter<\n CallbackQuery,\n {\n match: Record<T, string>\n }\n > {\n if (typeof params === 'function') {\n return async (query) => {\n if (!query.dataStr) return false\n\n const data = this.parse(query.dataStr)\n const fnResult = await params(query, data)\n\n if (typeof fnResult === 'boolean') {\n (\n query as CallbackQuery & {\n match: Record<T, string>\n }\n ).match = data\n\n return fnResult\n }\n\n // validate result\n for (const key in fnResult) {\n const value = data[key]\n if (value === undefined) return false\n\n let matchers = fnResult[key] as MaybeArray<string | RegExp>\n if (!Array.isArray(matchers)) matchers = [matchers]\n\n for (const matcher of matchers) {\n if (typeof matcher === 'string') {\n if (value !== matcher) return false\n } else if (!matcher.test(value)) return false\n }\n }\n\n (\n query as CallbackQuery & {\n match: Record<T, string>\n }\n ).match = data\n\n return true\n }\n }\n\n const parts: string[] = []\n\n this._fields.forEach((field) => {\n if (!(field in params)) {\n parts.push(`[^${this.sep}]*?`)\n\n return\n }\n\n const value = params[field]\n\n if (Array.isArray(value)) {\n parts.push(`(${value.map((i) => (typeof i === 'string' ? i : i.source)).join('|')})`)\n } else {\n // noinspection SuspiciousTypeOfGuard\n parts.push(typeof value === 'string' ? value : (value as RegExp).source)\n }\n })\n\n const regex = new RegExp(`^${this.prefix}${this.sep}${parts.join(this.sep)}$`)\n\n return (query) => {\n const m = query.dataStr?.match(regex)\n if (!m) return false\n ;(\n query as CallbackQuery & {\n match: Record<T, string>\n }\n ).match = this.parse(m[0])\n\n return true\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { BusinessMessage, OmitInputMessageId, ParametersSkip1 } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
3
|
+
import { DeleteMessagesParams, ForwardMessageOptions, SendCopyGroupParams, SendCopyParams } from '@mtcute/core/methods.js';
|
|
4
|
+
import { UpdateContext } from './base.js';
|
|
5
|
+
/**
|
|
6
|
+
* Context of a business message related update.
|
|
7
|
+
*
|
|
8
|
+
* This is a subclass of {@link BusinessMessage}, so all fields
|
|
9
|
+
* of the message are available.
|
|
10
|
+
*
|
|
11
|
+
* For message groups, own fields are related to the last message
|
|
12
|
+
* in the group. To access all messages, use {@link BusinessMessageContext#messages}.
|
|
13
|
+
*/
|
|
14
|
+
export declare class BusinessMessageContext extends BusinessMessage implements UpdateContext<BusinessMessage> {
|
|
15
|
+
readonly client: TelegramClient;
|
|
16
|
+
readonly _name = "new_business_message";
|
|
17
|
+
/**
|
|
18
|
+
* List of messages in the message group.
|
|
19
|
+
*
|
|
20
|
+
* For other updates, this is a list with a single element (`this`).
|
|
21
|
+
*/
|
|
22
|
+
readonly messages: BusinessMessageContext[];
|
|
23
|
+
/** Whether this update is about a message group */
|
|
24
|
+
readonly isMessageGroup: boolean;
|
|
25
|
+
constructor(client: TelegramClient, message: BusinessMessage | BusinessMessage[]);
|
|
26
|
+
/** Get all custom emojis contained in this message (message group), if any */
|
|
27
|
+
getCustomEmojis(): Promise<import("@mtcute/core").Sticker[]>;
|
|
28
|
+
/** Send a text message to the same chat (and topic, if applicable) as a given message */
|
|
29
|
+
answerText(...params: ParametersSkip1<TelegramClient['answerText']>): Promise<import("@mtcute/core").Message>;
|
|
30
|
+
/** Send a media to the same chat (and topic, if applicable) as a given message */
|
|
31
|
+
answerMedia(...params: ParametersSkip1<TelegramClient['answerMedia']>): Promise<import("@mtcute/core").Message>;
|
|
32
|
+
/** Send a media group to the same chat (and topic, if applicable) as a given message */
|
|
33
|
+
answerMediaGroup(...params: ParametersSkip1<TelegramClient['answerMediaGroup']>): Promise<import("@mtcute/core").Message[]>;
|
|
34
|
+
/** Send a text message in reply to this message */
|
|
35
|
+
replyText(...params: ParametersSkip1<TelegramClient['replyText']>): Promise<import("@mtcute/core").Message>;
|
|
36
|
+
/** Send a media in reply to this message */
|
|
37
|
+
replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>): Promise<import("@mtcute/core").Message>;
|
|
38
|
+
/** Send a media group in reply to this message */
|
|
39
|
+
replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>): Promise<import("@mtcute/core").Message[]>;
|
|
40
|
+
/** Send a text message in reply to this message */
|
|
41
|
+
quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]): Promise<import("@mtcute/core").Message>;
|
|
42
|
+
/** Send a media in reply to this message */
|
|
43
|
+
quoteWithMedia(params: Parameters<TelegramClient['quoteWithMedia']>[1]): Promise<import("@mtcute/core").Message>;
|
|
44
|
+
/** Send a media group in reply to this message */
|
|
45
|
+
quoteWithMediaGroup(params: Parameters<TelegramClient['quoteWithMediaGroup']>[1]): Promise<import("@mtcute/core").Message[]>;
|
|
46
|
+
/** Delete this message (message group) */
|
|
47
|
+
delete(params?: DeleteMessagesParams): Promise<void>;
|
|
48
|
+
/** Pin this message */
|
|
49
|
+
pin(params?: OmitInputMessageId<Parameters<TelegramClient['pinMessage']>[0]>): Promise<import("@mtcute/core").Message | null>;
|
|
50
|
+
/** Unpin this message */
|
|
51
|
+
unpin(): Promise<void>;
|
|
52
|
+
/** Edit this message */
|
|
53
|
+
edit(params: OmitInputMessageId<Parameters<TelegramClient['editMessage']>[0]>): Promise<import("@mtcute/core").Message>;
|
|
54
|
+
/** Forward this message (message group) */
|
|
55
|
+
forwardTo(params: ForwardMessageOptions): Promise<import("@mtcute/core").Message[]>;
|
|
56
|
+
/** Send a copy of this message (message group) */
|
|
57
|
+
copy(params: SendCopyParams & SendCopyGroupParams): Promise<import("@mtcute/core").Message> | Promise<import("@mtcute/core").Message[]>;
|
|
58
|
+
/** React to this message */
|
|
59
|
+
react(params: OmitInputMessageId<Parameters<TelegramClient['sendReaction']>[0]>): Promise<import("@mtcute/core").Message | null>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BusinessMessageContext = void 0;
|
|
4
|
+
const core_1 = require("@mtcute/core");
|
|
5
|
+
/**
|
|
6
|
+
* Context of a business message related update.
|
|
7
|
+
*
|
|
8
|
+
* This is a subclass of {@link BusinessMessage}, so all fields
|
|
9
|
+
* of the message are available.
|
|
10
|
+
*
|
|
11
|
+
* For message groups, own fields are related to the last message
|
|
12
|
+
* in the group. To access all messages, use {@link BusinessMessageContext#messages}.
|
|
13
|
+
*/
|
|
14
|
+
class BusinessMessageContext extends core_1.BusinessMessage {
|
|
15
|
+
client;
|
|
16
|
+
// this is primarily for proper types in filters, so don't bother much with actual value
|
|
17
|
+
_name = 'new_business_message';
|
|
18
|
+
/**
|
|
19
|
+
* List of messages in the message group.
|
|
20
|
+
*
|
|
21
|
+
* For other updates, this is a list with a single element (`this`).
|
|
22
|
+
*/
|
|
23
|
+
messages;
|
|
24
|
+
/** Whether this update is about a message group */
|
|
25
|
+
isMessageGroup;
|
|
26
|
+
constructor(client, message) {
|
|
27
|
+
const msg = Array.isArray(message) ? message[message.length - 1] : message;
|
|
28
|
+
super(msg.update, msg._peers);
|
|
29
|
+
this.client = client;
|
|
30
|
+
this.messages = Array.isArray(message) ? message.map((it) => new BusinessMessageContext(client, it)) : [this];
|
|
31
|
+
this.isMessageGroup = Array.isArray(message);
|
|
32
|
+
}
|
|
33
|
+
/** Get all custom emojis contained in this message (message group), if any */
|
|
34
|
+
getCustomEmojis() {
|
|
35
|
+
return this.client.getCustomEmojisFromMessages(this.messages);
|
|
36
|
+
}
|
|
37
|
+
/** Send a text message to the same chat (and topic, if applicable) as a given message */
|
|
38
|
+
answerText(...params) {
|
|
39
|
+
const [send, params_ = {}] = params;
|
|
40
|
+
params_.businessConnectionId = this.update.connectionId;
|
|
41
|
+
return this.client.answerText(this, send, params_);
|
|
42
|
+
}
|
|
43
|
+
/** Send a media to the same chat (and topic, if applicable) as a given message */
|
|
44
|
+
answerMedia(...params) {
|
|
45
|
+
const [send, params_ = {}] = params;
|
|
46
|
+
params_.businessConnectionId = this.update.connectionId;
|
|
47
|
+
return this.client.answerMedia(this, send, params_);
|
|
48
|
+
}
|
|
49
|
+
/** Send a media group to the same chat (and topic, if applicable) as a given message */
|
|
50
|
+
answerMediaGroup(...params) {
|
|
51
|
+
const [send, params_ = {}] = params;
|
|
52
|
+
params_.businessConnectionId = this.update.connectionId;
|
|
53
|
+
return this.client.answerMediaGroup(this, send, params_);
|
|
54
|
+
}
|
|
55
|
+
/** Send a text message in reply to this message */
|
|
56
|
+
replyText(...params) {
|
|
57
|
+
const [send, params_ = {}] = params;
|
|
58
|
+
params_.businessConnectionId = this.update.connectionId;
|
|
59
|
+
return this.client.replyText(this, send, params_);
|
|
60
|
+
}
|
|
61
|
+
/** Send a media in reply to this message */
|
|
62
|
+
replyMedia(...params) {
|
|
63
|
+
const [send, params_ = {}] = params;
|
|
64
|
+
params_.businessConnectionId = this.update.connectionId;
|
|
65
|
+
return this.client.replyMedia(this, send, params_);
|
|
66
|
+
}
|
|
67
|
+
/** Send a media group in reply to this message */
|
|
68
|
+
replyMediaGroup(...params) {
|
|
69
|
+
const [send, params_ = {}] = params;
|
|
70
|
+
params_.businessConnectionId = this.update.connectionId;
|
|
71
|
+
return this.client.replyMediaGroup(this, send, params_);
|
|
72
|
+
}
|
|
73
|
+
/** Send a text message in reply to this message */
|
|
74
|
+
quoteWithText(params) {
|
|
75
|
+
params.businessConnectionId = this.update.connectionId;
|
|
76
|
+
return this.client.quoteWithText(this, params);
|
|
77
|
+
}
|
|
78
|
+
/** Send a media in reply to this message */
|
|
79
|
+
quoteWithMedia(params) {
|
|
80
|
+
params.businessConnectionId = this.update.connectionId;
|
|
81
|
+
return this.client.quoteWithMedia(this, params);
|
|
82
|
+
}
|
|
83
|
+
/** Send a media group in reply to this message */
|
|
84
|
+
quoteWithMediaGroup(params) {
|
|
85
|
+
params.businessConnectionId = this.update.connectionId;
|
|
86
|
+
return this.client.quoteWithMediaGroup(this, params);
|
|
87
|
+
}
|
|
88
|
+
/** Delete this message (message group) */
|
|
89
|
+
delete(params) {
|
|
90
|
+
return this.client.deleteMessagesById(this.chat.inputPeer, this.messages.map((it) => it.id), params);
|
|
91
|
+
}
|
|
92
|
+
/** Pin this message */
|
|
93
|
+
pin(params) {
|
|
94
|
+
return this.client.pinMessage({
|
|
95
|
+
chatId: this.chat.inputPeer,
|
|
96
|
+
message: this.id,
|
|
97
|
+
...params,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/** Unpin this message */
|
|
101
|
+
unpin() {
|
|
102
|
+
return this.client.unpinMessage({
|
|
103
|
+
chatId: this.chat.inputPeer,
|
|
104
|
+
message: this.id,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/** Edit this message */
|
|
108
|
+
edit(params) {
|
|
109
|
+
return this.client.editMessage({
|
|
110
|
+
chatId: this.chat.inputPeer,
|
|
111
|
+
message: this.id,
|
|
112
|
+
...params,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/** Forward this message (message group) */
|
|
116
|
+
forwardTo(params) {
|
|
117
|
+
return this.client.forwardMessagesById({
|
|
118
|
+
fromChatId: this.chat.inputPeer,
|
|
119
|
+
messages: this.messages.map((it) => it.id),
|
|
120
|
+
...params,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/** Send a copy of this message (message group) */
|
|
124
|
+
copy(params) {
|
|
125
|
+
if (this.isMessageGroup) {
|
|
126
|
+
return this.client.sendCopyGroup({
|
|
127
|
+
messages: this.messages,
|
|
128
|
+
...params,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return this.client.sendCopy({
|
|
132
|
+
message: this,
|
|
133
|
+
...params,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/** React to this message */
|
|
137
|
+
react(params) {
|
|
138
|
+
return this.client.sendReaction({
|
|
139
|
+
chatId: this.chat.inputPeer,
|
|
140
|
+
message: this.id,
|
|
141
|
+
...params,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.BusinessMessageContext = BusinessMessageContext;
|
|
146
|
+
//# sourceMappingURL=business-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"business-message.js","sourceRoot":"","sources":["../../../src/context/business-message.ts"],"names":[],"mappings":";;;AAAA,uCAAmF;AAWnF;;;;;;;;GAQG;AACH,MAAa,sBAAuB,SAAQ,sBAAe;IAe1C;IAdb,wFAAwF;IAC/E,KAAK,GAAG,sBAAsB,CAAA;IAEvC;;;;OAIG;IACM,QAAQ,CAA0B;IAE3C,mDAAmD;IAC1C,cAAc,CAAS;IAEhC,YACa,MAAsB,EAC/B,OAA4C;QA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IACN,CAAC;IAED,wBAAwB;IACxB,IAAI,CAAC,MAAwE;QACzE,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;YAC3B,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YAC3B,OAAO,EAAE,IAAI,CAAC,EAAE;YAChB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;IAED,2CAA2C;IAC3C,SAAS,CAAC,MAA6B;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC;YACnC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YAC/B,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;YAC1C,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;IAED,kDAAkD;IAClD,IAAI,CAAC,MAA4C;QAC7C,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;gBAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,GAAG,MAAM;aACZ,CAAC,CAAA;QACN,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;YACxB,OAAO,EAAE,IAAI;YACb,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;IAED,4BAA4B;IAC5B,KAAK,CAAC,MAAyE;QAC3E,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;YAC5B,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YAC3B,OAAO,EAAE,IAAI,CAAC,EAAE;YAChB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;CACJ;AAtKD,wDAsKC","sourcesContent":["import { BusinessMessage, OmitInputMessageId, ParametersSkip1 } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\nimport {\n DeleteMessagesParams,\n ForwardMessageOptions,\n SendCopyGroupParams,\n SendCopyParams,\n} from '@mtcute/core/methods.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a business message related update.\n *\n * This is a subclass of {@link BusinessMessage}, so all fields\n * of the message are available.\n *\n * For message groups, own fields are related to the last message\n * in the group. To access all messages, use {@link BusinessMessageContext#messages}.\n */\nexport class BusinessMessageContext extends BusinessMessage implements UpdateContext<BusinessMessage> {\n // this is primarily for proper types in filters, so don't bother much with actual value\n readonly _name = 'new_business_message'\n\n /**\n * List of messages in the message group.\n *\n * For other updates, this is a list with a single element (`this`).\n */\n readonly messages: BusinessMessageContext[]\n\n /** Whether this update is about a message group */\n readonly isMessageGroup: boolean\n\n constructor(\n readonly client: TelegramClient,\n message: BusinessMessage | BusinessMessage[],\n ) {\n const msg = Array.isArray(message) ? message[message.length - 1] : message\n super(msg.update, msg._peers)\n\n this.messages = Array.isArray(message) ? message.map((it) => new BusinessMessageContext(client, it)) : [this]\n this.isMessageGroup = Array.isArray(message)\n }\n\n /** Get all custom emojis contained in this message (message group), if any */\n getCustomEmojis() {\n return this.client.getCustomEmojisFromMessages(this.messages)\n }\n\n /** Send a text message to the same chat (and topic, if applicable) as a given message */\n answerText(...params: ParametersSkip1<TelegramClient['answerText']>) {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.answerText(this, send, params_)\n }\n\n /** Send a media to the same chat (and topic, if applicable) as a given message */\n answerMedia(...params: ParametersSkip1<TelegramClient['answerMedia']>) {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.answerMedia(this, send, params_)\n }\n\n /** Send a media group to the same chat (and topic, if applicable) as a given message */\n answerMediaGroup(...params: ParametersSkip1<TelegramClient['answerMediaGroup']>) {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.answerMediaGroup(this, send, params_)\n }\n\n /** Send a text message in reply to this message */\n replyText(...params: ParametersSkip1<TelegramClient['replyText']>) {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.replyText(this, send, params_)\n }\n\n /** Send a media in reply to this message */\n replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>) {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.replyMedia(this, send, params_)\n }\n\n /** Send a media group in reply to this message */\n replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>) {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.replyMediaGroup(this, send, params_)\n }\n\n /** Send a text message in reply to this message */\n quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]) {\n params.businessConnectionId = this.update.connectionId\n\n return this.client.quoteWithText(this, params)\n }\n\n /** Send a media in reply to this message */\n quoteWithMedia(params: Parameters<TelegramClient['quoteWithMedia']>[1]) {\n params.businessConnectionId = this.update.connectionId\n\n return this.client.quoteWithMedia(this, params)\n }\n\n /** Send a media group in reply to this message */\n quoteWithMediaGroup(params: Parameters<TelegramClient['quoteWithMediaGroup']>[1]) {\n params.businessConnectionId = this.update.connectionId\n\n return this.client.quoteWithMediaGroup(this, params)\n }\n\n /** Delete this message (message group) */\n delete(params?: DeleteMessagesParams) {\n return this.client.deleteMessagesById(\n this.chat.inputPeer,\n this.messages.map((it) => it.id),\n params,\n )\n }\n\n /** Pin this message */\n pin(params?: OmitInputMessageId<Parameters<TelegramClient['pinMessage']>[0]>) {\n return this.client.pinMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n\n /** Unpin this message */\n unpin() {\n return this.client.unpinMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n })\n }\n\n /** Edit this message */\n edit(params: OmitInputMessageId<Parameters<TelegramClient['editMessage']>[0]>) {\n return this.client.editMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n\n /** Forward this message (message group) */\n forwardTo(params: ForwardMessageOptions) {\n return this.client.forwardMessagesById({\n fromChatId: this.chat.inputPeer,\n messages: this.messages.map((it) => it.id),\n ...params,\n })\n }\n\n /** Send a copy of this message (message group) */\n copy(params: SendCopyParams & SendCopyGroupParams) {\n if (this.isMessageGroup) {\n return this.client.sendCopyGroup({\n messages: this.messages,\n ...params,\n })\n }\n\n return this.client.sendCopy({\n message: this,\n ...params,\n })\n }\n\n /** React to this message */\n react(params: OmitInputMessageId<Parameters<TelegramClient['sendReaction']>[0]>) {\n return this.client.sendReaction({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n}\n"]}
|
package/cjs/context/parse.d.ts
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
+
import { ParsedUpdate } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
3
|
+
import { UpdateContextDistributed } from './base.js';
|
|
4
|
+
import { BusinessMessageContext } from './business-message.js';
|
|
5
|
+
import { CallbackQueryContext } from './callback-query.js';
|
|
6
|
+
import { ChatJoinRequestUpdateContext } from './chat-join-request.js';
|
|
7
|
+
import { ChosenInlineResultContext } from './chosen-inline-result.js';
|
|
8
|
+
import { InlineQueryContext } from './inline-query.js';
|
|
9
|
+
import { MessageContext } from './message.js';
|
|
10
|
+
import { PreCheckoutQueryContext } from './pre-checkout-query.js';
|
|
11
|
+
/** @internal */
|
|
12
|
+
export declare function _parsedUpdateToContext(client: TelegramClient, update: ParsedUpdate): BusinessMessageContext | CallbackQueryContext | ChatJoinRequestUpdateContext | ChosenInlineResultContext | InlineQueryContext | MessageContext | PreCheckoutQueryContext | UpdateContextDistributed<import("@mtcute/core").DeleteMessageUpdate | import("@mtcute/core").ChatMemberUpdate | import("@mtcute/core").InlineCallbackQuery | import("@mtcute/core").PollUpdate | import("@mtcute/core").PollVoteUpdate | import("@mtcute/core").UserStatusUpdate | import("@mtcute/core").UserTypingUpdate | import("@mtcute/core").HistoryReadUpdate | import("@mtcute/core").BotStoppedUpdate | import("@mtcute/core").ChatJoinRequestUpdate | import("@mtcute/core").StoryUpdate | import("@mtcute/core").DeleteStoryUpdate | import("@mtcute/core").BotReactionUpdate | import("@mtcute/core").BotReactionCountUpdate | import("@mtcute/core").BusinessConnection | import("@mtcute/core").DeleteBusinessMessageUpdate>;
|
|
1
13
|
export type UpdateContextType = ReturnType<typeof _parsedUpdateToContext>;
|
package/cjs/context/parse.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports._parsedUpdateToContext = void 0;
|
|
4
|
+
const business_message_js_1 = require("./business-message.js");
|
|
4
5
|
const callback_query_js_1 = require("./callback-query.js");
|
|
5
6
|
const chat_join_request_js_1 = require("./chat-join-request.js");
|
|
6
7
|
const chosen_inline_result_js_1 = require("./chosen-inline-result.js");
|
|
@@ -24,6 +25,10 @@ function _parsedUpdateToContext(client, update) {
|
|
|
24
25
|
return new chat_join_request_js_1.ChatJoinRequestUpdateContext(client, update.data);
|
|
25
26
|
case 'pre_checkout_query':
|
|
26
27
|
return new pre_checkout_query_js_1.PreCheckoutQueryContext(client, update.data);
|
|
28
|
+
case 'new_business_message':
|
|
29
|
+
case 'edit_business_message':
|
|
30
|
+
case 'business_message_group':
|
|
31
|
+
return new business_message_js_1.BusinessMessageContext(client, update.data);
|
|
27
32
|
}
|
|
28
33
|
const _update = update.data;
|
|
29
34
|
_update.client = client;
|
package/cjs/context/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/context/parse.ts"],"names":[],"mappings":";;;AAIA,2DAA0D;AAC1D,iEAAqE;AACrE,uEAAqE;AACrE,uDAAsD;AACtD,6CAA6C;AAC7C,mEAAiE;AAEjE,gBAAgB;AAChB,SAAgB,sBAAsB,CAAC,MAAsB,EAAE,MAAoB;IAC/E,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,aAAa,CAAC;QACnB,KAA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AAI,wCAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,KAAK,uBAAuB;YACxB,OAAO,IAAI,mDAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAChE,KAAK,oBAAoB;YACrB,OAAO,IAAI,+CAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC3D,KAAK,sBAAsB,CAAC;QAC5B,KAAK,uBAAuB,CAAC;QAC7B,KAAK,wBAAwB;YACzB,OAAO,IAAI,4CAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;IAC9D,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,IAAoD,CAAA;IAC3E,OAAO,CAAC,MAAM,GAAG,MAAM,CAAA;IACvB,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAA;IAE3B,OAAO,OAAO,CAAA;AAClB,CAAC;AA3BD,wDA2BC","sourcesContent":["import { ParsedUpdate } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContextDistributed } from './base.js'\nimport { BusinessMessageContext } from './business-message.js'\nimport { CallbackQueryContext } from './callback-query.js'\nimport { ChatJoinRequestUpdateContext } from './chat-join-request.js'\nimport { ChosenInlineResultContext } from './chosen-inline-result.js'\nimport { InlineQueryContext } from './inline-query.js'\nimport { MessageContext } from './message.js'\nimport { PreCheckoutQueryContext } from './pre-checkout-query.js'\n\n/** @internal */\nexport function _parsedUpdateToContext(client: TelegramClient, update: ParsedUpdate) {\n switch (update.name) {\n case 'new_message':\n case 'edit_message':\n case 'message_group':\n return new MessageContext(client, update.data)\n case 'inline_query':\n return new InlineQueryContext(client, update.data)\n case 'chosen_inline_result':\n return new ChosenInlineResultContext(client, update.data)\n case 'callback_query':\n return new CallbackQueryContext(client, update.data)\n case 'bot_chat_join_request':\n return new ChatJoinRequestUpdateContext(client, update.data)\n case 'pre_checkout_query':\n return new PreCheckoutQueryContext(client, update.data)\n case 'new_business_message':\n case 'edit_business_message':\n case 'business_message_group':\n return new BusinessMessageContext(client, update.data)\n }\n\n const _update = update.data as UpdateContextDistributed<typeof update.data>\n _update.client = client\n _update._name = update.name\n\n return _update\n}\n\nexport type UpdateContextType = ReturnType<typeof _parsedUpdateToContext>\n"]}
|
package/cjs/dispatcher.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, MaybePromise, ParsedUpdate, PeersIndex, PollUpdate, PollVoteUpdate, StoryUpdate, tl, UserStatusUpdate, UserTypingUpdate } from '@mtcute/core';
|
|
1
|
+
import { BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, BusinessConnection, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteBusinessMessageUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, MaybePromise, ParsedUpdate, PeersIndex, PollUpdate, PollVoteUpdate, StoryUpdate, tl, UserStatusUpdate, UserTypingUpdate } from '@mtcute/core';
|
|
2
2
|
import { TelegramClient } from '@mtcute/core/client.js';
|
|
3
3
|
import { UpdateContext } from './context/base.js';
|
|
4
|
+
import { BusinessMessageContext } from './context/business-message.js';
|
|
4
5
|
import { CallbackQueryContext, ChatJoinRequestUpdateContext, ChosenInlineResultContext, InlineCallbackQueryContext, InlineQueryContext, MessageContext, PreCheckoutQueryContext } from './context/index.js';
|
|
5
6
|
import { filters, UpdateFilter } from './filters/index.js';
|
|
6
|
-
import { BotChatJoinRequestHandler, BotReactionCountUpdateHandler, BotReactionUpdateHandler, BotStoppedHandler, CallbackQueryHandler, ChatJoinRequestHandler, ChatMemberUpdateHandler, ChosenInlineResultHandler, DeleteMessageHandler, DeleteStoryHandler, EditMessageHandler, HistoryReadHandler, InlineCallbackQueryHandler, InlineQueryHandler, MessageGroupHandler, NewMessageHandler, PollUpdateHandler, PollVoteHandler, PreCheckoutQueryHandler, RawUpdateHandler, StoryUpdateHandler, UpdateHandler, UserStatusUpdateHandler, UserTypingHandler } from './handler.js';
|
|
7
|
+
import { BotChatJoinRequestHandler, BotReactionCountUpdateHandler, BotReactionUpdateHandler, BotStoppedHandler, BusinessConnectionUpdateHandler, BusinessMessageGroupHandler, CallbackQueryHandler, ChatJoinRequestHandler, ChatMemberUpdateHandler, ChosenInlineResultHandler, DeleteBusinessMessageHandler, DeleteMessageHandler, DeleteStoryHandler, EditBusinessMessageHandler, EditMessageHandler, HistoryReadHandler, InlineCallbackQueryHandler, InlineQueryHandler, MessageGroupHandler, NewBusinessMessageHandler, NewMessageHandler, PollUpdateHandler, PollVoteHandler, PreCheckoutQueryHandler, RawUpdateHandler, StoryUpdateHandler, UpdateHandler, UserStatusUpdateHandler, UserTypingHandler } from './handler.js';
|
|
7
8
|
import { PropagationAction } from './propagation.js';
|
|
8
9
|
import { IStateStorageProvider, StateKeyDelegate, UpdateState } from './state/index.js';
|
|
9
10
|
export interface DispatcherParams {
|
|
@@ -24,6 +25,8 @@ export interface DispatcherParams {
|
|
|
24
25
|
*/
|
|
25
26
|
key?: StateKeyDelegate;
|
|
26
27
|
}
|
|
28
|
+
export interface DispatcherDependencies {
|
|
29
|
+
}
|
|
27
30
|
/**
|
|
28
31
|
* Updates dispatcher
|
|
29
32
|
*/
|
|
@@ -40,6 +43,7 @@ export declare class Dispatcher<State extends object = never> {
|
|
|
40
43
|
private _stateKeyDelegate?;
|
|
41
44
|
private _customStateKeyDelegate?;
|
|
42
45
|
private _customStorage?;
|
|
46
|
+
private _deps;
|
|
43
47
|
private _errorHandler?;
|
|
44
48
|
private _preUpdateHandler?;
|
|
45
49
|
private _postUpdateHandler?;
|
|
@@ -58,6 +62,22 @@ export declare class Dispatcher<State extends object = never> {
|
|
|
58
62
|
static scene<State extends object = Record<never, never>>(name: string, params?: Omit<DispatcherParams, 'sceneName'>): Dispatcher<State>;
|
|
59
63
|
/** For scene dispatchers, name of the scene */
|
|
60
64
|
get sceneName(): string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Inject a dependency to be available in this dispatcher and all its children.
|
|
67
|
+
*
|
|
68
|
+
* **Note**: This is only available for the root dispatcher.
|
|
69
|
+
*/
|
|
70
|
+
inject<Name extends keyof DispatcherDependencies>(name: Name, value: DispatcherDependencies[Name]): void;
|
|
71
|
+
/**
|
|
72
|
+
* Inject dependencies to be available in this dispatcher and all its children.
|
|
73
|
+
*
|
|
74
|
+
* **Note**: This is only available for the root dispatcher.
|
|
75
|
+
*/
|
|
76
|
+
inject(deps: Partial<DispatcherDependencies>): void;
|
|
77
|
+
/**
|
|
78
|
+
* Get the dependencies injected into this dispatcher.
|
|
79
|
+
*/
|
|
80
|
+
get deps(): DispatcherDependencies;
|
|
61
81
|
/**
|
|
62
82
|
* Bind the dispatcher to the client.
|
|
63
83
|
* Called by the constructor automatically if
|
|
@@ -690,4 +710,103 @@ export declare class Dispatcher<State extends object = never> {
|
|
|
690
710
|
* @param group Handler group index
|
|
691
711
|
*/
|
|
692
712
|
onBotReactionCountUpdate<Mod>(filter: UpdateFilter<UpdateContext<BotReactionCountUpdate>, Mod>, handler: BotReactionCountUpdateHandler<filters.Modify<UpdateContext<BotReactionCountUpdate>, Mod>>['callback'], group?: number): void;
|
|
713
|
+
/**
|
|
714
|
+
* Register a business connection update handler without any filters
|
|
715
|
+
*
|
|
716
|
+
* @param handler Business connection update handler
|
|
717
|
+
* @param group Handler group index
|
|
718
|
+
*/
|
|
719
|
+
onBusinessConnectionUpdate(handler: BusinessConnectionUpdateHandler['callback'], group?: number): void;
|
|
720
|
+
/**
|
|
721
|
+
* Register a business connection update handler with a filter
|
|
722
|
+
*
|
|
723
|
+
* @param filter Update filter
|
|
724
|
+
* @param handler Business connection update handler
|
|
725
|
+
* @param group Handler group index
|
|
726
|
+
*/
|
|
727
|
+
onBusinessConnectionUpdate<Mod>(filter: UpdateFilter<UpdateContext<BusinessConnection>, Mod>, handler: BusinessConnectionUpdateHandler<filters.Modify<UpdateContext<BusinessConnection>, Mod>>['callback'], group?: number): void;
|
|
728
|
+
/**
|
|
729
|
+
* Register a new business message handler without any filters
|
|
730
|
+
*
|
|
731
|
+
* @param handler New business message handler
|
|
732
|
+
* @param group Handler group index
|
|
733
|
+
*/
|
|
734
|
+
onNewBusinessMessage(handler: NewBusinessMessageHandler<BusinessMessageContext, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
|
|
735
|
+
/**
|
|
736
|
+
* Register a new business message handler with a filter
|
|
737
|
+
*
|
|
738
|
+
* @param filter Update filter
|
|
739
|
+
* @param handler New business message handler
|
|
740
|
+
* @param group Handler group index
|
|
741
|
+
*/
|
|
742
|
+
onNewBusinessMessage<Mod>(filter: UpdateFilter<BusinessMessageContext, Mod, State>, handler: NewBusinessMessageHandler<filters.Modify<BusinessMessageContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
|
|
743
|
+
/**
|
|
744
|
+
* Register a new business message handler with a filter
|
|
745
|
+
*
|
|
746
|
+
* @param filter Update filter
|
|
747
|
+
* @param handler New business message handler
|
|
748
|
+
* @param group Handler group index
|
|
749
|
+
*/
|
|
750
|
+
onNewBusinessMessage<Mod>(filter: UpdateFilter<BusinessMessageContext, Mod>, handler: NewBusinessMessageHandler<filters.Modify<BusinessMessageContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
|
|
751
|
+
/**
|
|
752
|
+
* Register an edit business message handler without any filters
|
|
753
|
+
*
|
|
754
|
+
* @param handler Edit business message handler
|
|
755
|
+
* @param group Handler group index
|
|
756
|
+
*/
|
|
757
|
+
onEditBusinessMessage(handler: EditBusinessMessageHandler<BusinessMessageContext, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
|
|
758
|
+
/**
|
|
759
|
+
* Register an edit business message handler with a filter
|
|
760
|
+
*
|
|
761
|
+
* @param filter Update filter
|
|
762
|
+
* @param handler Edit business message handler
|
|
763
|
+
* @param group Handler group index
|
|
764
|
+
*/
|
|
765
|
+
onEditBusinessMessage<Mod>(filter: UpdateFilter<BusinessMessageContext, Mod, State>, handler: EditBusinessMessageHandler<filters.Modify<BusinessMessageContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
|
|
766
|
+
/**
|
|
767
|
+
* Register an edit business message handler with a filter
|
|
768
|
+
*
|
|
769
|
+
* @param filter Update filter
|
|
770
|
+
* @param handler Edit business message handler
|
|
771
|
+
* @param group Handler group index
|
|
772
|
+
*/
|
|
773
|
+
onEditBusinessMessage<Mod>(filter: UpdateFilter<BusinessMessageContext, Mod>, handler: EditBusinessMessageHandler<filters.Modify<BusinessMessageContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
|
|
774
|
+
/**
|
|
775
|
+
* Register a business message group handler without any filters
|
|
776
|
+
*
|
|
777
|
+
* @param handler Business message group handler
|
|
778
|
+
* @param group Handler group index
|
|
779
|
+
*/
|
|
780
|
+
onBusinessMessageGroup(handler: BusinessMessageGroupHandler<BusinessMessageContext, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
|
|
781
|
+
/**
|
|
782
|
+
* Register a business message group handler with a filter
|
|
783
|
+
*
|
|
784
|
+
* @param filter Update filter
|
|
785
|
+
* @param handler Business message group handler
|
|
786
|
+
* @param group Handler group index
|
|
787
|
+
*/
|
|
788
|
+
onBusinessMessageGroup<Mod>(filter: UpdateFilter<BusinessMessageContext, Mod, State>, handler: BusinessMessageGroupHandler<filters.Modify<BusinessMessageContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
|
|
789
|
+
/**
|
|
790
|
+
* Register a business message group handler with a filter
|
|
791
|
+
*
|
|
792
|
+
* @param filter Update filter
|
|
793
|
+
* @param handler Business message group handler
|
|
794
|
+
* @param group Handler group index
|
|
795
|
+
*/
|
|
796
|
+
onBusinessMessageGroup<Mod>(filter: UpdateFilter<BusinessMessageContext, Mod>, handler: BusinessMessageGroupHandler<filters.Modify<BusinessMessageContext, Mod>, State extends never ? never : UpdateState<State>>['callback'], group?: number): void;
|
|
797
|
+
/**
|
|
798
|
+
* Register a delete business message handler without any filters
|
|
799
|
+
*
|
|
800
|
+
* @param handler Delete business message handler
|
|
801
|
+
* @param group Handler group index
|
|
802
|
+
*/
|
|
803
|
+
onDeleteBusinessMessage(handler: DeleteBusinessMessageHandler['callback'], group?: number): void;
|
|
804
|
+
/**
|
|
805
|
+
* Register a delete business message handler with a filter
|
|
806
|
+
*
|
|
807
|
+
* @param filter Update filter
|
|
808
|
+
* @param handler Delete business message handler
|
|
809
|
+
* @param group Handler group index
|
|
810
|
+
*/
|
|
811
|
+
onDeleteBusinessMessage<Mod>(filter: UpdateFilter<UpdateContext<DeleteBusinessMessageUpdate>, Mod>, handler: DeleteBusinessMessageHandler<filters.Modify<UpdateContext<DeleteBusinessMessageUpdate>, Mod>>['callback'], group?: number): void;
|
|
693
812
|
}
|