@overpod/mcp-telegram 1.26.0 → 1.27.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 (80) hide show
  1. package/dist/client.d.ts +12 -0
  2. package/dist/client.js +136 -0
  3. package/dist/index.js +15 -24
  4. package/dist/ipc-protocol.d.ts +19 -0
  5. package/dist/ipc-protocol.js +22 -0
  6. package/dist/lock.d.ts +12 -0
  7. package/dist/lock.js +83 -0
  8. package/dist/master.d.ts +1 -0
  9. package/dist/master.js +105 -0
  10. package/dist/rate-limiter.d.ts +1 -1
  11. package/dist/rate-limiter.js +8 -8
  12. package/dist/telegram-client.d.ts +6 -470
  13. package/dist/telegram-client.js +17 -874
  14. package/dist/telegram-helpers.d.ts +470 -0
  15. package/dist/telegram-helpers.js +870 -0
  16. package/dist/tools/account.js +7 -7
  17. package/dist/tools/boosts.js +4 -4
  18. package/dist/tools/chats.js +7 -7
  19. package/dist/tools/contacts.js +3 -3
  20. package/dist/tools/extras.js +3 -3
  21. package/dist/tools/group-calls.js +3 -3
  22. package/dist/tools/messages.js +17 -17
  23. package/dist/tools/quick-replies.js +3 -3
  24. package/dist/tools/reactions.js +2 -2
  25. package/dist/tools/shared.d.ts +3 -3
  26. package/dist/tools/shared.js +8 -7
  27. package/dist/tools/stars.js +3 -3
  28. package/dist/tools/stickers.js +5 -5
  29. package/dist/tools/stories.js +5 -5
  30. package/package.json +1 -1
  31. package/dist/__tests__/admin-log.test.d.ts +0 -1
  32. package/dist/__tests__/admin-log.test.js +0 -41
  33. package/dist/__tests__/approve-join-request.test.d.ts +0 -1
  34. package/dist/__tests__/approve-join-request.test.js +0 -107
  35. package/dist/__tests__/boosts.test.d.ts +0 -1
  36. package/dist/__tests__/boosts.test.js +0 -310
  37. package/dist/__tests__/broadcast-stats.test.d.ts +0 -1
  38. package/dist/__tests__/broadcast-stats.test.js +0 -172
  39. package/dist/__tests__/business-chat-links.test.d.ts +0 -1
  40. package/dist/__tests__/business-chat-links.test.js +0 -102
  41. package/dist/__tests__/get-message-buttons.test.d.ts +0 -1
  42. package/dist/__tests__/get-message-buttons.test.js +0 -122
  43. package/dist/__tests__/group-calls.test.d.ts +0 -1
  44. package/dist/__tests__/group-calls.test.js +0 -503
  45. package/dist/__tests__/inline-query-send.test.d.ts +0 -1
  46. package/dist/__tests__/inline-query-send.test.js +0 -94
  47. package/dist/__tests__/inline-query.test.d.ts +0 -1
  48. package/dist/__tests__/inline-query.test.js +0 -115
  49. package/dist/__tests__/megagroup-stats.test.d.ts +0 -1
  50. package/dist/__tests__/megagroup-stats.test.js +0 -166
  51. package/dist/__tests__/press-button.test.d.ts +0 -1
  52. package/dist/__tests__/press-button.test.js +0 -123
  53. package/dist/__tests__/quick-replies.test.d.ts +0 -1
  54. package/dist/__tests__/quick-replies.test.js +0 -245
  55. package/dist/__tests__/rate-limiter.test.d.ts +0 -1
  56. package/dist/__tests__/rate-limiter.test.js +0 -81
  57. package/dist/__tests__/reactions.test.d.ts +0 -1
  58. package/dist/__tests__/reactions.test.js +0 -23
  59. package/dist/__tests__/set-chat-permissions-merge.test.d.ts +0 -1
  60. package/dist/__tests__/set-chat-permissions-merge.test.js +0 -107
  61. package/dist/__tests__/set-chat-reactions.test.d.ts +0 -1
  62. package/dist/__tests__/set-chat-reactions.test.js +0 -129
  63. package/dist/__tests__/stars-status.test.d.ts +0 -1
  64. package/dist/__tests__/stars-status.test.js +0 -205
  65. package/dist/__tests__/stars-transactions.test.d.ts +0 -1
  66. package/dist/__tests__/stars-transactions.test.js +0 -82
  67. package/dist/__tests__/stories.test.d.ts +0 -1
  68. package/dist/__tests__/stories.test.js +0 -361
  69. package/dist/__tests__/toggle-anti-spam.test.d.ts +0 -1
  70. package/dist/__tests__/toggle-anti-spam.test.js +0 -80
  71. package/dist/__tests__/toggle-channel-signatures.test.d.ts +0 -1
  72. package/dist/__tests__/toggle-channel-signatures.test.js +0 -80
  73. package/dist/__tests__/toggle-forum-mode.test.d.ts +0 -1
  74. package/dist/__tests__/toggle-forum-mode.test.js +0 -80
  75. package/dist/__tests__/toggle-prehistory-hidden.test.d.ts +0 -1
  76. package/dist/__tests__/toggle-prehistory-hidden.test.js +0 -80
  77. package/dist/__tests__/tools/shared.test.d.ts +0 -1
  78. package/dist/__tests__/tools/shared.test.js +0 -110
  79. package/dist/__tests__/updates.test.d.ts +0 -1
  80. package/dist/__tests__/updates.test.js +0 -221
@@ -1,503 +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 { summarizeGroupCall, summarizeGroupCallInfo, summarizeGroupCallParticipant, summarizeGroupCallParticipants, TelegramService, } from "../telegram-client.js";
6
- import { isGroupCallsEnabled } from "../tools/group-calls.js";
7
- function makeService(invocations, responder) {
8
- const fakeClient = {
9
- invoke: async (req) => {
10
- invocations.push(req);
11
- return responder(req);
12
- },
13
- };
14
- const service = new TelegramService(1, "hash");
15
- const internals = service;
16
- internals.client = fakeClient;
17
- internals.connected = true;
18
- return service;
19
- }
20
- describe("summarizeGroupCallInfo", () => {
21
- it("maps an active GroupCall with flags and optional metadata", () => {
22
- const call = new Api.GroupCall({
23
- id: bigInt(100),
24
- accessHash: bigInt(200),
25
- participantsCount: 5,
26
- title: "Stand-up",
27
- recordStartDate: 1710000000,
28
- streamDcId: 2,
29
- unmutedVideoCount: 1,
30
- unmutedVideoLimit: 30,
31
- version: 7,
32
- joinMuted: true,
33
- canStartVideo: true,
34
- rtmpStream: false,
35
- });
36
- const out = summarizeGroupCallInfo(call);
37
- assert.strictEqual(out.kind, "active");
38
- if (out.kind !== "active")
39
- throw new Error("expected active");
40
- assert.strictEqual(out.id, "100");
41
- assert.strictEqual(out.accessHash, "200");
42
- assert.strictEqual(out.participantsCount, 5);
43
- assert.strictEqual(out.title, "Stand-up");
44
- assert.strictEqual(out.recordStartDate, 1710000000);
45
- assert.strictEqual(out.streamDcId, 2);
46
- assert.strictEqual(out.unmutedVideoCount, 1);
47
- assert.strictEqual(out.unmutedVideoLimit, 30);
48
- assert.strictEqual(out.version, 7);
49
- assert.strictEqual(out.joinMuted, true);
50
- assert.strictEqual(out.canStartVideo, true);
51
- assert.strictEqual(out.rtmpStream, false);
52
- });
53
- it("maps a discarded GroupCall with duration", () => {
54
- const call = new Api.GroupCallDiscarded({
55
- id: bigInt(5),
56
- accessHash: bigInt(6),
57
- duration: 1234,
58
- });
59
- const out = summarizeGroupCallInfo(call);
60
- assert.strictEqual(out.kind, "discarded");
61
- if (out.kind !== "discarded")
62
- throw new Error("expected discarded");
63
- assert.strictEqual(out.id, "5");
64
- assert.strictEqual(out.accessHash, "6");
65
- assert.strictEqual(out.duration, 1234);
66
- });
67
- });
68
- describe("summarizeGroupCallParticipant", () => {
69
- it("maps required fields and flags", () => {
70
- const p = new Api.GroupCallParticipant({
71
- peer: new Api.PeerUser({ userId: bigInt(99) }),
72
- date: 1700000000,
73
- source: 12345,
74
- muted: true,
75
- self: true,
76
- volume: 10000,
77
- about: "hello",
78
- raiseHandRating: bigInt(42),
79
- video: new Api.GroupCallParticipantVideo({
80
- endpoint: "vid-ep",
81
- sourceGroups: [],
82
- }),
83
- });
84
- const out = summarizeGroupCallParticipant(p);
85
- assert.deepStrictEqual(out.peer, { kind: "user", id: "99" });
86
- assert.strictEqual(out.date, 1700000000);
87
- assert.strictEqual(out.source, 12345);
88
- assert.strictEqual(out.muted, true);
89
- assert.strictEqual(out.self, true);
90
- assert.strictEqual(out.volume, 10000);
91
- assert.strictEqual(out.about, "hello");
92
- assert.strictEqual(out.raiseHandRating, "42");
93
- assert.strictEqual(out.hasVideo, true);
94
- assert.strictEqual(out.hasPresentation, undefined);
95
- });
96
- it("handles channel peer and leaves optional fields undefined", () => {
97
- const p = new Api.GroupCallParticipant({
98
- peer: new Api.PeerChannel({ channelId: bigInt(500) }),
99
- date: 1,
100
- source: 2,
101
- });
102
- const out = summarizeGroupCallParticipant(p);
103
- assert.deepStrictEqual(out.peer, { kind: "channel", id: "500" });
104
- assert.strictEqual(out.volume, undefined);
105
- assert.strictEqual(out.about, undefined);
106
- assert.strictEqual(out.raiseHandRating, undefined);
107
- assert.strictEqual(out.hasVideo, undefined);
108
- });
109
- });
110
- describe("summarizeGroupCall", () => {
111
- it("maps call info, participants and next offset", () => {
112
- const resp = new Api.phone.GroupCall({
113
- call: new Api.GroupCall({
114
- id: bigInt(1),
115
- accessHash: bigInt(2),
116
- participantsCount: 2,
117
- unmutedVideoLimit: 30,
118
- version: 1,
119
- }),
120
- participants: [
121
- new Api.GroupCallParticipant({
122
- peer: new Api.PeerUser({ userId: bigInt(10) }),
123
- date: 100,
124
- source: 1,
125
- }),
126
- new Api.GroupCallParticipant({
127
- peer: new Api.PeerUser({ userId: bigInt(11) }),
128
- date: 101,
129
- source: 2,
130
- }),
131
- ],
132
- participantsNextOffset: "next-cursor",
133
- chats: [],
134
- users: [],
135
- });
136
- const out = summarizeGroupCall(resp);
137
- assert.strictEqual(out.call.kind, "active");
138
- assert.strictEqual(out.call.id, "1");
139
- assert.strictEqual(out.participants.length, 2);
140
- assert.deepStrictEqual(out.participants[0].peer, { kind: "user", id: "10" });
141
- assert.strictEqual(out.participantsNextOffset, "next-cursor");
142
- });
143
- it("omits empty nextOffset", () => {
144
- const resp = new Api.phone.GroupCall({
145
- call: new Api.GroupCall({
146
- id: bigInt(1),
147
- accessHash: bigInt(2),
148
- participantsCount: 0,
149
- unmutedVideoLimit: 30,
150
- version: 1,
151
- }),
152
- participants: [],
153
- participantsNextOffset: "",
154
- chats: [],
155
- users: [],
156
- });
157
- const out = summarizeGroupCall(resp);
158
- assert.strictEqual(out.participants.length, 0);
159
- assert.strictEqual(out.participantsNextOffset, undefined);
160
- });
161
- });
162
- describe("TelegramService.getGroupCall", () => {
163
- it("resolves channel, extracts input group call from ChannelFull, and invokes phone.GetGroupCall", async () => {
164
- const channelEntity = new Api.Channel({
165
- id: bigInt(777),
166
- title: "Test Channel",
167
- photo: new Api.ChatPhotoEmpty(),
168
- date: 0,
169
- participantsCount: 5,
170
- accessHash: bigInt(888),
171
- });
172
- const inputCall = new Api.InputGroupCall({ id: bigInt(1001), accessHash: bigInt(2002) });
173
- const fullChannel = new Api.ChannelFull({
174
- id: bigInt(777),
175
- about: "x",
176
- readInboxMaxId: 0,
177
- readOutboxMaxId: 0,
178
- unreadCount: 0,
179
- chatPhoto: new Api.PhotoEmpty({ id: bigInt(0) }),
180
- notifySettings: new Api.PeerNotifySettings({}),
181
- botInfo: [],
182
- pts: 0,
183
- call: inputCall,
184
- });
185
- const fullResponse = new Api.messages.ChatFull({
186
- fullChat: fullChannel,
187
- chats: [channelEntity],
188
- users: [],
189
- });
190
- const groupCallResponse = new Api.phone.GroupCall({
191
- call: new Api.GroupCall({
192
- id: bigInt(1001),
193
- accessHash: bigInt(2002),
194
- participantsCount: 3,
195
- unmutedVideoLimit: 30,
196
- version: 1,
197
- }),
198
- participants: [],
199
- participantsNextOffset: "",
200
- chats: [],
201
- users: [],
202
- });
203
- const invocations = [];
204
- const service = makeService(invocations, (req) => {
205
- if (req instanceof Api.channels.GetFullChannel)
206
- return fullResponse;
207
- if (req instanceof Api.phone.GetGroupCall)
208
- return groupCallResponse;
209
- throw new Error(`Unexpected request ${req.className}`);
210
- });
211
- const internals = service;
212
- internals.resolveChat = async () => channelEntity;
213
- const out = await service.getGroupCall("@foo", { limit: 0 });
214
- const getCall = invocations.find((r) => r instanceof Api.phone.GetGroupCall);
215
- assert.ok(getCall, "phone.GetGroupCall should be invoked");
216
- assert.strictEqual(getCall.limit, 0);
217
- assert.ok(getCall.call instanceof Api.InputGroupCall);
218
- assert.strictEqual(getCall.call.id.toString(), "1001");
219
- assert.strictEqual(out.call.kind, "active");
220
- assert.strictEqual(out.call.id, "1001");
221
- });
222
- it("throws when chat has no active group call", async () => {
223
- const channelEntity = new Api.Channel({
224
- id: bigInt(1),
225
- title: "T",
226
- photo: new Api.ChatPhotoEmpty(),
227
- date: 0,
228
- participantsCount: 1,
229
- accessHash: bigInt(2),
230
- });
231
- const fullChannel = new Api.ChannelFull({
232
- id: bigInt(1),
233
- about: "x",
234
- readInboxMaxId: 0,
235
- readOutboxMaxId: 0,
236
- unreadCount: 0,
237
- chatPhoto: new Api.PhotoEmpty({ id: bigInt(0) }),
238
- notifySettings: new Api.PeerNotifySettings({}),
239
- botInfo: [],
240
- pts: 0,
241
- });
242
- const fullResponse = new Api.messages.ChatFull({
243
- fullChat: fullChannel,
244
- chats: [channelEntity],
245
- users: [],
246
- });
247
- const service = makeService([], () => fullResponse);
248
- const internals = service;
249
- internals.resolveChat = async () => channelEntity;
250
- await assert.rejects(() => service.getGroupCall("@no-call"), /No active group call/);
251
- });
252
- it("rejects non-group peers (e.g. users)", async () => {
253
- const userEntity = new Api.User({ id: bigInt(1), accessHash: bigInt(2), firstName: "x" });
254
- const service = makeService([], () => {
255
- throw new Error("should not invoke");
256
- });
257
- const internals = service;
258
- internals.resolveChat = async () => userEntity;
259
- await assert.rejects(() => service.getGroupCall("@user"), /only available for groups/);
260
- });
261
- });
262
- describe("summarizeGroupCallParticipants", () => {
263
- it("maps count, participants, nextOffset, and version", () => {
264
- const resp = new Api.phone.GroupParticipants({
265
- count: 7,
266
- participants: [
267
- new Api.GroupCallParticipant({
268
- peer: new Api.PeerUser({ userId: bigInt(42) }),
269
- date: 100,
270
- source: 555,
271
- }),
272
- ],
273
- nextOffset: "cursor-2",
274
- chats: [],
275
- users: [],
276
- version: 9,
277
- });
278
- const out = summarizeGroupCallParticipants(resp);
279
- assert.strictEqual(out.count, 7);
280
- assert.strictEqual(out.participants.length, 1);
281
- assert.deepStrictEqual(out.participants[0].peer, { kind: "user", id: "42" });
282
- assert.strictEqual(out.nextOffset, "cursor-2");
283
- assert.strictEqual(out.version, 9);
284
- });
285
- it("omits empty nextOffset", () => {
286
- const resp = new Api.phone.GroupParticipants({
287
- count: 0,
288
- participants: [],
289
- nextOffset: "",
290
- chats: [],
291
- users: [],
292
- version: 1,
293
- });
294
- const out = summarizeGroupCallParticipants(resp);
295
- assert.strictEqual(out.nextOffset, undefined);
296
- assert.strictEqual(out.participants.length, 0);
297
- });
298
- });
299
- describe("TelegramService.getGroupCallParticipants", () => {
300
- it("resolves call from chat and forwards ids/sources/offset/limit", async () => {
301
- const channelEntity = new Api.Channel({
302
- id: bigInt(777),
303
- title: "Call Chat",
304
- photo: new Api.ChatPhotoEmpty(),
305
- date: 0,
306
- participantsCount: 10,
307
- accessHash: bigInt(888),
308
- });
309
- const inputCall = new Api.InputGroupCall({ id: bigInt(1001), accessHash: bigInt(2002) });
310
- const fullChannel = new Api.ChannelFull({
311
- id: bigInt(777),
312
- about: "x",
313
- readInboxMaxId: 0,
314
- readOutboxMaxId: 0,
315
- unreadCount: 0,
316
- chatPhoto: new Api.PhotoEmpty({ id: bigInt(0) }),
317
- notifySettings: new Api.PeerNotifySettings({}),
318
- botInfo: [],
319
- pts: 0,
320
- call: inputCall,
321
- });
322
- const fullResponse = new Api.messages.ChatFull({
323
- fullChat: fullChannel,
324
- chats: [channelEntity],
325
- users: [],
326
- });
327
- const participantsResponse = new Api.phone.GroupParticipants({
328
- count: 3,
329
- participants: [
330
- new Api.GroupCallParticipant({
331
- peer: new Api.PeerUser({ userId: bigInt(50) }),
332
- date: 200,
333
- source: 111,
334
- }),
335
- ],
336
- nextOffset: "next-page",
337
- chats: [],
338
- users: [],
339
- version: 4,
340
- });
341
- const invocations = [];
342
- const service = makeService(invocations, (req) => {
343
- if (req instanceof Api.channels.GetFullChannel)
344
- return fullResponse;
345
- if (req instanceof Api.phone.GetGroupParticipants)
346
- return participantsResponse;
347
- throw new Error(`Unexpected request ${req.className}`);
348
- });
349
- const internals = service;
350
- internals.resolveChat = async () => channelEntity;
351
- internals.resolvePeer = async (id) => ({ stubPeerFor: id });
352
- const out = await service.getGroupCallParticipants("@foo", {
353
- ids: ["@alice", "123"],
354
- sources: [10, 20],
355
- offset: "start",
356
- limit: 50,
357
- });
358
- const req = invocations.find((r) => r instanceof Api.phone.GetGroupParticipants);
359
- assert.ok(req, "phone.GetGroupParticipants should be invoked");
360
- assert.ok(req.call instanceof Api.InputGroupCall);
361
- assert.strictEqual(req.call.id.toString(), "1001");
362
- assert.strictEqual(req.offset, "start");
363
- assert.strictEqual(req.limit, 50);
364
- assert.deepStrictEqual(req.sources, [10, 20]);
365
- assert.strictEqual(req.ids?.length, 2);
366
- assert.strictEqual(out.count, 3);
367
- assert.strictEqual(out.participants.length, 1);
368
- assert.deepStrictEqual(out.participants[0].peer, { kind: "user", id: "50" });
369
- assert.strictEqual(out.nextOffset, "next-page");
370
- assert.strictEqual(out.version, 4);
371
- });
372
- it("defaults to empty ids/sources, empty offset, limit 100", async () => {
373
- const channelEntity = new Api.Channel({
374
- id: bigInt(1),
375
- title: "C",
376
- photo: new Api.ChatPhotoEmpty(),
377
- date: 0,
378
- participantsCount: 2,
379
- accessHash: bigInt(2),
380
- });
381
- const inputCall = new Api.InputGroupCall({ id: bigInt(9), accessHash: bigInt(10) });
382
- const fullChannel = new Api.ChannelFull({
383
- id: bigInt(1),
384
- about: "x",
385
- readInboxMaxId: 0,
386
- readOutboxMaxId: 0,
387
- unreadCount: 0,
388
- chatPhoto: new Api.PhotoEmpty({ id: bigInt(0) }),
389
- notifySettings: new Api.PeerNotifySettings({}),
390
- botInfo: [],
391
- pts: 0,
392
- call: inputCall,
393
- });
394
- const fullResponse = new Api.messages.ChatFull({
395
- fullChat: fullChannel,
396
- chats: [channelEntity],
397
- users: [],
398
- });
399
- const participantsResponse = new Api.phone.GroupParticipants({
400
- count: 0,
401
- participants: [],
402
- nextOffset: "",
403
- chats: [],
404
- users: [],
405
- version: 1,
406
- });
407
- const invocations = [];
408
- const service = makeService(invocations, (req) => {
409
- if (req instanceof Api.channels.GetFullChannel)
410
- return fullResponse;
411
- if (req instanceof Api.phone.GetGroupParticipants)
412
- return participantsResponse;
413
- throw new Error("unexpected");
414
- });
415
- const internals = service;
416
- internals.resolveChat = async () => channelEntity;
417
- await service.getGroupCallParticipants("@foo");
418
- const req = invocations.find((r) => r instanceof Api.phone.GetGroupParticipants);
419
- assert.ok(req);
420
- assert.deepStrictEqual(req.ids, []);
421
- assert.deepStrictEqual(req.sources, []);
422
- assert.strictEqual(req.offset, "");
423
- assert.strictEqual(req.limit, 100);
424
- });
425
- it("throws when chat has no active group call", async () => {
426
- const channelEntity = new Api.Channel({
427
- id: bigInt(1),
428
- title: "T",
429
- photo: new Api.ChatPhotoEmpty(),
430
- date: 0,
431
- participantsCount: 1,
432
- accessHash: bigInt(2),
433
- });
434
- const fullChannel = new Api.ChannelFull({
435
- id: bigInt(1),
436
- about: "x",
437
- readInboxMaxId: 0,
438
- readOutboxMaxId: 0,
439
- unreadCount: 0,
440
- chatPhoto: new Api.PhotoEmpty({ id: bigInt(0) }),
441
- notifySettings: new Api.PeerNotifySettings({}),
442
- botInfo: [],
443
- pts: 0,
444
- });
445
- const fullResponse = new Api.messages.ChatFull({
446
- fullChat: fullChannel,
447
- chats: [channelEntity],
448
- users: [],
449
- });
450
- const service = makeService([], () => fullResponse);
451
- const internals = service;
452
- internals.resolveChat = async () => channelEntity;
453
- await assert.rejects(() => service.getGroupCallParticipants("@no-call"), /No active group call/);
454
- });
455
- it("rejects non-group peers", async () => {
456
- const userEntity = new Api.User({ id: bigInt(1), accessHash: bigInt(2), firstName: "x" });
457
- const service = makeService([], () => {
458
- throw new Error("should not invoke");
459
- });
460
- const internals = service;
461
- internals.resolveChat = async () => userEntity;
462
- await assert.rejects(() => service.getGroupCallParticipants("@user"), /only available for groups/);
463
- });
464
- });
465
- describe("isGroupCallsEnabled gate", () => {
466
- it("is off by default", () => {
467
- const prev = process.env.MCP_TELEGRAM_ENABLE_GROUP_CALLS;
468
- delete process.env.MCP_TELEGRAM_ENABLE_GROUP_CALLS;
469
- try {
470
- assert.strictEqual(isGroupCallsEnabled(), false);
471
- }
472
- finally {
473
- if (prev !== undefined)
474
- process.env.MCP_TELEGRAM_ENABLE_GROUP_CALLS = prev;
475
- }
476
- });
477
- it("turns on when env is '1'", () => {
478
- const prev = process.env.MCP_TELEGRAM_ENABLE_GROUP_CALLS;
479
- process.env.MCP_TELEGRAM_ENABLE_GROUP_CALLS = "1";
480
- try {
481
- assert.strictEqual(isGroupCallsEnabled(), true);
482
- }
483
- finally {
484
- if (prev === undefined)
485
- delete process.env.MCP_TELEGRAM_ENABLE_GROUP_CALLS;
486
- else
487
- process.env.MCP_TELEGRAM_ENABLE_GROUP_CALLS = prev;
488
- }
489
- });
490
- it("stays off for any non-'1' value", () => {
491
- const prev = process.env.MCP_TELEGRAM_ENABLE_GROUP_CALLS;
492
- process.env.MCP_TELEGRAM_ENABLE_GROUP_CALLS = "true";
493
- try {
494
- assert.strictEqual(isGroupCallsEnabled(), false);
495
- }
496
- finally {
497
- if (prev === undefined)
498
- delete process.env.MCP_TELEGRAM_ENABLE_GROUP_CALLS;
499
- else
500
- process.env.MCP_TELEGRAM_ENABLE_GROUP_CALLS = prev;
501
- }
502
- });
503
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,94 +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(chatEntity, invocations, responder) {
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 makeChannel(id) {
21
- return new Api.Channel({
22
- id: bigInt(id),
23
- title: "test",
24
- photo: new Api.ChatPhotoEmpty(),
25
- date: 0,
26
- accessHash: bigInt(1),
27
- megagroup: true,
28
- });
29
- }
30
- function updatesWithMessageId(randomId, messageId) {
31
- return new Api.Updates({
32
- updates: [new Api.UpdateMessageID({ id: messageId, randomId })],
33
- users: [],
34
- chats: [],
35
- date: 0,
36
- seq: 0,
37
- });
38
- }
39
- describe("TelegramService.sendInlineBotResult", () => {
40
- it("invokes SendInlineBotResult with resolved peer, queryId, resultId and returns messageId", async () => {
41
- const invocations = [];
42
- let capturedRandomId;
43
- const service = makeService(makeChannel(12345), invocations, (req) => {
44
- const r = req;
45
- capturedRandomId = r.randomId;
46
- return updatesWithMessageId(capturedRandomId, 4242);
47
- });
48
- const out = await service.sendInlineBotResult("12345", "9876543210", "r1");
49
- const call = invocations.find((r) => r instanceof Api.messages.SendInlineBotResult);
50
- assert.ok(call, "SendInlineBotResult was invoked");
51
- assert.strictEqual(call.queryId.toString(), "9876543210");
52
- assert.strictEqual(call.id, "r1");
53
- assert.ok(call.randomId, "randomId is set");
54
- assert.strictEqual(call.replyTo, undefined);
55
- assert.strictEqual(call.silent, undefined);
56
- assert.strictEqual(call.hideVia, undefined);
57
- assert.strictEqual(call.clearDraft, undefined);
58
- assert.deepStrictEqual(out, { messageId: 4242 });
59
- });
60
- it("passes replyTo, silent, hideVia, clearDraft when provided", async () => {
61
- const invocations = [];
62
- const service = makeService(makeChannel(10), invocations, (req) => {
63
- const r = req;
64
- return updatesWithMessageId(r.randomId, 7);
65
- });
66
- const out = await service.sendInlineBotResult("10", "1", "r1", {
67
- replyTo: 99,
68
- silent: true,
69
- hideVia: true,
70
- clearDraft: true,
71
- });
72
- const call = invocations.find((r) => r instanceof Api.messages.SendInlineBotResult);
73
- assert.ok(call);
74
- assert.ok(call.replyTo instanceof Api.InputReplyToMessage, "replyTo is InputReplyToMessage");
75
- assert.strictEqual(call.replyTo.replyToMsgId, 99);
76
- assert.strictEqual(call.silent, true);
77
- assert.strictEqual(call.hideVia, true);
78
- assert.strictEqual(call.clearDraft, true);
79
- assert.strictEqual(out.messageId, 7);
80
- });
81
- it("returns messageId=0 when update has no matching UpdateMessageID", async () => {
82
- const invocations = [];
83
- const service = makeService(makeChannel(10), invocations, () => {
84
- return new Api.Updates({ updates: [], users: [], chats: [], date: 0, seq: 0 });
85
- });
86
- const out = await service.sendInlineBotResult("10", "1", "r1");
87
- assert.strictEqual(out.messageId, 0);
88
- });
89
- it("throws when response is null/undefined", async () => {
90
- const invocations = [];
91
- const service = makeService(makeChannel(10), invocations, () => undefined);
92
- await assert.rejects(service.sendInlineBotResult("10", "1", "r1"), /No response/i);
93
- });
94
- });
@@ -1 +0,0 @@
1
- export {};