@mtcute/dispatcher 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/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/callback-data-builder.test.js +8 -8
- package/cjs/callback-data-builder.test.js.map +1 -1
- package/cjs/context/base.d.ts +1 -1
- package/cjs/context/base.js.map +1 -1
- package/cjs/context/callback-query.d.ts +2 -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 +1 -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 +1 -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 +1 -1
- package/cjs/context/inline-query.js +2 -2
- package/cjs/context/inline-query.js.map +1 -1
- package/cjs/context/message.d.ts +6 -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 +1 -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 +14 -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/bots.test.js +6 -5
- package/cjs/filters/bots.test.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 +3 -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/callback-data-builder.test.js +2 -2
- package/esm/callback-data-builder.test.js.map +1 -1
- package/esm/context/base.d.ts +1 -1
- package/esm/context/base.js.map +1 -1
- package/esm/context/callback-query.d.ts +2 -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 +1 -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 +1 -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 +1 -1
- package/esm/context/inline-query.js +1 -1
- package/esm/context/inline-query.js.map +1 -1
- package/esm/context/message.d.ts +6 -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 +1 -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 +14 -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/bots.test.js +4 -3
- package/esm/filters/bots.test.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 +3 -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 +10 -3
- 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/state/storage.d.ts +0 -96
- package/esm/state/storage.js +0 -13
- package/esm/state/storage.js.map +0 -1
|
@@ -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,MAA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AM,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;AAxHD,kDAwHC","sourcesContent":["import { CallbackQuery, MaybeArray, 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 * > **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"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
|
-
const
|
|
5
|
-
const utils_js_1 = require("@mtcute/
|
|
4
|
+
const core_1 = require("@mtcute/core");
|
|
5
|
+
const utils_js_1 = require("@mtcute/core/utils.js");
|
|
6
6
|
const test_1 = require("@mtcute/test");
|
|
7
7
|
const callback_data_builder_js_1 = require("./callback-data-builder.js");
|
|
8
8
|
(0, vitest_1.describe)('CallbackDataBuilder', () => {
|
|
@@ -12,14 +12,14 @@ const callback_data_builder_js_1 = require("./callback-data-builder.js");
|
|
|
12
12
|
});
|
|
13
13
|
(0, vitest_1.it)('should correctly throw on invalid data when building', () => {
|
|
14
14
|
const cdb = new callback_data_builder_js_1.CallbackDataBuilder('prefix', 'foo', 'bar');
|
|
15
|
-
(0, vitest_1.expect)(() => cdb.build({ foo: 'foo:1', bar: 'bar' })).toThrow(
|
|
15
|
+
(0, vitest_1.expect)(() => cdb.build({ foo: 'foo:1', bar: 'bar' })).toThrow(core_1.MtArgumentError);
|
|
16
16
|
});
|
|
17
17
|
(0, vitest_1.it)('should correctly throw on too long data when building', () => {
|
|
18
18
|
const cdb = new callback_data_builder_js_1.CallbackDataBuilder('prefix', 'foo', 'bar');
|
|
19
19
|
(0, vitest_1.expect)(() => cdb.build({
|
|
20
20
|
foo: 'foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo',
|
|
21
21
|
bar: 'bar',
|
|
22
|
-
})).toThrow(
|
|
22
|
+
})).toThrow(core_1.MtArgumentError);
|
|
23
23
|
});
|
|
24
24
|
(0, vitest_1.it)('should correctly parse data', () => {
|
|
25
25
|
const cdb = new callback_data_builder_js_1.CallbackDataBuilder('prefix', 'foo', 'bar');
|
|
@@ -27,16 +27,16 @@ const callback_data_builder_js_1 = require("./callback-data-builder.js");
|
|
|
27
27
|
});
|
|
28
28
|
(0, vitest_1.it)('should throw on invalid prefix when parsing', () => {
|
|
29
29
|
const cdb = new callback_data_builder_js_1.CallbackDataBuilder('prefix', 'foo', 'bar');
|
|
30
|
-
(0, vitest_1.expect)(() => cdb.parse('123:foo:bar')).toThrow(
|
|
30
|
+
(0, vitest_1.expect)(() => cdb.parse('123:foo:bar')).toThrow(core_1.MtArgumentError);
|
|
31
31
|
});
|
|
32
32
|
(0, vitest_1.it)('should throw on invalid parts count when parsing', () => {
|
|
33
33
|
const cdb = new callback_data_builder_js_1.CallbackDataBuilder('prefix', 'foo', 'bar');
|
|
34
|
-
(0, vitest_1.expect)(() => cdb.parse('prefix:foo:bar:baz')).toThrow(
|
|
34
|
+
(0, vitest_1.expect)(() => cdb.parse('prefix:foo:bar:baz')).toThrow(core_1.MtArgumentError);
|
|
35
35
|
});
|
|
36
36
|
(0, vitest_1.describe)('filter', () => {
|
|
37
|
-
const createCb = (data) => new
|
|
37
|
+
const createCb = (data) => new core_1.CallbackQuery((0, test_1.createStub)('updateBotCallbackQuery', {
|
|
38
38
|
data: (0, utils_js_1.utf8EncodeToBuffer)(data),
|
|
39
|
-
}), new
|
|
39
|
+
}), new core_1.PeersIndex());
|
|
40
40
|
const getFilterMatch = (filter, data) => {
|
|
41
41
|
const cb = createCb(data);
|
|
42
42
|
const matched = filter(cb);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callback-data-builder.test.js","sourceRoot":"","sources":["../../src/callback-data-builder.test.ts"],"names":[],"mappings":";;AAAA,mCAA6C;AAE7C,
|
|
1
|
+
{"version":3,"file":"callback-data-builder.test.js","sourceRoot":"","sources":["../../src/callback-data-builder.test.ts"],"names":[],"mappings":";;AAAA,mCAA6C;AAE7C,uCAAyE;AACzE,oDAA0D;AAC1D,uCAAyC;AAEzC,yEAAgE;AAGhE,IAAA,iBAAQ,EAAC,qBAAqB,EAAE,GAAG,EAAE;IACjC,IAAA,WAAE,EAAC,6BAA6B,EAAE,GAAG,EAAE;QACnC,MAAM,GAAG,GAAG,IAAI,8CAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;QAE3D,IAAA,eAAM,EAAC,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;IAC3E,CAAC,CAAC,CAAA;IAEF,IAAA,WAAE,EAAC,sDAAsD,EAAE,GAAG,EAAE;QAC5D,MAAM,GAAG,GAAG,IAAI,8CAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;QAE3D,IAAA,eAAM,EAAC,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,sBAAe,CAAC,CAAA;IAClF,CAAC,CAAC,CAAA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EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC;gBACzE,GAAG,EAAE,KAAK;gBACV,GAAG,EAAE,KAAK;aACb,CAAC,CAAA;YACF,IAAA,eAAM,EAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACtF,CAAC,CAAC,CAAA;QAEF,IAAA,WAAE,EAAC,0CAA0C,EAAE,GAAG,EAAE;YAChD,MAAM,GAAG,GAAG,IAAI,8CAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;YAE3D,IAAA,eAAM,EAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC;gBACzE,GAAG,EAAE,KAAK;gBACV,GAAG,EAAE,KAAK;aACb,CAAC,CAAA;YACF,IAAA,eAAM,EAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACtF,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA","sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { CallbackQuery, MtArgumentError, PeersIndex } from '@mtcute/core'\nimport { utf8EncodeToBuffer } from '@mtcute/core/utils.js'\nimport { createStub } from '@mtcute/test'\n\nimport { CallbackDataBuilder } from './callback-data-builder.js'\nimport { UpdateFilter } from './filters/index.js'\n\ndescribe('CallbackDataBuilder', () => {\n it('should correctly build data', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(cdb.build({ foo: 'foo', bar: 'bar' })).toEqual('prefix:foo:bar')\n })\n\n it('should correctly throw on invalid data when building', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(() => cdb.build({ foo: 'foo:1', bar: 'bar' })).toThrow(MtArgumentError)\n })\n\n it('should correctly throw on too long data when building', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(() =>\n cdb.build({\n foo: 'foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo',\n bar: 'bar',\n }),\n ).toThrow(MtArgumentError)\n })\n\n it('should correctly parse data', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(cdb.parse('prefix:foo:bar')).toEqual({ foo: 'foo', bar: 'bar' })\n })\n\n it('should throw on invalid prefix when parsing', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(() => cdb.parse('123:foo:bar')).toThrow(MtArgumentError)\n })\n\n it('should throw on invalid parts count when parsing', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(() => cdb.parse('prefix:foo:bar:baz')).toThrow(MtArgumentError)\n })\n\n describe('filter', () => {\n const createCb = (data: string) =>\n new CallbackQuery(\n createStub('updateBotCallbackQuery', {\n data: utf8EncodeToBuffer(data),\n }),\n new PeersIndex(),\n )\n\n const getFilterMatch = (filter: UpdateFilter<CallbackQuery>, data: string) => {\n const cb = createCb(data)\n\n const matched = filter(cb)\n if (!matched) return null\n\n // eslint-disable-next-line\n return (cb as any).match\n }\n\n it('should create a filter without params', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(getFilterMatch(cdb.filter(), 'prefix:foo:bar')).toEqual({\n foo: 'foo',\n bar: 'bar',\n })\n expect(getFilterMatch(cdb.filter(), 'prefix:foo:bar:baz')).toEqual(null)\n })\n\n it('should create a filter with params', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(getFilterMatch(cdb.filter({ foo: 'foo' }), 'prefix:foo:bar')).toEqual({\n foo: 'foo',\n bar: 'bar',\n })\n expect(getFilterMatch(cdb.filter({ foo: 'foo' }), 'prefix:bar:bar')).toEqual(null)\n })\n\n it('should create a filter with regex params', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(getFilterMatch(cdb.filter({ foo: /\\d+/ }), 'prefix:123:bar')).toEqual({\n foo: '123',\n bar: 'bar',\n })\n expect(getFilterMatch(cdb.filter({ foo: /\\d+/ }), 'prefix:bar:bar')).toEqual(null)\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, TelegramClient } from '@mtcute/
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/context/base.ts"],"names":[],"mappings":"","sourcesContent":["import { ParsedUpdate, TelegramClient } from '@mtcute/core'\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,4 @@
|
|
|
1
|
-
import { CallbackQuery, InlineCallbackQuery,
|
|
1
|
+
import { CallbackQuery, InlineCallbackQuery, MaybePromise, Message, TelegramClient } from '@mtcute/core';
|
|
2
2
|
import { UpdateContext } from './base.js';
|
|
3
3
|
/**
|
|
4
4
|
* Context of a callback query update.
|
|
@@ -25,7 +25,7 @@ export declare class CallbackQueryContext extends CallbackQuery implements Updat
|
|
|
25
25
|
/**
|
|
26
26
|
* Shortcut for getting the message and editing it.
|
|
27
27
|
*/
|
|
28
|
-
editMessageWith(handler: (msg: Message) =>
|
|
28
|
+
editMessageWith(handler: (msg: Message) => MaybePromise<Parameters<CallbackQueryContext['editMessage']>[0]>): Promise<Message | undefined>;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* 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,uCAAwG;AAIxG;;;;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,gBAAgB,CAAA;IAOjC,CAAC;IAED,oCAAoC;I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AC,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, TelegramClient } from '@mtcute/core'\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,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,uCAAuE;AAIvE;;;;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, TelegramClient } from '@mtcute/core'\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,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,uCAAkF;AAIlF;;;;;;;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, TelegramClient } from '@mtcute/core'\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,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,uCAA2E;AAI3E;;;;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, TelegramClient } from '@mtcute/core'\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,8 @@
|
|
|
1
|
-
import { Message, OmitInputMessageId, ParametersSkip1, Peer, TelegramClient } from '@mtcute/
|
|
2
|
-
import { DeleteMessagesParams } from '@mtcute/
|
|
3
|
-
import { ForwardMessageOptions } from '@mtcute/
|
|
4
|
-
import { SendCopyParams } from '@mtcute/
|
|
5
|
-
import { SendCopyGroupParams } from '@mtcute/
|
|
1
|
+
import { Message, OmitInputMessageId, ParametersSkip1, Peer, TelegramClient } from '@mtcute/core';
|
|
2
|
+
import { DeleteMessagesParams } from '@mtcute/core/highlevel/methods/messages/delete-messages.js';
|
|
3
|
+
import { ForwardMessageOptions } from '@mtcute/core/highlevel/methods/messages/forward-messages.js';
|
|
4
|
+
import { SendCopyParams } from '@mtcute/core/highlevel/methods/messages/send-copy.js';
|
|
5
|
+
import { SendCopyGroupParams } from '@mtcute/core/highlevel/methods/messages/send-copy-group.js';
|
|
6
6
|
import { UpdateContext } from './base.js';
|
|
7
7
|
/**
|
|
8
8
|
* Context of a message-related update.
|
|
@@ -36,7 +36,7 @@ export declare class MessageContext extends Message implements UpdateContext<Mes
|
|
|
36
36
|
/** If this is a channel post, get its automatic forward in the discussion group */
|
|
37
37
|
getDiscussionMessage(): Promise<Message | null>;
|
|
38
38
|
/** Get all custom emojis contained in this message (message group), if any */
|
|
39
|
-
getCustomEmojis(): Promise<import("@mtcute/
|
|
39
|
+
getCustomEmojis(): Promise<import("@mtcute/core").Sticker[]>;
|
|
40
40
|
/** Send a text message to the same chat (and topic, if applicable) as a given message */
|
|
41
41
|
answerText(...params: ParametersSkip1<TelegramClient['answerText']>): Promise<Message>;
|
|
42
42
|
/** 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,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;QAC1E,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC,CAAA;QAJlC,WAAM,GAAN,MAAM,CAAgB;QAdnC,wFAAwF;QAC/E,UAAK,GAAG,aAAa,CAAA;QAmB1B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QACrG,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAChD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,iBAAiB;QACnB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK;YAA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,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;YACrB,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;gBAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,GAAG,MAAM;aACZ,CAAC,CAAA;SACL;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;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,uCAAsH;AAStH;;;;;;;;GAQG;AACH,MAAa,cAAe,SAAQ,cAAO;IAcvC,YACa,MAAsB,EAC/B,OAA4B;QAE5B,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;QAC1E,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC,CAAA;QAJlC,WAAM,GAAN,MAAM,CAAgB;QAdnC,wFAAwF;QAC/E,UAAK,GAAG,aAAa,CAAA;QAmB1B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QACrG,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAChD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,iBAAiB;QACn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AS;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;YACrB,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;gBAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,GAAG,MAAM;aACZ,CAAC,CAAA;SACL;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;AA9LD,wCA8LC","sourcesContent":["import { Message, MtPeerNotFoundError, OmitInputMessageId, ParametersSkip1, Peer, TelegramClient } from '@mtcute/core'\n// todo: fix these imports when packaging\nimport { DeleteMessagesParams } from '@mtcute/core/src/highlevel/methods/messages/delete-messages.js'\nimport { ForwardMessageOptions } from '@mtcute/core/src/highlevel/methods/messages/forward-messages.js'\nimport { SendCopyParams } from '@mtcute/core/src/highlevel/methods/messages/send-copy.js'\nimport { SendCopyGroupParams } from '@mtcute/core/src/highlevel/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"]}
|
package/cjs/context/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/context/parse.ts"],"names":[],"mappings":";;;AAGA,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, TelegramClient } from '@mtcute/
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/context/parse.ts"],"names":[],"mappings":";;;AAGA,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, TelegramClient } from '@mtcute/core'\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,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+D;AAI/D;;;;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, TelegramClient } from '@mtcute/core'\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"]}
|