@overpod/mcp-telegram 1.26.0 → 1.26.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/dist/index.js +4 -1
- package/dist/rate-limiter.d.ts +1 -1
- package/dist/rate-limiter.js +8 -8
- package/dist/telegram-client.d.ts +6 -470
- package/dist/telegram-client.js +17 -874
- package/dist/telegram-helpers.d.ts +470 -0
- package/dist/telegram-helpers.js +870 -0
- package/dist/tools/account.js +7 -7
- package/dist/tools/boosts.js +4 -4
- package/dist/tools/chats.js +7 -7
- package/dist/tools/contacts.js +3 -3
- package/dist/tools/extras.js +3 -3
- package/dist/tools/group-calls.js +3 -3
- package/dist/tools/messages.js +17 -17
- package/dist/tools/quick-replies.js +3 -3
- package/dist/tools/reactions.js +2 -2
- package/dist/tools/shared.d.ts +3 -3
- package/dist/tools/shared.js +8 -7
- package/dist/tools/stars.js +3 -3
- package/dist/tools/stickers.js +5 -5
- package/dist/tools/stories.js +5 -5
- package/package.json +1 -1
- package/dist/__tests__/admin-log.test.d.ts +0 -1
- package/dist/__tests__/admin-log.test.js +0 -41
- package/dist/__tests__/approve-join-request.test.d.ts +0 -1
- package/dist/__tests__/approve-join-request.test.js +0 -107
- package/dist/__tests__/boosts.test.d.ts +0 -1
- package/dist/__tests__/boosts.test.js +0 -310
- package/dist/__tests__/broadcast-stats.test.d.ts +0 -1
- package/dist/__tests__/broadcast-stats.test.js +0 -172
- package/dist/__tests__/business-chat-links.test.d.ts +0 -1
- package/dist/__tests__/business-chat-links.test.js +0 -102
- package/dist/__tests__/get-message-buttons.test.d.ts +0 -1
- package/dist/__tests__/get-message-buttons.test.js +0 -122
- package/dist/__tests__/group-calls.test.d.ts +0 -1
- package/dist/__tests__/group-calls.test.js +0 -503
- package/dist/__tests__/inline-query-send.test.d.ts +0 -1
- package/dist/__tests__/inline-query-send.test.js +0 -94
- package/dist/__tests__/inline-query.test.d.ts +0 -1
- package/dist/__tests__/inline-query.test.js +0 -115
- package/dist/__tests__/megagroup-stats.test.d.ts +0 -1
- package/dist/__tests__/megagroup-stats.test.js +0 -166
- package/dist/__tests__/press-button.test.d.ts +0 -1
- package/dist/__tests__/press-button.test.js +0 -123
- package/dist/__tests__/quick-replies.test.d.ts +0 -1
- package/dist/__tests__/quick-replies.test.js +0 -245
- package/dist/__tests__/rate-limiter.test.d.ts +0 -1
- package/dist/__tests__/rate-limiter.test.js +0 -81
- package/dist/__tests__/reactions.test.d.ts +0 -1
- package/dist/__tests__/reactions.test.js +0 -23
- package/dist/__tests__/set-chat-permissions-merge.test.d.ts +0 -1
- package/dist/__tests__/set-chat-permissions-merge.test.js +0 -107
- package/dist/__tests__/set-chat-reactions.test.d.ts +0 -1
- package/dist/__tests__/set-chat-reactions.test.js +0 -129
- package/dist/__tests__/stars-status.test.d.ts +0 -1
- package/dist/__tests__/stars-status.test.js +0 -205
- package/dist/__tests__/stars-transactions.test.d.ts +0 -1
- package/dist/__tests__/stars-transactions.test.js +0 -82
- package/dist/__tests__/stories.test.d.ts +0 -1
- package/dist/__tests__/stories.test.js +0 -361
- package/dist/__tests__/toggle-anti-spam.test.d.ts +0 -1
- package/dist/__tests__/toggle-anti-spam.test.js +0 -80
- package/dist/__tests__/toggle-channel-signatures.test.d.ts +0 -1
- package/dist/__tests__/toggle-channel-signatures.test.js +0 -80
- package/dist/__tests__/toggle-forum-mode.test.d.ts +0 -1
- package/dist/__tests__/toggle-forum-mode.test.js +0 -80
- package/dist/__tests__/toggle-prehistory-hidden.test.d.ts +0 -1
- package/dist/__tests__/toggle-prehistory-hidden.test.js +0 -80
- package/dist/__tests__/tools/shared.test.d.ts +0 -1
- package/dist/__tests__/tools/shared.test.js +0 -110
- package/dist/__tests__/updates.test.d.ts +0 -1
- package/dist/__tests__/updates.test.js +0 -221
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert";
|
|
2
|
-
import { describe, it } from "node:test";
|
|
3
|
-
import bigInt from "big-integer";
|
|
4
|
-
import { Api } from "telegram/tl/index.js";
|
|
5
|
-
import { TelegramService } from "../telegram-client.js";
|
|
6
|
-
function makeService(entity, invocations) {
|
|
7
|
-
const fakeClient = {
|
|
8
|
-
invoke: async (req) => {
|
|
9
|
-
invocations.push(req);
|
|
10
|
-
return undefined;
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
const service = new TelegramService(1, "hash");
|
|
14
|
-
const internals = service;
|
|
15
|
-
internals.client = fakeClient;
|
|
16
|
-
internals.connected = true;
|
|
17
|
-
internals.resolveChat = async () => entity;
|
|
18
|
-
return service;
|
|
19
|
-
}
|
|
20
|
-
describe("TelegramService.togglePrehistoryHidden", () => {
|
|
21
|
-
it("invokes channels.TogglePreHistoryHidden with enabled=true for supergroup", async () => {
|
|
22
|
-
const megagroup = new Api.Channel({
|
|
23
|
-
id: bigInt(12345),
|
|
24
|
-
title: "supergroup",
|
|
25
|
-
photo: new Api.ChatPhotoEmpty(),
|
|
26
|
-
date: 0,
|
|
27
|
-
accessHash: bigInt(1),
|
|
28
|
-
megagroup: true,
|
|
29
|
-
});
|
|
30
|
-
const invocations = [];
|
|
31
|
-
const service = makeService(megagroup, invocations);
|
|
32
|
-
await service.togglePrehistoryHidden("12345", true);
|
|
33
|
-
const call = invocations.find((r) => r instanceof Api.channels.TogglePreHistoryHidden);
|
|
34
|
-
assert.ok(call, "TogglePreHistoryHidden was invoked");
|
|
35
|
-
assert.strictEqual(call.enabled, true);
|
|
36
|
-
});
|
|
37
|
-
it("invokes channels.TogglePreHistoryHidden with enabled=false", async () => {
|
|
38
|
-
const megagroup = new Api.Channel({
|
|
39
|
-
id: bigInt(22222),
|
|
40
|
-
title: "supergroup",
|
|
41
|
-
photo: new Api.ChatPhotoEmpty(),
|
|
42
|
-
date: 0,
|
|
43
|
-
accessHash: bigInt(1),
|
|
44
|
-
megagroup: true,
|
|
45
|
-
});
|
|
46
|
-
const invocations = [];
|
|
47
|
-
const service = makeService(megagroup, invocations);
|
|
48
|
-
await service.togglePrehistoryHidden("22222", false);
|
|
49
|
-
const call = invocations.find((r) => r instanceof Api.channels.TogglePreHistoryHidden);
|
|
50
|
-
assert.ok(call);
|
|
51
|
-
assert.strictEqual(call.enabled, false);
|
|
52
|
-
});
|
|
53
|
-
it("rejects broadcast channels (not megagroup)", async () => {
|
|
54
|
-
const broadcast = new Api.Channel({
|
|
55
|
-
id: bigInt(33333),
|
|
56
|
-
title: "broadcast",
|
|
57
|
-
photo: new Api.ChatPhotoEmpty(),
|
|
58
|
-
date: 0,
|
|
59
|
-
accessHash: bigInt(1),
|
|
60
|
-
broadcast: true,
|
|
61
|
-
});
|
|
62
|
-
const invocations = [];
|
|
63
|
-
const service = makeService(broadcast, invocations);
|
|
64
|
-
await assert.rejects(service.togglePrehistoryHidden("33333", true), /supergroups, not broadcast channels/);
|
|
65
|
-
assert.strictEqual(invocations.find((r) => r instanceof Api.channels.TogglePreHistoryHidden), undefined, "no API call on invalid target");
|
|
66
|
-
});
|
|
67
|
-
it("rejects non-channel entities (basic group)", async () => {
|
|
68
|
-
const chat = new Api.Chat({
|
|
69
|
-
id: bigInt(44444),
|
|
70
|
-
title: "basic group",
|
|
71
|
-
photo: new Api.ChatPhotoEmpty(),
|
|
72
|
-
participantsCount: 5,
|
|
73
|
-
date: 0,
|
|
74
|
-
version: 0,
|
|
75
|
-
});
|
|
76
|
-
const invocations = [];
|
|
77
|
-
const service = makeService(chat, invocations);
|
|
78
|
-
await assert.rejects(service.togglePrehistoryHidden("44444", true), /supergroups/);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert";
|
|
2
|
-
import { describe, it } from "node:test";
|
|
3
|
-
import { DESTRUCTIVE, fail, formatReactions, ok, READ_ONLY, sanitize, WRITE } from "../../tools/shared.js";
|
|
4
|
-
describe("shared utilities", () => {
|
|
5
|
-
describe("ok()", () => {
|
|
6
|
-
it("should return success response with text content", () => {
|
|
7
|
-
const result = ok("Operation successful");
|
|
8
|
-
assert.deepStrictEqual(result, {
|
|
9
|
-
content: [{ type: "text", text: "Operation successful" }],
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
it("should handle empty string", () => {
|
|
13
|
-
const result = ok("");
|
|
14
|
-
assert.deepStrictEqual(result, {
|
|
15
|
-
content: [{ type: "text", text: "" }],
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
describe("fail()", () => {
|
|
20
|
-
it("should return error response with isError flag", () => {
|
|
21
|
-
const error = new Error("Something went wrong");
|
|
22
|
-
const result = fail(error);
|
|
23
|
-
assert.deepStrictEqual(result, {
|
|
24
|
-
content: [{ type: "text", text: "Error: Something went wrong" }],
|
|
25
|
-
isError: true,
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
it("should handle non-Error objects", () => {
|
|
29
|
-
const result = fail({ message: "Custom error" });
|
|
30
|
-
assert.ok(result.content[0].text.includes("Error:"));
|
|
31
|
-
assert.strictEqual(result.isError, true);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
describe("sanitize()", () => {
|
|
35
|
-
it("should remove unpaired high surrogates", () => {
|
|
36
|
-
const input = "Hello\uD800World";
|
|
37
|
-
const result = sanitize(input);
|
|
38
|
-
assert.strictEqual(result, "Hello\uFFFDWorld");
|
|
39
|
-
});
|
|
40
|
-
it("should remove unpaired low surrogates", () => {
|
|
41
|
-
const input = "Hello\uDC00World";
|
|
42
|
-
const result = sanitize(input);
|
|
43
|
-
assert.strictEqual(result, "Hello\uFFFDWorld");
|
|
44
|
-
});
|
|
45
|
-
it("should preserve valid surrogate pairs", () => {
|
|
46
|
-
const input = "Hello\uD83D\uDE00World"; // 😀 emoji
|
|
47
|
-
const result = sanitize(input);
|
|
48
|
-
assert.strictEqual(result, "Hello\uD83D\uDE00World");
|
|
49
|
-
});
|
|
50
|
-
it("should handle normal text without surrogates", () => {
|
|
51
|
-
const input = "Hello World";
|
|
52
|
-
const result = sanitize(input);
|
|
53
|
-
assert.strictEqual(result, "Hello World");
|
|
54
|
-
});
|
|
55
|
-
it("should handle empty string", () => {
|
|
56
|
-
const result = sanitize("");
|
|
57
|
-
assert.strictEqual(result, "");
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
describe("formatReactions()", () => {
|
|
61
|
-
it("should format reactions with counts", () => {
|
|
62
|
-
const reactions = [
|
|
63
|
-
{ emoji: "👍", count: 5, me: false },
|
|
64
|
-
{ emoji: "❤️", count: 3, me: true },
|
|
65
|
-
{ emoji: "🔥", count: 1, me: false },
|
|
66
|
-
];
|
|
67
|
-
const result = formatReactions(reactions);
|
|
68
|
-
assert.strictEqual(result, " [👍×5 ❤️×3(me) 🔥×1]");
|
|
69
|
-
});
|
|
70
|
-
it("should mark reactions from current user", () => {
|
|
71
|
-
const reactions = [{ emoji: "👍", count: 2, me: true }];
|
|
72
|
-
const result = formatReactions(reactions);
|
|
73
|
-
assert.strictEqual(result, " [👍×2(me)]");
|
|
74
|
-
});
|
|
75
|
-
it("should return empty string for undefined reactions", () => {
|
|
76
|
-
const result = formatReactions(undefined);
|
|
77
|
-
assert.strictEqual(result, "");
|
|
78
|
-
});
|
|
79
|
-
it("should return empty string for empty reactions array", () => {
|
|
80
|
-
const result = formatReactions([]);
|
|
81
|
-
assert.strictEqual(result, "");
|
|
82
|
-
});
|
|
83
|
-
it("should handle single reaction", () => {
|
|
84
|
-
const reactions = [{ emoji: "🎉", count: 1, me: false }];
|
|
85
|
-
const result = formatReactions(reactions);
|
|
86
|
-
assert.strictEqual(result, " [🎉×1]");
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
describe("MCP tool annotations", () => {
|
|
90
|
-
it("should define READ_ONLY preset", () => {
|
|
91
|
-
assert.deepStrictEqual(READ_ONLY, {
|
|
92
|
-
readOnlyHint: true,
|
|
93
|
-
openWorldHint: true,
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
it("should define WRITE preset", () => {
|
|
97
|
-
assert.deepStrictEqual(WRITE, {
|
|
98
|
-
readOnlyHint: false,
|
|
99
|
-
openWorldHint: true,
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
it("should define DESTRUCTIVE preset", () => {
|
|
103
|
-
assert.deepStrictEqual(DESTRUCTIVE, {
|
|
104
|
-
readOnlyHint: false,
|
|
105
|
-
destructiveHint: true,
|
|
106
|
-
openWorldHint: true,
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert";
|
|
2
|
-
import { describe, it } from "node:test";
|
|
3
|
-
import bigInt from "big-integer";
|
|
4
|
-
import { Api } from "telegram/tl/index.js";
|
|
5
|
-
import { peerToCompact, summarizeChannelDifference, summarizeUpdatesDifference, TelegramService, } from "../telegram-client.js";
|
|
6
|
-
function makeService(invocations, responder, chatEntity) {
|
|
7
|
-
const fakeClient = {
|
|
8
|
-
invoke: async (req) => {
|
|
9
|
-
invocations.push(req);
|
|
10
|
-
return responder(req);
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
const service = new TelegramService(1, "hash");
|
|
14
|
-
const internals = service;
|
|
15
|
-
internals.client = fakeClient;
|
|
16
|
-
internals.connected = true;
|
|
17
|
-
internals.resolveChat = async () => chatEntity;
|
|
18
|
-
return service;
|
|
19
|
-
}
|
|
20
|
-
function makeState(pts, qts, date, seq = 0, unreadCount = 0) {
|
|
21
|
-
return new Api.updates.State({ pts, qts, date, seq, unreadCount });
|
|
22
|
-
}
|
|
23
|
-
function makeChannel(id, megagroup = true) {
|
|
24
|
-
return new Api.Channel({
|
|
25
|
-
id: bigInt(id),
|
|
26
|
-
title: "c",
|
|
27
|
-
photo: new Api.ChatPhotoEmpty(),
|
|
28
|
-
date: 0,
|
|
29
|
-
accessHash: bigInt(1),
|
|
30
|
-
megagroup,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
function makeMessage(id, peerId, text = "hi") {
|
|
34
|
-
return new Api.Message({ id, peerId, date: 10, message: text });
|
|
35
|
-
}
|
|
36
|
-
describe("peerToCompact", () => {
|
|
37
|
-
it("maps PeerUser/PeerChat/PeerChannel to compact kind+id", () => {
|
|
38
|
-
assert.deepStrictEqual(peerToCompact(new Api.PeerUser({ userId: bigInt(5) })), { kind: "user", id: "5" });
|
|
39
|
-
assert.deepStrictEqual(peerToCompact(new Api.PeerChat({ chatId: bigInt(6) })), { kind: "chat", id: "6" });
|
|
40
|
-
assert.deepStrictEqual(peerToCompact(new Api.PeerChannel({ channelId: bigInt(7) })), {
|
|
41
|
-
kind: "channel",
|
|
42
|
-
id: "7",
|
|
43
|
-
});
|
|
44
|
-
assert.strictEqual(peerToCompact(undefined), undefined);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
describe("TelegramService.getUpdatesState", () => {
|
|
48
|
-
it("invokes updates.GetState and returns compact state", async () => {
|
|
49
|
-
const invocations = [];
|
|
50
|
-
const service = makeService(invocations, () => makeState(100, 200, 300, 4, 5));
|
|
51
|
-
const out = await service.getUpdatesState();
|
|
52
|
-
assert.ok(invocations.find((r) => r instanceof Api.updates.GetState));
|
|
53
|
-
assert.deepStrictEqual(out, { pts: 100, qts: 200, date: 300, seq: 4, unreadCount: 5 });
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
describe("summarizeUpdatesDifference", () => {
|
|
57
|
-
it("handles DifferenceEmpty as final with no messages", () => {
|
|
58
|
-
const diff = new Api.updates.DifferenceEmpty({ date: 400, seq: 1 });
|
|
59
|
-
const out = summarizeUpdatesDifference(diff, { pts: 10, qts: 20, date: 30 });
|
|
60
|
-
assert.strictEqual(out.isFinal, true);
|
|
61
|
-
assert.strictEqual(out.state.pts, 10);
|
|
62
|
-
assert.strictEqual(out.state.qts, 20);
|
|
63
|
-
assert.strictEqual(out.state.date, 400);
|
|
64
|
-
assert.deepStrictEqual(out.newMessages, []);
|
|
65
|
-
assert.deepStrictEqual(out.deletedMessageIds, []);
|
|
66
|
-
assert.strictEqual(out.fallback, undefined);
|
|
67
|
-
});
|
|
68
|
-
it("handles Difference (final) with newMessages, deleted updates, and final state", () => {
|
|
69
|
-
const msg = makeMessage(1, new Api.PeerUser({ userId: bigInt(7) }), "yo");
|
|
70
|
-
const del = new Api.UpdateDeleteMessages({ messages: [5, 6], pts: 11, ptsCount: 2 });
|
|
71
|
-
const delCh = new Api.UpdateDeleteChannelMessages({
|
|
72
|
-
channelId: bigInt(999),
|
|
73
|
-
messages: [20, 21],
|
|
74
|
-
pts: 22,
|
|
75
|
-
ptsCount: 2,
|
|
76
|
-
});
|
|
77
|
-
const diff = new Api.updates.Difference({
|
|
78
|
-
newMessages: [msg],
|
|
79
|
-
newEncryptedMessages: [],
|
|
80
|
-
otherUpdates: [del, delCh],
|
|
81
|
-
chats: [],
|
|
82
|
-
users: [],
|
|
83
|
-
state: makeState(50, 60, 70, 8, 1),
|
|
84
|
-
});
|
|
85
|
-
const out = summarizeUpdatesDifference(diff, { pts: 1, qts: 2, date: 3 });
|
|
86
|
-
assert.strictEqual(out.isFinal, true);
|
|
87
|
-
assert.deepStrictEqual(out.state, { pts: 50, qts: 60, date: 70, seq: 8, unreadCount: 1 });
|
|
88
|
-
assert.strictEqual(out.newMessages.length, 1);
|
|
89
|
-
assert.strictEqual(out.newMessages[0].text, "yo");
|
|
90
|
-
assert.deepStrictEqual(out.newMessages[0].peer, { kind: "user", id: "7" });
|
|
91
|
-
assert.strictEqual(out.newMessages[0].isService, false);
|
|
92
|
-
assert.strictEqual(out.deletedMessageIds.length, 2);
|
|
93
|
-
assert.deepStrictEqual(out.deletedMessageIds[0], { messageIds: [5, 6] });
|
|
94
|
-
assert.deepStrictEqual(out.deletedMessageIds[1], {
|
|
95
|
-
peer: { kind: "channel", id: "999" },
|
|
96
|
-
messageIds: [20, 21],
|
|
97
|
-
});
|
|
98
|
-
assert.deepStrictEqual(out.otherUpdates.map((u) => u.type), ["UpdateDeleteMessages", "UpdateDeleteChannelMessages"]);
|
|
99
|
-
});
|
|
100
|
-
it("handles DifferenceSlice as non-final with intermediateState", () => {
|
|
101
|
-
const diff = new Api.updates.DifferenceSlice({
|
|
102
|
-
newMessages: [],
|
|
103
|
-
newEncryptedMessages: [],
|
|
104
|
-
otherUpdates: [],
|
|
105
|
-
chats: [],
|
|
106
|
-
users: [],
|
|
107
|
-
intermediateState: makeState(77, 88, 99, 0, 0),
|
|
108
|
-
});
|
|
109
|
-
const out = summarizeUpdatesDifference(diff, { pts: 1, qts: 2, date: 3 });
|
|
110
|
-
assert.strictEqual(out.isFinal, false);
|
|
111
|
-
assert.strictEqual(out.state.pts, 77);
|
|
112
|
-
});
|
|
113
|
-
it("handles DifferenceTooLong with fallback hint", () => {
|
|
114
|
-
const diff = new Api.updates.DifferenceTooLong({ pts: 500 });
|
|
115
|
-
const out = summarizeUpdatesDifference(diff, { pts: 1, qts: 2, date: 3 });
|
|
116
|
-
assert.strictEqual(out.isFinal, true);
|
|
117
|
-
assert.strictEqual(out.state.pts, 500);
|
|
118
|
-
assert.ok(out.fallback);
|
|
119
|
-
assert.strictEqual(out.fallback?.kind, "tooLong");
|
|
120
|
-
assert.match(out.fallback?.suggestedAction ?? "", /telegram-read-messages|resync/);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
describe("TelegramService.getUpdates", () => {
|
|
124
|
-
it("invokes updates.GetDifference with cursor and caps ptsLimit to 1000", async () => {
|
|
125
|
-
const invocations = [];
|
|
126
|
-
const service = makeService(invocations, () => new Api.updates.DifferenceEmpty({ date: 99, seq: 0 }));
|
|
127
|
-
await service.getUpdates({ pts: 10, qts: 20, date: 30, ptsLimit: 5000 });
|
|
128
|
-
const call = invocations.find((r) => r instanceof Api.updates.GetDifference);
|
|
129
|
-
assert.ok(call);
|
|
130
|
-
assert.strictEqual(call.pts, 10);
|
|
131
|
-
assert.strictEqual(call.qts, 20);
|
|
132
|
-
assert.strictEqual(call.date, 30);
|
|
133
|
-
assert.strictEqual(call.ptsLimit, 1000);
|
|
134
|
-
});
|
|
135
|
-
it("applies defaults when ptsLimit/ptsTotalLimit omitted", async () => {
|
|
136
|
-
const invocations = [];
|
|
137
|
-
const service = makeService(invocations, () => new Api.updates.DifferenceEmpty({ date: 1, seq: 0 }));
|
|
138
|
-
await service.getUpdates({ pts: 1, qts: 1, date: 1 });
|
|
139
|
-
const call = invocations.find((r) => r instanceof Api.updates.GetDifference);
|
|
140
|
-
assert.ok(call);
|
|
141
|
-
assert.strictEqual(call.ptsLimit, 100);
|
|
142
|
-
assert.strictEqual(call.ptsTotalLimit, 1000);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
describe("summarizeChannelDifference", () => {
|
|
146
|
-
it("summarizes ChannelDifferenceEmpty", () => {
|
|
147
|
-
const diff = new Api.updates.ChannelDifferenceEmpty({ final: true, pts: 42, timeout: 30 });
|
|
148
|
-
const out = summarizeChannelDifference(diff, "100", 0);
|
|
149
|
-
assert.strictEqual(out.pts, 42);
|
|
150
|
-
assert.strictEqual(out.isFinal, true);
|
|
151
|
-
assert.strictEqual(out.timeout, 30);
|
|
152
|
-
assert.deepStrictEqual(out.newMessages, []);
|
|
153
|
-
});
|
|
154
|
-
it("summarizes ChannelDifference with newMessages/otherUpdates", () => {
|
|
155
|
-
const msg = makeMessage(10, new Api.PeerChannel({ channelId: bigInt(100) }), "chan-msg");
|
|
156
|
-
const diff = new Api.updates.ChannelDifference({
|
|
157
|
-
final: false,
|
|
158
|
-
pts: 55,
|
|
159
|
-
newMessages: [msg],
|
|
160
|
-
otherUpdates: [],
|
|
161
|
-
chats: [],
|
|
162
|
-
users: [],
|
|
163
|
-
});
|
|
164
|
-
const out = summarizeChannelDifference(diff, "100", 0);
|
|
165
|
-
assert.strictEqual(out.pts, 55);
|
|
166
|
-
assert.strictEqual(out.isFinal, false);
|
|
167
|
-
assert.strictEqual(out.newMessages.length, 1);
|
|
168
|
-
assert.strictEqual(out.newMessages[0].text, "chan-msg");
|
|
169
|
-
});
|
|
170
|
-
it("summarizes ChannelDifferenceTooLong with fallback and dialog snapshot messages", () => {
|
|
171
|
-
const msg = makeMessage(1, new Api.PeerChannel({ channelId: bigInt(100) }), "snap");
|
|
172
|
-
const diff = new Api.updates.ChannelDifferenceTooLong({
|
|
173
|
-
final: true,
|
|
174
|
-
dialog: new Api.Dialog({
|
|
175
|
-
peer: new Api.PeerChannel({ channelId: bigInt(100) }),
|
|
176
|
-
topMessage: 1,
|
|
177
|
-
readInboxMaxId: 0,
|
|
178
|
-
readOutboxMaxId: 0,
|
|
179
|
-
unreadCount: 0,
|
|
180
|
-
unreadMentionsCount: 0,
|
|
181
|
-
unreadReactionsCount: 0,
|
|
182
|
-
notifySettings: new Api.PeerNotifySettings({}),
|
|
183
|
-
}),
|
|
184
|
-
messages: [msg],
|
|
185
|
-
chats: [],
|
|
186
|
-
users: [],
|
|
187
|
-
});
|
|
188
|
-
const out = summarizeChannelDifference(diff, "100", 42);
|
|
189
|
-
assert.strictEqual(out.pts, 42);
|
|
190
|
-
assert.strictEqual(out.newMessages.length, 1);
|
|
191
|
-
assert.ok(out.fallback);
|
|
192
|
-
assert.strictEqual(out.fallback?.kind, "tooLong");
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
describe("TelegramService.getChannelUpdates", () => {
|
|
196
|
-
it("invokes updates.GetChannelDifference with resolved channel and caps limit", async () => {
|
|
197
|
-
const invocations = [];
|
|
198
|
-
const chan = makeChannel(100);
|
|
199
|
-
const service = makeService(invocations, () => new Api.updates.ChannelDifferenceEmpty({ final: true, pts: 7 }), chan);
|
|
200
|
-
await service.getChannelUpdates("100", { pts: 5, limit: 9999999, force: true });
|
|
201
|
-
const call = invocations.find((r) => r instanceof Api.updates.GetChannelDifference);
|
|
202
|
-
assert.ok(call);
|
|
203
|
-
assert.strictEqual(call.pts, 5);
|
|
204
|
-
assert.strictEqual(call.limit, 1_000);
|
|
205
|
-
assert.strictEqual(call.force, true);
|
|
206
|
-
assert.ok(call.filter instanceof Api.ChannelMessagesFilterEmpty);
|
|
207
|
-
});
|
|
208
|
-
it("rejects when chat entity is not a channel", async () => {
|
|
209
|
-
const invocations = [];
|
|
210
|
-
const notChan = new Api.Chat({
|
|
211
|
-
id: bigInt(1),
|
|
212
|
-
title: "c",
|
|
213
|
-
photo: new Api.ChatPhotoEmpty(),
|
|
214
|
-
participantsCount: 1,
|
|
215
|
-
date: 0,
|
|
216
|
-
version: 1,
|
|
217
|
-
});
|
|
218
|
-
const service = makeService(invocations, () => new Api.updates.ChannelDifferenceEmpty({ final: true, pts: 0 }), notChan);
|
|
219
|
-
await assert.rejects(service.getChannelUpdates("1", { pts: 1 }), /channels\/supergroups/i);
|
|
220
|
-
});
|
|
221
|
-
});
|