@mtkruto/node 0.0.993 → 0.0.994
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/5_client.d.ts +2 -1
- package/esm/5_client.js +2 -1
- package/esm/client/0_message.d.ts +3 -3
- package/esm/client/0_message.js +3 -3
- package/esm/client/0_utilities.d.ts +2 -0
- package/esm/client/0_utilities.js +1 -0
- package/esm/client/3_types.d.ts +221 -0
- package/esm/client/3_types.js +1 -0
- package/esm/client/4_composer.d.ts +13 -0
- package/esm/client/4_composer.js +80 -0
- package/esm/client/5_client.d.ts +207 -0
- package/esm/client/{3_client.js → 5_client.js} +92 -153
- package/esm/mod.d.ts +1 -1
- package/esm/mod.js +1 -1
- package/esm/tl/6_message.d.ts +2 -2
- package/esm/tl/6_message.js +2 -2
- package/esm/tl/7_message_container.d.ts +3 -3
- package/esm/tl/7_message_container.js +2 -2
- package/package.json +1 -1
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/5_client.d.ts +2 -1
- package/script/5_client.js +4 -1
- package/script/client/0_message.d.ts +3 -3
- package/script/client/0_message.js +2 -2
- package/script/client/0_utilities.d.ts +2 -0
- package/script/client/0_utilities.js +3 -1
- package/script/client/3_types.d.ts +221 -0
- package/script/client/3_types.js +2 -0
- package/script/client/4_composer.d.ts +13 -0
- package/script/client/4_composer.js +85 -0
- package/script/client/5_client.d.ts +207 -0
- package/script/client/{3_client.js → 5_client.js} +91 -151
- package/script/mod.d.ts +1 -1
- package/script/mod.js +2 -14
- package/script/tl/6_message.d.ts +2 -2
- package/script/tl/6_message.js +4 -4
- package/script/tl/7_message_container.d.ts +3 -3
- package/script/tl/7_message_container.js +1 -1
- package/esm/client/3_client.d.ts +0 -414
- package/script/client/3_client.d.ts +0 -414
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Client = exports.
|
|
3
|
+
exports.Client = exports.restartAuth = exports.getMessageWithReply = exports.handleMigrationError = exports.getStickerSetName = exports.getEntity = void 0;
|
|
4
4
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
5
5
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
6
6
|
const _2_tl_js_1 = require("../2_tl.js");
|
|
@@ -13,6 +13,7 @@ const _0_password_js_1 = require("./0_password.js");
|
|
|
13
13
|
const _0_html_js_1 = require("./0_html.js");
|
|
14
14
|
const _2_client_plain_js_1 = require("./2_client_plain.js");
|
|
15
15
|
const _1_client_abstract_js_1 = require("./1_client_abstract.js");
|
|
16
|
+
const _4_composer_js_1 = require("./4_composer.js");
|
|
16
17
|
const d = (0, _0_deps_js_1.debug)("Client");
|
|
17
18
|
const dGap = (0, _0_deps_js_1.debug)("Client/recoverUpdateGap");
|
|
18
19
|
const dGapC = (0, _0_deps_js_1.debug)("Client/recoverChannelUpdateGap");
|
|
@@ -23,11 +24,6 @@ exports.getStickerSetName = Symbol();
|
|
|
23
24
|
exports.handleMigrationError = Symbol();
|
|
24
25
|
exports.getMessageWithReply = Symbol();
|
|
25
26
|
exports.restartAuth = Symbol();
|
|
26
|
-
var ParseMode;
|
|
27
|
-
(function (ParseMode) {
|
|
28
|
-
ParseMode["None"] = "none";
|
|
29
|
-
ParseMode["HTML"] = "html";
|
|
30
|
-
})(ParseMode = exports.ParseMode || (exports.ParseMode = {}));
|
|
31
27
|
class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
32
28
|
/**
|
|
33
29
|
* Constructs the client.
|
|
@@ -220,7 +216,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
220
216
|
writable: true,
|
|
221
217
|
value: new _1_utilities_js_1.Queue("processUpdates")
|
|
222
218
|
});
|
|
223
|
-
Object.defineProperty(this, "
|
|
219
|
+
Object.defineProperty(this, "_handler", {
|
|
224
220
|
enumerable: true,
|
|
225
221
|
configurable: true,
|
|
226
222
|
writable: true,
|
|
@@ -228,7 +224,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
228
224
|
next();
|
|
229
225
|
}
|
|
230
226
|
});
|
|
231
|
-
this.parseMode = params?.parseMode ??
|
|
227
|
+
this.parseMode = params?.parseMode ?? "none";
|
|
232
228
|
this.appVersion = params?.appVersion ?? _4_constants_js_1.APP_VERSION;
|
|
233
229
|
this.deviceModel = params?.deviceModel ?? _4_constants_js_1.DEVICE_MODEL;
|
|
234
230
|
this.langCode = params?.langCode ?? _4_constants_js_1.LANG_CODE;
|
|
@@ -239,7 +235,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
239
235
|
this.autoStart = params?.autoStart ?? true;
|
|
240
236
|
}
|
|
241
237
|
propagateConnectionState(connectionState) {
|
|
242
|
-
return this.
|
|
238
|
+
return this._handler({ connectionState }, _0_utilities_js_1.resolve);
|
|
243
239
|
}
|
|
244
240
|
/**
|
|
245
241
|
* Sets the DC and resets the auth key stored in the session provider
|
|
@@ -312,6 +308,16 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
312
308
|
release();
|
|
313
309
|
}
|
|
314
310
|
}
|
|
311
|
+
async assertUser(source) {
|
|
312
|
+
if (await this.storage.getAccountType() != "user") {
|
|
313
|
+
throw new Error(`${source}: not user a client`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
async assertBot(source) {
|
|
317
|
+
if (await this.storage.getAccountType() != "bot") {
|
|
318
|
+
throw new Error(`${source}: not a bot client`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
315
321
|
async fetchState(source) {
|
|
316
322
|
const state = await this.invoke(new _2_tl_js_1.functions.UpdatesGetState());
|
|
317
323
|
this.updateState = state;
|
|
@@ -356,7 +362,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
356
362
|
}
|
|
357
363
|
async propagateAuthorizationState(authorized) {
|
|
358
364
|
if (this.lastPropagatedAuthorizationState != authorized) {
|
|
359
|
-
await this.
|
|
365
|
+
await this._handler({ authorizationState: { authorized } }, _0_utilities_js_1.resolve);
|
|
360
366
|
this.lastPropagatedAuthorizationState = authorized;
|
|
361
367
|
}
|
|
362
368
|
}
|
|
@@ -681,7 +687,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
681
687
|
this.state.seqNo++;
|
|
682
688
|
}
|
|
683
689
|
const messageId = this.lastMsgId = (0, _0_message_js_1.getMessageId)(this.lastMsgId);
|
|
684
|
-
const message = new _2_tl_js_1.
|
|
690
|
+
const message = new _2_tl_js_1.Message_(messageId, seqNo, function_);
|
|
685
691
|
await this.transport.transport.send(await (0, _0_message_js_1.encryptMessage)(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
|
|
686
692
|
d("invoked %s", function_.constructor.name);
|
|
687
693
|
if (noWait) {
|
|
@@ -1176,6 +1182,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1176
1182
|
}
|
|
1177
1183
|
return messages;
|
|
1178
1184
|
}
|
|
1185
|
+
async resolveSendAs(params) {
|
|
1186
|
+
await this.assertUser("sendAs");
|
|
1187
|
+
return params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined;
|
|
1188
|
+
}
|
|
1179
1189
|
/**
|
|
1180
1190
|
* Send a text message.
|
|
1181
1191
|
*
|
|
@@ -1183,50 +1193,16 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1183
1193
|
* @param text The message's text.
|
|
1184
1194
|
*/
|
|
1185
1195
|
async sendMessage(chatId, text, params) {
|
|
1186
|
-
const
|
|
1187
|
-
const
|
|
1188
|
-
switch (parseMode) {
|
|
1189
|
-
case ParseMode.None:
|
|
1190
|
-
break;
|
|
1191
|
-
case ParseMode.HTML: {
|
|
1192
|
-
const [newText, entitiesToPush] = (0, _0_html_js_1.parseHtml)(text);
|
|
1193
|
-
text = newText;
|
|
1194
|
-
for (const entity of entitiesToPush) {
|
|
1195
|
-
entities_.push(entity);
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
let replyMarkup = undefined;
|
|
1200
|
-
if (params?.replyMarkup) {
|
|
1201
|
-
if ("inlineKeyboard" in params.replyMarkup) {
|
|
1202
|
-
replyMarkup = await (0, _3_types_js_1.inlineKeyboardMarkupToTlObject)(params.replyMarkup, async (v) => {
|
|
1203
|
-
const inputPeer = await this.getInputPeer(v).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerUser));
|
|
1204
|
-
return new _2_tl_js_1.types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
|
-
else if ("keyboard" in params.replyMarkup) {
|
|
1208
|
-
replyMarkup = (0, _3_types_js_1.replyKeyboardMarkupToTlObject)(params.replyMarkup);
|
|
1209
|
-
}
|
|
1210
|
-
else if ("removeKeyboard" in params.replyMarkup) {
|
|
1211
|
-
replyMarkup = (0, _3_types_js_1.replyKeyboardRemoveToTlObject)(params.replyMarkup);
|
|
1212
|
-
}
|
|
1213
|
-
else if ("forceReply" in params.replyMarkup) {
|
|
1214
|
-
replyMarkup = (0, _3_types_js_1.forceReplyToTlObject)(params.replyMarkup);
|
|
1215
|
-
}
|
|
1216
|
-
else {
|
|
1217
|
-
throw new Error("The replyMarkup parameter has an unexpected type");
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1196
|
+
const [message, entities] = this.parseText(text, params);
|
|
1197
|
+
const replyMarkup = await this.constructReplyMarkup(params);
|
|
1220
1198
|
const peer = await this.getInputPeer(chatId);
|
|
1221
1199
|
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
1222
|
-
const message = text;
|
|
1223
1200
|
const noWebpage = params?.disableWebPagePreview ? true : undefined;
|
|
1224
1201
|
const silent = params?.disableNotification ? true : undefined;
|
|
1225
1202
|
const noforwards = params?.protectContent ? true : undefined;
|
|
1226
1203
|
const replyToMsgId = params?.replyToMessageId;
|
|
1227
1204
|
const topMsgId = params?.messageThreadId;
|
|
1228
|
-
const sendAs =
|
|
1229
|
-
const entities = entities_?.length > 0 ? entities_.map((v) => (0, _3_types_js_1.messageEntityToTlObject)(v)) : undefined;
|
|
1205
|
+
const sendAs = await this.resolveSendAs(params);
|
|
1230
1206
|
const result = await this.invoke(new _2_tl_js_1.functions.MessagesSendMessage({
|
|
1231
1207
|
peer,
|
|
1232
1208
|
randomId,
|
|
@@ -1239,56 +1215,46 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1239
1215
|
entities,
|
|
1240
1216
|
replyMarkup,
|
|
1241
1217
|
}));
|
|
1242
|
-
|
|
1218
|
+
const message_ = await this.updatesToMessages(chatId, result).then((v) => v[0]);
|
|
1219
|
+
return Client.assertMsgHas(message_, "text");
|
|
1243
1220
|
}
|
|
1244
|
-
|
|
1245
|
-
* Edit a message's text.
|
|
1246
|
-
*
|
|
1247
|
-
* @param chatId The chat where the message is.
|
|
1248
|
-
* @param messageId The ID of the message.
|
|
1249
|
-
* @param text The new text of the message.
|
|
1250
|
-
*/
|
|
1251
|
-
async editMessageText(chatId, messageId, text, params) {
|
|
1221
|
+
parseText(text, params) {
|
|
1252
1222
|
const entities_ = params?.entities ?? [];
|
|
1253
1223
|
const parseMode = params?.parseMode ?? this.parseMode;
|
|
1254
1224
|
switch (parseMode) {
|
|
1255
|
-
case
|
|
1225
|
+
case "none":
|
|
1256
1226
|
break;
|
|
1257
|
-
case
|
|
1227
|
+
case "html": {
|
|
1258
1228
|
const [newText, entitiesToPush] = (0, _0_html_js_1.parseHtml)(text);
|
|
1259
1229
|
text = newText;
|
|
1260
1230
|
for (const entity of entitiesToPush) {
|
|
1261
1231
|
entities_.push(entity);
|
|
1262
1232
|
}
|
|
1233
|
+
break;
|
|
1263
1234
|
}
|
|
1235
|
+
default:
|
|
1236
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1264
1237
|
}
|
|
1265
|
-
let replyMarkup = undefined;
|
|
1266
|
-
if (params?.replyMarkup) {
|
|
1267
|
-
if ("inlineKeyboard" in params.replyMarkup) {
|
|
1268
|
-
replyMarkup = await (0, _3_types_js_1.inlineKeyboardMarkupToTlObject)(params.replyMarkup, async (v) => {
|
|
1269
|
-
const inputPeer = await this.getInputPeer(v).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerUser));
|
|
1270
|
-
return new _2_tl_js_1.types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
|
|
1271
|
-
});
|
|
1272
|
-
}
|
|
1273
|
-
else if ("keyboard" in params.replyMarkup) {
|
|
1274
|
-
replyMarkup = (0, _3_types_js_1.replyKeyboardMarkupToTlObject)(params.replyMarkup);
|
|
1275
|
-
}
|
|
1276
|
-
else if ("removeKeyboard" in params.replyMarkup) {
|
|
1277
|
-
replyMarkup = (0, _3_types_js_1.replyKeyboardRemoveToTlObject)(params.replyMarkup);
|
|
1278
|
-
}
|
|
1279
|
-
else if ("forceReply" in params.replyMarkup) {
|
|
1280
|
-
replyMarkup = (0, _3_types_js_1.forceReplyToTlObject)(params.replyMarkup);
|
|
1281
|
-
}
|
|
1282
|
-
else {
|
|
1283
|
-
throw new Error("The replyMarkup parameter has an unexpected type");
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
const id = messageId;
|
|
1287
|
-
const peer = await this.getInputPeer(chatId);
|
|
1288
1238
|
const entities = entities_?.length > 0 ? entities_.map((v) => (0, _3_types_js_1.messageEntityToTlObject)(v)) : undefined;
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1239
|
+
return [text, entities];
|
|
1240
|
+
}
|
|
1241
|
+
/**
|
|
1242
|
+
* Edit a message's text.
|
|
1243
|
+
*
|
|
1244
|
+
* @param chatId The chat where the message is.
|
|
1245
|
+
* @param messageId The ID of the message.
|
|
1246
|
+
* @param text The new text of the message.
|
|
1247
|
+
*/
|
|
1248
|
+
async editMessageText(chatId, messageId, text, params) {
|
|
1249
|
+
const [message, entities] = this.parseText(text, params);
|
|
1250
|
+
await this.invoke(new _2_tl_js_1.functions.MessagesEditMessage({
|
|
1251
|
+
id: messageId,
|
|
1252
|
+
peer: await this.getInputPeer(chatId),
|
|
1253
|
+
entities,
|
|
1254
|
+
message,
|
|
1255
|
+
noWebpage: params?.disableWebPagePreview ? true : undefined,
|
|
1256
|
+
replyMarkup: await this.constructReplyMarkup(params),
|
|
1257
|
+
}));
|
|
1292
1258
|
}
|
|
1293
1259
|
async getMessagesInner(chatId_, messageIds) {
|
|
1294
1260
|
const peer = await this.getInputPeer(chatId_);
|
|
@@ -1487,7 +1453,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1487
1453
|
update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
|
|
1488
1454
|
const key = update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ? "message" : "editedMessage";
|
|
1489
1455
|
const message = await (0, _3_types_js_1.constructMessage)(update.message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this));
|
|
1490
|
-
await this.
|
|
1456
|
+
await this._handler({ [key]: message }, _0_utilities_js_1.resolve);
|
|
1491
1457
|
}
|
|
1492
1458
|
if (update instanceof _2_tl_js_1.types.UpdateDeleteMessages) {
|
|
1493
1459
|
const deletedMessages = new Array();
|
|
@@ -1502,7 +1468,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1502
1468
|
}
|
|
1503
1469
|
}
|
|
1504
1470
|
if (deletedMessages.length > 0) {
|
|
1505
|
-
await this.
|
|
1471
|
+
await this._handler({ deletedMessages: deletedMessages }, _0_utilities_js_1.resolve);
|
|
1506
1472
|
}
|
|
1507
1473
|
}
|
|
1508
1474
|
else if (update instanceof _2_tl_js_1.types.UpdateDeleteChannelMessages) {
|
|
@@ -1516,50 +1482,18 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1516
1482
|
await this.storage.setMessage(chatId, messageId, null);
|
|
1517
1483
|
}
|
|
1518
1484
|
if (deletedMessages.length > 0) {
|
|
1519
|
-
await this.
|
|
1485
|
+
await this._handler({ deletedMessages: deletedMessages }, _0_utilities_js_1.resolve);
|
|
1520
1486
|
}
|
|
1521
1487
|
}
|
|
1522
1488
|
if (update instanceof _2_tl_js_1.types.UpdateBotCallbackQuery || update instanceof _2_tl_js_1.types.UpdateInlineBotCallbackQuery) {
|
|
1523
|
-
await this.
|
|
1489
|
+
await this._handler({ callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update, this[exports.getEntity].bind(this), this[exports.getMessageWithReply].bind(this)) }, _0_utilities_js_1.resolve);
|
|
1524
1490
|
}
|
|
1525
1491
|
else if (update instanceof _2_tl_js_1.types.UpdateBotInlineQuery) {
|
|
1526
|
-
await this.
|
|
1492
|
+
await this._handler({ inlineQuery: await (0, _3_types_js_1.constructInlineQuery)(update, this[exports.getEntity].bind(this)) }, _0_utilities_js_1.resolve);
|
|
1527
1493
|
}
|
|
1528
1494
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
this.handler = async (upd, next) => {
|
|
1532
|
-
let called = false;
|
|
1533
|
-
await handler(upd, async () => {
|
|
1534
|
-
if (called)
|
|
1535
|
-
return;
|
|
1536
|
-
called = true;
|
|
1537
|
-
await middleware(upd, next);
|
|
1538
|
-
});
|
|
1539
|
-
};
|
|
1540
|
-
}
|
|
1541
|
-
on(filter, handler) {
|
|
1542
|
-
const type = typeof filter === "string" ? filter : filter[0];
|
|
1543
|
-
const keys = Array.isArray(filter) ? filter.slice(1) : [];
|
|
1544
|
-
this.use((update, next) => {
|
|
1545
|
-
if (type in update) {
|
|
1546
|
-
if (keys.length > 0) {
|
|
1547
|
-
for (const key of keys) {
|
|
1548
|
-
// deno-lint-ignore ban-ts-comment
|
|
1549
|
-
// @ts-ignore
|
|
1550
|
-
if (!(key in update[type])) {
|
|
1551
|
-
return next();
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
// deno-lint-ignore ban-ts-comment
|
|
1556
|
-
// @ts-ignore
|
|
1557
|
-
return handler(update, next);
|
|
1558
|
-
}
|
|
1559
|
-
else {
|
|
1560
|
-
return next();
|
|
1561
|
-
}
|
|
1562
|
-
});
|
|
1495
|
+
set handler(handler) {
|
|
1496
|
+
this._handler = (0, _4_composer_js_1.call)(handler);
|
|
1563
1497
|
}
|
|
1564
1498
|
/**
|
|
1565
1499
|
* Answer a callback query. Bot-only.
|
|
@@ -1567,6 +1501,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1567
1501
|
* @param id ID of the callback query to answer.
|
|
1568
1502
|
*/
|
|
1569
1503
|
async answerCallbackQuery(id, params) {
|
|
1504
|
+
await this.assertBot("answerCallbackQuery");
|
|
1570
1505
|
await this.invoke(new _2_tl_js_1.functions.MessagesSetBotCallbackAnswer({
|
|
1571
1506
|
queryId: BigInt(id),
|
|
1572
1507
|
cacheTime: params?.cacheTime ?? 0,
|
|
@@ -1574,16 +1509,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1574
1509
|
alert: params?.alert ? true : undefined,
|
|
1575
1510
|
}));
|
|
1576
1511
|
}
|
|
1577
|
-
async
|
|
1578
|
-
const peer = await this.getInputPeer(chatId);
|
|
1579
|
-
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
1580
|
-
const silent = params?.disableNotification ? true : undefined;
|
|
1581
|
-
const noforwards = params?.protectContent ? true : undefined;
|
|
1582
|
-
const replyToMsgId = params?.replyToMessageId;
|
|
1583
|
-
const topMsgId = params?.messageThreadId;
|
|
1584
|
-
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined;
|
|
1512
|
+
async constructReplyMarkup(params) {
|
|
1585
1513
|
let replyMarkup = undefined;
|
|
1586
1514
|
if (params?.replyMarkup) {
|
|
1515
|
+
await this.assertBot("replyMarkup");
|
|
1587
1516
|
if ("inlineKeyboard" in params.replyMarkup) {
|
|
1588
1517
|
replyMarkup = await (0, _3_types_js_1.inlineKeyboardMarkupToTlObject)(params.replyMarkup, async (v) => {
|
|
1589
1518
|
const inputPeer = await this.getInputPeer(v).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerUser));
|
|
@@ -1603,24 +1532,34 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1603
1532
|
throw new Error("The replyMarkup parameter has an unexpected type");
|
|
1604
1533
|
}
|
|
1605
1534
|
}
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
case ParseMode.None:
|
|
1612
|
-
break;
|
|
1613
|
-
case ParseMode.HTML: {
|
|
1614
|
-
const [newText, entitiesToPush] = (0, _0_html_js_1.parseHtml)(explanation);
|
|
1615
|
-
explanation = newText;
|
|
1616
|
-
for (const entity of entitiesToPush) {
|
|
1617
|
-
explanationEntities_.push(entity);
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1535
|
+
return replyMarkup;
|
|
1536
|
+
}
|
|
1537
|
+
static assertMsgHas(message, key) {
|
|
1538
|
+
if (!(key in message) || message[key] === undefined) {
|
|
1539
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1621
1540
|
}
|
|
1622
|
-
|
|
1623
|
-
|
|
1541
|
+
return message;
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* Send a poll.
|
|
1545
|
+
*
|
|
1546
|
+
* @param chatId The chat to send the poll to.
|
|
1547
|
+
* @param question The poll's question.
|
|
1548
|
+
* @param options The poll's options.
|
|
1549
|
+
*/
|
|
1550
|
+
async sendPoll(chatId, question, options, params) {
|
|
1551
|
+
const peer = await this.getInputPeer(chatId);
|
|
1552
|
+
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
1553
|
+
const silent = params?.disableNotification ? true : undefined;
|
|
1554
|
+
const noforwards = params?.protectContent ? true : undefined;
|
|
1555
|
+
const replyToMsgId = params?.replyToMessageId;
|
|
1556
|
+
const topMsgId = params?.messageThreadId;
|
|
1557
|
+
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
1558
|
+
const replyMarkup = await this.constructReplyMarkup(params);
|
|
1559
|
+
const explanation = params?.explanation;
|
|
1560
|
+
const parseResult = explanation !== undefined ? this.parseText(explanation, { parseMode: params?.explanationParseMode, entities: params?.explanationEntities }) : undefined;
|
|
1561
|
+
const solution = parseResult === undefined ? undefined : parseResult[0];
|
|
1562
|
+
const solutionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
1624
1563
|
const answers = options.map((v, i) => new _2_tl_js_1.types.PollAnswer({ option: new Uint8Array([i]), text: v }));
|
|
1625
1564
|
const poll = new _2_tl_js_1.types.Poll({
|
|
1626
1565
|
id: (0, _1_utilities_js_1.getRandomId)(),
|
|
@@ -1639,7 +1578,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1639
1578
|
solution,
|
|
1640
1579
|
solutionEntities,
|
|
1641
1580
|
});
|
|
1642
|
-
await this.invoke(new _2_tl_js_1.functions.MessagesSendMedia({
|
|
1581
|
+
const result = await this.invoke(new _2_tl_js_1.functions.MessagesSendMedia({
|
|
1643
1582
|
peer,
|
|
1644
1583
|
randomId,
|
|
1645
1584
|
silent,
|
|
@@ -1650,7 +1589,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1650
1589
|
media,
|
|
1651
1590
|
message: "",
|
|
1652
1591
|
}));
|
|
1592
|
+
const message = await this.updatesToMessages(chatId, result).then((v) => v[0]);
|
|
1593
|
+
return Client.assertMsgHas(message, "poll");
|
|
1653
1594
|
}
|
|
1654
1595
|
}
|
|
1655
1596
|
exports.Client = Client;
|
|
1656
|
-
const resolve = () => Promise.resolve();
|
package/script/mod.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const utils: {
|
|
|
4
4
|
checkPassword: typeof checkPassword;
|
|
5
5
|
getRandomId: typeof getRandomId;
|
|
6
6
|
};
|
|
7
|
-
export *
|
|
7
|
+
export * from "./2_tl.js";
|
|
8
8
|
export * from "./2_connection.js";
|
|
9
9
|
export * from "./3_storage.js";
|
|
10
10
|
export * from "./3_transport.js";
|
package/script/mod.js
CHANGED
|
@@ -10,27 +10,15 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
15
|
};
|
|
28
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.SYSTEM_VERSION = exports.SYSTEM_LANG_CODE = exports.LAYER = exports.LANG_PACK = exports.LANG_CODE = exports.INITIAL_DC = exports.DEVICE_MODEL = exports.APP_VERSION = exports.
|
|
17
|
+
exports.SYSTEM_VERSION = exports.SYSTEM_LANG_CODE = exports.LAYER = exports.LANG_PACK = exports.LANG_CODE = exports.INITIAL_DC = exports.DEVICE_MODEL = exports.APP_VERSION = exports.utils = void 0;
|
|
30
18
|
const _1_utilities_js_1 = require("./1_utilities.js");
|
|
31
19
|
const _0_password_js_1 = require("./client/0_password.js");
|
|
32
20
|
exports.utils = { checkPassword: _0_password_js_1.checkPassword, getRandomId: _1_utilities_js_1.getRandomId };
|
|
33
|
-
|
|
21
|
+
__exportStar(require("./2_tl.js"), exports);
|
|
34
22
|
__exportStar(require("./2_connection.js"), exports);
|
|
35
23
|
__exportStar(require("./3_storage.js"), exports);
|
|
36
24
|
__exportStar(require("./3_transport.js"), exports);
|
package/script/tl/6_message.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ReadObject, TLReader } from "./3_tl_reader.js";
|
|
2
2
|
import { RPCResult } from "./5_rpc_result.js";
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class Message_ {
|
|
4
4
|
readonly id: bigint;
|
|
5
5
|
readonly seqNo: number;
|
|
6
6
|
readonly body: ReadObject | RPCResult;
|
|
7
7
|
constructor(id: bigint, seqNo: number, body: ReadObject | RPCResult);
|
|
8
8
|
serialize(): Uint8Array;
|
|
9
|
-
static deserialize(reader: TLReader):
|
|
9
|
+
static deserialize(reader: TLReader): Message_;
|
|
10
10
|
}
|
package/script/tl/6_message.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Message_ = void 0;
|
|
4
4
|
const _1_tl_object_js_1 = require("./1_tl_object.js");
|
|
5
5
|
const _3_tl_reader_js_1 = require("./3_tl_reader.js");
|
|
6
6
|
const _4_tl_writer_js_1 = require("./4_tl_writer.js");
|
|
@@ -20,7 +20,7 @@ function calculateLength(object) {
|
|
|
20
20
|
}
|
|
21
21
|
return length;
|
|
22
22
|
}
|
|
23
|
-
class
|
|
23
|
+
class Message_ {
|
|
24
24
|
constructor(id, seqNo, body) {
|
|
25
25
|
Object.defineProperty(this, "id", {
|
|
26
26
|
enumerable: true,
|
|
@@ -67,7 +67,7 @@ class Message {
|
|
|
67
67
|
body = reader.readObject(cid);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
return new
|
|
70
|
+
return new Message_(id_, seqNo, body);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
exports.
|
|
73
|
+
exports.Message_ = Message_;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { id } from "./1_tl_object.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Message_ } from "./6_message.js";
|
|
3
3
|
export declare class MessageContainer {
|
|
4
|
-
messages:
|
|
4
|
+
messages: Message_[];
|
|
5
5
|
static get [id](): number;
|
|
6
|
-
constructor(messages:
|
|
6
|
+
constructor(messages: Message_[]);
|
|
7
7
|
serialize(): Uint8Array;
|
|
8
8
|
static deserialize(buffer: Uint8Array): MessageContainer;
|
|
9
9
|
}
|
|
@@ -31,7 +31,7 @@ class MessageContainer {
|
|
|
31
31
|
const length = reader.readInt32();
|
|
32
32
|
const messages = new Array();
|
|
33
33
|
for (let i = 0; i < length; i++) {
|
|
34
|
-
messages.push(_6_message_js_1.
|
|
34
|
+
messages.push(_6_message_js_1.Message_.deserialize(reader));
|
|
35
35
|
}
|
|
36
36
|
return new MessageContainer(messages);
|
|
37
37
|
}
|