@mtcute/dispatcher 0.1.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/LICENSE +8 -0
- package/README.md +26 -0
- package/cjs/callback-data-builder.d.ts +43 -0
- package/cjs/callback-data-builder.js +99 -0
- package/cjs/callback-data-builder.js.map +1 -0
- package/cjs/context/base.d.ts +8 -0
- package/cjs/context/base.js +3 -0
- package/cjs/context/base.js.map +1 -0
- package/cjs/context/callback-query.d.ts +27 -0
- package/cjs/context/callback-query.js +56 -0
- package/cjs/context/callback-query.js.map +1 -0
- package/cjs/context/chat-join-request.d.ts +16 -0
- package/cjs/context/chat-join-request.js +34 -0
- package/cjs/context/chat-join-request.js.map +1 -0
- package/cjs/context/chosen-inline-result.d.ts +21 -0
- package/cjs/context/chosen-inline-result.js +35 -0
- package/cjs/context/chosen-inline-result.js.map +1 -0
- package/cjs/context/index.d.ts +8 -0
- package/cjs/context/index.js +24 -0
- package/cjs/context/index.js.map +1 -0
- package/cjs/context/inline-query.d.ts +14 -0
- package/cjs/context/inline-query.js +22 -0
- package/cjs/context/inline-query.js.map +1 -0
- package/cjs/context/message.d.ts +72 -0
- package/cjs/context/message.js +142 -0
- package/cjs/context/message.js.map +1 -0
- package/cjs/context/parse.d.ts +1 -0
- package/cjs/context/parse.js +34 -0
- package/cjs/context/parse.js.map +1 -0
- package/cjs/context/pre-checkout-query.d.ts +16 -0
- package/cjs/context/pre-checkout-query.js +26 -0
- package/cjs/context/pre-checkout-query.js.map +1 -0
- package/cjs/dispatcher.d.ts +641 -0
- package/cjs/dispatcher.js +765 -0
- package/cjs/dispatcher.js.map +1 -0
- package/cjs/filters/bots.d.ts +70 -0
- package/cjs/filters/bots.js +129 -0
- package/cjs/filters/bots.js.map +1 -0
- package/cjs/filters/bundle.d.ts +10 -0
- package/cjs/filters/bundle.js +27 -0
- package/cjs/filters/bundle.js.map +1 -0
- package/cjs/filters/chat.d.ts +27 -0
- package/cjs/filters/chat.js +55 -0
- package/cjs/filters/chat.js.map +1 -0
- package/cjs/filters/group.d.ts +25 -0
- package/cjs/filters/group.js +72 -0
- package/cjs/filters/group.js.map +1 -0
- package/cjs/filters/index.d.ts +3 -0
- package/cjs/filters/index.js +29 -0
- package/cjs/filters/index.js.map +1 -0
- package/cjs/filters/logic.d.ts +29 -0
- package/cjs/filters/logic.js +114 -0
- package/cjs/filters/logic.js.map +1 -0
- package/cjs/filters/message.d.ts +295 -0
- package/cjs/filters/message.js +150 -0
- package/cjs/filters/message.js.map +1 -0
- package/cjs/filters/state.d.ts +15 -0
- package/cjs/filters/state.js +32 -0
- package/cjs/filters/state.js.map +1 -0
- package/cjs/filters/text.d.ts +64 -0
- package/cjs/filters/text.js +132 -0
- package/cjs/filters/text.js.map +1 -0
- package/cjs/filters/types.d.ts +91 -0
- package/cjs/filters/types.js +6 -0
- package/cjs/filters/types.js.map +1 -0
- package/cjs/filters/updates.d.ts +46 -0
- package/cjs/filters/updates.js +46 -0
- package/cjs/filters/updates.js.map +1 -0
- package/cjs/filters/user.d.ts +24 -0
- package/cjs/filters/user.js +76 -0
- package/cjs/filters/user.js.map +1 -0
- package/cjs/handler.d.ts +31 -0
- package/cjs/handler.js +4 -0
- package/cjs/handler.js.map +1 -0
- package/cjs/index.d.ts +8 -0
- package/cjs/index.js +25 -0
- package/cjs/index.js.map +1 -0
- package/cjs/package.json +3 -0
- package/cjs/propagation.d.ts +21 -0
- package/cjs/propagation.js +26 -0
- package/cjs/propagation.js.map +1 -0
- package/cjs/state/index.d.ts +3 -0
- package/cjs/state/index.js +20 -0
- package/cjs/state/index.js.map +1 -0
- package/cjs/state/key.d.ts +23 -0
- package/cjs/state/key.js +45 -0
- package/cjs/state/key.js.map +1 -0
- package/cjs/state/storage.d.ts +75 -0
- package/cjs/state/storage.js +17 -0
- package/cjs/state/storage.js.map +1 -0
- package/cjs/state/update-state.d.ts +151 -0
- package/cjs/state/update-state.js +211 -0
- package/cjs/state/update-state.js.map +1 -0
- package/cjs/wizard.d.ts +60 -0
- package/cjs/wizard.js +103 -0
- package/cjs/wizard.js.map +1 -0
- package/esm/callback-data-builder.d.ts +43 -0
- package/esm/callback-data-builder.js +95 -0
- package/esm/callback-data-builder.js.map +1 -0
- package/esm/context/base.d.ts +8 -0
- package/esm/context/base.js +2 -0
- package/esm/context/base.js.map +1 -0
- package/esm/context/callback-query.d.ts +27 -0
- package/esm/context/callback-query.js +52 -0
- package/esm/context/callback-query.js.map +1 -0
- package/esm/context/chat-join-request.d.ts +16 -0
- package/esm/context/chat-join-request.js +30 -0
- package/esm/context/chat-join-request.js.map +1 -0
- package/esm/context/chosen-inline-result.d.ts +21 -0
- package/esm/context/chosen-inline-result.js +31 -0
- package/esm/context/chosen-inline-result.js.map +1 -0
- package/esm/context/index.d.ts +8 -0
- package/esm/context/index.js +8 -0
- package/esm/context/index.js.map +1 -0
- package/esm/context/inline-query.d.ts +14 -0
- package/esm/context/inline-query.js +18 -0
- package/esm/context/inline-query.js.map +1 -0
- package/esm/context/message.d.ts +72 -0
- package/esm/context/message.js +138 -0
- package/esm/context/message.js.map +1 -0
- package/esm/context/parse.d.ts +1 -0
- package/esm/context/parse.js +30 -0
- package/esm/context/parse.js.map +1 -0
- package/esm/context/pre-checkout-query.d.ts +16 -0
- package/esm/context/pre-checkout-query.js +22 -0
- package/esm/context/pre-checkout-query.js.map +1 -0
- package/esm/dispatcher.d.ts +641 -0
- package/esm/dispatcher.js +761 -0
- package/esm/dispatcher.js.map +1 -0
- package/esm/filters/bots.d.ts +70 -0
- package/esm/filters/bots.js +125 -0
- package/esm/filters/bots.js.map +1 -0
- package/esm/filters/bundle.d.ts +10 -0
- package/esm/filters/bundle.js +11 -0
- package/esm/filters/bundle.js.map +1 -0
- package/esm/filters/chat.d.ts +27 -0
- package/esm/filters/chat.js +50 -0
- package/esm/filters/chat.js.map +1 -0
- package/esm/filters/group.d.ts +25 -0
- package/esm/filters/group.js +67 -0
- package/esm/filters/group.js.map +1 -0
- package/esm/filters/index.d.ts +3 -0
- package/esm/filters/index.js +3 -0
- package/esm/filters/index.js.map +1 -0
- package/esm/filters/logic.d.ts +29 -0
- package/esm/filters/logic.js +107 -0
- package/esm/filters/logic.js.map +1 -0
- package/esm/filters/message.d.ts +295 -0
- package/esm/filters/message.js +130 -0
- package/esm/filters/message.js.map +1 -0
- package/esm/filters/state.d.ts +15 -0
- package/esm/filters/state.js +27 -0
- package/esm/filters/state.js.map +1 -0
- package/esm/filters/text.d.ts +64 -0
- package/esm/filters/text.js +124 -0
- package/esm/filters/text.js.map +1 -0
- package/esm/filters/types.d.ts +91 -0
- package/esm/filters/types.js +5 -0
- package/esm/filters/types.js.map +1 -0
- package/esm/filters/updates.d.ts +46 -0
- package/esm/filters/updates.js +39 -0
- package/esm/filters/updates.js.map +1 -0
- package/esm/filters/user.d.ts +24 -0
- package/esm/filters/user.js +70 -0
- package/esm/filters/user.js.map +1 -0
- package/esm/handler.d.ts +31 -0
- package/esm/handler.js +3 -0
- package/esm/handler.js.map +1 -0
- package/esm/index.d.ts +8 -0
- package/esm/index.js +9 -0
- package/esm/index.js.map +1 -0
- package/esm/propagation.d.ts +21 -0
- package/esm/propagation.js +23 -0
- package/esm/propagation.js.map +1 -0
- package/esm/state/index.d.ts +3 -0
- package/esm/state/index.js +4 -0
- package/esm/state/index.js.map +1 -0
- package/esm/state/key.d.ts +23 -0
- package/esm/state/key.js +41 -0
- package/esm/state/key.js.map +1 -0
- package/esm/state/storage.d.ts +75 -0
- package/esm/state/storage.js +13 -0
- package/esm/state/storage.js.map +1 -0
- package/esm/state/update-state.d.ts +151 -0
- package/esm/state/update-state.js +206 -0
- package/esm/state/update-state.js.map +1 -0
- package/esm/wizard.d.ts +60 -0
- package/esm/wizard.js +99 -0
- package/esm/wizard.js.map +1 -0
- package/package.json +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2023 Alina Sireneva
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @mtcute/dispatcher
|
|
2
|
+
|
|
3
|
+
📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_dispatcher.html)
|
|
4
|
+
🧐 [Guide](https://mtcute.dev/guide/dispatcher/intro.html)
|
|
5
|
+
|
|
6
|
+
Dispatcher and bot framework based on @mtcute/client.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
- **Straightforward**: Simple and expressive API
|
|
10
|
+
- **State**: Supports storing state for each chat
|
|
11
|
+
- **Filters**: Powerful and easy-to-use filtering system
|
|
12
|
+
- **Middleware**: Basic middleware support for updates
|
|
13
|
+
- **Scenes**: Built-in support for scenes
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { NodeTelegramClient, Dispatcher } from '@mtcute/node'
|
|
19
|
+
|
|
20
|
+
const tg = new NodeTelegramClient({ ... })
|
|
21
|
+
const dp = Dispatcher.for(tg)
|
|
22
|
+
|
|
23
|
+
dp.onNewMessage(async (msg) => {
|
|
24
|
+
await msg.replyText('Hello world!')
|
|
25
|
+
})
|
|
26
|
+
```
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CallbackQuery, MaybeArray } from '@mtcute/client';
|
|
2
|
+
import { UpdateFilter } from './filters/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Callback data builder, inspired by [aiogram](https://github.com/aiogram/aiogram).
|
|
5
|
+
*
|
|
6
|
+
* This can be used to simplify management of different callbacks.
|
|
7
|
+
*
|
|
8
|
+
* [Learn more in the docs](/guide/topics/keyboards.html#callback-data-builders)
|
|
9
|
+
*/
|
|
10
|
+
export declare class CallbackDataBuilder<T extends string> {
|
|
11
|
+
prefix: string;
|
|
12
|
+
private readonly _fields;
|
|
13
|
+
sep: string;
|
|
14
|
+
/**
|
|
15
|
+
* @param prefix Prefix for the data. Use something unique across your bot.
|
|
16
|
+
* @param fields Field names in the order they will be serialized.
|
|
17
|
+
*/
|
|
18
|
+
constructor(prefix: string, ...fields: T[]);
|
|
19
|
+
/**
|
|
20
|
+
* Build a callback data string
|
|
21
|
+
*
|
|
22
|
+
* @param obj Object containing the data
|
|
23
|
+
*/
|
|
24
|
+
build(obj: Record<T, string>): string;
|
|
25
|
+
/**
|
|
26
|
+
* Parse callback data to object
|
|
27
|
+
*
|
|
28
|
+
* @param data Callback data as string
|
|
29
|
+
*/
|
|
30
|
+
parse(data: string): Record<T, string>;
|
|
31
|
+
/**
|
|
32
|
+
* Create a filter for this callback data.
|
|
33
|
+
*
|
|
34
|
+
* > **Note**: `params` object will be compiled to a RegExp,
|
|
35
|
+
* > so avoid using characters that have special meaning in regex,
|
|
36
|
+
* > or use RegExp directly to let the IDE guide you.
|
|
37
|
+
*
|
|
38
|
+
* @param params
|
|
39
|
+
*/
|
|
40
|
+
filter(params: Partial<Record<T, MaybeArray<string | RegExp>>>): UpdateFilter<CallbackQuery, {
|
|
41
|
+
match: Record<T, string>;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CallbackDataBuilder = void 0;
|
|
4
|
+
const client_1 = require("@mtcute/client");
|
|
5
|
+
/**
|
|
6
|
+
* Callback data builder, inspired by [aiogram](https://github.com/aiogram/aiogram).
|
|
7
|
+
*
|
|
8
|
+
* This can be used to simplify management of different callbacks.
|
|
9
|
+
*
|
|
10
|
+
* [Learn more in the docs](/guide/topics/keyboards.html#callback-data-builders)
|
|
11
|
+
*/
|
|
12
|
+
class CallbackDataBuilder {
|
|
13
|
+
/**
|
|
14
|
+
* @param prefix Prefix for the data. Use something unique across your bot.
|
|
15
|
+
* @param fields Field names in the order they will be serialized.
|
|
16
|
+
*/
|
|
17
|
+
constructor(prefix, ...fields) {
|
|
18
|
+
this.prefix = prefix;
|
|
19
|
+
this.sep = ':';
|
|
20
|
+
this._fields = fields;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Build a callback data string
|
|
24
|
+
*
|
|
25
|
+
* @param obj Object containing the data
|
|
26
|
+
*/
|
|
27
|
+
build(obj) {
|
|
28
|
+
const ret = this.prefix +
|
|
29
|
+
this.sep +
|
|
30
|
+
this._fields
|
|
31
|
+
.map((f) => {
|
|
32
|
+
const val = obj[f];
|
|
33
|
+
if (val.includes(this.sep)) {
|
|
34
|
+
throw new client_1.MtArgumentError(`Value for ${f} ${val} contains separator ${this.sep} and cannot be used.`);
|
|
35
|
+
}
|
|
36
|
+
return val;
|
|
37
|
+
})
|
|
38
|
+
.join(this.sep);
|
|
39
|
+
if (ret.length > 64) {
|
|
40
|
+
throw new client_1.MtArgumentError('Resulting callback data is too long.');
|
|
41
|
+
}
|
|
42
|
+
return ret;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parse callback data to object
|
|
46
|
+
*
|
|
47
|
+
* @param data Callback data as string
|
|
48
|
+
*/
|
|
49
|
+
parse(data) {
|
|
50
|
+
const parts = data.split(this.sep);
|
|
51
|
+
if (parts[0] !== this.prefix) {
|
|
52
|
+
throw new client_1.MtArgumentError('Invalid data passed');
|
|
53
|
+
}
|
|
54
|
+
if (parts.length !== this._fields.length + 1) {
|
|
55
|
+
throw new client_1.MtArgumentError('Invalid data passed');
|
|
56
|
+
}
|
|
57
|
+
const ret = {};
|
|
58
|
+
parts.forEach((it, idx) => {
|
|
59
|
+
ret[this._fields[idx - 1]] = it;
|
|
60
|
+
});
|
|
61
|
+
return ret;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a filter for this callback data.
|
|
65
|
+
*
|
|
66
|
+
* > **Note**: `params` object will be compiled to a RegExp,
|
|
67
|
+
* > so avoid using characters that have special meaning in regex,
|
|
68
|
+
* > or use RegExp directly to let the IDE guide you.
|
|
69
|
+
*
|
|
70
|
+
* @param params
|
|
71
|
+
*/
|
|
72
|
+
filter(params) {
|
|
73
|
+
const parts = [];
|
|
74
|
+
this._fields.forEach((field) => {
|
|
75
|
+
if (!(field in params)) {
|
|
76
|
+
parts.push(`[^${this.sep}]*?`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const value = params[field];
|
|
80
|
+
if (Array.isArray(value)) {
|
|
81
|
+
parts.push(`(${value.map((i) => (typeof i === 'string' ? i : i.source)).join('|')})`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// noinspection SuspiciousTypeOfGuard
|
|
85
|
+
parts.push(typeof value === 'string' ? value : value.source);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
const regex = new RegExp(`^${this.prefix}${this.sep}${parts.join(this.sep)}$`);
|
|
89
|
+
return (query) => {
|
|
90
|
+
const m = query.dataStr?.match(regex);
|
|
91
|
+
if (!m)
|
|
92
|
+
return false;
|
|
93
|
+
query.match = this.parse(m[0]);
|
|
94
|
+
return true;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.CallbackDataBuilder = CallbackDataBuilder;
|
|
99
|
+
//# sourceMappingURL=callback-data-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback-data-builder.js","sourceRoot":"","sources":["../../src/callback-data-builder.ts"],"names":[],"mappings":"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","sourcesContent":["import { CallbackQuery, MaybeArray, MtArgumentError } from '@mtcute/client'\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 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"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ParsedUpdate, TelegramClient } from '@mtcute/client';
|
|
2
|
+
export type UpdateContext<T> = T & {
|
|
3
|
+
client: TelegramClient;
|
|
4
|
+
_name: Extract<ParsedUpdate, {
|
|
5
|
+
data: T;
|
|
6
|
+
}>['name'];
|
|
7
|
+
};
|
|
8
|
+
export type UpdateContextDistributed<T> = T extends never ? never : UpdateContext<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/context/base.ts"],"names":[],"mappings":"","sourcesContent":["import { ParsedUpdate, TelegramClient } from '@mtcute/client'\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"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CallbackQuery, TelegramClient } from '@mtcute/client';
|
|
2
|
+
import { UpdateContext } from './base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Context of a callback query update.
|
|
5
|
+
*
|
|
6
|
+
* This is a subclass of {@link CallbackQuery}, so all its fields are also available.
|
|
7
|
+
*/
|
|
8
|
+
export declare class CallbackQueryContext extends CallbackQuery implements UpdateContext<CallbackQuery> {
|
|
9
|
+
readonly client: TelegramClient;
|
|
10
|
+
readonly _name = "callback_query";
|
|
11
|
+
constructor(client: TelegramClient, query: CallbackQuery);
|
|
12
|
+
/** Answer to this callback query */
|
|
13
|
+
answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* * Message that contained the callback button that was clicked.
|
|
16
|
+
*
|
|
17
|
+
* Note that the message may have been deleted, in which case
|
|
18
|
+
* `MessageNotFoundError` is thrown.
|
|
19
|
+
*
|
|
20
|
+
* Can only be used if `isInline = false`
|
|
21
|
+
*/
|
|
22
|
+
getMessage(): Promise<import("@mtcute/client").Message>;
|
|
23
|
+
/**
|
|
24
|
+
* Edit the message that contained the callback button that was clicked.
|
|
25
|
+
*/
|
|
26
|
+
editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>): Promise<void | import("@mtcute/client").Message>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CallbackQueryContext = void 0;
|
|
4
|
+
const client_1 = require("@mtcute/client");
|
|
5
|
+
/**
|
|
6
|
+
* Context of a callback query update.
|
|
7
|
+
*
|
|
8
|
+
* This is a subclass of {@link CallbackQuery}, so all its fields are also available.
|
|
9
|
+
*/
|
|
10
|
+
class CallbackQueryContext extends client_1.CallbackQuery {
|
|
11
|
+
constructor(client, query) {
|
|
12
|
+
super(query.raw, query._peers);
|
|
13
|
+
this.client = client;
|
|
14
|
+
this._name = 'callback_query';
|
|
15
|
+
}
|
|
16
|
+
/** Answer to this callback query */
|
|
17
|
+
answer(params) {
|
|
18
|
+
return this.client.answerCallbackQuery(this.id, params);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* * Message that contained the callback button that was clicked.
|
|
22
|
+
*
|
|
23
|
+
* Note that the message may have been deleted, in which case
|
|
24
|
+
* `MessageNotFoundError` is thrown.
|
|
25
|
+
*
|
|
26
|
+
* Can only be used if `isInline = false`
|
|
27
|
+
*/
|
|
28
|
+
async getMessage() {
|
|
29
|
+
if (this.raw._ !== 'updateBotCallbackQuery') {
|
|
30
|
+
throw new client_1.MtArgumentError('Cannot get message for inline callback query');
|
|
31
|
+
}
|
|
32
|
+
const [msg] = await this.client.getMessages(this.raw.peer, this.raw.msgId);
|
|
33
|
+
if (!msg) {
|
|
34
|
+
throw new client_1.MtMessageNotFoundError((0, client_1.getMarkedPeerId)(this.raw.peer), this.raw.msgId, 'Message not found');
|
|
35
|
+
}
|
|
36
|
+
return msg;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Edit the message that contained the callback button that was clicked.
|
|
40
|
+
*/
|
|
41
|
+
async editMessage(params) {
|
|
42
|
+
if (this.raw._ === 'updateInlineBotCallbackQuery') {
|
|
43
|
+
return this.client.editInlineMessage({
|
|
44
|
+
messageId: this.raw.msgId,
|
|
45
|
+
...params,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return this.client.editMessage({
|
|
49
|
+
chatId: this.raw.peer,
|
|
50
|
+
message: this.raw.msgId,
|
|
51
|
+
...params,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.CallbackQueryContext = CallbackQueryContext;
|
|
56
|
+
//# sourceMappingURL=callback-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback-query.js","sourceRoot":"","sources":["../../../src/context/callback-query.ts"],"names":[],"mappings":";;;AAAA,2CAAwH;AAIxH;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,sBAAa;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;IACpC,MAAM,CAAC,MAA4D;QAC/D,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,UAAU;QACZ,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,wBAAwB,EAAE;YACzC,MAAM,IAAI,wBAAe,CAAC,8CAA8C,CAAC,CAAA;SAC5E;QAED,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAE1E,IAAI,CAAC,GAAG,EAAE;YACN,MAAM,IAAI,+BAAsB,CAAC,IAAA,wBAAe,EAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAA;SACxG;QAED,OAAO,GAAG,CAAA;IACd,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,MAA6E;QAC3F,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,8BAA8B,EAAE;YAC/C,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;gBACjC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK;gBACzB,GAAG,MAAM;aACZ,CAAC,CAAA;SACL;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;YAC3B,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI;YACrB,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK;YACvB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;CACJ;AAtDD,oDAsDC","sourcesContent":["import { CallbackQuery, getMarkedPeerId, MtArgumentError, MtMessageNotFoundError, TelegramClient } from '@mtcute/client'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a callback query update.\n *\n * This is a subclass of {@link CallbackQuery}, so all its fields are also available.\n */\nexport class CallbackQueryContext extends CallbackQuery implements UpdateContext<CallbackQuery> {\n readonly _name = 'callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: CallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * * Message that contained the callback button that was clicked.\n *\n * Note that the message may have been deleted, in which case\n * `MessageNotFoundError` is thrown.\n *\n * Can only be used if `isInline = false`\n */\n async getMessage() {\n if (this.raw._ !== 'updateBotCallbackQuery') {\n throw new MtArgumentError('Cannot get message for inline callback query')\n }\n\n const [msg] = await this.client.getMessages(this.raw.peer, this.raw.msgId)\n\n if (!msg) {\n throw new MtMessageNotFoundError(getMarkedPeerId(this.raw.peer), this.raw.msgId, 'Message not found')\n }\n\n return msg\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 if (this.raw._ === 'updateInlineBotCallbackQuery') {\n return this.client.editInlineMessage({\n messageId: this.raw.msgId,\n ...params,\n })\n }\n\n return this.client.editMessage({\n chatId: this.raw.peer,\n message: this.raw.msgId,\n ...params,\n })\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BotChatJoinRequestUpdate, TelegramClient } from '@mtcute/client';
|
|
2
|
+
import { UpdateContext } from './base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Context of a chat join request update (for bots).
|
|
5
|
+
*
|
|
6
|
+
* This is a subclass of {@link BotChatJoinRequestUpdate}, so all its fields are also available.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ChatJoinRequestUpdateContext extends BotChatJoinRequestUpdate implements UpdateContext<BotChatJoinRequestUpdate> {
|
|
9
|
+
readonly client: TelegramClient;
|
|
10
|
+
readonly _name = "bot_chat_join_request";
|
|
11
|
+
constructor(client: TelegramClient, update: BotChatJoinRequestUpdate);
|
|
12
|
+
/** Approve the request */
|
|
13
|
+
approve(): Promise<void>;
|
|
14
|
+
/** Decline the request */
|
|
15
|
+
decline(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatJoinRequestUpdateContext = void 0;
|
|
4
|
+
const client_1 = require("@mtcute/client");
|
|
5
|
+
/**
|
|
6
|
+
* Context of a chat join request update (for bots).
|
|
7
|
+
*
|
|
8
|
+
* This is a subclass of {@link BotChatJoinRequestUpdate}, so all its fields are also available.
|
|
9
|
+
*/
|
|
10
|
+
class ChatJoinRequestUpdateContext extends client_1.BotChatJoinRequestUpdate {
|
|
11
|
+
constructor(client, update) {
|
|
12
|
+
super(update.raw, update._peers);
|
|
13
|
+
this.client = client;
|
|
14
|
+
this._name = 'bot_chat_join_request';
|
|
15
|
+
}
|
|
16
|
+
/** Approve the request */
|
|
17
|
+
approve() {
|
|
18
|
+
return this.client.hideJoinRequest({
|
|
19
|
+
action: 'approve',
|
|
20
|
+
user: this.user.inputPeer,
|
|
21
|
+
chatId: this.chat.inputPeer,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/** Decline the request */
|
|
25
|
+
decline() {
|
|
26
|
+
return this.client.hideJoinRequest({
|
|
27
|
+
action: 'decline',
|
|
28
|
+
user: this.user.inputPeer,
|
|
29
|
+
chatId: this.chat.inputPeer,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ChatJoinRequestUpdateContext = ChatJoinRequestUpdateContext;
|
|
34
|
+
//# sourceMappingURL=chat-join-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-join-request.js","sourceRoot":"","sources":["../../../src/context/chat-join-request.ts"],"names":[],"mappings":";;;AAAA,2CAAyE;AAIzE;;;;GAIG;AACH,MAAa,4BACT,SAAQ,iCAAwB;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/client'\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"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ChosenInlineResult, TelegramClient } from '@mtcute/client';
|
|
2
|
+
import { UpdateContext } from './base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Context of a chosen inline result update.
|
|
5
|
+
*
|
|
6
|
+
* This is a subclass of {@link ChosenInlineResult}, so all its fields are also available.
|
|
7
|
+
*
|
|
8
|
+
* > **Note**: To receive these updates, you must enable
|
|
9
|
+
* > Inline feedback in [@BotFather](//t.me/botfather)
|
|
10
|
+
*/
|
|
11
|
+
export declare class ChosenInlineResultContext extends ChosenInlineResult implements UpdateContext<ChosenInlineResult> {
|
|
12
|
+
readonly client: TelegramClient;
|
|
13
|
+
readonly _name = "chosen_inline_result";
|
|
14
|
+
constructor(client: TelegramClient, result: ChosenInlineResult);
|
|
15
|
+
/**
|
|
16
|
+
* Edit the message that was sent when this inline result that was chosen.
|
|
17
|
+
*
|
|
18
|
+
* > **Note**: This method can only be used if the message contained a reply markup
|
|
19
|
+
*/
|
|
20
|
+
editMessage(params: Parameters<TelegramClient['editInlineMessage']>[0]): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChosenInlineResultContext = void 0;
|
|
4
|
+
const client_1 = require("@mtcute/client");
|
|
5
|
+
/**
|
|
6
|
+
* Context of a chosen inline result update.
|
|
7
|
+
*
|
|
8
|
+
* This is a subclass of {@link ChosenInlineResult}, so all its fields are also available.
|
|
9
|
+
*
|
|
10
|
+
* > **Note**: To receive these updates, you must enable
|
|
11
|
+
* > Inline feedback in [@BotFather](//t.me/botfather)
|
|
12
|
+
*/
|
|
13
|
+
class ChosenInlineResultContext extends client_1.ChosenInlineResult {
|
|
14
|
+
constructor(client, result) {
|
|
15
|
+
super(result.raw, result._peers);
|
|
16
|
+
this.client = client;
|
|
17
|
+
this._name = 'chosen_inline_result';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Edit the message that was sent when this inline result that was chosen.
|
|
21
|
+
*
|
|
22
|
+
* > **Note**: This method can only be used if the message contained a reply markup
|
|
23
|
+
*/
|
|
24
|
+
async editMessage(params) {
|
|
25
|
+
if (!this.raw.msgId) {
|
|
26
|
+
throw new client_1.MtArgumentError('No message ID, make sure you have included reply markup!');
|
|
27
|
+
}
|
|
28
|
+
return this.client.editInlineMessage({
|
|
29
|
+
...params,
|
|
30
|
+
messageId: this.raw.msgId,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.ChosenInlineResultContext = ChosenInlineResultContext;
|
|
35
|
+
//# sourceMappingURL=chosen-inline-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chosen-inline-result.js","sourceRoot":"","sources":["../../../src/context/chosen-inline-result.ts"],"names":[],"mappings":";;;AAAA,2CAAoF;AAIpF;;;;;;;GAOG;AACH,MAAa,yBAA0B,SAAQ,2BAAkB;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,wBAAe,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/client'\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"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './base.js';
|
|
2
|
+
export * from './callback-query.js';
|
|
3
|
+
export * from './chat-join-request.js';
|
|
4
|
+
export * from './chosen-inline-result.js';
|
|
5
|
+
export * from './inline-query.js';
|
|
6
|
+
export * from './message.js';
|
|
7
|
+
export { UpdateContextType } from './parse.js';
|
|
8
|
+
export * from './pre-checkout-query.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./base.js"), exports);
|
|
18
|
+
__exportStar(require("./callback-query.js"), exports);
|
|
19
|
+
__exportStar(require("./chat-join-request.js"), exports);
|
|
20
|
+
__exportStar(require("./chosen-inline-result.js"), exports);
|
|
21
|
+
__exportStar(require("./inline-query.js"), exports);
|
|
22
|
+
__exportStar(require("./message.js"), exports);
|
|
23
|
+
__exportStar(require("./pre-checkout-query.js"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/context/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,sDAAmC;AACnC,yDAAsC;AACtC,4DAAyC;AACzC,oDAAiC;AACjC,+CAA4B;AAE5B,0DAAuC","sourcesContent":["export * from './base.js'\nexport * from './callback-query.js'\nexport * from './chat-join-request.js'\nexport * from './chosen-inline-result.js'\nexport * from './inline-query.js'\nexport * from './message.js'\nexport { UpdateContextType } from './parse.js'\nexport * from './pre-checkout-query.js'\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { InlineQuery, ParametersSkip1, TelegramClient } from '@mtcute/client';
|
|
2
|
+
import { UpdateContext } from './base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Context of an inline query update.
|
|
5
|
+
*
|
|
6
|
+
* This is a subclass of {@link InlineQuery}, so all its fields are also available.
|
|
7
|
+
*/
|
|
8
|
+
export declare class InlineQueryContext extends InlineQuery implements UpdateContext<InlineQuery> {
|
|
9
|
+
readonly client: TelegramClient;
|
|
10
|
+
readonly _name = "inline_query";
|
|
11
|
+
constructor(client: TelegramClient, query: InlineQuery);
|
|
12
|
+
/** Answer to this inline query */
|
|
13
|
+
answer(...params: ParametersSkip1<TelegramClient['answerInlineQuery']>): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InlineQueryContext = void 0;
|
|
4
|
+
const client_1 = require("@mtcute/client");
|
|
5
|
+
/**
|
|
6
|
+
* Context of an inline query update.
|
|
7
|
+
*
|
|
8
|
+
* This is a subclass of {@link InlineQuery}, so all its fields are also available.
|
|
9
|
+
*/
|
|
10
|
+
class InlineQueryContext extends client_1.InlineQuery {
|
|
11
|
+
constructor(client, query) {
|
|
12
|
+
super(query.raw, query._peers);
|
|
13
|
+
this.client = client;
|
|
14
|
+
this._name = 'inline_query';
|
|
15
|
+
}
|
|
16
|
+
/** Answer to this inline query */
|
|
17
|
+
answer(...params) {
|
|
18
|
+
return this.client.answerInlineQuery(this.id, ...params);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.InlineQueryContext = InlineQueryContext;
|
|
22
|
+
//# sourceMappingURL=inline-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-query.js","sourceRoot":"","sources":["../../../src/context/inline-query.ts"],"names":[],"mappings":";;;AAAA,2CAA6E;AAI7E;;;;GAIG;AACH,MAAa,kBAAmB,SAAQ,oBAAW;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/client'\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"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Message, OmitInputMessageId, ParametersSkip1, TelegramClient } from '@mtcute/client';
|
|
2
|
+
import { DeleteMessagesParams } from '@mtcute/client/methods/messages/delete-messages.js';
|
|
3
|
+
import { ForwardMessageOptions } from '@mtcute/client/methods/messages/forward-messages.js';
|
|
4
|
+
import { SendCopyParams } from '@mtcute/client/methods/messages/send-copy.js';
|
|
5
|
+
import { SendCopyGroupParams } from '@mtcute/client/methods/messages/send-copy-group.js';
|
|
6
|
+
import { UpdateContext } from './base.js';
|
|
7
|
+
/**
|
|
8
|
+
* Context of a message-related update.
|
|
9
|
+
*
|
|
10
|
+
* This is a subclass of {@link Message}, so all fields
|
|
11
|
+
* of the message are available.
|
|
12
|
+
*
|
|
13
|
+
* For message groups, own fields are related to the last message
|
|
14
|
+
* in the group. To access all messages, use {@link MessageContext#messages}.
|
|
15
|
+
*/
|
|
16
|
+
export declare class MessageContext extends Message implements UpdateContext<Message> {
|
|
17
|
+
readonly client: TelegramClient;
|
|
18
|
+
readonly _name = "new_message";
|
|
19
|
+
/**
|
|
20
|
+
* List of messages in the message group.
|
|
21
|
+
*
|
|
22
|
+
* For other updates, this is a list with a single element (`this`).
|
|
23
|
+
*/
|
|
24
|
+
readonly messages: MessageContext[];
|
|
25
|
+
/** Whether this update is about a message group */
|
|
26
|
+
readonly isMessageGroup: boolean;
|
|
27
|
+
constructor(client: TelegramClient, message: Message | Message[]);
|
|
28
|
+
/** Get a message that this message is a reply to */
|
|
29
|
+
getReplyTo(): Promise<Message | null>;
|
|
30
|
+
/** If this is a channel post, get its automatic forward in the discussion group */
|
|
31
|
+
getDiscussionMessage(): Promise<Message | null>;
|
|
32
|
+
/** Get all custom emojis contained in this message (message group), if any */
|
|
33
|
+
getCustomEmojis(): Promise<import("@mtcute/client").Sticker[]>;
|
|
34
|
+
/** Send a text message to the same chat (and topic, if applicable) as a given message */
|
|
35
|
+
answerText(...params: ParametersSkip1<TelegramClient['answerText']>): Promise<Message>;
|
|
36
|
+
/** Send a media to the same chat (and topic, if applicable) as a given message */
|
|
37
|
+
answerMedia(...params: ParametersSkip1<TelegramClient['answerMedia']>): Promise<Message>;
|
|
38
|
+
/** Send a media group to the same chat (and topic, if applicable) as a given message */
|
|
39
|
+
answerMediaGroup(...params: ParametersSkip1<TelegramClient['answerMediaGroup']>): Promise<Message[]>;
|
|
40
|
+
/** Send a text message in reply to this message */
|
|
41
|
+
replyText(...params: ParametersSkip1<TelegramClient['replyText']>): Promise<Message>;
|
|
42
|
+
/** Send a media in reply to this message */
|
|
43
|
+
replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>): Promise<Message>;
|
|
44
|
+
/** Send a media group in reply to this message */
|
|
45
|
+
replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>): Promise<Message[]>;
|
|
46
|
+
/** Send a text message in reply to this message */
|
|
47
|
+
quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]): Promise<Message>;
|
|
48
|
+
/** Send a media in reply to this message */
|
|
49
|
+
quoteWithMedia(params: Parameters<TelegramClient['quoteWithMedia']>[1]): Promise<Message>;
|
|
50
|
+
/** Send a media group in reply to this message */
|
|
51
|
+
quoteWithMediaGroup(params: Parameters<TelegramClient['quoteWithMediaGroup']>[1]): Promise<Message[]>;
|
|
52
|
+
/** Send a text as a comment to this message */
|
|
53
|
+
commentText(...params: ParametersSkip1<TelegramClient['commentText']>): Promise<Message>;
|
|
54
|
+
/** Send a media as a comment to this message */
|
|
55
|
+
commentMedia(...params: ParametersSkip1<TelegramClient['commentMedia']>): Promise<Message>;
|
|
56
|
+
/** Send a media group as a comment to this message */
|
|
57
|
+
commentMediaGroup(...params: ParametersSkip1<TelegramClient['commentMediaGroup']>): Promise<Message[]>;
|
|
58
|
+
/** Delete this message (message group) */
|
|
59
|
+
delete(params?: DeleteMessagesParams): Promise<void>;
|
|
60
|
+
/** Pin this message */
|
|
61
|
+
pin(params?: OmitInputMessageId<Parameters<TelegramClient['pinMessage']>[0]>): Promise<Message | null>;
|
|
62
|
+
/** Unpin this message */
|
|
63
|
+
unpin(): Promise<void>;
|
|
64
|
+
/** Edit this message */
|
|
65
|
+
edit(params: OmitInputMessageId<Parameters<TelegramClient['editMessage']>[0]>): Promise<Message>;
|
|
66
|
+
/** Forward this message (message group) */
|
|
67
|
+
forwardTo(params: ForwardMessageOptions): Promise<Message[]>;
|
|
68
|
+
/** Send a copy of this message (message group) */
|
|
69
|
+
copy(params: SendCopyParams & SendCopyGroupParams): Promise<Message> | Promise<Message[]>;
|
|
70
|
+
/** React to this message */
|
|
71
|
+
react(params: OmitInputMessageId<Parameters<TelegramClient['sendReaction']>[0]>): Promise<Message>;
|
|
72
|
+
}
|