teleproto 1.214.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CryptoFile.d.ts +2 -0
- package/CryptoFile.js +37 -0
- package/Helpers.d.ts +150 -0
- package/Helpers.js +477 -0
- package/LICENSE +23 -0
- package/Password.d.ts +14 -0
- package/Password.js +270 -0
- package/README.md +98 -0
- package/Utils.d.ts +227 -0
- package/Utils.js +1247 -0
- package/Version.d.ts +1 -0
- package/Version.js +4 -0
- package/client/2fa.d.ts +48 -0
- package/client/2fa.js +108 -0
- package/client/TelegramClient.d.ts +1043 -0
- package/client/TelegramClient.js +1181 -0
- package/client/account.d.ts +0 -0
- package/client/account.js +1 -0
- package/client/auth.d.ts +92 -0
- package/client/auth.js +388 -0
- package/client/bots.d.ts +6 -0
- package/client/bots.js +23 -0
- package/client/buttons.d.ts +4 -0
- package/client/buttons.js +86 -0
- package/client/chats.d.ts +45 -0
- package/client/chats.js +350 -0
- package/client/dialogs.d.ts +52 -0
- package/client/dialogs.js +174 -0
- package/client/downloads.d.ts +156 -0
- package/client/downloads.js +614 -0
- package/client/fs.d.ts +1 -0
- package/client/fs.js +17 -0
- package/client/index.d.ts +15 -0
- package/client/index.js +64 -0
- package/client/messageParse.d.ts +17 -0
- package/client/messageParse.js +191 -0
- package/client/messages.d.ts +263 -0
- package/client/messages.js +813 -0
- package/client/os.d.ts +2 -0
- package/client/os.js +37 -0
- package/client/path.d.ts +2 -0
- package/client/path.js +7 -0
- package/client/telegramBaseClient.d.ts +237 -0
- package/client/telegramBaseClient.js +368 -0
- package/client/updates.d.ts +33 -0
- package/client/updates.js +260 -0
- package/client/uploads.d.ts +136 -0
- package/client/uploads.js +514 -0
- package/client/users.d.ts +29 -0
- package/client/users.js +490 -0
- package/crypto/AuthKey.d.ts +19 -0
- package/crypto/AuthKey.js +76 -0
- package/crypto/CTR.d.ts +5 -0
- package/crypto/CTR.js +16 -0
- package/crypto/Factorizator.d.ts +19 -0
- package/crypto/Factorizator.js +74 -0
- package/crypto/IGE.d.ts +11 -0
- package/crypto/IGE.js +115 -0
- package/crypto/RSA.d.ts +14 -0
- package/crypto/RSA.js +70 -0
- package/crypto/converters.d.ts +19 -0
- package/crypto/converters.js +52 -0
- package/crypto/crypto.d.ts +19 -0
- package/crypto/crypto.js +58 -0
- package/crypto/words.d.ts +6 -0
- package/crypto/words.js +47 -0
- package/define.d.ts +77 -0
- package/entityCache.d.ts +7 -0
- package/entityCache.js +79 -0
- package/errors/Common.d.ts +71 -0
- package/errors/Common.js +122 -0
- package/errors/RPCBaseErrors.d.ts +84 -0
- package/errors/RPCBaseErrors.js +134 -0
- package/errors/RPCErrorList.d.ts +37 -0
- package/errors/RPCErrorList.js +117 -0
- package/errors/index.d.ts +11 -0
- package/errors/index.js +32 -0
- package/events/Album.d.ts +36 -0
- package/events/Album.js +104 -0
- package/events/CallbackQuery.d.ts +73 -0
- package/events/CallbackQuery.js +193 -0
- package/events/DeletedMessage.d.ts +45 -0
- package/events/DeletedMessage.js +63 -0
- package/events/EditedMessage.d.ts +30 -0
- package/events/EditedMessage.js +41 -0
- package/events/NewMessage.d.ts +89 -0
- package/events/NewMessage.js +182 -0
- package/events/Raw.d.ts +29 -0
- package/events/Raw.js +43 -0
- package/events/common.d.ts +66 -0
- package/events/common.js +141 -0
- package/events/index.d.ts +2 -0
- package/events/index.js +8 -0
- package/extensions/AsyncQueue.d.ts +10 -0
- package/extensions/AsyncQueue.js +32 -0
- package/extensions/BinaryReader.d.ts +99 -0
- package/extensions/BinaryReader.js +242 -0
- package/extensions/BinaryWriter.d.ts +6 -0
- package/extensions/BinaryWriter.js +15 -0
- package/extensions/Deferred.d.ts +8 -0
- package/extensions/Deferred.js +16 -0
- package/extensions/Logger.d.ts +54 -0
- package/extensions/Logger.js +128 -0
- package/extensions/MessagePacker.d.ts +21 -0
- package/extensions/MessagePacker.js +154 -0
- package/extensions/PendingState.d.ts +12 -0
- package/extensions/PendingState.js +29 -0
- package/extensions/PromisedNetSockets.d.ts +24 -0
- package/extensions/PromisedNetSockets.js +192 -0
- package/extensions/PromisedWebSockets.d.ts +18 -0
- package/extensions/PromisedWebSockets.js +124 -0
- package/extensions/html.d.ts +5 -0
- package/extensions/html.js +228 -0
- package/extensions/index.d.ts +7 -0
- package/extensions/index.js +17 -0
- package/extensions/markdown.d.ts +5 -0
- package/extensions/markdown.js +76 -0
- package/extensions/markdownv2.d.ts +5 -0
- package/extensions/markdownv2.js +51 -0
- package/extensions/net.d.ts +1 -0
- package/extensions/net.js +17 -0
- package/extensions/socks.d.ts +1 -0
- package/extensions/socks.js +17 -0
- package/index.d.ts +14 -0
- package/index.js +62 -0
- package/inspect.d.ts +1 -0
- package/inspect.js +5 -0
- package/network/Authenticator.d.ts +12 -0
- package/network/Authenticator.js +192 -0
- package/network/MTProtoPlainSender.d.ts +19 -0
- package/network/MTProtoPlainSender.js +74 -0
- package/network/MTProtoSender.d.ts +290 -0
- package/network/MTProtoSender.js +873 -0
- package/network/MTProtoState.d.ts +102 -0
- package/network/MTProtoState.js +267 -0
- package/network/RequestState.d.ts +18 -0
- package/network/RequestState.js +35 -0
- package/network/connection/Connection.d.ts +69 -0
- package/network/connection/Connection.js +162 -0
- package/network/connection/TCPAbridged.d.ts +19 -0
- package/network/connection/TCPAbridged.js +58 -0
- package/network/connection/TCPFull.d.ts +16 -0
- package/network/connection/TCPFull.js +61 -0
- package/network/connection/TCPMTProxy.d.ts +49 -0
- package/network/connection/TCPMTProxy.js +121 -0
- package/network/connection/TCPObfuscated.d.ts +18 -0
- package/network/connection/TCPObfuscated.js +78 -0
- package/network/connection/index.d.ts +4 -0
- package/network/connection/index.js +11 -0
- package/network/index.d.ts +11 -0
- package/network/index.js +23 -0
- package/package.json +50 -0
- package/requestIter.d.ts +24 -0
- package/requestIter.js +109 -0
- package/sessions/Abstract.d.ts +103 -0
- package/sessions/Abstract.js +6 -0
- package/sessions/Memory.d.ts +38 -0
- package/sessions/Memory.js +272 -0
- package/sessions/StoreSession.d.ts +14 -0
- package/sessions/StoreSession.js +77 -0
- package/sessions/StringSession.d.ts +32 -0
- package/sessions/StringSession.js +116 -0
- package/sessions/index.d.ts +4 -0
- package/sessions/index.js +11 -0
- package/sessions/localStorage.d.ts +1 -0
- package/sessions/localStorage.js +4 -0
- package/tl/AllTLObjects.d.ts +3 -0
- package/tl/AllTLObjects.js +17 -0
- package/tl/MTProtoRequest.d.ts +18 -0
- package/tl/MTProtoRequest.js +38 -0
- package/tl/api.d.ts +32488 -0
- package/tl/api.js +507 -0
- package/tl/apiTl.d.ts +2 -0
- package/tl/apiTl.js +2209 -0
- package/tl/core/GZIPPacked.d.ts +15 -0
- package/tl/core/GZIPPacked.js +51 -0
- package/tl/core/MessageContainer.d.ts +12 -0
- package/tl/core/MessageContainer.js +42 -0
- package/tl/core/RPCResult.d.ts +14 -0
- package/tl/core/RPCResult.js +32 -0
- package/tl/core/TLMessage.d.ts +10 -0
- package/tl/core/TLMessage.js +14 -0
- package/tl/core/index.d.ts +6 -0
- package/tl/core/index.js +16 -0
- package/tl/custom/button.d.ts +24 -0
- package/tl/custom/button.js +78 -0
- package/tl/custom/chatGetter.d.ts +29 -0
- package/tl/custom/chatGetter.js +116 -0
- package/tl/custom/dialog.d.ts +30 -0
- package/tl/custom/dialog.js +40 -0
- package/tl/custom/draft.d.ts +21 -0
- package/tl/custom/draft.js +48 -0
- package/tl/custom/file.d.ts +21 -0
- package/tl/custom/file.js +68 -0
- package/tl/custom/forward.d.ts +15 -0
- package/tl/custom/forward.js +47 -0
- package/tl/custom/index.d.ts +1 -0
- package/tl/custom/index.js +5 -0
- package/tl/custom/inlineResult.d.ts +32 -0
- package/tl/custom/inlineResult.js +87 -0
- package/tl/custom/inlineResults.d.ts +20 -0
- package/tl/custom/inlineResults.js +26 -0
- package/tl/custom/message.d.ts +427 -0
- package/tl/custom/message.js +716 -0
- package/tl/custom/messageButton.d.ts +54 -0
- package/tl/custom/messageButton.js +152 -0
- package/tl/custom/senderGetter.d.ts +28 -0
- package/tl/custom/senderGetter.js +55 -0
- package/tl/generateModule.d.ts +1 -0
- package/tl/generateModule.js +17 -0
- package/tl/generationHelpers.d.ts +11 -0
- package/tl/generationHelpers.js +289 -0
- package/tl/index.d.ts +3 -0
- package/tl/index.js +10 -0
- package/tl/patched/index.d.ts +2 -0
- package/tl/patched/index.js +76 -0
- package/tl/schemaTl.d.ts +2 -0
- package/tl/schemaTl.js +64 -0
- package/tl/types-generator/generate.d.ts +1 -0
- package/tl/types-generator/generate.js +84 -0
- package/tl/types-generator/template.d.ts +6 -0
- package/tl/types-generator/template.js +257 -0
|
@@ -0,0 +1,716 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.CustomMessage = void 0;
|
|
37
|
+
const senderGetter_1 = require("./senderGetter");
|
|
38
|
+
const api_1 = require("../api");
|
|
39
|
+
const chatGetter_1 = require("./chatGetter");
|
|
40
|
+
const utils = __importStar(require("../../Utils"));
|
|
41
|
+
const forward_1 = require("./forward");
|
|
42
|
+
const file_1 = require("./file");
|
|
43
|
+
const Helpers_1 = require("../../Helpers");
|
|
44
|
+
const users_1 = require("../../client/users");
|
|
45
|
+
const Logger_1 = require("../../extensions/Logger");
|
|
46
|
+
const messageButton_1 = require("./messageButton");
|
|
47
|
+
const inspect_1 = require("../../inspect");
|
|
48
|
+
/**
|
|
49
|
+
* This custom class aggregates both {@link Api.Message} and {@link Api.MessageService} to ease accessing their members.<br/>
|
|
50
|
+
* <br/>
|
|
51
|
+
* Remember that this class implements {@link ChatGetter} and {@link SenderGetter}<br/>
|
|
52
|
+
* which means you have access to all their sender and chat properties and methods.
|
|
53
|
+
*/
|
|
54
|
+
class CustomMessage extends senderGetter_1.SenderGetter {
|
|
55
|
+
[inspect_1.inspect.custom]() {
|
|
56
|
+
return (0, Helpers_1.betterConsoleLog)(this);
|
|
57
|
+
}
|
|
58
|
+
init({ id, peerId = undefined, date = undefined, out = undefined, mentioned = undefined, mediaUnread = undefined, silent = undefined, post = undefined, fromId = undefined, replyTo = undefined, message = undefined, fwdFrom = undefined, viaBotId = undefined, media = undefined, replyMarkup = undefined, entities = undefined, views = undefined, editDate = undefined, postAuthor = undefined, groupedId = undefined, fromScheduled = undefined, legacy = undefined, editHide = undefined, pinned = undefined, restrictionReason = undefined, forwards = undefined, replies = undefined, action = undefined, reactions = undefined, noforwards = undefined, ttlPeriod = undefined, _entities = new Map(), }) {
|
|
59
|
+
if (!id)
|
|
60
|
+
throw new Error("id is a required attribute for Message");
|
|
61
|
+
let senderId = undefined;
|
|
62
|
+
if (fromId) {
|
|
63
|
+
senderId = utils.getPeerId(fromId);
|
|
64
|
+
}
|
|
65
|
+
else if (peerId) {
|
|
66
|
+
if (post || (!out && peerId instanceof api_1.Api.PeerUser)) {
|
|
67
|
+
senderId = utils.getPeerId(peerId);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Common properties to all messages
|
|
71
|
+
this._entities = _entities;
|
|
72
|
+
this.out = out;
|
|
73
|
+
this.mentioned = mentioned;
|
|
74
|
+
this.mediaUnread = mediaUnread;
|
|
75
|
+
this.silent = silent;
|
|
76
|
+
this.post = post;
|
|
77
|
+
this.post = post;
|
|
78
|
+
this.fromScheduled = fromScheduled;
|
|
79
|
+
this.legacy = legacy;
|
|
80
|
+
this.editHide = editHide;
|
|
81
|
+
this.ttlPeriod = ttlPeriod;
|
|
82
|
+
this.id = id;
|
|
83
|
+
this.fromId = fromId;
|
|
84
|
+
this.peerId = peerId;
|
|
85
|
+
this.fwdFrom = fwdFrom;
|
|
86
|
+
this.viaBotId = viaBotId;
|
|
87
|
+
this.replyTo = replyTo;
|
|
88
|
+
this.date = date;
|
|
89
|
+
this.message = message;
|
|
90
|
+
this.media = media instanceof api_1.Api.MessageMediaEmpty ? media : undefined;
|
|
91
|
+
this.replyMarkup = replyMarkup;
|
|
92
|
+
this.entities = entities;
|
|
93
|
+
this.views = views;
|
|
94
|
+
this.forwards = forwards;
|
|
95
|
+
this.replies = replies;
|
|
96
|
+
this.editDate = editDate;
|
|
97
|
+
this.pinned = pinned;
|
|
98
|
+
this.postAuthor = postAuthor;
|
|
99
|
+
this.groupedId = groupedId;
|
|
100
|
+
this.restrictionReason = restrictionReason;
|
|
101
|
+
this.action = action;
|
|
102
|
+
this.noforwards = noforwards;
|
|
103
|
+
this.reactions = reactions;
|
|
104
|
+
this._client = undefined;
|
|
105
|
+
this._text = undefined;
|
|
106
|
+
this._file = undefined;
|
|
107
|
+
this._replyMessage = undefined;
|
|
108
|
+
this._buttons = undefined;
|
|
109
|
+
this._buttonsFlat = undefined;
|
|
110
|
+
this._buttonsCount = 0;
|
|
111
|
+
this._viaBot = undefined;
|
|
112
|
+
this._viaInputBot = undefined;
|
|
113
|
+
this._actionEntities = undefined;
|
|
114
|
+
// Note: these calls would reset the client
|
|
115
|
+
chatGetter_1.ChatGetter.initChatClass(this, { chatPeer: peerId, broadcast: post });
|
|
116
|
+
senderGetter_1.SenderGetter.initSenderClass(this, {
|
|
117
|
+
senderId: senderId ? (0, Helpers_1.returnBigInt)(senderId) : undefined,
|
|
118
|
+
});
|
|
119
|
+
this._forward = undefined;
|
|
120
|
+
}
|
|
121
|
+
constructor(args) {
|
|
122
|
+
super();
|
|
123
|
+
this.init(args);
|
|
124
|
+
}
|
|
125
|
+
_finishInit(client, entities, inputChat) {
|
|
126
|
+
this._client = client;
|
|
127
|
+
const cache = client._entityCache;
|
|
128
|
+
if (this.senderId) {
|
|
129
|
+
[this._sender, this._inputSender] = utils._getEntityPair(this.senderId.toString(), entities, cache);
|
|
130
|
+
}
|
|
131
|
+
if (this.chatId) {
|
|
132
|
+
[this._chat, this._inputChat] = utils._getEntityPair(this.chatId.toString(), entities, cache);
|
|
133
|
+
}
|
|
134
|
+
if (inputChat) {
|
|
135
|
+
// This has priority
|
|
136
|
+
this._inputChat = inputChat;
|
|
137
|
+
}
|
|
138
|
+
if (this.viaBotId) {
|
|
139
|
+
[this._viaBot, this._viaInputBot] = utils._getEntityPair(this.viaBotId.toString(), entities, cache);
|
|
140
|
+
}
|
|
141
|
+
if (this.fwdFrom) {
|
|
142
|
+
this._forward = new forward_1.Forward(this._client, this.fwdFrom, entities);
|
|
143
|
+
}
|
|
144
|
+
if (this.action) {
|
|
145
|
+
if (this.action instanceof api_1.Api.MessageActionChatAddUser ||
|
|
146
|
+
this.action instanceof api_1.Api.MessageActionChatCreate) {
|
|
147
|
+
this._actionEntities = this.action.users.map((i) => entities.get(i.toString()));
|
|
148
|
+
}
|
|
149
|
+
else if (this.action instanceof api_1.Api.MessageActionChatDeleteUser) {
|
|
150
|
+
this._actionEntities = [
|
|
151
|
+
entities.get(this.action.userId.toString()),
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
else if (this.action instanceof api_1.Api.MessageActionChatJoinedByLink) {
|
|
155
|
+
this._actionEntities = [
|
|
156
|
+
entities.get(utils.getPeerId(new api_1.Api.PeerChannel({
|
|
157
|
+
channelId: this.action.inviterId,
|
|
158
|
+
}))),
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
else if (this.action instanceof api_1.Api.MessageActionChannelMigrateFrom) {
|
|
162
|
+
this._actionEntities = [
|
|
163
|
+
entities.get(utils.getPeerId(new api_1.Api.PeerChat({ chatId: this.action.chatId }))),
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
get client() {
|
|
169
|
+
return this._client;
|
|
170
|
+
}
|
|
171
|
+
get text() {
|
|
172
|
+
if (this._text === undefined && this._client) {
|
|
173
|
+
if (!this._client.parseMode) {
|
|
174
|
+
this._text = this.message;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
this._text = this._client.parseMode.unparse(this.message || "", this.entities || []);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return this._text || "";
|
|
181
|
+
}
|
|
182
|
+
set text(value) {
|
|
183
|
+
this._text = value;
|
|
184
|
+
if (this._client && this._client.parseMode) {
|
|
185
|
+
[this.message, this.entities] = this._client.parseMode.parse(value);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
this.message = value;
|
|
189
|
+
this.entities = [];
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
get rawText() {
|
|
193
|
+
return this.message || "";
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* @param {string} value
|
|
197
|
+
*/
|
|
198
|
+
set rawText(value) {
|
|
199
|
+
this.message = value;
|
|
200
|
+
this.entities = [];
|
|
201
|
+
this._text = "";
|
|
202
|
+
}
|
|
203
|
+
get isReply() {
|
|
204
|
+
return !!this.replyTo;
|
|
205
|
+
}
|
|
206
|
+
get forward() {
|
|
207
|
+
return this._forward;
|
|
208
|
+
}
|
|
209
|
+
async _refetchSender() {
|
|
210
|
+
await this._reloadMessage();
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Re-fetches this message to reload the sender and chat entities,
|
|
214
|
+
* along with their input versions.
|
|
215
|
+
* @private
|
|
216
|
+
*/
|
|
217
|
+
async _reloadMessage() {
|
|
218
|
+
if (!this._client)
|
|
219
|
+
return;
|
|
220
|
+
let msg = undefined;
|
|
221
|
+
try {
|
|
222
|
+
const chat = this.isChannel ? await this.getInputChat() : undefined;
|
|
223
|
+
let temp = await this._client.getMessages(chat, { ids: this.id });
|
|
224
|
+
if (temp) {
|
|
225
|
+
msg = temp[0];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
this._client._log.error("Got error while trying to finish init message with id " +
|
|
230
|
+
this.id);
|
|
231
|
+
if (this._client._errorHandler) {
|
|
232
|
+
await this._client._errorHandler(e);
|
|
233
|
+
}
|
|
234
|
+
if (this._client._log.canSend(Logger_1.LogLevel.ERROR)) {
|
|
235
|
+
console.error(e);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (msg == undefined)
|
|
239
|
+
return;
|
|
240
|
+
this._sender = msg._sender;
|
|
241
|
+
this._inputSender = msg._inputSender;
|
|
242
|
+
this._chat = msg._chat;
|
|
243
|
+
this._inputChat = msg._inputChat;
|
|
244
|
+
this._viaBot = msg._viaBot;
|
|
245
|
+
this._viaInputBot = msg._viaInputBot;
|
|
246
|
+
this._forward = msg._forward;
|
|
247
|
+
this._actionEntities = msg._actionEntities;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Returns a list of lists of `MessageButton <MessageButton>`, if any.
|
|
251
|
+
* Otherwise, it returns `undefined`.
|
|
252
|
+
*/
|
|
253
|
+
get buttons() {
|
|
254
|
+
if (!this._buttons && this.replyMarkup) {
|
|
255
|
+
if (!this.inputChat) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
const bot = this._neededMarkupBot();
|
|
260
|
+
this._setButtons(this.inputChat, bot);
|
|
261
|
+
}
|
|
262
|
+
catch (e) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return this._buttons;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Returns `buttons` when that property fails (this is rarely needed).
|
|
270
|
+
*/
|
|
271
|
+
async getButtons() {
|
|
272
|
+
if (!this.buttons && this.replyMarkup) {
|
|
273
|
+
const chat = await this.getInputChat();
|
|
274
|
+
if (!chat)
|
|
275
|
+
return;
|
|
276
|
+
let bot;
|
|
277
|
+
try {
|
|
278
|
+
bot = this._neededMarkupBot();
|
|
279
|
+
}
|
|
280
|
+
catch (e) {
|
|
281
|
+
await this._reloadMessage();
|
|
282
|
+
bot = this._neededMarkupBot();
|
|
283
|
+
}
|
|
284
|
+
this._setButtons(chat, bot);
|
|
285
|
+
}
|
|
286
|
+
return this._buttons;
|
|
287
|
+
}
|
|
288
|
+
get buttonCount() {
|
|
289
|
+
if (!this._buttonsCount) {
|
|
290
|
+
if (this.replyMarkup instanceof api_1.Api.ReplyInlineMarkup ||
|
|
291
|
+
this.replyMarkup instanceof api_1.Api.ReplyKeyboardMarkup) {
|
|
292
|
+
this._buttonsCount = this.replyMarkup.rows
|
|
293
|
+
.map((r) => r.buttons.length)
|
|
294
|
+
.reduce(function (a, b) {
|
|
295
|
+
return a + b;
|
|
296
|
+
}, 0);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
this._buttonsCount = 0;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return this._buttonsCount;
|
|
303
|
+
}
|
|
304
|
+
get file() {
|
|
305
|
+
if (!this._file) {
|
|
306
|
+
const media = this.photo || this.document;
|
|
307
|
+
if (media) {
|
|
308
|
+
this._file = new file_1.File(media);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return this._file;
|
|
312
|
+
}
|
|
313
|
+
get photo() {
|
|
314
|
+
if (this.media instanceof api_1.Api.MessageMediaPhoto) {
|
|
315
|
+
if (this.media.photo instanceof api_1.Api.Photo)
|
|
316
|
+
return this.media.photo;
|
|
317
|
+
}
|
|
318
|
+
else if (this.action instanceof api_1.Api.MessageActionChatEditPhoto) {
|
|
319
|
+
return this.action.photo;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
return this.webPreview && this.webPreview.photo instanceof api_1.Api.Photo
|
|
323
|
+
? this.webPreview.photo
|
|
324
|
+
: undefined;
|
|
325
|
+
}
|
|
326
|
+
return undefined;
|
|
327
|
+
}
|
|
328
|
+
get document() {
|
|
329
|
+
if (this.media instanceof api_1.Api.MessageMediaDocument) {
|
|
330
|
+
if (this.media.document instanceof api_1.Api.Document)
|
|
331
|
+
return this.media.document;
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
const web = this.webPreview;
|
|
335
|
+
return web && web.document instanceof api_1.Api.Document
|
|
336
|
+
? web.document
|
|
337
|
+
: undefined;
|
|
338
|
+
}
|
|
339
|
+
return undefined;
|
|
340
|
+
}
|
|
341
|
+
get webPreview() {
|
|
342
|
+
if (this.media instanceof api_1.Api.MessageMediaWebPage) {
|
|
343
|
+
if (this.media.webpage instanceof api_1.Api.WebPage)
|
|
344
|
+
return this.media.webpage;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
get audio() {
|
|
348
|
+
return this._documentByAttribute(api_1.Api.DocumentAttributeAudio, (attr) => !attr.voice);
|
|
349
|
+
}
|
|
350
|
+
get voice() {
|
|
351
|
+
return this._documentByAttribute(api_1.Api.DocumentAttributeAudio, (attr) => !!attr.voice);
|
|
352
|
+
}
|
|
353
|
+
get video() {
|
|
354
|
+
return this._documentByAttribute(api_1.Api.DocumentAttributeVideo);
|
|
355
|
+
}
|
|
356
|
+
get videoNote() {
|
|
357
|
+
return this._documentByAttribute(api_1.Api.DocumentAttributeVideo, (attr) => !!attr.roundMessage);
|
|
358
|
+
}
|
|
359
|
+
get gif() {
|
|
360
|
+
return this._documentByAttribute(api_1.Api.DocumentAttributeAnimated);
|
|
361
|
+
}
|
|
362
|
+
get sticker() {
|
|
363
|
+
return this._documentByAttribute(api_1.Api.DocumentAttributeSticker);
|
|
364
|
+
}
|
|
365
|
+
get contact() {
|
|
366
|
+
if (this.media instanceof api_1.Api.MessageMediaContact) {
|
|
367
|
+
return this.media;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
get game() {
|
|
371
|
+
if (this.media instanceof api_1.Api.MessageMediaGame) {
|
|
372
|
+
return this.media.game;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
get geo() {
|
|
376
|
+
if (this.media instanceof api_1.Api.MessageMediaGeo ||
|
|
377
|
+
this.media instanceof api_1.Api.MessageMediaGeoLive ||
|
|
378
|
+
this.media instanceof api_1.Api.MessageMediaVenue) {
|
|
379
|
+
return this.media.geo;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
get invoice() {
|
|
383
|
+
if (this.media instanceof api_1.Api.MessageMediaInvoice) {
|
|
384
|
+
return this.media;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
get poll() {
|
|
388
|
+
if (this.media instanceof api_1.Api.MessageMediaPoll) {
|
|
389
|
+
return this.media;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
get venue() {
|
|
393
|
+
if (this.media instanceof api_1.Api.MessageMediaVenue) {
|
|
394
|
+
return this.media;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
get dice() {
|
|
398
|
+
if (this.media instanceof api_1.Api.MessageMediaDice) {
|
|
399
|
+
return this.media;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
get actionEntities() {
|
|
403
|
+
return this._actionEntities;
|
|
404
|
+
}
|
|
405
|
+
get viaBot() {
|
|
406
|
+
return this._viaBot;
|
|
407
|
+
}
|
|
408
|
+
get viaInputBot() {
|
|
409
|
+
return this._viaInputBot;
|
|
410
|
+
}
|
|
411
|
+
get replyToMsgId() {
|
|
412
|
+
var _a;
|
|
413
|
+
return (_a = this.replyTo) === null || _a === void 0 ? void 0 : _a.replyToMsgId;
|
|
414
|
+
}
|
|
415
|
+
get toId() {
|
|
416
|
+
if (this._client && !this.out && this.isPrivate) {
|
|
417
|
+
return new api_1.Api.PeerUser({
|
|
418
|
+
userId: (0, users_1._selfId)(this._client),
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
return this.peerId;
|
|
422
|
+
}
|
|
423
|
+
getEntitiesText(cls) {
|
|
424
|
+
let ent = this.entities;
|
|
425
|
+
if (!ent || ent.length == 0)
|
|
426
|
+
return;
|
|
427
|
+
if (cls) {
|
|
428
|
+
ent = ent.filter((v) => v instanceof cls);
|
|
429
|
+
}
|
|
430
|
+
const texts = utils.getInnerText(this.message || "", ent);
|
|
431
|
+
const zip = (rows) => rows[0].map((_, c) => rows.map((row) => row[c]));
|
|
432
|
+
return zip([ent, texts]);
|
|
433
|
+
}
|
|
434
|
+
async getReplyMessage() {
|
|
435
|
+
if (!this._replyMessage && this._client) {
|
|
436
|
+
if (!this.replyTo)
|
|
437
|
+
return undefined;
|
|
438
|
+
// Bots cannot access other bots' messages by their ID.
|
|
439
|
+
// However they can access them through replies...
|
|
440
|
+
this._replyMessage = (await this._client.getMessages(this.isChannel ? await this.getInputChat() : undefined, {
|
|
441
|
+
ids: new api_1.Api.InputMessageReplyTo({ id: this.id }),
|
|
442
|
+
}))[0];
|
|
443
|
+
if (!this._replyMessage) {
|
|
444
|
+
// ...unless the current message got deleted.
|
|
445
|
+
//
|
|
446
|
+
// If that's the case, give it a second chance accessing
|
|
447
|
+
// directly by its ID.
|
|
448
|
+
this._replyMessage = (await this._client.getMessages(this.isChannel ? this._inputChat : undefined, {
|
|
449
|
+
ids: this.replyToMsgId,
|
|
450
|
+
}))[0];
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return this._replyMessage;
|
|
454
|
+
}
|
|
455
|
+
async respond(params) {
|
|
456
|
+
if (this._client) {
|
|
457
|
+
return this._client.sendMessage((await this.getInputChat()), params);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
async reply(params) {
|
|
461
|
+
if (this._client) {
|
|
462
|
+
params.replyTo = this.id;
|
|
463
|
+
return this._client.sendMessage((await this.getInputChat()), params);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
async forwardTo(entity) {
|
|
467
|
+
if (this._client) {
|
|
468
|
+
entity = await this._client.getInputEntity(entity);
|
|
469
|
+
const params = {
|
|
470
|
+
messages: [this.id],
|
|
471
|
+
fromPeer: (await this.getInputChat()),
|
|
472
|
+
};
|
|
473
|
+
return this._client.forwardMessages(entity, params);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
async edit(params) {
|
|
477
|
+
const param = params;
|
|
478
|
+
if (this.fwdFrom || !this._client)
|
|
479
|
+
return undefined;
|
|
480
|
+
if (param.linkPreview == undefined) {
|
|
481
|
+
param.linkPreview = !!this.webPreview;
|
|
482
|
+
}
|
|
483
|
+
if (param.buttons == undefined) {
|
|
484
|
+
param.buttons = this.replyMarkup;
|
|
485
|
+
}
|
|
486
|
+
param.message = this.id;
|
|
487
|
+
return this._client.editMessage((await this.getInputChat()), param);
|
|
488
|
+
}
|
|
489
|
+
async delete({ revoke } = { revoke: false }) {
|
|
490
|
+
if (this._client) {
|
|
491
|
+
return this._client.deleteMessages(await this.getInputChat(), [this.id], {
|
|
492
|
+
revoke,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
async pin(params) {
|
|
497
|
+
if (this._client) {
|
|
498
|
+
const entity = await this.getInputChat();
|
|
499
|
+
if (entity === undefined) {
|
|
500
|
+
throw Error("Failed to pin message due to cannot get input chat.");
|
|
501
|
+
}
|
|
502
|
+
return this._client.pinMessage(entity, this.id, params);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
async unpin(params) {
|
|
506
|
+
if (this._client) {
|
|
507
|
+
const entity = await this.getInputChat();
|
|
508
|
+
if (entity === undefined) {
|
|
509
|
+
throw Error("Failed to unpin message due to cannot get input chat.");
|
|
510
|
+
}
|
|
511
|
+
return this._client.unpinMessage(entity, this.id, params);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
async downloadMedia(params) {
|
|
515
|
+
// small hack for patched method
|
|
516
|
+
if (this._client)
|
|
517
|
+
return this._client.downloadMedia(this, params || {});
|
|
518
|
+
}
|
|
519
|
+
async markAsRead() {
|
|
520
|
+
if (this._client) {
|
|
521
|
+
const entity = await this.getInputChat();
|
|
522
|
+
if (entity === undefined) {
|
|
523
|
+
throw Error(`Failed to mark message id ${this.id} as read due to cannot get input chat.`);
|
|
524
|
+
}
|
|
525
|
+
return this._client.markAsRead(entity, this.id);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
async click({ i, j, text, filter, data, sharePhone, shareGeo, password, }) {
|
|
529
|
+
if (!this.client) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
if (data) {
|
|
533
|
+
const chat = await this.getInputChat();
|
|
534
|
+
if (!chat) {
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
const button = new api_1.Api.KeyboardButtonCallback({
|
|
538
|
+
text: "",
|
|
539
|
+
data: data,
|
|
540
|
+
});
|
|
541
|
+
return await new messageButton_1.MessageButton(this.client, button, chat, undefined, this.id).click({
|
|
542
|
+
sharePhone: sharePhone,
|
|
543
|
+
shareGeo: shareGeo,
|
|
544
|
+
password: password,
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
if (this.poll) {
|
|
548
|
+
function findPoll(answers) {
|
|
549
|
+
if (i != undefined) {
|
|
550
|
+
if (Array.isArray(i)) {
|
|
551
|
+
const corrects = [];
|
|
552
|
+
for (let x = 0; x < i.length; x++) {
|
|
553
|
+
corrects.push(answers[x].option);
|
|
554
|
+
}
|
|
555
|
+
return corrects;
|
|
556
|
+
}
|
|
557
|
+
return [answers[i].option];
|
|
558
|
+
}
|
|
559
|
+
if (text != undefined) {
|
|
560
|
+
if (typeof text == "function") {
|
|
561
|
+
for (const answer of answers) {
|
|
562
|
+
if (text(answer.text)) {
|
|
563
|
+
return [answer.option];
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
for (const answer of answers) {
|
|
569
|
+
if (answer.text.text == text) {
|
|
570
|
+
return [answer.option];
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
if (filter != undefined) {
|
|
577
|
+
for (const answer of answers) {
|
|
578
|
+
if (filter(answer)) {
|
|
579
|
+
return [answer.option];
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
const options = findPoll(this.poll.poll.answers) || [];
|
|
586
|
+
return await this.client.invoke(new api_1.Api.messages.SendVote({
|
|
587
|
+
peer: this.inputChat,
|
|
588
|
+
msgId: this.id,
|
|
589
|
+
options: options,
|
|
590
|
+
}));
|
|
591
|
+
}
|
|
592
|
+
if (!(await this.getButtons())) {
|
|
593
|
+
return; // Accessing the property sets this._buttons[_flat]
|
|
594
|
+
}
|
|
595
|
+
function findButton(self) {
|
|
596
|
+
if (!self._buttonsFlat || !self._buttons) {
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
if (Array.isArray(i)) {
|
|
600
|
+
i = i[0];
|
|
601
|
+
}
|
|
602
|
+
if (text != undefined) {
|
|
603
|
+
if (typeof text == "function") {
|
|
604
|
+
for (const button of self._buttonsFlat) {
|
|
605
|
+
if (text(button.text)) {
|
|
606
|
+
return button;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
for (const button of self._buttonsFlat) {
|
|
612
|
+
if (button.text == text) {
|
|
613
|
+
return button;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
if (filter != undefined) {
|
|
620
|
+
for (const button of self._buttonsFlat) {
|
|
621
|
+
if (filter(button)) {
|
|
622
|
+
return button;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
if (i == undefined) {
|
|
628
|
+
i = 0;
|
|
629
|
+
}
|
|
630
|
+
if (j == undefined) {
|
|
631
|
+
return self._buttonsFlat[i];
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
return self._buttons[i][j];
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
const button = findButton(this);
|
|
638
|
+
if (button) {
|
|
639
|
+
return await button.click({
|
|
640
|
+
sharePhone: sharePhone,
|
|
641
|
+
shareGeo: shareGeo,
|
|
642
|
+
password: password,
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Helper methods to set the buttons given the input sender and chat.
|
|
648
|
+
*/
|
|
649
|
+
_setButtons(chat, bot) {
|
|
650
|
+
if (this.client &&
|
|
651
|
+
(this.replyMarkup instanceof api_1.Api.ReplyInlineMarkup ||
|
|
652
|
+
this.replyMarkup instanceof api_1.Api.ReplyKeyboardMarkup)) {
|
|
653
|
+
this._buttons = [];
|
|
654
|
+
this._buttonsFlat = [];
|
|
655
|
+
for (const row of this.replyMarkup.rows) {
|
|
656
|
+
const tmp = [];
|
|
657
|
+
for (const button of row.buttons) {
|
|
658
|
+
const btn = new messageButton_1.MessageButton(this.client, button, chat, bot, this.id);
|
|
659
|
+
tmp.push(btn);
|
|
660
|
+
this._buttonsFlat.push(btn);
|
|
661
|
+
}
|
|
662
|
+
this._buttons.push(tmp);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
*Returns the input peer of the bot that's needed for the reply markup.
|
|
668
|
+
|
|
669
|
+
This is necessary for `KeyboardButtonSwitchInline` since we need
|
|
670
|
+
to know what bot we want to start. Raises ``Error`` if the bot
|
|
671
|
+
cannot be found but is needed. Returns `None` if it's not needed.
|
|
672
|
+
*/
|
|
673
|
+
_neededMarkupBot() {
|
|
674
|
+
if (!this.client || this.replyMarkup == undefined) {
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
if (!(this.replyMarkup instanceof api_1.Api.ReplyInlineMarkup ||
|
|
678
|
+
this.replyMarkup instanceof api_1.Api.ReplyKeyboardMarkup)) {
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
for (const row of this.replyMarkup.rows) {
|
|
682
|
+
for (const button of row.buttons) {
|
|
683
|
+
if (button instanceof api_1.Api.KeyboardButtonSwitchInline) {
|
|
684
|
+
if (button.samePeer || !this.viaBotId) {
|
|
685
|
+
const bot = this._inputSender;
|
|
686
|
+
if (!bot)
|
|
687
|
+
throw new Error("No input sender");
|
|
688
|
+
return bot;
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
const ent = this.client._entityCache.get(this.viaBotId);
|
|
692
|
+
if (!ent)
|
|
693
|
+
throw new Error("No input sender");
|
|
694
|
+
return ent;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
// TODO fix this
|
|
701
|
+
_documentByAttribute(kind, condition) {
|
|
702
|
+
const doc = this.document;
|
|
703
|
+
if (doc) {
|
|
704
|
+
for (const attr of doc.attributes) {
|
|
705
|
+
if (attr instanceof kind) {
|
|
706
|
+
if (condition == undefined ||
|
|
707
|
+
(typeof condition == "function" && condition(attr))) {
|
|
708
|
+
return doc;
|
|
709
|
+
}
|
|
710
|
+
return undefined;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
exports.CustomMessage = CustomMessage;
|