@mtcute/dispatcher 0.17.2 → 0.18.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.
Files changed (111) hide show
  1. package/callback-data-builder.cjs +126 -0
  2. package/callback-data-builder.d.cts +49 -0
  3. package/callback-data-builder.js +121 -0
  4. package/callback-data-builder.test.d.cts +1 -0
  5. package/context/base.d.cts +9 -0
  6. package/context/business-message.cjs +143 -0
  7. package/context/business-message.d.cts +60 -0
  8. package/context/business-message.js +138 -0
  9. package/context/callback-query.cjs +92 -0
  10. package/context/callback-query.d.cts +62 -0
  11. package/context/callback-query.js +87 -0
  12. package/context/chat-join-request.cjs +32 -0
  13. package/context/chat-join-request.d.cts +17 -0
  14. package/context/chat-join-request.d.ts +1 -1
  15. package/context/chat-join-request.js +27 -0
  16. package/context/chosen-inline-result.cjs +30 -0
  17. package/context/chosen-inline-result.d.cts +22 -0
  18. package/context/chosen-inline-result.d.ts +1 -1
  19. package/context/chosen-inline-result.js +25 -0
  20. package/context/index.d.cts +9 -0
  21. package/context/inline-query.cjs +20 -0
  22. package/context/inline-query.d.cts +15 -0
  23. package/context/inline-query.js +15 -0
  24. package/context/message.cjs +182 -0
  25. package/context/message.d.cts +82 -0
  26. package/context/message.d.ts +2 -2
  27. package/context/message.js +177 -0
  28. package/context/parse.cjs +45 -0
  29. package/context/parse.d.cts +13 -0
  30. package/context/parse.js +40 -0
  31. package/context/pre-checkout-query.cjs +24 -0
  32. package/context/pre-checkout-query.d.cts +17 -0
  33. package/context/pre-checkout-query.d.ts +1 -1
  34. package/context/pre-checkout-query.js +19 -0
  35. package/context/scene-transition.cjs +52 -0
  36. package/context/scene-transition.d.cts +24 -0
  37. package/context/scene-transition.d.ts +1 -1
  38. package/context/scene-transition.js +47 -0
  39. package/dispatcher.cjs +860 -0
  40. package/dispatcher.d.cts +880 -0
  41. package/dispatcher.d.ts +4 -4
  42. package/dispatcher.js +855 -0
  43. package/filters/bots.cjs +94 -0
  44. package/filters/bots.d.cts +62 -0
  45. package/filters/bots.d.ts +2 -4
  46. package/filters/bots.js +89 -0
  47. package/filters/bots.test.d.cts +1 -0
  48. package/filters/bundle.cjs +79 -0
  49. package/filters/bundle.d.cts +10 -0
  50. package/filters/bundle.js +74 -0
  51. package/filters/chat.cjs +43 -0
  52. package/filters/chat.d.cts +29 -0
  53. package/filters/chat.d.ts +8 -6
  54. package/filters/chat.js +38 -0
  55. package/filters/group.cjs +49 -0
  56. package/filters/group.d.cts +26 -0
  57. package/filters/group.js +44 -0
  58. package/filters/index.d.cts +4 -0
  59. package/filters/logic.cjs +57 -0
  60. package/filters/logic.d.cts +29 -0
  61. package/filters/logic.js +52 -0
  62. package/filters/logic.test.d.cts +1 -0
  63. package/filters/message.cjs +130 -0
  64. package/filters/message.d.cts +223 -0
  65. package/filters/message.d.ts +5 -1
  66. package/filters/message.js +125 -0
  67. package/filters/state.cjs +21 -0
  68. package/filters/state.d.cts +15 -0
  69. package/filters/state.js +16 -0
  70. package/filters/text.cjs +87 -0
  71. package/filters/text.d.cts +64 -0
  72. package/filters/text.d.ts +2 -2
  73. package/filters/text.js +82 -0
  74. package/filters/types.d.cts +91 -0
  75. package/filters/updates.cjs +27 -0
  76. package/filters/updates.d.cts +39 -0
  77. package/filters/updates.js +22 -0
  78. package/filters/user.cjs +57 -0
  79. package/filters/user.d.cts +24 -0
  80. package/filters/user.js +52 -0
  81. package/handler.d.cts +41 -0
  82. package/handler.d.ts +1 -1
  83. package/index.cjs +37 -2528
  84. package/index.js +16 -2507
  85. package/package.json +10 -9
  86. package/propagation.cjs +15 -0
  87. package/propagation.d.cts +22 -0
  88. package/propagation.js +10 -0
  89. package/state/index.d.cts +5 -0
  90. package/state/key.cjs +32 -0
  91. package/state/key.d.cts +24 -0
  92. package/state/key.js +27 -0
  93. package/state/provider.d.cts +5 -0
  94. package/state/providers/index.d.cts +2 -0
  95. package/state/providers/memory.cjs +79 -0
  96. package/state/providers/memory.d.cts +29 -0
  97. package/state/providers/memory.js +74 -0
  98. package/state/providers/sqlite.cjs +99 -0
  99. package/state/providers/sqlite.d.cts +28 -0
  100. package/state/providers/sqlite.js +94 -0
  101. package/state/repository.d.cts +62 -0
  102. package/state/service.cjs +69 -0
  103. package/state/service.d.cts +20 -0
  104. package/state/service.js +64 -0
  105. package/state/update-state.cjs +206 -0
  106. package/state/update-state.d.cts +151 -0
  107. package/state/update-state.d.ts +1 -1
  108. package/state/update-state.js +201 -0
  109. package/wizard.cjs +90 -0
  110. package/wizard.d.cts +64 -0
  111. package/wizard.js +85 -0
@@ -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,49 @@
1
+ import { BusinessCallbackQuery, CallbackQuery, InlineCallbackQuery, MaybeArray, MaybePromise } from '@mtcute/core';
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
+ * @param safe If `true`, will return `null` instead of throwing on invalid data
30
+ */
31
+ parse(data: string, safe?: false): Record<T, string>;
32
+ parse(data: string, safe: true): Record<T, string> | null;
33
+ /**
34
+ * Create a filter for this callback data.
35
+ *
36
+ * You can either pass an object with field names as keys and values as strings or regexes,
37
+ * which will be compiled to a RegExp, or a function that will be called with the parsed data.
38
+ * Note that the strings will be passed to `RegExp` **directly**, so you may want to escape them.
39
+ *
40
+ * When using a function, you can either return a boolean, or an object with field names as keys
41
+ * and values as strings or regexes. In the latter case, the resulting object will be matched
42
+ * against the parsed data the same way as if you passed it directly.
43
+ *
44
+ * @param params
45
+ */
46
+ filter<Update extends CallbackQuery | InlineCallbackQuery | BusinessCallbackQuery>(params?: ((upd: Update, parsed: Record<T, string>) => MaybePromise<Partial<Record<T, MaybeArray<string | RegExp>>> | boolean>) | Partial<Record<T, MaybeArray<string | RegExp>>>): UpdateFilter<Update, {
47
+ match: Record<T, string>;
48
+ }>;
49
+ }
@@ -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 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { ParsedUpdate } from '@mtcute/core';
2
+ import { 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>;
@@ -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,60 @@
1
+ import { Message, OmitInputMessageId, ParametersSkip1, Sticker, BusinessMessage } from '@mtcute/core';
2
+ import { TelegramClient } from '@mtcute/core/client.js';
3
+ import { DeleteMessagesParams, ForwardMessageOptions, SendCopyGroupParams, SendCopyParams } from '@mtcute/core/methods.js';
4
+ import { UpdateContext } from './base.js';
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
+ export declare class BusinessMessageContext extends BusinessMessage implements UpdateContext<BusinessMessage> {
15
+ readonly client: TelegramClient;
16
+ readonly _name: "new_business_message";
17
+ /**
18
+ * List of messages in the message group.
19
+ *
20
+ * For other updates, this is a list with a single element (`this`).
21
+ */
22
+ readonly messages: BusinessMessageContext[];
23
+ /** Whether this update is about a message group */
24
+ readonly isMessageGroup: boolean;
25
+ constructor(client: TelegramClient, message: BusinessMessage | BusinessMessage[]);
26
+ /** Get all custom emojis contained in this message (message group), if any */
27
+ getCustomEmojis(): Promise<Sticker[]>;
28
+ /** Send a text message to the same chat (and topic, if applicable) as a given message */
29
+ answerText(...params: ParametersSkip1<TelegramClient['answerText']>): Promise<Message>;
30
+ /** Send a media to the same chat (and topic, if applicable) as a given message */
31
+ answerMedia(...params: ParametersSkip1<TelegramClient['answerMedia']>): Promise<Message>;
32
+ /** Send a media group to the same chat (and topic, if applicable) as a given message */
33
+ answerMediaGroup(...params: ParametersSkip1<TelegramClient['answerMediaGroup']>): Promise<Message[]>;
34
+ /** Send a text message in reply to this message */
35
+ replyText(...params: ParametersSkip1<TelegramClient['replyText']>): Promise<Message>;
36
+ /** Send a media in reply to this message */
37
+ replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>): Promise<Message>;
38
+ /** Send a media group in reply to this message */
39
+ replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>): Promise<Message[]>;
40
+ /** Send a text message in reply to this message */
41
+ quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]): Promise<Message>;
42
+ /** Send a media in reply to this message */
43
+ quoteWithMedia(params: Parameters<TelegramClient['quoteWithMedia']>[1]): Promise<Message>;
44
+ /** Send a media group in reply to this message */
45
+ quoteWithMediaGroup(params: Parameters<TelegramClient['quoteWithMediaGroup']>[1]): Promise<Message[]>;
46
+ /** Delete this message (message group) */
47
+ delete(params?: DeleteMessagesParams): Promise<void>;
48
+ /** Pin this message */
49
+ pin(params?: OmitInputMessageId<Parameters<TelegramClient['pinMessage']>[0]>): Promise<Message | null>;
50
+ /** Unpin this message */
51
+ unpin(): Promise<void>;
52
+ /** Edit this message */
53
+ edit(params: OmitInputMessageId<Parameters<TelegramClient['editMessage']>[0]>): Promise<Message>;
54
+ /** Forward this message (message group) */
55
+ forwardTo(params: ForwardMessageOptions): Promise<Message[]>;
56
+ /** Send a copy of this message (message group) */
57
+ copy(params: SendCopyParams & SendCopyGroupParams): Promise<Message | Message[]>;
58
+ /** React to this message */
59
+ react(params: OmitInputMessageId<Parameters<TelegramClient['sendReaction']>[0]>): Promise<Message | null>;
60
+ }
@@ -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
+ };