@mtcute/dispatcher 0.16.7 → 0.16.13

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.
Files changed (237) hide show
  1. package/{cjs/callback-data-builder.d.ts → callback-data-builder.d.ts} +2 -2
  2. package/callback-data-builder.test.d.ts +1 -0
  3. package/{esm/context → context}/base.d.ts +2 -2
  4. package/{esm/context → context}/business-message.d.ts +5 -6
  5. package/{esm/context → context}/callback-query.d.ts +6 -7
  6. package/{cjs/context → context}/chat-join-request.d.ts +3 -3
  7. package/{esm/context → context}/chosen-inline-result.d.ts +3 -3
  8. package/{esm/context → context}/inline-query.d.ts +4 -5
  9. package/{cjs/context → context}/message.d.ts +11 -6
  10. package/{cjs/context → context}/parse.d.ts +3 -3
  11. package/{esm/context → context}/pre-checkout-query.d.ts +3 -3
  12. package/{esm/context → context}/scene-transition.d.ts +1 -1
  13. package/{cjs/dispatcher.d.ts → dispatcher.d.ts} +9 -10
  14. package/{cjs/filters → filters}/bots.d.ts +4 -4
  15. package/filters/bots.test.d.ts +1 -0
  16. package/{cjs/filters → filters}/chat.d.ts +3 -3
  17. package/{esm/filters → filters}/group.d.ts +4 -4
  18. package/{cjs/filters → filters}/logic.d.ts +1 -1
  19. package/filters/logic.test.d.ts +1 -0
  20. package/{esm/filters → filters}/message.d.ts +9 -5
  21. package/{cjs/filters → filters}/state.d.ts +2 -2
  22. package/{esm/filters → filters}/text.d.ts +3 -3
  23. package/{cjs/filters → filters}/types.d.ts +2 -2
  24. package/{cjs/filters → filters}/updates.d.ts +2 -2
  25. package/{cjs/filters → filters}/user.d.ts +3 -4
  26. package/{cjs/handler.d.ts → handler.d.ts} +5 -5
  27. package/index.cjs +2534 -0
  28. package/index.d.ts +8 -1
  29. package/index.js +2529 -1
  30. package/package.json +28 -24
  31. package/{cjs/state → state}/key.d.ts +3 -3
  32. package/state/provider.d.ts +5 -0
  33. package/{cjs/state → state}/providers/memory.d.ts +3 -4
  34. package/{esm/state → state}/providers/sqlite.d.ts +3 -3
  35. package/{cjs/state → state}/repository.d.ts +1 -1
  36. package/{esm/state → state}/service.d.ts +2 -2
  37. package/{cjs/state → state}/update-state.d.ts +2 -2
  38. package/{esm/wizard.d.ts → wizard.d.ts} +5 -6
  39. package/cjs/callback-data-builder.js +0 -141
  40. package/cjs/callback-data-builder.js.map +0 -1
  41. package/cjs/context/base.d.ts +0 -9
  42. package/cjs/context/base.js +0 -3
  43. package/cjs/context/base.js.map +0 -1
  44. package/cjs/context/business-message.d.ts +0 -61
  45. package/cjs/context/business-message.js +0 -146
  46. package/cjs/context/business-message.js.map +0 -1
  47. package/cjs/context/callback-query.d.ts +0 -63
  48. package/cjs/context/callback-query.js +0 -109
  49. package/cjs/context/callback-query.js.map +0 -1
  50. package/cjs/context/chat-join-request.js +0 -35
  51. package/cjs/context/chat-join-request.js.map +0 -1
  52. package/cjs/context/chosen-inline-result.d.ts +0 -22
  53. package/cjs/context/chosen-inline-result.js +0 -36
  54. package/cjs/context/chosen-inline-result.js.map +0 -1
  55. package/cjs/context/index.js +0 -25
  56. package/cjs/context/index.js.map +0 -1
  57. package/cjs/context/inline-query.d.ts +0 -16
  58. package/cjs/context/inline-query.js +0 -23
  59. package/cjs/context/inline-query.js.map +0 -1
  60. package/cjs/context/message.js +0 -171
  61. package/cjs/context/message.js.map +0 -1
  62. package/cjs/context/parse.js +0 -42
  63. package/cjs/context/parse.js.map +0 -1
  64. package/cjs/context/pre-checkout-query.d.ts +0 -17
  65. package/cjs/context/pre-checkout-query.js +0 -27
  66. package/cjs/context/pre-checkout-query.js.map +0 -1
  67. package/cjs/context/scene-transition.d.ts +0 -24
  68. package/cjs/context/scene-transition.js +0 -52
  69. package/cjs/context/scene-transition.js.map +0 -1
  70. package/cjs/dispatcher.js +0 -908
  71. package/cjs/dispatcher.js.map +0 -1
  72. package/cjs/filters/bots.js +0 -135
  73. package/cjs/filters/bots.js.map +0 -1
  74. package/cjs/filters/bundle.js +0 -27
  75. package/cjs/filters/bundle.js.map +0 -1
  76. package/cjs/filters/chat.js +0 -56
  77. package/cjs/filters/chat.js.map +0 -1
  78. package/cjs/filters/group.d.ts +0 -26
  79. package/cjs/filters/group.js +0 -69
  80. package/cjs/filters/group.js.map +0 -1
  81. package/cjs/filters/index.js +0 -29
  82. package/cjs/filters/index.js.map +0 -1
  83. package/cjs/filters/logic.js +0 -112
  84. package/cjs/filters/logic.js.map +0 -1
  85. package/cjs/filters/message.d.ts +0 -215
  86. package/cjs/filters/message.js +0 -191
  87. package/cjs/filters/message.js.map +0 -1
  88. package/cjs/filters/state.js +0 -33
  89. package/cjs/filters/state.js.map +0 -1
  90. package/cjs/filters/text.d.ts +0 -64
  91. package/cjs/filters/text.js +0 -136
  92. package/cjs/filters/text.js.map +0 -1
  93. package/cjs/filters/types.js +0 -3
  94. package/cjs/filters/types.js.map +0 -1
  95. package/cjs/filters/updates.js +0 -40
  96. package/cjs/filters/updates.js.map +0 -1
  97. package/cjs/filters/user.js +0 -77
  98. package/cjs/filters/user.js.map +0 -1
  99. package/cjs/handler.js +0 -4
  100. package/cjs/handler.js.map +0 -1
  101. package/cjs/index.js +0 -31
  102. package/cjs/index.js.map +0 -1
  103. package/cjs/package.json +0 -3
  104. package/cjs/propagation.js +0 -27
  105. package/cjs/propagation.js.map +0 -1
  106. package/cjs/state/index.js +0 -22
  107. package/cjs/state/index.js.map +0 -1
  108. package/cjs/state/key.js +0 -43
  109. package/cjs/state/key.js.map +0 -1
  110. package/cjs/state/provider.d.ts +0 -5
  111. package/cjs/state/provider.js +0 -3
  112. package/cjs/state/provider.js.map +0 -1
  113. package/cjs/state/providers/index.js +0 -19
  114. package/cjs/state/providers/index.js.map +0 -1
  115. package/cjs/state/providers/memory.js +0 -81
  116. package/cjs/state/providers/memory.js.map +0 -1
  117. package/cjs/state/providers/sqlite.d.ts +0 -28
  118. package/cjs/state/providers/sqlite.js +0 -100
  119. package/cjs/state/providers/sqlite.js.map +0 -1
  120. package/cjs/state/repository.js +0 -3
  121. package/cjs/state/repository.js.map +0 -1
  122. package/cjs/state/service.d.ts +0 -20
  123. package/cjs/state/service.js +0 -70
  124. package/cjs/state/service.js.map +0 -1
  125. package/cjs/state/update-state.js +0 -219
  126. package/cjs/state/update-state.js.map +0 -1
  127. package/cjs/wizard.d.ts +0 -65
  128. package/cjs/wizard.js +0 -105
  129. package/cjs/wizard.js.map +0 -1
  130. package/esm/callback-data-builder.d.ts +0 -49
  131. package/esm/callback-data-builder.js +0 -137
  132. package/esm/callback-data-builder.js.map +0 -1
  133. package/esm/context/base.js +0 -2
  134. package/esm/context/base.js.map +0 -1
  135. package/esm/context/business-message.js +0 -142
  136. package/esm/context/business-message.js.map +0 -1
  137. package/esm/context/callback-query.js +0 -103
  138. package/esm/context/callback-query.js.map +0 -1
  139. package/esm/context/chat-join-request.d.ts +0 -17
  140. package/esm/context/chat-join-request.js +0 -31
  141. package/esm/context/chat-join-request.js.map +0 -1
  142. package/esm/context/chosen-inline-result.js +0 -32
  143. package/esm/context/chosen-inline-result.js.map +0 -1
  144. package/esm/context/index.d.ts +0 -9
  145. package/esm/context/index.js +0 -9
  146. package/esm/context/index.js.map +0 -1
  147. package/esm/context/inline-query.js +0 -19
  148. package/esm/context/inline-query.js.map +0 -1
  149. package/esm/context/message.d.ts +0 -77
  150. package/esm/context/message.js +0 -167
  151. package/esm/context/message.js.map +0 -1
  152. package/esm/context/parse.d.ts +0 -13
  153. package/esm/context/parse.js +0 -39
  154. package/esm/context/parse.js.map +0 -1
  155. package/esm/context/pre-checkout-query.js +0 -23
  156. package/esm/context/pre-checkout-query.js.map +0 -1
  157. package/esm/context/scene-transition.js +0 -48
  158. package/esm/context/scene-transition.js.map +0 -1
  159. package/esm/dispatcher.d.ts +0 -881
  160. package/esm/dispatcher.js +0 -904
  161. package/esm/dispatcher.js.map +0 -1
  162. package/esm/filters/bots.d.ts +0 -64
  163. package/esm/filters/bots.js +0 -131
  164. package/esm/filters/bots.js.map +0 -1
  165. package/esm/filters/bundle.d.ts +0 -10
  166. package/esm/filters/bundle.js +0 -11
  167. package/esm/filters/bundle.js.map +0 -1
  168. package/esm/filters/chat.d.ts +0 -27
  169. package/esm/filters/chat.js +0 -51
  170. package/esm/filters/chat.js.map +0 -1
  171. package/esm/filters/group.js +0 -65
  172. package/esm/filters/group.js.map +0 -1
  173. package/esm/filters/index.d.ts +0 -4
  174. package/esm/filters/index.js +0 -3
  175. package/esm/filters/index.js.map +0 -1
  176. package/esm/filters/logic.d.ts +0 -29
  177. package/esm/filters/logic.js +0 -105
  178. package/esm/filters/logic.js.map +0 -1
  179. package/esm/filters/message.js +0 -168
  180. package/esm/filters/message.js.map +0 -1
  181. package/esm/filters/state.d.ts +0 -15
  182. package/esm/filters/state.js +0 -28
  183. package/esm/filters/state.js.map +0 -1
  184. package/esm/filters/text.js +0 -129
  185. package/esm/filters/text.js.map +0 -1
  186. package/esm/filters/types.d.ts +0 -91
  187. package/esm/filters/types.js +0 -2
  188. package/esm/filters/types.js.map +0 -1
  189. package/esm/filters/updates.d.ts +0 -39
  190. package/esm/filters/updates.js +0 -34
  191. package/esm/filters/updates.js.map +0 -1
  192. package/esm/filters/user.d.ts +0 -25
  193. package/esm/filters/user.js +0 -71
  194. package/esm/filters/user.js.map +0 -1
  195. package/esm/handler.d.ts +0 -41
  196. package/esm/handler.js +0 -3
  197. package/esm/handler.js.map +0 -1
  198. package/esm/index.d.ts +0 -8
  199. package/esm/index.js +0 -9
  200. package/esm/index.js.map +0 -1
  201. package/esm/propagation.d.ts +0 -22
  202. package/esm/propagation.js +0 -24
  203. package/esm/propagation.js.map +0 -1
  204. package/esm/state/index.d.ts +0 -5
  205. package/esm/state/index.js +0 -6
  206. package/esm/state/index.js.map +0 -1
  207. package/esm/state/key.d.ts +0 -24
  208. package/esm/state/key.js +0 -39
  209. package/esm/state/key.js.map +0 -1
  210. package/esm/state/provider.d.ts +0 -5
  211. package/esm/state/provider.js +0 -2
  212. package/esm/state/provider.js.map +0 -1
  213. package/esm/state/providers/index.d.ts +0 -2
  214. package/esm/state/providers/index.js +0 -3
  215. package/esm/state/providers/index.js.map +0 -1
  216. package/esm/state/providers/memory.d.ts +0 -30
  217. package/esm/state/providers/memory.js +0 -77
  218. package/esm/state/providers/memory.js.map +0 -1
  219. package/esm/state/providers/sqlite.js +0 -96
  220. package/esm/state/providers/sqlite.js.map +0 -1
  221. package/esm/state/repository.d.ts +0 -62
  222. package/esm/state/repository.js +0 -2
  223. package/esm/state/repository.js.map +0 -1
  224. package/esm/state/service.js +0 -66
  225. package/esm/state/service.js.map +0 -1
  226. package/esm/state/update-state.d.ts +0 -151
  227. package/esm/state/update-state.js +0 -214
  228. package/esm/state/update-state.js.map +0 -1
  229. package/esm/wizard.js +0 -101
  230. package/esm/wizard.js.map +0 -1
  231. /package/{cjs/context → context}/index.d.ts +0 -0
  232. /package/{cjs/filters → filters}/bundle.d.ts +0 -0
  233. /package/{cjs/filters → filters}/index.d.ts +0 -0
  234. /package/{cjs/index.d.ts → index.d.cts} +0 -0
  235. /package/{cjs/propagation.d.ts → propagation.d.ts} +0 -0
  236. /package/{cjs/state → state}/index.d.ts +0 -0
  237. /package/{cjs/state → state}/providers/index.d.ts +0 -0
package/package.json CHANGED
@@ -1,27 +1,31 @@
1
1
  {
2
- "name": "@mtcute/dispatcher",
3
- "type": "module",
4
- "version": "0.16.7",
5
- "description": "Updates dispatcher and bot framework for @mtcute/client",
6
- "author": "alina sireneva <alina@tei.su>",
7
- "license": "MIT",
8
- "sideEffects": false,
9
- "exports": {
10
- ".": {
11
- "import": "./esm/index.js",
12
- "require": "./cjs/index.js"
2
+ "name": "@mtcute/dispatcher",
3
+ "type": "module",
4
+ "version": "0.16.13",
5
+ "description": "Updates dispatcher and bot framework for @mtcute/client",
6
+ "author": "alina sireneva <alina@tei.su>",
7
+ "license": "MIT",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./index.d.ts",
13
+ "default": "./index.js"
14
+ },
15
+ "require": {
16
+ "types": "./index.d.cts",
17
+ "default": "./index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "scripts": {},
22
+ "dependencies": {
23
+ "@mtcute/core": "^0.16.13",
24
+ "events": "3.2.0"
25
+ },
26
+ "homepage": "https://mtcute.dev",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/mtcute/mtcute"
13
30
  }
14
- },
15
- "scripts": {},
16
- "dependencies": {
17
- "@mtcute/core": "^0.16.7",
18
- "events": "3.2.0"
19
- },
20
- "main": "cjs/index.js",
21
- "module": "esm/index.js",
22
- "homepage": "https://mtcute.dev",
23
- "repository": {
24
- "type": "git",
25
- "url": "https://github.com/mtcute/mtcute"
26
- }
27
31
  }
@@ -1,6 +1,6 @@
1
- import type { MaybePromise, Peer } from '@mtcute/core';
2
- import type { BusinessMessageContext } from '../context/business-message.js';
3
- import type { CallbackQueryContext, MessageContext } from '../context/index.js';
1
+ import { MaybePromise, Peer } from '@mtcute/core';
2
+ import { BusinessMessageContext } from '../context/business-message.js';
3
+ import { CallbackQueryContext, MessageContext } from '../context/index.js';
4
4
  /**
5
5
  * Function that determines how the state key is derived.
6
6
  *
@@ -0,0 +1,5 @@
1
+ import { IStorageProvider } from '@mtcute/core';
2
+ import { IStateRepository } from './repository.js';
3
+ export type IStateStorageProvider = IStorageProvider<{
4
+ state: IStateRepository;
5
+ }>;
@@ -1,7 +1,6 @@
1
- import type { MaybePromise } from '@mtcute/core';
2
- import { MemoryStorageDriver } from '@mtcute/core';
3
- import type { IStateStorageProvider } from '../provider.js';
4
- import type { IStateRepository } from '../repository.js';
1
+ import { MaybePromise, MemoryStorageDriver } from '@mtcute/core';
2
+ import { IStateStorageProvider } from '../provider.js';
3
+ import { IStateRepository } from '../repository.js';
5
4
  interface StateDto {
6
5
  value: string;
7
6
  expiresAt?: number;
@@ -1,6 +1,6 @@
1
- import type { BaseSqliteStorage, BaseSqliteStorageDriver, MaybePromise } from '@mtcute/core';
2
- import type { IStateStorageProvider } from '../provider.js';
3
- import type { IStateRepository } from '../repository.js';
1
+ import { BaseSqliteStorage, BaseSqliteStorageDriver, MaybePromise } from '@mtcute/core';
2
+ import { IStateStorageProvider } from '../provider.js';
3
+ import { IStateRepository } from '../repository.js';
4
4
  declare class SqliteStateRepository implements IStateRepository {
5
5
  readonly _driver: BaseSqliteStorageDriver;
6
6
  constructor(_driver: BaseSqliteStorageDriver);
@@ -1,4 +1,4 @@
1
- import type { MaybePromise } from '@mtcute/core';
1
+ import { MaybePromise } from '@mtcute/core';
2
2
  /**
3
3
  * Interface for FSM storage for the dispatcher.
4
4
  *
@@ -1,5 +1,5 @@
1
- import type { MaybePromise } from '@mtcute/core';
2
- import type { IStateStorageProvider } from './provider.js';
1
+ import { MaybePromise } from '@mtcute/core';
2
+ import { IStateStorageProvider } from './provider.js';
3
3
  export declare class StateService {
4
4
  readonly provider: IStateStorageProvider;
5
5
  constructor(provider: IStateStorageProvider);
@@ -1,6 +1,6 @@
1
1
  import { MtcuteError } from '@mtcute/core';
2
- import type { Dispatcher } from '../dispatcher.js';
3
- import type { StateService } from './service.js';
2
+ import { Dispatcher } from '../dispatcher.js';
3
+ import { StateService } from './service.js';
4
4
  /**
5
5
  * Error thrown by `.rateLimit()`
6
6
  */
@@ -1,9 +1,8 @@
1
- import type { MaybePromise } from '@mtcute/core';
2
- import type { MessageContext } from './context/message.js';
3
- import type { DispatcherParams } from './dispatcher.js';
4
- import { Dispatcher } from './dispatcher.js';
5
- import type { UpdateFilter } from './filters/index.js';
6
- import type { UpdateState } from './state/update-state.js';
1
+ import { MaybePromise } from '@mtcute/core';
2
+ import { MessageContext } from './context/message.js';
3
+ import { DispatcherParams, Dispatcher } from './dispatcher.js';
4
+ import { UpdateFilter } from './filters/index.js';
5
+ import { UpdateState } from './state/update-state.js';
7
6
  /**
8
7
  * Action for the wizard scene.
9
8
  *
@@ -1,141 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CallbackDataBuilder = void 0;
4
- const core_1 = require("@mtcute/core");
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
- prefix;
14
- _fields;
15
- sep = ':';
16
- /**
17
- * @param prefix Prefix for the data. Use something unique across your bot.
18
- * @param fields Field names in the order they will be serialized.
19
- */
20
- constructor(prefix, ...fields) {
21
- this.prefix = prefix;
22
- this._fields = fields;
23
- }
24
- /**
25
- * Build a callback data string
26
- *
27
- * @param obj Object containing the data
28
- */
29
- build(obj) {
30
- const ret = this.prefix
31
- + this.sep
32
- + this._fields
33
- .map((f) => {
34
- const val = obj[f];
35
- if (val.includes(this.sep)) {
36
- throw new core_1.MtArgumentError(`Value for ${f} ${val} contains separator ${this.sep} and cannot be used.`);
37
- }
38
- return val;
39
- })
40
- .join(this.sep);
41
- if (ret.length > 64) {
42
- throw new core_1.MtArgumentError('Resulting callback data is too long.');
43
- }
44
- return ret;
45
- }
46
- parse(data, safe = false) {
47
- const parts = data.split(this.sep);
48
- if (parts[0] !== this.prefix) {
49
- if (safe)
50
- return null;
51
- throw new core_1.MtArgumentError(`Invalid data passed: "${data}" (bad prefix, expected ${this.prefix}, got ${parts[0]})`);
52
- }
53
- if (parts.length !== this._fields.length + 1) {
54
- if (safe)
55
- return null;
56
- throw new core_1.MtArgumentError(`Invalid data passed: "${data}" (bad parts count, expected ${this._fields.length}, got ${parts.length - 1})`);
57
- }
58
- const ret = {};
59
- parts.forEach((it, idx) => {
60
- if (idx === 0)
61
- return; // skip prefix
62
- ret[this._fields[idx - 1]] = it;
63
- });
64
- return ret;
65
- }
66
- /**
67
- * Create a filter for this callback data.
68
- *
69
- * You can either pass an object with field names as keys and values as strings or regexes,
70
- * which will be compiled to a RegExp, or a function that will be called with the parsed data.
71
- * Note that the strings will be passed to `RegExp` **directly**, so you may want to escape them.
72
- *
73
- * When using a function, you can either return a boolean, or an object with field names as keys
74
- * and values as strings or regexes. In the latter case, the resulting object will be matched
75
- * against the parsed data the same way as if you passed it directly.
76
- *
77
- * @param params
78
- */
79
- filter(params = {}) {
80
- if (typeof params === 'function') {
81
- return async (query) => {
82
- if (!query.dataStr)
83
- return false;
84
- const data = this.parse(query.dataStr, true);
85
- if (!data)
86
- return false;
87
- const fnResult = await params(query, data);
88
- if (typeof fnResult === 'boolean') {
89
- query.match = data;
90
- return fnResult;
91
- }
92
- // validate result
93
- for (const key in fnResult) {
94
- const value = data[key];
95
- if (value === undefined)
96
- return false;
97
- let matchers = fnResult[key];
98
- if (!Array.isArray(matchers))
99
- matchers = [matchers];
100
- for (const matcher of matchers) {
101
- if (typeof matcher === 'string') {
102
- if (value !== matcher)
103
- return false;
104
- }
105
- else if (!matcher.test(value)) {
106
- return false;
107
- }
108
- }
109
- }
110
- query.match = data;
111
- return true;
112
- };
113
- }
114
- const parts = [];
115
- this._fields.forEach((field) => {
116
- if (!(field in params)) {
117
- parts.push(`[^${this.sep}]*?`);
118
- return;
119
- }
120
- const value = params[field];
121
- if (Array.isArray(value)) {
122
- parts.push(`(${value.map(i => (typeof i === 'string' ? i : i.source)).join('|')})`);
123
- }
124
- else {
125
- // noinspection SuspiciousTypeOfGuard
126
- parts.push(typeof value === 'string' ? value : value.source);
127
- }
128
- });
129
- const regex = new RegExp(`^${this.prefix}${this.sep}${parts.join(this.sep)}$`);
130
- return (query) => {
131
- const m = query.dataStr?.match(regex);
132
- if (!m) {
133
- return false;
134
- }
135
- query.match = this.parse(m[0]);
136
- return true;
137
- };
138
- }
139
- }
140
- exports.CallbackDataBuilder = CallbackDataBuilder;
141
- //# sourceMappingURL=callback-data-builder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"callback-data-builder.js","sourceRoot":"","sources":["../../src/callback-data-builder.ts"],"names":[],"mappings":";;;AAOA,uCAEqB;AAIrB;;;;;;GAMG;AACH,MAAa,mBAAmB;IAUjB;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,CAAC,GAAG,CAAC,CAAA;YACvF,CAAC;iBAAM,CAAC;gBACJ,qCAAqC;gBACrC,KAAK,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,KAAgB,CAAC,MAAM,CAAC,CAAA;YAC5E,CAAC;QACL,CAAC,CAAC,CAAA;QAEF,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAE9E,OAAO,CAAC,KAAK,EAAE,EAAE;YACb,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;YACrC,IAAI,CAAC,CAAC,EAAE,CAAC;gBACL,OAAO,KAAK,CAAA;YAChB,CAAC;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;AA7LD,kDA6LC","sourcesContent":["import type {\n BusinessCallbackQuery,\n CallbackQuery,\n InlineCallbackQuery,\n MaybeArray,\n MaybePromise,\n} from '@mtcute/core'\nimport {\n MtArgumentError,\n} from '@mtcute/core'\n\nimport type { 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 * @param safe If `true`, will return `null` instead of throwing on invalid data\n */\n parse(data: string, safe?: false): Record<T, string>\n parse(data: string, safe: true): Record<T, string> | null\n parse(data: string, safe = false): Record<T, string> | null {\n const parts = data.split(this.sep)\n\n if (parts[0] !== this.prefix) {\n if (safe) return null\n throw new MtArgumentError(\n `Invalid data passed: \"${data}\" (bad prefix, expected ${this.prefix}, got ${parts[0]})`,\n )\n }\n\n if (parts.length !== this._fields.length + 1) {\n if (safe) return null\n throw new MtArgumentError(\n `Invalid data passed: \"${data}\" (bad parts count, expected ${this._fields.length}, got ${\n parts.length - 1\n })`,\n )\n }\n\n const ret = {} as Record<T, string>\n parts.forEach((it, idx) => {\n if (idx === 0) return // skip prefix\n\n ret[this._fields[idx - 1]] = it\n })\n\n return ret\n }\n\n /**\n * Create a filter for this callback data.\n *\n * You can either pass an object with field names as keys and values as strings or regexes,\n * which will be compiled to a RegExp, or a function that will be called with the parsed data.\n * Note that the strings will be passed to `RegExp` **directly**, so you may want to escape them.\n *\n * When using a function, you can either return a boolean, or an object with field names as keys\n * and values as strings or regexes. In the latter case, the resulting object will be matched\n * against the parsed data the same way as if you passed it directly.\n *\n * @param params\n */\n filter<Update extends CallbackQuery | InlineCallbackQuery | BusinessCallbackQuery>(\n params:\n | ((\n upd: Update,\n parsed: Record<T, string>,\n ) => MaybePromise<Partial<Record<T, MaybeArray<string | RegExp>>> | boolean>)\n | Partial<Record<T, MaybeArray<string | RegExp>>> = {},\n ): UpdateFilter<\n Update,\n {\n match: Record<T, string>\n }\n > {\n if (typeof params === 'function') {\n return async (query) => {\n if (!query.dataStr) return false\n\n const data = this.parse(query.dataStr, true)\n if (!data) return false\n\n const fnResult = await params(query, data)\n\n if (typeof fnResult === 'boolean') {\n (\n query as Update & {\n match: Record<T, string>\n }\n ).match = data\n\n return fnResult\n }\n\n // validate result\n for (const key in fnResult) {\n const value = data[key]\n if (value === undefined) return false\n\n let matchers = fnResult[key] as MaybeArray<string | RegExp>\n if (!Array.isArray(matchers)) matchers = [matchers]\n\n for (const matcher of matchers) {\n if (typeof matcher === 'string') {\n if (value !== matcher) return false\n } else if (!matcher.test(value)) {\n return false\n }\n }\n }\n\n (\n query as Update & {\n match: Record<T, string>\n }\n ).match = data\n\n return true\n }\n }\n\n const parts: string[] = []\n\n this._fields.forEach((field) => {\n if (!(field in params)) {\n parts.push(`[^${this.sep}]*?`)\n\n return\n }\n\n const value = params[field]\n\n if (Array.isArray(value)) {\n parts.push(`(${value.map(i => (typeof i === 'string' ? i : i.source)).join('|')})`)\n } else {\n // noinspection SuspiciousTypeOfGuard\n parts.push(typeof value === 'string' ? value : (value as RegExp).source)\n }\n })\n\n const regex = new RegExp(`^${this.prefix}${this.sep}${parts.join(this.sep)}$`)\n\n return (query) => {\n const m = query.dataStr?.match(regex)\n if (!m) {\n return false\n }(\n query as Update & {\n match: Record<T, string>\n }\n ).match = this.parse(m[0])\n\n return true\n }\n }\n}\n"]}
@@ -1,9 +0,0 @@
1
- import type { ParsedUpdate } from '@mtcute/core';
2
- import type { TelegramClient } from '@mtcute/core/client.js';
3
- export type UpdateContext<T> = T & {
4
- client: TelegramClient;
5
- _name: Extract<ParsedUpdate, {
6
- data: T;
7
- }>['name'];
8
- };
9
- export type UpdateContextDistributed<T> = T extends never ? never : UpdateContext<T>;
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=base.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/context/base.ts"],"names":[],"mappings":"","sourcesContent":["import type { ParsedUpdate } from '@mtcute/core'\nimport type { TelegramClient } from '@mtcute/core/client.js'\n\nexport type UpdateContext<T> = T & {\n client: TelegramClient\n _name: Extract<ParsedUpdate, { data: T }>['name']\n}\n\nexport type UpdateContextDistributed<T> = T extends never ? never : UpdateContext<T>\n"]}
@@ -1,61 +0,0 @@
1
- import type { Message, OmitInputMessageId, ParametersSkip1, Sticker } from '@mtcute/core';
2
- import { BusinessMessage } from '@mtcute/core';
3
- import type { TelegramClient } from '@mtcute/core/client.js';
4
- import type { DeleteMessagesParams, ForwardMessageOptions, SendCopyGroupParams, SendCopyParams } from '@mtcute/core/methods.js';
5
- import type { UpdateContext } from './base.js';
6
- /**
7
- * Context of a business message related update.
8
- *
9
- * This is a subclass of {@link BusinessMessage}, so all fields
10
- * of the message are available.
11
- *
12
- * For message groups, own fields are related to the last message
13
- * in the group. To access all messages, use {@link BusinessMessageContext#messages}.
14
- */
15
- export declare class BusinessMessageContext extends BusinessMessage implements UpdateContext<BusinessMessage> {
16
- readonly client: TelegramClient;
17
- readonly _name = "new_business_message";
18
- /**
19
- * List of messages in the message group.
20
- *
21
- * For other updates, this is a list with a single element (`this`).
22
- */
23
- readonly messages: BusinessMessageContext[];
24
- /** Whether this update is about a message group */
25
- readonly isMessageGroup: boolean;
26
- constructor(client: TelegramClient, message: BusinessMessage | BusinessMessage[]);
27
- /** Get all custom emojis contained in this message (message group), if any */
28
- getCustomEmojis(): Promise<Sticker[]>;
29
- /** Send a text message to the same chat (and topic, if applicable) as a given message */
30
- answerText(...params: ParametersSkip1<TelegramClient['answerText']>): Promise<Message>;
31
- /** Send a media to the same chat (and topic, if applicable) as a given message */
32
- answerMedia(...params: ParametersSkip1<TelegramClient['answerMedia']>): Promise<Message>;
33
- /** Send a media group to the same chat (and topic, if applicable) as a given message */
34
- answerMediaGroup(...params: ParametersSkip1<TelegramClient['answerMediaGroup']>): Promise<Message[]>;
35
- /** Send a text message in reply to this message */
36
- replyText(...params: ParametersSkip1<TelegramClient['replyText']>): Promise<Message>;
37
- /** Send a media in reply to this message */
38
- replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>): Promise<Message>;
39
- /** Send a media group in reply to this message */
40
- replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>): Promise<Message[]>;
41
- /** Send a text message in reply to this message */
42
- quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]): Promise<Message>;
43
- /** Send a media in reply to this message */
44
- quoteWithMedia(params: Parameters<TelegramClient['quoteWithMedia']>[1]): Promise<Message>;
45
- /** Send a media group in reply to this message */
46
- quoteWithMediaGroup(params: Parameters<TelegramClient['quoteWithMediaGroup']>[1]): Promise<Message[]>;
47
- /** Delete this message (message group) */
48
- delete(params?: DeleteMessagesParams): Promise<void>;
49
- /** Pin this message */
50
- pin(params?: OmitInputMessageId<Parameters<TelegramClient['pinMessage']>[0]>): Promise<Message | null>;
51
- /** Unpin this message */
52
- unpin(): Promise<void>;
53
- /** Edit this message */
54
- edit(params: OmitInputMessageId<Parameters<TelegramClient['editMessage']>[0]>): Promise<Message>;
55
- /** Forward this message (message group) */
56
- forwardTo(params: ForwardMessageOptions): Promise<Message[]>;
57
- /** Send a copy of this message (message group) */
58
- copy(params: SendCopyParams & SendCopyGroupParams): Promise<Message | Message[]>;
59
- /** React to this message */
60
- react(params: OmitInputMessageId<Parameters<TelegramClient['sendReaction']>[0]>): Promise<Message | null>;
61
- }
@@ -1,146 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BusinessMessageContext = void 0;
4
- const core_1 = require("@mtcute/core");
5
- /**
6
- * Context of a business message related update.
7
- *
8
- * This is a subclass of {@link BusinessMessage}, so all fields
9
- * of the message are available.
10
- *
11
- * For message groups, own fields are related to the last message
12
- * in the group. To access all messages, use {@link BusinessMessageContext#messages}.
13
- */
14
- class BusinessMessageContext extends core_1.BusinessMessage {
15
- client;
16
- // this is primarily for proper types in filters, so don't bother much with actual value
17
- _name = 'new_business_message';
18
- /**
19
- * List of messages in the message group.
20
- *
21
- * For other updates, this is a list with a single element (`this`).
22
- */
23
- messages;
24
- /** Whether this update is about a message group */
25
- isMessageGroup;
26
- constructor(client, message) {
27
- const msg = Array.isArray(message) ? message[message.length - 1] : message;
28
- super(msg.update, msg._peers);
29
- this.client = client;
30
- this.messages = Array.isArray(message) ? message.map(it => new BusinessMessageContext(client, it)) : [this];
31
- this.isMessageGroup = Array.isArray(message);
32
- }
33
- /** Get all custom emojis contained in this message (message group), if any */
34
- getCustomEmojis() {
35
- return this.client.getCustomEmojisFromMessages(this.messages);
36
- }
37
- /** Send a text message to the same chat (and topic, if applicable) as a given message */
38
- answerText(...params) {
39
- const [send, params_ = {}] = params;
40
- params_.businessConnectionId = this.update.connectionId;
41
- return this.client.answerText(this, send, params_);
42
- }
43
- /** Send a media to the same chat (and topic, if applicable) as a given message */
44
- answerMedia(...params) {
45
- const [send, params_ = {}] = params;
46
- params_.businessConnectionId = this.update.connectionId;
47
- return this.client.answerMedia(this, send, params_);
48
- }
49
- /** Send a media group to the same chat (and topic, if applicable) as a given message */
50
- answerMediaGroup(...params) {
51
- const [send, params_ = {}] = params;
52
- params_.businessConnectionId = this.update.connectionId;
53
- return this.client.answerMediaGroup(this, send, params_);
54
- }
55
- /** Send a text message in reply to this message */
56
- replyText(...params) {
57
- const [send, params_ = {}] = params;
58
- params_.businessConnectionId = this.update.connectionId;
59
- return this.client.replyText(this, send, params_);
60
- }
61
- /** Send a media in reply to this message */
62
- replyMedia(...params) {
63
- const [send, params_ = {}] = params;
64
- params_.businessConnectionId = this.update.connectionId;
65
- return this.client.replyMedia(this, send, params_);
66
- }
67
- /** Send a media group in reply to this message */
68
- replyMediaGroup(...params) {
69
- const [send, params_ = {}] = params;
70
- params_.businessConnectionId = this.update.connectionId;
71
- return this.client.replyMediaGroup(this, send, params_);
72
- }
73
- /** Send a text message in reply to this message */
74
- quoteWithText(params) {
75
- params.businessConnectionId = this.update.connectionId;
76
- return this.client.quoteWithText(this, params);
77
- }
78
- /** Send a media in reply to this message */
79
- quoteWithMedia(params) {
80
- params.businessConnectionId = this.update.connectionId;
81
- return this.client.quoteWithMedia(this, params);
82
- }
83
- /** Send a media group in reply to this message */
84
- quoteWithMediaGroup(params) {
85
- params.businessConnectionId = this.update.connectionId;
86
- return this.client.quoteWithMediaGroup(this, params);
87
- }
88
- /** Delete this message (message group) */
89
- delete(params) {
90
- return this.client.deleteMessagesById(this.chat.inputPeer, this.messages.map(it => it.id), params);
91
- }
92
- /** Pin this message */
93
- pin(params) {
94
- return this.client.pinMessage({
95
- chatId: this.chat.inputPeer,
96
- message: this.id,
97
- ...params,
98
- });
99
- }
100
- /** Unpin this message */
101
- unpin() {
102
- return this.client.unpinMessage({
103
- chatId: this.chat.inputPeer,
104
- message: this.id,
105
- });
106
- }
107
- /** Edit this message */
108
- edit(params) {
109
- return this.client.editMessage({
110
- chatId: this.chat.inputPeer,
111
- message: this.id,
112
- ...params,
113
- });
114
- }
115
- /** Forward this message (message group) */
116
- forwardTo(params) {
117
- return this.client.forwardMessagesById({
118
- fromChatId: this.chat.inputPeer,
119
- messages: this.messages.map(it => it.id),
120
- ...params,
121
- });
122
- }
123
- /** Send a copy of this message (message group) */
124
- copy(params) {
125
- if (this.isMessageGroup) {
126
- return this.client.sendCopyGroup({
127
- messages: this.messages,
128
- ...params,
129
- });
130
- }
131
- return this.client.sendCopy({
132
- message: this,
133
- ...params,
134
- });
135
- }
136
- /** React to this message */
137
- react(params) {
138
- return this.client.sendReaction({
139
- chatId: this.chat.inputPeer,
140
- message: this.id,
141
- ...params,
142
- });
143
- }
144
- }
145
- exports.BusinessMessageContext = BusinessMessageContext;
146
- //# sourceMappingURL=business-message.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"business-message.js","sourceRoot":"","sources":["../../../src/context/business-message.ts"],"names":[],"mappings":";;;AACA,uCAA8C;AAW9C;;;;;;;;GAQG;AAC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AM;SACZ,CAAC,CAAA;IACN,CAAC;CACJ;AAtKD,wDAsKC","sourcesContent":["import type { Message, OmitInputMessageId, ParametersSkip1, Sticker } from '@mtcute/core'\nimport { BusinessMessage } from '@mtcute/core'\nimport type { TelegramClient } from '@mtcute/core/client.js'\nimport type {\n DeleteMessagesParams,\n ForwardMessageOptions,\n SendCopyGroupParams,\n SendCopyParams,\n} from '@mtcute/core/methods.js'\n\nimport type { UpdateContext } from './base.js'\n\n/**\n * Context of a business message related update.\n *\n * This is a subclass of {@link BusinessMessage}, so all fields\n * of the message are available.\n *\n * For message groups, own fields are related to the last message\n * in the group. To access all messages, use {@link BusinessMessageContext#messages}.\n */\nexport class BusinessMessageContext extends BusinessMessage implements UpdateContext<BusinessMessage> {\n // this is primarily for proper types in filters, so don't bother much with actual value\n readonly _name = 'new_business_message'\n\n /**\n * List of messages in the message group.\n *\n * For other updates, this is a list with a single element (`this`).\n */\n readonly messages: BusinessMessageContext[]\n\n /** Whether this update is about a message group */\n readonly isMessageGroup: boolean\n\n constructor(\n readonly client: TelegramClient,\n message: BusinessMessage | BusinessMessage[],\n ) {\n const msg = Array.isArray(message) ? message[message.length - 1] : message\n super(msg.update, msg._peers)\n\n this.messages = Array.isArray(message) ? message.map(it => new BusinessMessageContext(client, it)) : [this]\n this.isMessageGroup = Array.isArray(message)\n }\n\n /** Get all custom emojis contained in this message (message group), if any */\n getCustomEmojis(): Promise<Sticker[]> {\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']>): Promise<Message> {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.answerText(this, send, params_)\n }\n\n /** Send a media to the same chat (and topic, if applicable) as a given message */\n answerMedia(...params: ParametersSkip1<TelegramClient['answerMedia']>): Promise<Message> {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.answerMedia(this, send, params_)\n }\n\n /** Send a media group to the same chat (and topic, if applicable) as a given message */\n answerMediaGroup(...params: ParametersSkip1<TelegramClient['answerMediaGroup']>): Promise<Message[]> {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.answerMediaGroup(this, send, params_)\n }\n\n /** Send a text message in reply to this message */\n replyText(...params: ParametersSkip1<TelegramClient['replyText']>): Promise<Message> {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.replyText(this, send, params_)\n }\n\n /** Send a media in reply to this message */\n replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>): Promise<Message> {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.replyMedia(this, send, params_)\n }\n\n /** Send a media group in reply to this message */\n replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>): Promise<Message[]> {\n const [send, params_ = {}] = params\n params_.businessConnectionId = this.update.connectionId\n\n return this.client.replyMediaGroup(this, send, params_)\n }\n\n /** Send a text message in reply to this message */\n quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]): Promise<Message> {\n params.businessConnectionId = this.update.connectionId\n\n return this.client.quoteWithText(this, params)\n }\n\n /** Send a media in reply to this message */\n quoteWithMedia(params: Parameters<TelegramClient['quoteWithMedia']>[1]): Promise<Message> {\n params.businessConnectionId = this.update.connectionId\n\n return this.client.quoteWithMedia(this, params)\n }\n\n /** Send a media group in reply to this message */\n quoteWithMediaGroup(params: Parameters<TelegramClient['quoteWithMediaGroup']>[1]): Promise<Message[]> {\n params.businessConnectionId = this.update.connectionId\n\n return this.client.quoteWithMediaGroup(this, params)\n }\n\n /** Delete this message (message group) */\n delete(params?: DeleteMessagesParams): Promise<void> {\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]>): Promise<Message | null> {\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(): Promise<void> {\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]>): Promise<Message> {\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): Promise<Message[]> {\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): Promise<Message | Message[]> {\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]>): Promise<Message | null> {\n return this.client.sendReaction({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n}\n"]}
@@ -1,63 +0,0 @@
1
- import type { MaybePromise, Message } from '@mtcute/core';
2
- import { BusinessCallbackQuery, CallbackQuery, InlineCallbackQuery } from '@mtcute/core';
3
- import type { TelegramClient } from '@mtcute/core/client.js';
4
- import type { UpdateContext } from './base.js';
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
- export declare class CallbackQueryContext extends CallbackQuery implements UpdateContext<CallbackQuery> {
11
- readonly client: TelegramClient;
12
- readonly _name = "callback_query";
13
- constructor(client: TelegramClient, query: CallbackQuery);
14
- /** Answer to this callback query */
15
- answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]): Promise<void>;
16
- /**
17
- * Get the message containing the callback button being clicked.
18
- *
19
- * Note that the message may have been deleted, in which case
20
- * `null` will be returned.
21
- */
22
- getMessage(): Promise<Message | null>;
23
- /**
24
- * Edit the message that contained the callback button that was clicked.
25
- */
26
- editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>): Promise<Message>;
27
- /**
28
- * Shortcut for getting the message and editing it.
29
- */
30
- editMessageWith(handler: (msg: Message) => MaybePromise<Parameters<CallbackQueryContext['editMessage']>[0]>): Promise<Message | undefined>;
31
- }
32
- /**
33
- * Context of an inline-originated callback query update.
34
- *
35
- * This is a subclass of {@link InlineCallbackQuery}, so all its fields are also available.
36
- */
37
- export declare class InlineCallbackQueryContext extends InlineCallbackQuery implements UpdateContext<InlineCallbackQuery> {
38
- readonly client: TelegramClient;
39
- readonly _name = "inline_callback_query";
40
- constructor(client: TelegramClient, query: InlineCallbackQuery);
41
- /** Answer to this callback query */
42
- answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]): Promise<void>;
43
- /**
44
- * Edit the message that contained the callback button that was clicked.
45
- */
46
- editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>): Promise<void>;
47
- }
48
- /**
49
- * Context of an callback query update originated from a business connection message
50
- *
51
- * This is a subclass of {@link BusinessCallbackQuery}, so all its fields are also available.
52
- */
53
- export declare class BusinessCallbackQueryContext extends BusinessCallbackQuery implements UpdateContext<BusinessCallbackQuery> {
54
- readonly client: TelegramClient;
55
- readonly _name = "business_callback_query";
56
- constructor(client: TelegramClient, query: BusinessCallbackQuery);
57
- /** Answer to this callback query */
58
- answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]): Promise<void>;
59
- /**
60
- * Edit the message that contained the callback button that was clicked.
61
- */
62
- editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>): Promise<Message>;
63
- }