@mtcute/dispatcher 0.6.0 → 0.8.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/README.md +3 -3
- package/cjs/callback-data-builder.d.ts +1 -1
- package/cjs/callback-data-builder.js +5 -5
- package/cjs/callback-data-builder.js.map +1 -1
- package/cjs/context/base.d.ts +2 -1
- package/cjs/context/base.js.map +1 -1
- package/cjs/context/callback-query.d.ts +3 -2
- package/cjs/context/callback-query.js +3 -3
- package/cjs/context/callback-query.js.map +1 -1
- package/cjs/context/chat-join-request.d.ts +2 -1
- package/cjs/context/chat-join-request.js +2 -2
- package/cjs/context/chat-join-request.js.map +1 -1
- package/cjs/context/chosen-inline-result.d.ts +2 -1
- package/cjs/context/chosen-inline-result.js +3 -3
- package/cjs/context/chosen-inline-result.js.map +1 -1
- package/cjs/context/inline-query.d.ts +2 -1
- package/cjs/context/inline-query.js +2 -2
- package/cjs/context/inline-query.js.map +1 -1
- package/cjs/context/message.d.ts +4 -6
- package/cjs/context/message.js +3 -3
- package/cjs/context/message.js.map +1 -1
- package/cjs/context/parse.js.map +1 -1
- package/cjs/context/pre-checkout-query.d.ts +2 -1
- package/cjs/context/pre-checkout-query.js +2 -2
- package/cjs/context/pre-checkout-query.js.map +1 -1
- package/cjs/dispatcher.d.ts +15 -9
- package/cjs/dispatcher.js +41 -78
- package/cjs/dispatcher.js.map +1 -1
- package/cjs/filters/bots.d.ts +6 -6
- package/cjs/filters/bots.js +2 -2
- package/cjs/filters/bots.js.map +1 -1
- package/cjs/filters/chat.d.ts +1 -1
- package/cjs/filters/chat.js +1 -1
- package/cjs/filters/chat.js.map +1 -1
- package/cjs/filters/group.d.ts +1 -1
- package/cjs/filters/group.js.map +1 -1
- package/cjs/filters/logic.js.map +1 -1
- package/cjs/filters/message.d.ts +75 -67
- package/cjs/filters/message.js +3 -3
- package/cjs/filters/message.js.map +1 -1
- package/cjs/filters/state.d.ts +2 -2
- package/cjs/filters/state.js.map +1 -1
- package/cjs/filters/text.d.ts +1 -1
- package/cjs/filters/text.js.map +1 -1
- package/cjs/filters/types.d.ts +2 -2
- package/cjs/filters/types.js.map +1 -1
- package/cjs/filters/updates.d.ts +1 -1
- package/cjs/filters/updates.js.map +1 -1
- package/cjs/filters/user.d.ts +1 -1
- package/cjs/filters/user.js +4 -4
- package/cjs/filters/user.js.map +1 -1
- package/cjs/handler.d.ts +4 -3
- package/cjs/handler.js.map +1 -1
- package/cjs/propagation.js +1 -1
- package/cjs/propagation.js.map +1 -1
- package/cjs/state/index.d.ts +3 -1
- package/cjs/state/index.js +3 -1
- package/cjs/state/index.js.map +1 -1
- package/cjs/state/key.d.ts +2 -2
- package/cjs/state/key.js +2 -2
- package/cjs/state/key.js.map +1 -1
- package/cjs/state/provider.d.ts +5 -0
- package/cjs/state/provider.js +3 -0
- package/cjs/state/provider.js.map +1 -0
- package/cjs/state/providers/index.d.ts +2 -0
- package/cjs/state/providers/index.js +19 -0
- package/cjs/state/providers/index.js.map +1 -0
- package/cjs/state/providers/memory.d.ts +29 -0
- package/cjs/state/providers/memory.js +76 -0
- package/cjs/state/providers/memory.js.map +1 -0
- package/cjs/state/providers/sqlite.d.ts +29 -0
- package/cjs/state/providers/sqlite.js +89 -0
- package/cjs/state/providers/sqlite.js.map +1 -0
- package/cjs/state/repository.d.ts +62 -0
- package/cjs/state/repository.js +3 -0
- package/cjs/state/repository.js.map +1 -0
- package/cjs/state/service.d.ts +19 -0
- package/cjs/state/service.js +68 -0
- package/cjs/state/service.js.map +1 -0
- package/cjs/state/update-state.d.ts +3 -3
- package/cjs/state/update-state.js +7 -7
- package/cjs/state/update-state.js.map +1 -1
- package/cjs/wizard.d.ts +2 -2
- package/cjs/wizard.js +1 -1
- package/cjs/wizard.js.map +1 -1
- package/esm/callback-data-builder.d.ts +1 -1
- package/esm/callback-data-builder.js +1 -1
- package/esm/callback-data-builder.js.map +1 -1
- package/esm/context/base.d.ts +2 -1
- package/esm/context/base.js.map +1 -1
- package/esm/context/callback-query.d.ts +3 -2
- package/esm/context/callback-query.js +1 -1
- package/esm/context/callback-query.js.map +1 -1
- package/esm/context/chat-join-request.d.ts +2 -1
- package/esm/context/chat-join-request.js +1 -1
- package/esm/context/chat-join-request.js.map +1 -1
- package/esm/context/chosen-inline-result.d.ts +2 -1
- package/esm/context/chosen-inline-result.js +1 -1
- package/esm/context/chosen-inline-result.js.map +1 -1
- package/esm/context/inline-query.d.ts +2 -1
- package/esm/context/inline-query.js +1 -1
- package/esm/context/inline-query.js.map +1 -1
- package/esm/context/message.d.ts +4 -6
- package/esm/context/message.js +1 -1
- package/esm/context/message.js.map +1 -1
- package/esm/context/parse.js.map +1 -1
- package/esm/context/pre-checkout-query.d.ts +2 -1
- package/esm/context/pre-checkout-query.js +1 -1
- package/esm/context/pre-checkout-query.js.map +1 -1
- package/esm/dispatcher.d.ts +15 -9
- package/esm/dispatcher.js +29 -66
- package/esm/dispatcher.js.map +1 -1
- package/esm/filters/bots.d.ts +6 -6
- package/esm/filters/bots.js +2 -2
- package/esm/filters/bots.js.map +1 -1
- package/esm/filters/chat.d.ts +2 -2
- package/esm/filters/chat.js +1 -1
- package/esm/filters/chat.js.map +1 -1
- package/esm/filters/group.d.ts +1 -1
- package/esm/filters/group.js.map +1 -1
- package/esm/filters/logic.js.map +1 -1
- package/esm/filters/message.d.ts +77 -69
- package/esm/filters/message.js +1 -1
- package/esm/filters/message.js.map +1 -1
- package/esm/filters/state.d.ts +2 -2
- package/esm/filters/state.js.map +1 -1
- package/esm/filters/text.d.ts +1 -1
- package/esm/filters/text.js.map +1 -1
- package/esm/filters/types.d.ts +2 -2
- package/esm/filters/types.js.map +1 -1
- package/esm/filters/updates.d.ts +1 -1
- package/esm/filters/updates.js.map +1 -1
- package/esm/filters/user.d.ts +1 -1
- package/esm/filters/user.js +3 -3
- package/esm/filters/user.js.map +1 -1
- package/esm/handler.d.ts +4 -3
- package/esm/handler.js.map +1 -1
- package/esm/propagation.js +1 -1
- package/esm/propagation.js.map +1 -1
- package/esm/state/index.d.ts +3 -1
- package/esm/state/index.js +3 -1
- package/esm/state/index.js.map +1 -1
- package/esm/state/key.d.ts +2 -2
- package/esm/state/key.js +1 -1
- package/esm/state/key.js.map +1 -1
- package/esm/state/provider.d.ts +5 -0
- package/esm/state/provider.js +2 -0
- package/esm/state/provider.js.map +1 -0
- package/esm/state/providers/index.d.ts +2 -0
- package/esm/state/providers/index.js +3 -0
- package/esm/state/providers/index.js.map +1 -0
- package/esm/state/providers/memory.d.ts +29 -0
- package/esm/state/providers/memory.js +72 -0
- package/esm/state/providers/memory.js.map +1 -0
- package/esm/state/providers/sqlite.d.ts +29 -0
- package/esm/state/providers/sqlite.js +85 -0
- package/esm/state/providers/sqlite.js.map +1 -0
- package/esm/state/repository.d.ts +62 -0
- package/esm/state/repository.js +2 -0
- package/esm/state/repository.js.map +1 -0
- package/esm/state/service.d.ts +19 -0
- package/esm/state/service.js +64 -0
- package/esm/state/service.js.map +1 -0
- package/esm/state/update-state.d.ts +3 -3
- package/esm/state/update-state.js +2 -2
- package/esm/state/update-state.js.map +1 -1
- package/esm/wizard.d.ts +2 -2
- package/esm/wizard.js +1 -1
- package/esm/wizard.js.map +1 -1
- package/package.json +11 -3
- package/cjs/callback-data-builder.test.d.ts +0 -1
- package/cjs/callback-data-builder.test.js +0 -74
- package/cjs/callback-data-builder.test.js.map +0 -1
- package/cjs/filters/bots.test.d.ts +0 -1
- package/cjs/filters/bots.test.js +0 -120
- package/cjs/filters/bots.test.js.map +0 -1
- package/cjs/filters/logic.test.d.ts +0 -1
- package/cjs/filters/logic.test.js +0 -169
- package/cjs/filters/logic.test.js.map +0 -1
- package/cjs/state/storage.d.ts +0 -96
- package/cjs/state/storage.js +0 -17
- package/cjs/state/storage.js.map +0 -1
- package/esm/callback-data-builder.test.d.ts +0 -1
- package/esm/callback-data-builder.test.js +0 -72
- package/esm/callback-data-builder.test.js.map +0 -1
- package/esm/filters/bots.test.d.ts +0 -1
- package/esm/filters/bots.test.js +0 -118
- package/esm/filters/bots.test.js.map +0 -1
- package/esm/filters/logic.test.d.ts +0 -1
- package/esm/filters/logic.test.js +0 -167
- package/esm/filters/logic.test.js.map +0 -1
- package/esm/state/storage.d.ts +0 -96
- package/esm/state/storage.js +0 -13
- package/esm/state/storage.js.map +0 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_dispatcher.html)
|
|
4
4
|
🧐 [Guide](https://mtcute.dev/guide/dispatcher/intro.html)
|
|
5
5
|
|
|
6
|
-
Dispatcher and bot framework based on @mtcute/
|
|
6
|
+
Dispatcher and bot framework based on @mtcute/core.
|
|
7
7
|
|
|
8
8
|
## Features
|
|
9
9
|
- **Straightforward**: Simple and expressive API
|
|
@@ -15,9 +15,9 @@ Dispatcher and bot framework based on @mtcute/client.
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import {
|
|
18
|
+
import { Dispatcher } from '@mtcute/dispatcher'
|
|
19
19
|
|
|
20
|
-
const tg = new
|
|
20
|
+
const tg = new TelegramClient({ ... })
|
|
21
21
|
const dp = Dispatcher.for(tg)
|
|
22
22
|
|
|
23
23
|
dp.onNewMessage(async (msg) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CallbackDataBuilder = void 0;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@mtcute/core");
|
|
5
5
|
/**
|
|
6
6
|
* Callback data builder, inspired by [aiogram](https://github.com/aiogram/aiogram).
|
|
7
7
|
*
|
|
@@ -31,13 +31,13 @@ class CallbackDataBuilder {
|
|
|
31
31
|
.map((f) => {
|
|
32
32
|
const val = obj[f];
|
|
33
33
|
if (val.includes(this.sep)) {
|
|
34
|
-
throw new
|
|
34
|
+
throw new core_1.MtArgumentError(`Value for ${f} ${val} contains separator ${this.sep} and cannot be used.`);
|
|
35
35
|
}
|
|
36
36
|
return val;
|
|
37
37
|
})
|
|
38
38
|
.join(this.sep);
|
|
39
39
|
if (ret.length > 64) {
|
|
40
|
-
throw new
|
|
40
|
+
throw new core_1.MtArgumentError('Resulting callback data is too long.');
|
|
41
41
|
}
|
|
42
42
|
return ret;
|
|
43
43
|
}
|
|
@@ -49,10 +49,10 @@ class CallbackDataBuilder {
|
|
|
49
49
|
parse(data) {
|
|
50
50
|
const parts = data.split(this.sep);
|
|
51
51
|
if (parts[0] !== this.prefix) {
|
|
52
|
-
throw new
|
|
52
|
+
throw new core_1.MtArgumentError('Invalid data passed');
|
|
53
53
|
}
|
|
54
54
|
if (parts.length !== this._fields.length + 1) {
|
|
55
|
-
throw new
|
|
55
|
+
throw new core_1.MtArgumentError('Invalid data passed');
|
|
56
56
|
}
|
|
57
57
|
const ret = {};
|
|
58
58
|
parts.forEach((it, idx) => {
|
|
@@ -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,uCAAyE;AAIzE;;;;;;GAMG;AACH,MAAa,mBAAmB;IAK5B;;;OAGG;IACH,YACW,MAAc,EACrB,GAAG,MAAW;QADP,WAAM,GAAN,MAAM,CAAQ;QAPzB,QAAG,GAAG,GAAG,CAAA;QAUL,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,IA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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 * > **Note**: `params` object will be compiled to a RegExp,\n * > so avoid using characters that have special meaning in regex,\n * > or use RegExp directly to let the IDE guide you.\n *\n * @param params\n */\n filter(params: Partial<Record<T, MaybeArray<string | RegExp>>> = {}): UpdateFilter<\n CallbackQuery,\n {\n match: Record<T, string>\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"]}
|
package/cjs/context/base.d.ts
CHANGED
package/cjs/context/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/context/base.ts"],"names":[],"mappings":"","sourcesContent":["import { ParsedUpdate
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/context/base.ts"],"names":[],"mappings":"","sourcesContent":["import { ParsedUpdate } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nexport type UpdateContext<T> = T & {\n client: TelegramClient\n _name: Extract<ParsedUpdate, { data: T }>['name']\n}\n\nexport type UpdateContextDistributed<T> = T extends never ? never : UpdateContext<T>\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { CallbackQuery, InlineCallbackQuery,
|
|
1
|
+
import { CallbackQuery, InlineCallbackQuery, MaybePromise, Message } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
2
3
|
import { UpdateContext } from './base.js';
|
|
3
4
|
/**
|
|
4
5
|
* Context of a callback query update.
|
|
@@ -25,7 +26,7 @@ export declare class CallbackQueryContext extends CallbackQuery implements Updat
|
|
|
25
26
|
/**
|
|
26
27
|
* Shortcut for getting the message and editing it.
|
|
27
28
|
*/
|
|
28
|
-
editMessageWith(handler: (msg: Message) =>
|
|
29
|
+
editMessageWith(handler: (msg: Message) => MaybePromise<Parameters<CallbackQueryContext['editMessage']>[0]>): Promise<Message | undefined>;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* Context of an inline-originated callback query update.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InlineCallbackQueryContext = exports.CallbackQueryContext = void 0;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@mtcute/core");
|
|
5
5
|
/**
|
|
6
6
|
* Context of a callback query update.
|
|
7
7
|
*
|
|
8
8
|
* This is a subclass of {@link CallbackQuery}, so all its fields are also available.
|
|
9
9
|
*/
|
|
10
|
-
class CallbackQueryContext extends
|
|
10
|
+
class CallbackQueryContext extends core_1.CallbackQuery {
|
|
11
11
|
constructor(client, query) {
|
|
12
12
|
super(query.raw, query._peers);
|
|
13
13
|
this.client = client;
|
|
@@ -55,7 +55,7 @@ exports.CallbackQueryContext = CallbackQueryContext;
|
|
|
55
55
|
*
|
|
56
56
|
* This is a subclass of {@link InlineCallbackQuery}, so all its fields are also available.
|
|
57
57
|
*/
|
|
58
|
-
class InlineCallbackQueryContext extends
|
|
58
|
+
class InlineCallbackQueryContext extends core_1.InlineCallbackQuery {
|
|
59
59
|
constructor(client, query) {
|
|
60
60
|
super(query.raw, query._peers);
|
|
61
61
|
this.client = client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callback-query.js","sourceRoot":"","sources":["../../../src/context/callback-query.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"callback-query.js","sourceRoot":"","sources":["../../../src/context/callback-query.ts"],"names":[],"mappings":";;;AAAA,uCAAwF;AAKxF;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,oBAAa;IAGnD,YACa,MAAsB,EAC/B,KAAoB;QAEpB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,g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A;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;AAxBD,gEAwBC","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,4 +1,5 @@
|
|
|
1
|
-
import { BotChatJoinRequestUpdate
|
|
1
|
+
import { BotChatJoinRequestUpdate } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
2
3
|
import { UpdateContext } from './base.js';
|
|
3
4
|
/**
|
|
4
5
|
* Context of a chat join request update (for bots).
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChatJoinRequestUpdateContext = void 0;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@mtcute/core");
|
|
5
5
|
/**
|
|
6
6
|
* Context of a chat join request update (for bots).
|
|
7
7
|
*
|
|
8
8
|
* This is a subclass of {@link BotChatJoinRequestUpdate}, so all its fields are also available.
|
|
9
9
|
*/
|
|
10
|
-
class ChatJoinRequestUpdateContext extends
|
|
10
|
+
class ChatJoinRequestUpdateContext extends core_1.BotChatJoinRequestUpdate {
|
|
11
11
|
constructor(client, update) {
|
|
12
12
|
super(update.raw, update._peers);
|
|
13
13
|
this.client = client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-join-request.js","sourceRoot":"","sources":["../../../src/context/chat-join-request.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"chat-join-request.js","sourceRoot":"","sources":["../../../src/context/chat-join-request.ts"],"names":[],"mappings":";;;AAAA,uCAAuD;AAKvD;;;;GAIG;AACH,MAAa,4BACT,SAAQ,+BAAwB;IAIhC,YACa,MAAsB,EAC/B,MAAgC;QAEhC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAHvB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,uBAAuB,CAAA;IAOxC,CAAC;IAED,0BAA0B;IAC1B,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YAC/B,MAAM,EAAE,SAAS;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;SAC9B,CAAC,CAAA;IACN,CAAC;IAED,0BAA0B;IAC1B,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YAC/B,MAAM,EAAE,SAAS;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;SAC9B,CAAC,CAAA;IACN,CAAC;CACJ;AA7BD,oEA6BC","sourcesContent":["import { BotChatJoinRequestUpdate } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a chat join request update (for bots).\n *\n * This is a subclass of {@link BotChatJoinRequestUpdate}, so all its fields are also available.\n */\nexport class ChatJoinRequestUpdateContext\n extends BotChatJoinRequestUpdate\n implements UpdateContext<BotChatJoinRequestUpdate> {\n readonly _name = 'bot_chat_join_request'\n\n constructor(\n readonly client: TelegramClient,\n update: BotChatJoinRequestUpdate,\n ) {\n super(update.raw, update._peers)\n }\n\n /** Approve the request */\n approve(): Promise<void> {\n return this.client.hideJoinRequest({\n action: 'approve',\n user: this.user.inputPeer,\n chatId: this.chat.inputPeer,\n })\n }\n\n /** Decline the request */\n decline(): Promise<void> {\n return this.client.hideJoinRequest({\n action: 'decline',\n user: this.user.inputPeer,\n chatId: this.chat.inputPeer,\n })\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ChosenInlineResult
|
|
1
|
+
import { ChosenInlineResult } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
2
3
|
import { UpdateContext } from './base.js';
|
|
3
4
|
/**
|
|
4
5
|
* Context of a chosen inline result update.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChosenInlineResultContext = void 0;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@mtcute/core");
|
|
5
5
|
/**
|
|
6
6
|
* Context of a chosen inline result update.
|
|
7
7
|
*
|
|
@@ -10,7 +10,7 @@ const client_1 = require("@mtcute/client");
|
|
|
10
10
|
* > **Note**: To receive these updates, you must enable
|
|
11
11
|
* > Inline feedback in [@BotFather](//t.me/botfather)
|
|
12
12
|
*/
|
|
13
|
-
class ChosenInlineResultContext extends
|
|
13
|
+
class ChosenInlineResultContext extends core_1.ChosenInlineResult {
|
|
14
14
|
constructor(client, result) {
|
|
15
15
|
super(result.raw, result._peers);
|
|
16
16
|
this.client = client;
|
|
@@ -23,7 +23,7 @@ class ChosenInlineResultContext extends client_1.ChosenInlineResult {
|
|
|
23
23
|
*/
|
|
24
24
|
async editMessage(params) {
|
|
25
25
|
if (!this.raw.msgId) {
|
|
26
|
-
throw new
|
|
26
|
+
throw new core_1.MtArgumentError('No message ID, make sure you have included reply markup!');
|
|
27
27
|
}
|
|
28
28
|
return this.client.editInlineMessage({
|
|
29
29
|
...params,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chosen-inline-result.js","sourceRoot":"","sources":["../../../src/context/chosen-inline-result.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"chosen-inline-result.js","sourceRoot":"","sources":["../../../src/context/chosen-inline-result.ts"],"names":[],"mappings":";;;AAAA,uCAAkE;AAKlE;;;;;;;GAOG;AACH,MAAa,yBAA0B,SAAQ,yBAAkB;IAG7D,YACa,MAAsB,EAC/B,MAA0B;QAE1B,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAHvB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,sBAAsB,CAAA;IAOvC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,MAA0D;QACxE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;YACjB,MAAM,IAAI,sBAAe,CAAC,0DAA0D,CAAC,CAAA;SACxF;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;YACjC,GAAG,MAAM;YACT,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK;SAC5B,CAAC,CAAA;IACN,CAAC;CACJ;AAzBD,8DAyBC","sourcesContent":["import { ChosenInlineResult, MtArgumentError } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a chosen inline result update.\n *\n * This is a subclass of {@link ChosenInlineResult}, so all its fields are also available.\n *\n * > **Note**: To receive these updates, you must enable\n * > Inline feedback in [@BotFather](//t.me/botfather)\n */\nexport class ChosenInlineResultContext extends ChosenInlineResult implements UpdateContext<ChosenInlineResult> {\n readonly _name = 'chosen_inline_result'\n\n constructor(\n readonly client: TelegramClient,\n result: ChosenInlineResult,\n ) {\n super(result.raw, result._peers)\n }\n\n /**\n * Edit the message that was sent when this inline result that was chosen.\n *\n * > **Note**: This method can only be used if the message contained a reply markup\n */\n async editMessage(params: Parameters<TelegramClient['editInlineMessage']>[0]): Promise<void> {\n if (!this.raw.msgId) {\n throw new MtArgumentError('No message ID, make sure you have included reply markup!')\n }\n\n return this.client.editInlineMessage({\n ...params,\n messageId: this.raw.msgId,\n })\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { InlineQuery, ParametersSkip1
|
|
1
|
+
import { InlineQuery, ParametersSkip1 } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
2
3
|
import { UpdateContext } from './base.js';
|
|
3
4
|
/**
|
|
4
5
|
* Context of an inline query update.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InlineQueryContext = void 0;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@mtcute/core");
|
|
5
5
|
/**
|
|
6
6
|
* Context of an inline query update.
|
|
7
7
|
*
|
|
8
8
|
* This is a subclass of {@link InlineQuery}, so all its fields are also available.
|
|
9
9
|
*/
|
|
10
|
-
class InlineQueryContext extends
|
|
10
|
+
class InlineQueryContext extends core_1.InlineQuery {
|
|
11
11
|
constructor(client, query) {
|
|
12
12
|
super(query.raw, query._peers);
|
|
13
13
|
this.client = client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline-query.js","sourceRoot":"","sources":["../../../src/context/inline-query.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"inline-query.js","sourceRoot":"","sources":["../../../src/context/inline-query.ts"],"names":[],"mappings":";;;AAAA,uCAA2D;AAK3D;;;;GAIG;AACH,MAAa,kBAAmB,SAAQ,kBAAW;IAG/C,YACa,MAAsB,EAC/B,KAAkB;QAElB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,cAAc,CAAA;IAO/B,CAAC;IAED,kCAAkC;IAClC,MAAM,CAAC,GAAG,MAA4D;QAClE,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,CAAA;IAC5D,CAAC;CACJ;AAdD,gDAcC","sourcesContent":["import { InlineQuery, ParametersSkip1 } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of an inline query update.\n *\n * This is a subclass of {@link InlineQuery}, so all its fields are also available.\n */\nexport class InlineQueryContext extends InlineQuery implements UpdateContext<InlineQuery> {\n readonly _name = 'inline_query'\n\n constructor(\n readonly client: TelegramClient,\n query: InlineQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this inline query */\n answer(...params: ParametersSkip1<TelegramClient['answerInlineQuery']>) {\n return this.client.answerInlineQuery(this.id, ...params)\n }\n}\n"]}
|
package/cjs/context/message.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { Message, OmitInputMessageId, ParametersSkip1, Peer
|
|
2
|
-
import {
|
|
3
|
-
import { ForwardMessageOptions } from '@mtcute/
|
|
4
|
-
import { SendCopyParams } from '@mtcute/client/methods/messages/send-copy.js';
|
|
5
|
-
import { SendCopyGroupParams } from '@mtcute/client/methods/messages/send-copy-group.js';
|
|
1
|
+
import { Message, OmitInputMessageId, ParametersSkip1, Peer } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
3
|
+
import { DeleteMessagesParams, ForwardMessageOptions, SendCopyGroupParams, SendCopyParams } from '@mtcute/core/methods.js';
|
|
6
4
|
import { UpdateContext } from './base.js';
|
|
7
5
|
/**
|
|
8
6
|
* Context of a message-related update.
|
|
@@ -36,7 +34,7 @@ export declare class MessageContext extends Message implements UpdateContext<Mes
|
|
|
36
34
|
/** If this is a channel post, get its automatic forward in the discussion group */
|
|
37
35
|
getDiscussionMessage(): Promise<Message | null>;
|
|
38
36
|
/** Get all custom emojis contained in this message (message group), if any */
|
|
39
|
-
getCustomEmojis(): Promise<import("@mtcute/
|
|
37
|
+
getCustomEmojis(): Promise<import("@mtcute/core").Sticker[]>;
|
|
40
38
|
/** Send a text message to the same chat (and topic, if applicable) as a given message */
|
|
41
39
|
answerText(...params: ParametersSkip1<TelegramClient['answerText']>): Promise<Message>;
|
|
42
40
|
/** Send a media to the same chat (and topic, if applicable) as a given message */
|
package/cjs/context/message.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MessageContext = void 0;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@mtcute/core");
|
|
5
5
|
/**
|
|
6
6
|
* Context of a message-related update.
|
|
7
7
|
*
|
|
@@ -11,7 +11,7 @@ const client_1 = require("@mtcute/client");
|
|
|
11
11
|
* For message groups, own fields are related to the last message
|
|
12
12
|
* in the group. To access all messages, use {@link MessageContext#messages}.
|
|
13
13
|
*/
|
|
14
|
-
class MessageContext extends
|
|
14
|
+
class MessageContext extends core_1.Message {
|
|
15
15
|
constructor(client, message) {
|
|
16
16
|
const msg = Array.isArray(message) ? message[message.length - 1] : message;
|
|
17
17
|
super(msg.raw, msg._peers, msg.isScheduled);
|
|
@@ -37,7 +37,7 @@ class MessageContext extends client_1.Message {
|
|
|
37
37
|
res = await this.client.getChat(this.sender);
|
|
38
38
|
}
|
|
39
39
|
if (!res)
|
|
40
|
-
throw new
|
|
40
|
+
throw new core_1.MtPeerNotFoundError('Failed to fetch sender');
|
|
41
41
|
Object.defineProperty(this, 'sender', { value: res });
|
|
42
42
|
return res;
|
|
43
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/context/message.ts"],"names":[],"mappings":";;;AAAA,2CAAwH;AAQxH;;;;;;;;GAQG;AACH,MAAa,cAAe,SAAQ,gBAAO;IAcvC,YACa,MAAsB,EAC/B,OAA4B;QAE5B,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OA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B,OAAO,EAAE,IAAI,CAAC,EAAE;YAChB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;CACJ;AA9LD,wCA8LC","sourcesContent":["import { Message, MtPeerNotFoundError, OmitInputMessageId, ParametersSkip1, Peer, TelegramClient } from '@mtcute/client'\nimport { DeleteMessagesParams } from '@mtcute/client/src/methods/messages/delete-messages.js'\nimport { ForwardMessageOptions } from '@mtcute/client/src/methods/messages/forward-messages.js'\nimport { SendCopyParams } from '@mtcute/client/src/methods/messages/send-copy.js'\nimport { SendCopyGroupParams } from '@mtcute/client/src/methods/messages/send-copy-group.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a message-related update.\n *\n * This is a subclass of {@link Message}, 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 MessageContext#messages}.\n */\nexport class MessageContext extends Message implements UpdateContext<Message> {\n // this is primarily for proper types in filters, so don't bother much with actual value\n readonly _name = 'new_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: MessageContext[]\n\n /** Whether this update is about a message group */\n readonly isMessageGroup: boolean\n\n constructor(\n readonly client: TelegramClient,\n message: Message | Message[],\n ) {\n const msg = Array.isArray(message) ? message[message.length - 1] : message\n super(msg.raw, msg._peers, msg.isScheduled)\n\n this.messages = Array.isArray(message) ? message.map((it) => new MessageContext(client, it)) : [this]\n this.isMessageGroup = Array.isArray(message)\n }\n\n /**\n * Get complete information about {@link sender}\n *\n * Learn more: [Incomplete peers](https://mtcute.dev/guide/topics/peers.html#incomplete-peers)\n */\n async getCompleteSender(): Promise<Peer> {\n if (!this.sender.isMin) return this.sender\n\n let res\n\n if (this.sender.type === 'user') {\n [res] = await this.client.getUsers(this.sender)\n } else {\n res = await this.client.getChat(this.sender)\n }\n\n if (!res) throw new MtPeerNotFoundError('Failed to fetch sender')\n\n Object.defineProperty(this, 'sender', { value: res })\n\n return res\n }\n\n /** Get a message that this message is a reply to */\n getReplyTo() {\n return this.client.getReplyTo(this)\n }\n\n /** If this is a channel post, get its automatic forward in the discussion group */\n getDiscussionMessage() {\n return this.client.getDiscussionMessage({ chatId: this.chat.inputPeer, message: this.id })\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 return this.client.answerText(this, ...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 return this.client.answerMedia(this, ...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 return this.client.answerMediaGroup(this, ...params)\n }\n\n /** Send a text message in reply to this message */\n replyText(...params: ParametersSkip1<TelegramClient['replyText']>) {\n return this.client.replyText(this, ...params)\n }\n\n /** Send a media in reply to this message */\n replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>) {\n return this.client.replyMedia(this, ...params)\n }\n\n /** Send a media group in reply to this message */\n replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>) {\n return this.client.replyMediaGroup(this, ...params)\n }\n\n /** Send a text message in reply to this message */\n quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]) {\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 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 return this.client.quoteWithMediaGroup(this, params)\n }\n\n /** Send a text as a comment to this message */\n commentText(...params: ParametersSkip1<TelegramClient['commentText']>) {\n return this.client.commentText(this, ...params)\n }\n\n /** Send a media as a comment to this message */\n commentMedia(...params: ParametersSkip1<TelegramClient['commentMedia']>) {\n return this.client.commentMedia(this, ...params)\n }\n\n /** Send a media group as a comment to this message */\n commentMediaGroup(...params: ParametersSkip1<TelegramClient['commentMediaGroup']>) {\n return this.client.commentMediaGroup(this, ...params)\n }\n\n /** Delete this message (message group) */\n delete(params?: DeleteMessagesParams) {\n return this.client.deleteMessagesById(\n this.chat.inputPeer,\n this.messages.map((it) => it.id),\n params,\n )\n }\n\n /** Pin this message */\n pin(params?: OmitInputMessageId<Parameters<TelegramClient['pinMessage']>[0]>) {\n return this.client.pinMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n\n /** Unpin this message */\n unpin() {\n return this.client.unpinMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n })\n }\n\n /** Edit this message */\n edit(params: OmitInputMessageId<Parameters<TelegramClient['editMessage']>[0]>) {\n return this.client.editMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n\n /** Forward this message (message group) */\n forwardTo(params: ForwardMessageOptions) {\n return this.client.forwardMessagesById({\n fromChatId: this.chat.inputPeer,\n messages: this.messages.map((it) => it.id),\n ...params,\n })\n }\n\n /** Send a copy of this message (message group) */\n copy(params: SendCopyParams & SendCopyGroupParams) {\n if (this.isMessageGroup) {\n return this.client.sendCopyGroup({\n messages: this.messages,\n ...params,\n })\n }\n\n return this.client.sendCopy({\n message: this,\n ...params,\n })\n }\n\n /** React to this message */\n react(params: OmitInputMessageId<Parameters<TelegramClient['sendReaction']>[0]>) {\n return this.client.sendReaction({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/context/message.ts"],"names":[],"mappings":";;;AAAA,uCAAsG;AAMtG;;;;;;;;GAQG;AACH,MAAa,cAAe,SAAQ,cAAO;IAcvC,YACa,MAAsB,EAC/B,OAA4B;QAE5B,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,C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B,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YAC3B,OAAO,EAAE,IAAI,CAAC,EAAE;YAChB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;CACJ;AA9LD,wCA8LC","sourcesContent":["import { Message, MtPeerNotFoundError, OmitInputMessageId, ParametersSkip1, Peer } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\nimport { DeleteMessagesParams, ForwardMessageOptions, SendCopyGroupParams, SendCopyParams } from '@mtcute/core/methods.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a message-related update.\n *\n * This is a subclass of {@link Message}, 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 MessageContext#messages}.\n */\nexport class MessageContext extends Message implements UpdateContext<Message> {\n // this is primarily for proper types in filters, so don't bother much with actual value\n readonly _name = 'new_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: MessageContext[]\n\n /** Whether this update is about a message group */\n readonly isMessageGroup: boolean\n\n constructor(\n readonly client: TelegramClient,\n message: Message | Message[],\n ) {\n const msg = Array.isArray(message) ? message[message.length - 1] : message\n super(msg.raw, msg._peers, msg.isScheduled)\n\n this.messages = Array.isArray(message) ? message.map((it) => new MessageContext(client, it)) : [this]\n this.isMessageGroup = Array.isArray(message)\n }\n\n /**\n * Get complete information about {@link sender}\n *\n * Learn more: [Incomplete peers](https://mtcute.dev/guide/topics/peers.html#incomplete-peers)\n */\n async getCompleteSender(): Promise<Peer> {\n if (!this.sender.isMin) return this.sender\n\n let res\n\n if (this.sender.type === 'user') {\n [res] = await this.client.getUsers(this.sender)\n } else {\n res = await this.client.getChat(this.sender)\n }\n\n if (!res) throw new MtPeerNotFoundError('Failed to fetch sender')\n\n Object.defineProperty(this, 'sender', { value: res })\n\n return res\n }\n\n /** Get a message that this message is a reply to */\n getReplyTo() {\n return this.client.getReplyTo(this)\n }\n\n /** If this is a channel post, get its automatic forward in the discussion group */\n getDiscussionMessage() {\n return this.client.getDiscussionMessage({ chatId: this.chat.inputPeer, message: this.id })\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 return this.client.answerText(this, ...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 return this.client.answerMedia(this, ...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 return this.client.answerMediaGroup(this, ...params)\n }\n\n /** Send a text message in reply to this message */\n replyText(...params: ParametersSkip1<TelegramClient['replyText']>) {\n return this.client.replyText(this, ...params)\n }\n\n /** Send a media in reply to this message */\n replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>) {\n return this.client.replyMedia(this, ...params)\n }\n\n /** Send a media group in reply to this message */\n replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>) {\n return this.client.replyMediaGroup(this, ...params)\n }\n\n /** Send a text message in reply to this message */\n quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]) {\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 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 return this.client.quoteWithMediaGroup(this, params)\n }\n\n /** Send a text as a comment to this message */\n commentText(...params: ParametersSkip1<TelegramClient['commentText']>) {\n return this.client.commentText(this, ...params)\n }\n\n /** Send a media as a comment to this message */\n commentMedia(...params: ParametersSkip1<TelegramClient['commentMedia']>) {\n return this.client.commentMedia(this, ...params)\n }\n\n /** Send a media group as a comment to this message */\n commentMediaGroup(...params: ParametersSkip1<TelegramClient['commentMediaGroup']>) {\n return this.client.commentMediaGroup(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.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/context/parse.ts"],"names":[],"mappings":";;;
|
|
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;QACjB,KAAK,aAAa,CAAC;QACnB,KAAK,cAAc,CAAC;QACpB,KAAK,eAAe;YAChB,OAAO,IAAI,2BAAc,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAClD,KAAK,cAAc;YACf,OAAO,IAAI,oCAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACtD,KAAK,sBAAsB;YACvB,OAAO,IAAI,mDAAyB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC7D,KAAK,gBAAgB;YACjB,OAAO,IAAI,wCAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,KAAK,uBAAuB;YACxB,OAAO,IAAI,mDAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAChE,KAAK,oBAAoB;YACrB,OAAO,IAAI,+CAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;KAC9D;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,IAAoD,CAAA;IAC3E,OAAO,CAAC,MAAM,GAAG,MAAM,CAAA;IACvB,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAA;IAE3B,OAAO,OAAO,CAAA;AAClB,CAAC;AAvBD,wDAuBC","sourcesContent":["import { ParsedUpdate } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContextDistributed } from './base.js'\nimport { CallbackQueryContext } from './callback-query.js'\nimport { ChatJoinRequestUpdateContext } from './chat-join-request.js'\nimport { ChosenInlineResultContext } from './chosen-inline-result.js'\nimport { InlineQueryContext } from './inline-query.js'\nimport { MessageContext } from './message.js'\nimport { PreCheckoutQueryContext } from './pre-checkout-query.js'\n\n/** @internal */\nexport function _parsedUpdateToContext(client: TelegramClient, update: ParsedUpdate) {\n switch (update.name) {\n case 'new_message':\n case 'edit_message':\n case 'message_group':\n return new MessageContext(client, update.data)\n case 'inline_query':\n return new InlineQueryContext(client, update.data)\n case 'chosen_inline_result':\n return new ChosenInlineResultContext(client, update.data)\n case 'callback_query':\n return new CallbackQueryContext(client, update.data)\n case 'bot_chat_join_request':\n return new ChatJoinRequestUpdateContext(client, update.data)\n case 'pre_checkout_query':\n return new PreCheckoutQueryContext(client, update.data)\n }\n\n const _update = update.data as UpdateContextDistributed<typeof update.data>\n _update.client = client\n _update._name = update.name\n\n return _update\n}\n\nexport type UpdateContextType = ReturnType<typeof _parsedUpdateToContext>\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { PreCheckoutQuery
|
|
1
|
+
import { PreCheckoutQuery } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
2
3
|
import { UpdateContext } from './base.js';
|
|
3
4
|
/**
|
|
4
5
|
* Context of a pre-checkout query update
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PreCheckoutQueryContext = void 0;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@mtcute/core");
|
|
5
5
|
/**
|
|
6
6
|
* Context of a pre-checkout query update
|
|
7
7
|
*
|
|
8
8
|
* This is a subclass of {@link PreCheckoutQuery}, so all its fields are also available.
|
|
9
9
|
*/
|
|
10
|
-
class PreCheckoutQueryContext extends
|
|
10
|
+
class PreCheckoutQueryContext extends core_1.PreCheckoutQuery {
|
|
11
11
|
constructor(client, query) {
|
|
12
12
|
super(query.raw, query._peers);
|
|
13
13
|
this.client = client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pre-checkout-query.js","sourceRoot":"","sources":["../../../src/context/pre-checkout-query.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"pre-checkout-query.js","sourceRoot":"","sources":["../../../src/context/pre-checkout-query.ts"],"names":[],"mappings":";;;AAAA,uCAA+C;AAK/C;;;;GAIG;AACH,MAAa,uBAAwB,SAAQ,uBAAgB;IAGzD,YACa,MAAsB,EAC/B,KAAuB;QAEvB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,oBAAoB,CAAA;IAOrC,CAAC;IAED,wBAAwB;IACxB,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAC/D,CAAC;IAED,kDAAkD;IAClD,OAAO,CAAC,KAAK,GAAG,EAAE;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IAC1E,CAAC;CACJ;AAnBD,0DAmBC","sourcesContent":["import { PreCheckoutQuery } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a pre-checkout query update\n *\n * This is a subclass of {@link PreCheckoutQuery}, so all its fields are also available.\n */\nexport class PreCheckoutQueryContext extends PreCheckoutQuery implements UpdateContext<PreCheckoutQuery> {\n readonly _name = 'pre_checkout_query'\n\n constructor(\n readonly client: TelegramClient,\n query: PreCheckoutQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Approve the query */\n approve(): Promise<void> {\n return this.client.answerPreCheckoutQuery(this.raw.queryId)\n }\n\n /** Decline the query, optionally with an error */\n decline(error = ''): Promise<void> {\n return this.client.answerPreCheckoutQuery(this.raw.queryId, { error })\n }\n}\n"]}
|
package/cjs/dispatcher.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate,
|
|
1
|
+
import { BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, MaybePromise, ParsedUpdate, PeersIndex, PollUpdate, PollVoteUpdate, StoryUpdate, tl, UserStatusUpdate, UserTypingUpdate } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
2
3
|
import { UpdateContext } from './context/base.js';
|
|
3
4
|
import { CallbackQueryContext, ChatJoinRequestUpdateContext, ChosenInlineResultContext, InlineCallbackQueryContext, InlineQueryContext, MessageContext, PreCheckoutQueryContext } from './context/index.js';
|
|
4
5
|
import { filters, UpdateFilter } from './filters/index.js';
|
|
5
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';
|
|
6
7
|
import { PropagationAction } from './propagation.js';
|
|
7
|
-
import {
|
|
8
|
+
import { IStateStorageProvider, StateKeyDelegate, UpdateState } from './state/index.js';
|
|
8
9
|
export interface DispatcherParams {
|
|
9
10
|
/**
|
|
10
11
|
* If this dispatcher can be used as a scene, its unique name.
|
|
@@ -17,7 +18,7 @@ export interface DispatcherParams {
|
|
|
17
18
|
*
|
|
18
19
|
* @default Client's storage
|
|
19
20
|
*/
|
|
20
|
-
storage?:
|
|
21
|
+
storage?: IStateStorageProvider;
|
|
21
22
|
/**
|
|
22
23
|
* Custom key delegate for the dispatcher.
|
|
23
24
|
*/
|
|
@@ -57,8 +58,6 @@ export declare class Dispatcher<State extends object = never> {
|
|
|
57
58
|
static scene<State extends object = Record<never, never>>(name: string, params?: Omit<DispatcherParams, 'sceneName'>): Dispatcher<State>;
|
|
58
59
|
/** For scene dispatchers, name of the scene */
|
|
59
60
|
get sceneName(): string | undefined;
|
|
60
|
-
private _onClientBeforeConnect;
|
|
61
|
-
private _onClientBeforeClose;
|
|
62
61
|
/**
|
|
63
62
|
* Bind the dispatcher to the client.
|
|
64
63
|
* Called by the constructor automatically if
|
|
@@ -71,6 +70,13 @@ export declare class Dispatcher<State extends object = never> {
|
|
|
71
70
|
* Unbind a dispatcher from the client.
|
|
72
71
|
*/
|
|
73
72
|
unbind(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Destroy the dispatcher and all its children.
|
|
75
|
+
*
|
|
76
|
+
* When destroying, all the registered handlers are removed,
|
|
77
|
+
* and the underlying storage is freed.
|
|
78
|
+
*/
|
|
79
|
+
destroy(): Promise<void>;
|
|
74
80
|
/**
|
|
75
81
|
* Process a raw update with this dispatcher.
|
|
76
82
|
* Calling this method without bound client will not work.
|
|
@@ -149,7 +155,7 @@ export declare class Dispatcher<State extends object = never> {
|
|
|
149
155
|
*
|
|
150
156
|
* @param handler Error handler
|
|
151
157
|
*/
|
|
152
|
-
onError<T = {}>(handler: ((err: Error, update: ParsedUpdate & T, state?: UpdateState<State>) =>
|
|
158
|
+
onError<T = {}>(handler: ((err: Error, update: ParsedUpdate & T, state?: UpdateState<State>) => MaybePromise<boolean>) | null): void;
|
|
153
159
|
/**
|
|
154
160
|
* Register pre-update middleware.
|
|
155
161
|
*
|
|
@@ -162,7 +168,7 @@ export declare class Dispatcher<State extends object = never> {
|
|
|
162
168
|
*
|
|
163
169
|
* @param handler Pre-update middleware
|
|
164
170
|
*/
|
|
165
|
-
onPreUpdate<T = {}>(handler: ((update: ParsedUpdate & T, state?: UpdateState<State>) =>
|
|
171
|
+
onPreUpdate<T = {}>(handler: ((update: ParsedUpdate & T, state?: UpdateState<State>) => MaybePromise<PropagationAction | void>) | null): void;
|
|
166
172
|
/**
|
|
167
173
|
* Register post-update middleware.
|
|
168
174
|
*
|
|
@@ -175,12 +181,12 @@ export declare class Dispatcher<State extends object = never> {
|
|
|
175
181
|
*
|
|
176
182
|
* @param handler Pre-update middleware
|
|
177
183
|
*/
|
|
178
|
-
onPostUpdate<T = {}>(handler: ((handled: boolean, update: ParsedUpdate & T, state?: UpdateState<State>) =>
|
|
184
|
+
onPostUpdate<T = {}>(handler: ((handled: boolean, update: ParsedUpdate & T, state?: UpdateState<State>) => MaybePromise<void>) | null): void;
|
|
179
185
|
/**
|
|
180
186
|
* Set error handler that will propagate
|
|
181
187
|
* the error to the parent dispatcher
|
|
182
188
|
*/
|
|
183
|
-
propagateErrorToParent(err: Error, update: ParsedUpdate, state?: UpdateState<State>):
|
|
189
|
+
propagateErrorToParent(err: Error, update: ParsedUpdate, state?: UpdateState<State>): MaybePromise<boolean>;
|
|
184
190
|
/**
|
|
185
191
|
* Get parent dispatcher if current dispatcher is a child.
|
|
186
192
|
* Otherwise, return `null`
|