@mtcute/dispatcher 0.17.0 → 0.18.0-rc.5

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 (72) hide show
  1. package/callback-data-builder.cjs +126 -0
  2. package/callback-data-builder.js +121 -0
  3. package/context/business-message.cjs +143 -0
  4. package/context/business-message.js +138 -0
  5. package/context/callback-query.cjs +92 -0
  6. package/context/callback-query.js +87 -0
  7. package/context/chat-join-request.cjs +32 -0
  8. package/context/chat-join-request.d.ts +1 -1
  9. package/context/chat-join-request.js +27 -0
  10. package/context/chosen-inline-result.cjs +30 -0
  11. package/context/chosen-inline-result.d.ts +1 -1
  12. package/context/chosen-inline-result.js +25 -0
  13. package/context/inline-query.cjs +20 -0
  14. package/context/inline-query.js +15 -0
  15. package/context/message.cjs +182 -0
  16. package/context/message.d.ts +2 -2
  17. package/context/message.js +177 -0
  18. package/context/parse.cjs +45 -0
  19. package/context/parse.js +40 -0
  20. package/context/pre-checkout-query.cjs +24 -0
  21. package/context/pre-checkout-query.d.ts +1 -1
  22. package/context/pre-checkout-query.js +19 -0
  23. package/context/scene-transition.cjs +52 -0
  24. package/context/scene-transition.d.ts +1 -1
  25. package/context/scene-transition.js +47 -0
  26. package/dispatcher.cjs +860 -0
  27. package/dispatcher.d.ts +4 -4
  28. package/dispatcher.js +855 -0
  29. package/filters/bots.cjs +94 -0
  30. package/filters/bots.d.ts +2 -4
  31. package/filters/bots.js +89 -0
  32. package/filters/bundle.cjs +79 -0
  33. package/filters/bundle.js +74 -0
  34. package/filters/chat.cjs +43 -0
  35. package/filters/chat.d.ts +8 -6
  36. package/filters/chat.js +38 -0
  37. package/filters/group.cjs +49 -0
  38. package/filters/group.js +44 -0
  39. package/filters/logic.cjs +57 -0
  40. package/filters/logic.js +52 -0
  41. package/filters/message.cjs +130 -0
  42. package/filters/message.d.ts +5 -1
  43. package/filters/message.js +125 -0
  44. package/filters/state.cjs +21 -0
  45. package/filters/state.js +16 -0
  46. package/filters/text.cjs +87 -0
  47. package/filters/text.d.ts +2 -2
  48. package/filters/text.js +82 -0
  49. package/filters/updates.cjs +27 -0
  50. package/filters/updates.js +22 -0
  51. package/filters/user.cjs +57 -0
  52. package/filters/user.js +52 -0
  53. package/handler.d.ts +1 -1
  54. package/index.cjs +37 -2528
  55. package/index.js +16 -2507
  56. package/package.json +14 -13
  57. package/propagation.cjs +15 -0
  58. package/propagation.js +10 -0
  59. package/state/key.cjs +32 -0
  60. package/state/key.js +27 -0
  61. package/state/providers/memory.cjs +79 -0
  62. package/state/providers/memory.js +74 -0
  63. package/state/providers/sqlite.cjs +99 -0
  64. package/state/providers/sqlite.js +94 -0
  65. package/state/service.cjs +69 -0
  66. package/state/service.js +64 -0
  67. package/state/update-state.cjs +206 -0
  68. package/state/update-state.d.ts +1 -1
  69. package/state/update-state.js +201 -0
  70. package/wizard.cjs +90 -0
  71. package/wizard.js +85 -0
  72. package/index.d.cts +0 -8
@@ -0,0 +1,126 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const core = require("@mtcute/core");
9
+ class CallbackDataBuilder {
10
+ /**
11
+ * @param prefix Prefix for the data. Use something unique across your bot.
12
+ * @param fields Field names in the order they will be serialized.
13
+ */
14
+ constructor(prefix, ...fields) {
15
+ this.prefix = prefix;
16
+ this._fields = fields;
17
+ }
18
+ _fields;
19
+ sep = ":";
20
+ /**
21
+ * Build a callback data string
22
+ *
23
+ * @param obj Object containing the data
24
+ */
25
+ build(obj) {
26
+ const ret = this.prefix + this.sep + this._fields.map((f) => {
27
+ const val = obj[f];
28
+ if (val.includes(this.sep)) {
29
+ throw new core.MtArgumentError(
30
+ `Value for ${f} ${val} contains separator ${this.sep} and cannot be used.`
31
+ );
32
+ }
33
+ return val;
34
+ }).join(this.sep);
35
+ if (ret.length > 64) {
36
+ throw new core.MtArgumentError("Resulting callback data is too long.");
37
+ }
38
+ return ret;
39
+ }
40
+ parse(data, safe = false) {
41
+ const parts = data.split(this.sep);
42
+ if (parts[0] !== this.prefix) {
43
+ if (safe) return null;
44
+ throw new core.MtArgumentError(
45
+ `Invalid data passed: "${data}" (bad prefix, expected ${this.prefix}, got ${parts[0]})`
46
+ );
47
+ }
48
+ if (parts.length !== this._fields.length + 1) {
49
+ if (safe) return null;
50
+ throw new core.MtArgumentError(
51
+ `Invalid data passed: "${data}" (bad parts count, expected ${this._fields.length}, got ${parts.length - 1})`
52
+ );
53
+ }
54
+ const ret = {};
55
+ parts.forEach((it, idx) => {
56
+ if (idx === 0) return;
57
+ ret[this._fields[idx - 1]] = it;
58
+ });
59
+ return ret;
60
+ }
61
+ /**
62
+ * Create a filter for this callback data.
63
+ *
64
+ * You can either pass an object with field names as keys and values as strings or regexes,
65
+ * which will be compiled to a RegExp, or a function that will be called with the parsed data.
66
+ * Note that the strings will be passed to `RegExp` **directly**, so you may want to escape them.
67
+ *
68
+ * When using a function, you can either return a boolean, or an object with field names as keys
69
+ * and values as strings or regexes. In the latter case, the resulting object will be matched
70
+ * against the parsed data the same way as if you passed it directly.
71
+ *
72
+ * @param params
73
+ */
74
+ filter(params = {}) {
75
+ if (typeof params === "function") {
76
+ return async (query) => {
77
+ if (!query.dataStr) return false;
78
+ const data = this.parse(query.dataStr, true);
79
+ if (!data) return false;
80
+ const fnResult = await params(query, data);
81
+ if (typeof fnResult === "boolean") {
82
+ query.match = data;
83
+ return fnResult;
84
+ }
85
+ for (const key in fnResult) {
86
+ const value = data[key];
87
+ if (value === void 0) return false;
88
+ let matchers = fnResult[key];
89
+ if (!Array.isArray(matchers)) matchers = [matchers];
90
+ for (const matcher of matchers) {
91
+ if (typeof matcher === "string") {
92
+ if (value !== matcher) return false;
93
+ } else if (!matcher.test(value)) {
94
+ return false;
95
+ }
96
+ }
97
+ }
98
+ query.match = data;
99
+ return true;
100
+ };
101
+ }
102
+ const parts = [];
103
+ this._fields.forEach((field) => {
104
+ if (!(field in params)) {
105
+ parts.push(`[^${this.sep}]*?`);
106
+ return;
107
+ }
108
+ const value = params[field];
109
+ if (Array.isArray(value)) {
110
+ parts.push(`(${value.map((i) => typeof i === "string" ? i : i.source).join("|")})`);
111
+ } else {
112
+ parts.push(typeof value === "string" ? value : value.source);
113
+ }
114
+ });
115
+ const regex = new RegExp(`^${this.prefix}${this.sep}${parts.join(this.sep)}$`);
116
+ return (query) => {
117
+ const m = query.dataStr?.match(regex);
118
+ if (!m) {
119
+ return false;
120
+ }
121
+ query.match = this.parse(m[0]);
122
+ return true;
123
+ };
124
+ }
125
+ }
126
+ exports.CallbackDataBuilder = CallbackDataBuilder;
@@ -0,0 +1,121 @@
1
+ import { MtArgumentError } from "@mtcute/core";
2
+ class CallbackDataBuilder {
3
+ /**
4
+ * @param prefix Prefix for the data. Use something unique across your bot.
5
+ * @param fields Field names in the order they will be serialized.
6
+ */
7
+ constructor(prefix, ...fields) {
8
+ this.prefix = prefix;
9
+ this._fields = fields;
10
+ }
11
+ _fields;
12
+ sep = ":";
13
+ /**
14
+ * Build a callback data string
15
+ *
16
+ * @param obj Object containing the data
17
+ */
18
+ build(obj) {
19
+ const ret = this.prefix + this.sep + this._fields.map((f) => {
20
+ const val = obj[f];
21
+ if (val.includes(this.sep)) {
22
+ throw new MtArgumentError(
23
+ `Value for ${f} ${val} contains separator ${this.sep} and cannot be used.`
24
+ );
25
+ }
26
+ return val;
27
+ }).join(this.sep);
28
+ if (ret.length > 64) {
29
+ throw new MtArgumentError("Resulting callback data is too long.");
30
+ }
31
+ return ret;
32
+ }
33
+ parse(data, safe = false) {
34
+ const parts = data.split(this.sep);
35
+ if (parts[0] !== this.prefix) {
36
+ if (safe) return null;
37
+ throw new MtArgumentError(
38
+ `Invalid data passed: "${data}" (bad prefix, expected ${this.prefix}, got ${parts[0]})`
39
+ );
40
+ }
41
+ if (parts.length !== this._fields.length + 1) {
42
+ if (safe) return null;
43
+ throw new MtArgumentError(
44
+ `Invalid data passed: "${data}" (bad parts count, expected ${this._fields.length}, got ${parts.length - 1})`
45
+ );
46
+ }
47
+ const ret = {};
48
+ parts.forEach((it, idx) => {
49
+ if (idx === 0) return;
50
+ ret[this._fields[idx - 1]] = it;
51
+ });
52
+ return ret;
53
+ }
54
+ /**
55
+ * Create a filter for this callback data.
56
+ *
57
+ * You can either pass an object with field names as keys and values as strings or regexes,
58
+ * which will be compiled to a RegExp, or a function that will be called with the parsed data.
59
+ * Note that the strings will be passed to `RegExp` **directly**, so you may want to escape them.
60
+ *
61
+ * When using a function, you can either return a boolean, or an object with field names as keys
62
+ * and values as strings or regexes. In the latter case, the resulting object will be matched
63
+ * against the parsed data the same way as if you passed it directly.
64
+ *
65
+ * @param params
66
+ */
67
+ filter(params = {}) {
68
+ if (typeof params === "function") {
69
+ return async (query) => {
70
+ if (!query.dataStr) return false;
71
+ const data = this.parse(query.dataStr, true);
72
+ if (!data) return false;
73
+ const fnResult = await params(query, data);
74
+ if (typeof fnResult === "boolean") {
75
+ query.match = data;
76
+ return fnResult;
77
+ }
78
+ for (const key in fnResult) {
79
+ const value = data[key];
80
+ if (value === void 0) return false;
81
+ let matchers = fnResult[key];
82
+ if (!Array.isArray(matchers)) matchers = [matchers];
83
+ for (const matcher of matchers) {
84
+ if (typeof matcher === "string") {
85
+ if (value !== matcher) return false;
86
+ } else if (!matcher.test(value)) {
87
+ return false;
88
+ }
89
+ }
90
+ }
91
+ query.match = data;
92
+ return true;
93
+ };
94
+ }
95
+ const parts = [];
96
+ this._fields.forEach((field) => {
97
+ if (!(field in params)) {
98
+ parts.push(`[^${this.sep}]*?`);
99
+ return;
100
+ }
101
+ const value = params[field];
102
+ if (Array.isArray(value)) {
103
+ parts.push(`(${value.map((i) => typeof i === "string" ? i : i.source).join("|")})`);
104
+ } else {
105
+ parts.push(typeof value === "string" ? value : value.source);
106
+ }
107
+ });
108
+ const regex = new RegExp(`^${this.prefix}${this.sep}${parts.join(this.sep)}$`);
109
+ return (query) => {
110
+ const m = query.dataStr?.match(regex);
111
+ if (!m) {
112
+ return false;
113
+ }
114
+ query.match = this.parse(m[0]);
115
+ return true;
116
+ };
117
+ }
118
+ }
119
+ export {
120
+ CallbackDataBuilder
121
+ };
@@ -0,0 +1,143 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const core = require("@mtcute/core");
9
+ class BusinessMessageContext extends core.BusinessMessage {
10
+ constructor(client, message) {
11
+ const msg = Array.isArray(message) ? message[message.length - 1] : message;
12
+ super(msg.update, msg._peers);
13
+ this.client = client;
14
+ this.messages = Array.isArray(message) ? message.map((it) => new BusinessMessageContext(client, it)) : [this];
15
+ this.isMessageGroup = Array.isArray(message);
16
+ }
17
+ // this is primarily for proper types in filters, so don't bother much with actual value
18
+ _name = "new_business_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
+ messages;
25
+ /** Whether this update is about a message group */
26
+ isMessageGroup;
27
+ /** Get all custom emojis contained in this message (message group), if any */
28
+ getCustomEmojis() {
29
+ return this.client.getCustomEmojisFromMessages(this.messages);
30
+ }
31
+ /** Send a text message to the same chat (and topic, if applicable) as a given message */
32
+ answerText(...params) {
33
+ const [send, params_ = {}] = params;
34
+ params_.businessConnectionId = this.update.connectionId;
35
+ return this.client.answerText(this, send, params_);
36
+ }
37
+ /** Send a media to the same chat (and topic, if applicable) as a given message */
38
+ answerMedia(...params) {
39
+ const [send, params_ = {}] = params;
40
+ params_.businessConnectionId = this.update.connectionId;
41
+ return this.client.answerMedia(this, send, params_);
42
+ }
43
+ /** Send a media group to the same chat (and topic, if applicable) as a given message */
44
+ answerMediaGroup(...params) {
45
+ const [send, params_ = {}] = params;
46
+ params_.businessConnectionId = this.update.connectionId;
47
+ return this.client.answerMediaGroup(this, send, params_);
48
+ }
49
+ /** Send a text message in reply to this message */
50
+ replyText(...params) {
51
+ const [send, params_ = {}] = params;
52
+ params_.businessConnectionId = this.update.connectionId;
53
+ return this.client.replyText(this, send, params_);
54
+ }
55
+ /** Send a media in reply to this message */
56
+ replyMedia(...params) {
57
+ const [send, params_ = {}] = params;
58
+ params_.businessConnectionId = this.update.connectionId;
59
+ return this.client.replyMedia(this, send, params_);
60
+ }
61
+ /** Send a media group in reply to this message */
62
+ replyMediaGroup(...params) {
63
+ const [send, params_ = {}] = params;
64
+ params_.businessConnectionId = this.update.connectionId;
65
+ return this.client.replyMediaGroup(this, send, params_);
66
+ }
67
+ /** Send a text message in reply to this message */
68
+ quoteWithText(params) {
69
+ params.businessConnectionId = this.update.connectionId;
70
+ return this.client.quoteWithText(this, params);
71
+ }
72
+ /** Send a media in reply to this message */
73
+ quoteWithMedia(params) {
74
+ params.businessConnectionId = this.update.connectionId;
75
+ return this.client.quoteWithMedia(this, params);
76
+ }
77
+ /** Send a media group in reply to this message */
78
+ quoteWithMediaGroup(params) {
79
+ params.businessConnectionId = this.update.connectionId;
80
+ return this.client.quoteWithMediaGroup(this, params);
81
+ }
82
+ /** Delete this message (message group) */
83
+ delete(params) {
84
+ return this.client.deleteMessagesById(
85
+ this.chat.inputPeer,
86
+ this.messages.map((it) => it.id),
87
+ params
88
+ );
89
+ }
90
+ /** Pin this message */
91
+ pin(params) {
92
+ return this.client.pinMessage({
93
+ chatId: this.chat.inputPeer,
94
+ message: this.id,
95
+ ...params
96
+ });
97
+ }
98
+ /** Unpin this message */
99
+ unpin() {
100
+ return this.client.unpinMessage({
101
+ chatId: this.chat.inputPeer,
102
+ message: this.id
103
+ });
104
+ }
105
+ /** Edit this message */
106
+ edit(params) {
107
+ return this.client.editMessage({
108
+ chatId: this.chat.inputPeer,
109
+ message: this.id,
110
+ ...params
111
+ });
112
+ }
113
+ /** Forward this message (message group) */
114
+ forwardTo(params) {
115
+ return this.client.forwardMessagesById({
116
+ fromChatId: this.chat.inputPeer,
117
+ messages: this.messages.map((it) => it.id),
118
+ ...params
119
+ });
120
+ }
121
+ /** Send a copy of this message (message group) */
122
+ copy(params) {
123
+ if (this.isMessageGroup) {
124
+ return this.client.sendCopyGroup({
125
+ messages: this.messages,
126
+ ...params
127
+ });
128
+ }
129
+ return this.client.sendCopy({
130
+ message: this,
131
+ ...params
132
+ });
133
+ }
134
+ /** React to this message */
135
+ react(params) {
136
+ return this.client.sendReaction({
137
+ chatId: this.chat.inputPeer,
138
+ message: this.id,
139
+ ...params
140
+ });
141
+ }
142
+ }
143
+ exports.BusinessMessageContext = BusinessMessageContext;
@@ -0,0 +1,138 @@
1
+ import { BusinessMessage } from "@mtcute/core";
2
+ class BusinessMessageContext extends BusinessMessage {
3
+ constructor(client, message) {
4
+ const msg = Array.isArray(message) ? message[message.length - 1] : message;
5
+ super(msg.update, msg._peers);
6
+ this.client = client;
7
+ this.messages = Array.isArray(message) ? message.map((it) => new BusinessMessageContext(client, it)) : [this];
8
+ this.isMessageGroup = Array.isArray(message);
9
+ }
10
+ // this is primarily for proper types in filters, so don't bother much with actual value
11
+ _name = "new_business_message";
12
+ /**
13
+ * List of messages in the message group.
14
+ *
15
+ * For other updates, this is a list with a single element (`this`).
16
+ */
17
+ messages;
18
+ /** Whether this update is about a message group */
19
+ isMessageGroup;
20
+ /** Get all custom emojis contained in this message (message group), if any */
21
+ getCustomEmojis() {
22
+ return this.client.getCustomEmojisFromMessages(this.messages);
23
+ }
24
+ /** Send a text message to the same chat (and topic, if applicable) as a given message */
25
+ answerText(...params) {
26
+ const [send, params_ = {}] = params;
27
+ params_.businessConnectionId = this.update.connectionId;
28
+ return this.client.answerText(this, send, params_);
29
+ }
30
+ /** Send a media to the same chat (and topic, if applicable) as a given message */
31
+ answerMedia(...params) {
32
+ const [send, params_ = {}] = params;
33
+ params_.businessConnectionId = this.update.connectionId;
34
+ return this.client.answerMedia(this, send, params_);
35
+ }
36
+ /** Send a media group to the same chat (and topic, if applicable) as a given message */
37
+ answerMediaGroup(...params) {
38
+ const [send, params_ = {}] = params;
39
+ params_.businessConnectionId = this.update.connectionId;
40
+ return this.client.answerMediaGroup(this, send, params_);
41
+ }
42
+ /** Send a text message in reply to this message */
43
+ replyText(...params) {
44
+ const [send, params_ = {}] = params;
45
+ params_.businessConnectionId = this.update.connectionId;
46
+ return this.client.replyText(this, send, params_);
47
+ }
48
+ /** Send a media in reply to this message */
49
+ replyMedia(...params) {
50
+ const [send, params_ = {}] = params;
51
+ params_.businessConnectionId = this.update.connectionId;
52
+ return this.client.replyMedia(this, send, params_);
53
+ }
54
+ /** Send a media group in reply to this message */
55
+ replyMediaGroup(...params) {
56
+ const [send, params_ = {}] = params;
57
+ params_.businessConnectionId = this.update.connectionId;
58
+ return this.client.replyMediaGroup(this, send, params_);
59
+ }
60
+ /** Send a text message in reply to this message */
61
+ quoteWithText(params) {
62
+ params.businessConnectionId = this.update.connectionId;
63
+ return this.client.quoteWithText(this, params);
64
+ }
65
+ /** Send a media in reply to this message */
66
+ quoteWithMedia(params) {
67
+ params.businessConnectionId = this.update.connectionId;
68
+ return this.client.quoteWithMedia(this, params);
69
+ }
70
+ /** Send a media group in reply to this message */
71
+ quoteWithMediaGroup(params) {
72
+ params.businessConnectionId = this.update.connectionId;
73
+ return this.client.quoteWithMediaGroup(this, params);
74
+ }
75
+ /** Delete this message (message group) */
76
+ delete(params) {
77
+ return this.client.deleteMessagesById(
78
+ this.chat.inputPeer,
79
+ this.messages.map((it) => it.id),
80
+ params
81
+ );
82
+ }
83
+ /** Pin this message */
84
+ pin(params) {
85
+ return this.client.pinMessage({
86
+ chatId: this.chat.inputPeer,
87
+ message: this.id,
88
+ ...params
89
+ });
90
+ }
91
+ /** Unpin this message */
92
+ unpin() {
93
+ return this.client.unpinMessage({
94
+ chatId: this.chat.inputPeer,
95
+ message: this.id
96
+ });
97
+ }
98
+ /** Edit this message */
99
+ edit(params) {
100
+ return this.client.editMessage({
101
+ chatId: this.chat.inputPeer,
102
+ message: this.id,
103
+ ...params
104
+ });
105
+ }
106
+ /** Forward this message (message group) */
107
+ forwardTo(params) {
108
+ return this.client.forwardMessagesById({
109
+ fromChatId: this.chat.inputPeer,
110
+ messages: this.messages.map((it) => it.id),
111
+ ...params
112
+ });
113
+ }
114
+ /** Send a copy of this message (message group) */
115
+ copy(params) {
116
+ if (this.isMessageGroup) {
117
+ return this.client.sendCopyGroup({
118
+ messages: this.messages,
119
+ ...params
120
+ });
121
+ }
122
+ return this.client.sendCopy({
123
+ message: this,
124
+ ...params
125
+ });
126
+ }
127
+ /** React to this message */
128
+ react(params) {
129
+ return this.client.sendReaction({
130
+ chatId: this.chat.inputPeer,
131
+ message: this.id,
132
+ ...params
133
+ });
134
+ }
135
+ }
136
+ export {
137
+ BusinessMessageContext
138
+ };
@@ -0,0 +1,92 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const core = require("@mtcute/core");
9
+ class CallbackQueryContext extends core.CallbackQuery {
10
+ constructor(client, query) {
11
+ super(query.raw, query._peers);
12
+ this.client = client;
13
+ }
14
+ _name = "callback_query";
15
+ /** Answer to this callback query */
16
+ answer(params) {
17
+ return this.client.answerCallbackQuery(this.id, params);
18
+ }
19
+ /**
20
+ * Get the message containing the callback button being clicked.
21
+ *
22
+ * Note that the message may have been deleted, in which case
23
+ * `null` will be returned.
24
+ */
25
+ async getMessage() {
26
+ return this.client.getCallbackQueryMessage(this);
27
+ }
28
+ /**
29
+ * Edit the message that contained the callback button that was clicked.
30
+ */
31
+ async editMessage(params) {
32
+ return this.client.editMessage({
33
+ chatId: this.raw.peer,
34
+ message: this.raw.msgId,
35
+ ...params
36
+ });
37
+ }
38
+ /**
39
+ * Shortcut for getting the message and editing it.
40
+ */
41
+ async editMessageWith(handler) {
42
+ const msg = await this.getMessage();
43
+ if (!msg) return;
44
+ const res = await handler(msg);
45
+ if (!res) return;
46
+ return this.editMessage(res);
47
+ }
48
+ }
49
+ class InlineCallbackQueryContext extends core.InlineCallbackQuery {
50
+ constructor(client, query) {
51
+ super(query.raw, query._peers);
52
+ this.client = client;
53
+ }
54
+ _name = "inline_callback_query";
55
+ /** Answer to this callback query */
56
+ answer(params) {
57
+ return this.client.answerCallbackQuery(this.id, params);
58
+ }
59
+ /**
60
+ * Edit the message that contained the callback button that was clicked.
61
+ */
62
+ async editMessage(params) {
63
+ return this.client.editInlineMessage({
64
+ messageId: this.raw.msgId,
65
+ ...params
66
+ });
67
+ }
68
+ }
69
+ class BusinessCallbackQueryContext extends core.BusinessCallbackQuery {
70
+ constructor(client, query) {
71
+ super(query.raw, query._peers);
72
+ this.client = client;
73
+ }
74
+ _name = "business_callback_query";
75
+ /** Answer to this callback query */
76
+ answer(params) {
77
+ return this.client.answerCallbackQuery(this.id, params);
78
+ }
79
+ /**
80
+ * Edit the message that contained the callback button that was clicked.
81
+ */
82
+ async editMessage(params) {
83
+ return this.client.editMessage({
84
+ message: this.message,
85
+ businessConnectionId: this.connectionId,
86
+ ...params
87
+ });
88
+ }
89
+ }
90
+ exports.BusinessCallbackQueryContext = BusinessCallbackQueryContext;
91
+ exports.CallbackQueryContext = CallbackQueryContext;
92
+ exports.InlineCallbackQueryContext = InlineCallbackQueryContext;