@imessaging/telegram-mtproto 0.8.0 → 0.8.1
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/package.json +2 -2
- package/src/incoming.ts +2 -0
- package/src/telegram-mtproto-transport.ts +38 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imessaging/telegram-mtproto",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Telegram MTProto user-account transport for imessaging",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"messaging",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"test": "bun test"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@imessaging/core": "^0.8.
|
|
34
|
+
"@imessaging/core": "^0.8.1",
|
|
35
35
|
"big-integer": "^1.6.52"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
package/src/incoming.ts
CHANGED
|
@@ -18,6 +18,7 @@ export type MtprotoMessageLike = {
|
|
|
18
18
|
date?: number | null;
|
|
19
19
|
editDate?: number | null;
|
|
20
20
|
groupedId?: { toString(): string } | null;
|
|
21
|
+
mentioned?: boolean | null;
|
|
21
22
|
peerId?: MtprotoPeerLike;
|
|
22
23
|
fromId?: MtprotoPeerLike;
|
|
23
24
|
media?: MtprotoMediaLike;
|
|
@@ -298,6 +299,7 @@ export function toIncomingMessage(
|
|
|
298
299
|
editedAt: message.editDate ? new Date(message.editDate * 1000) : undefined,
|
|
299
300
|
attachments: collectAttachments(message, chatId),
|
|
300
301
|
links: collectLinks(message),
|
|
302
|
+
mentionsMe: typeof message.mentioned === "boolean" ? message.mentioned : undefined,
|
|
301
303
|
replyToMessageId,
|
|
302
304
|
threadId,
|
|
303
305
|
forwardedFrom: toForwardedFrom(message.fwdFrom),
|
|
@@ -43,6 +43,7 @@ export type TelegramChatSummary = {
|
|
|
43
43
|
title: string;
|
|
44
44
|
username?: string;
|
|
45
45
|
unreadCount: number;
|
|
46
|
+
unreadMentions: number;
|
|
46
47
|
};
|
|
47
48
|
|
|
48
49
|
export type TelegramMtprotoTransportOptions = {
|
|
@@ -408,7 +409,14 @@ export class TelegramMtprotoTransport
|
|
|
408
409
|
);
|
|
409
410
|
}
|
|
410
411
|
|
|
411
|
-
summaries.push({
|
|
412
|
+
summaries.push({
|
|
413
|
+
chatId,
|
|
414
|
+
chatType,
|
|
415
|
+
title,
|
|
416
|
+
username,
|
|
417
|
+
unreadCount: dialog.unreadCount,
|
|
418
|
+
unreadMentions: dialog.unreadMentionsCount ?? 0,
|
|
419
|
+
});
|
|
412
420
|
if (summaries.length >= limit) break;
|
|
413
421
|
}
|
|
414
422
|
return summaries;
|
|
@@ -417,16 +425,21 @@ export class TelegramMtprotoTransport
|
|
|
417
425
|
/**
|
|
418
426
|
* Последние `limit` сообщений чата, от старых к новым, ВКЛЮЧАЯ свои — это чтение истории, а не приём.
|
|
419
427
|
* Служебные события (вход в группу, закреп) пропускаются: текста и вложений у них нет.
|
|
428
|
+
*
|
|
429
|
+
* @param options.mentionsOnly Только упоминания аккаунта. Фильтр работает на уровне всего чата;
|
|
430
|
+
* вызывающий код должен сам отфильтровать результат по `threadId`.
|
|
420
431
|
*/
|
|
421
432
|
async history(
|
|
422
433
|
recipient: TelegramRecipient,
|
|
423
|
-
options?: { limit?: number; threadId?: number },
|
|
434
|
+
options?: { limit?: number; threadId?: number; mentionsOnly?: boolean },
|
|
424
435
|
): Promise<IncomingMessage[]> {
|
|
425
436
|
this.assertConnected();
|
|
426
437
|
const peer = await this.getInputPeer(recipient);
|
|
438
|
+
// gramjs игнорирует filter, если передан replyTo, поэтому для mentionsOnly replyTo не передаём
|
|
427
439
|
const messages = await this.client.getMessages(peer, {
|
|
428
440
|
limit: options?.limit ?? 30,
|
|
429
|
-
replyTo: options?.threadId,
|
|
441
|
+
replyTo: options?.mentionsOnly ? undefined : options?.threadId,
|
|
442
|
+
filter: options?.mentionsOnly ? new Api.InputMessagesFilterMyMentions() : undefined,
|
|
430
443
|
});
|
|
431
444
|
return [...messages]
|
|
432
445
|
.reverse()
|
|
@@ -440,6 +453,28 @@ export class TelegramMtprotoTransport
|
|
|
440
453
|
);
|
|
441
454
|
}
|
|
442
455
|
|
|
456
|
+
/**
|
|
457
|
+
* Запросить конкретные сообщения по их номерам.
|
|
458
|
+
* Контекст для упоминаний, то есть сообщение, на которое кто-то ответил.
|
|
459
|
+
* Если запросить пустой список, вернёт `[]` без сетевых вызовов (но после проверки соединения).
|
|
460
|
+
*/
|
|
461
|
+
async messagesByIds(recipient: TelegramRecipient, ids: number[]): Promise<IncomingMessage[]> {
|
|
462
|
+
this.assertConnected();
|
|
463
|
+
if (ids.length === 0) return [];
|
|
464
|
+
const peer = await this.getInputPeer(recipient);
|
|
465
|
+
const messages = await this.client.getMessages(peer, { ids });
|
|
466
|
+
return messages
|
|
467
|
+
.filter((message) => message && message.className === "Message")
|
|
468
|
+
.map((message) =>
|
|
469
|
+
toIncomingMessage(
|
|
470
|
+
message as unknown as MtprotoMessageLike,
|
|
471
|
+
this.id,
|
|
472
|
+
this.options.accountId,
|
|
473
|
+
),
|
|
474
|
+
)
|
|
475
|
+
.sort((a, b) => Number(a.messageId) - Number(b.messageId));
|
|
476
|
+
}
|
|
477
|
+
|
|
443
478
|
private async sendWithRetry(message: OutboundMessage, retried: boolean): Promise<SendResult> {
|
|
444
479
|
try {
|
|
445
480
|
const peer = await this.getInputPeer(message.recipient);
|