@mtkruto/node 0.0.990 → 0.0.991

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.
@@ -194,6 +194,8 @@ export declare class Client extends ClientAbstract {
194
194
  private connectionInited;
195
195
  disconnect(): Promise<void>;
196
196
  private initConnection;
197
+ private lastPropagatedAuthorizationState;
198
+ private propagateAuthorizationState;
197
199
  /**
198
200
  * Calls [initConnection](1) and authorizes the client with one of the following:
199
201
  *
@@ -243,7 +245,10 @@ export declare class Client extends ClientAbstract {
243
245
  private getLocalState;
244
246
  private recoverUpdateGap;
245
247
  private recoverChannelUpdateGap;
248
+ private getUserAccessHash;
249
+ private getChannelAccessHash;
246
250
  getInputPeer(id: ChatID): Promise<types.InputPeerChat | types.InputPeerUser | types.InputPeerChannel>;
251
+ private getInputPeerInner;
247
252
  [getEntity](peer: types.PeerUser): Promise<types.User | null>;
248
253
  [getEntity](peer: types.PeerChat): Promise<types.Chat | null>;
249
254
  [getEntity](peer: types.PeerChannel): Promise<types.Channel | null>;
@@ -309,16 +314,21 @@ export declare class Client extends ClientAbstract {
309
314
  private handleUpdate;
310
315
  handler: Handler;
311
316
  use(middleware: Handler): void;
312
- on<U extends keyof Update, K extends keyof Update[U]>(filter: Update[U] extends string ? U : Update[U] extends Array<any> ? U : U | [U, ...K[]], handler: Handler<Pick<{
317
+ on<U extends keyof Update, K extends keyof Update[U]>(filter: U extends FilterableUpdates ? U | [U, K, ...K[]] : U, handler: Handler<Pick<{
313
318
  [P in U]: With<Update[U], K>;
314
319
  }, U>>): void;
315
320
  }
316
321
  type With<T, K extends keyof T> = T & Required<Pick<T, K>>;
317
322
  export type ConnectionState = "not-connected" | "updating" | "ready";
323
+ export type AuthorizationState = {
324
+ authorized: boolean;
325
+ };
326
+ type FilterableUpdates = "message" | "editedMessage";
318
327
  export interface Update {
319
328
  message: Message;
320
329
  editedMessage: Message;
321
330
  connectionState: ConnectionState;
331
+ authorizationState: AuthorizationState;
322
332
  deletedMessages: [Message, ...Message[]];
323
333
  }
324
334
  export interface Handler<U extends Partial<Update> = Partial<Update>> {
@@ -204,6 +204,12 @@ export class Client extends ClientAbstract {
204
204
  writable: true,
205
205
  value: false
206
206
  });
207
+ Object.defineProperty(this, "lastPropagatedAuthorizationState", {
208
+ enumerable: true,
209
+ configurable: true,
210
+ writable: true,
211
+ value: null
212
+ });
207
213
  Object.defineProperty(this, "autoStarted", {
208
214
  enumerable: true,
209
215
  configurable: true,
@@ -278,11 +284,11 @@ export class Client extends ClientAbstract {
278
284
  * Before establishing the connection, the session is saved.
279
285
  */
280
286
  async connect() {
287
+ if (this.connected) {
288
+ return;
289
+ }
281
290
  const release = await this.connectMutex.acquire();
282
291
  try {
283
- if (this.connected) {
284
- return;
285
- }
286
292
  if (!this.storageInited) {
287
293
  await this.storage.init();
288
294
  this.storageInited = true;
@@ -362,6 +368,12 @@ export class Client extends ClientAbstract {
362
368
  d("connection inited");
363
369
  }
364
370
  }
371
+ async propagateAuthorizationState(authorized) {
372
+ if (this.lastPropagatedAuthorizationState != authorized) {
373
+ await this.handler({ authorizationState: { authorized } }, resolve);
374
+ this.lastPropagatedAuthorizationState = authorized;
375
+ }
376
+ }
365
377
  /**
366
378
  * Calls [initConnection](1) and authorizes the client with one of the following:
367
379
  *
@@ -399,6 +411,7 @@ export class Client extends ClientAbstract {
399
411
  await this.initConnection();
400
412
  try {
401
413
  await this.fetchState("authorize");
414
+ await this.propagateAuthorizationState(true);
402
415
  d("already authorized");
403
416
  return;
404
417
  }
@@ -432,6 +445,7 @@ export class Client extends ClientAbstract {
432
445
  }
433
446
  }
434
447
  dAuth("authorized as bot");
448
+ await this.propagateAuthorizationState(true);
435
449
  await this.fetchState("authorize");
436
450
  return;
437
451
  }
@@ -493,6 +507,7 @@ export class Client extends ClientAbstract {
493
507
  }));
494
508
  await this.storage.setAccountType("user");
495
509
  dAuth("authorized as user");
510
+ await this.propagateAuthorizationState(true);
496
511
  await this.fetchState("authorize");
497
512
  return;
498
513
  }
@@ -520,6 +535,7 @@ export class Client extends ClientAbstract {
520
535
  await this.invoke(new functions.AuthCheckPassword({ password: input }));
521
536
  await this.storage.setAccountType("user");
522
537
  dAuth("authorized as user");
538
+ await this.propagateAuthorizationState(true);
523
539
  await this.fetchState("authorize");
524
540
  break;
525
541
  }
@@ -542,6 +558,7 @@ export class Client extends ClientAbstract {
542
558
  try {
543
559
  await this.fetchState("authorize");
544
560
  d("already authorized");
561
+ await this.propagateAuthorizationState(true);
545
562
  return;
546
563
  }
547
564
  catch (err) {
@@ -684,9 +701,18 @@ export class Client extends ClientAbstract {
684
701
  if (noWait) {
685
702
  return;
686
703
  }
687
- const result = await new Promise((resolve, reject) => {
688
- this.promises.set(message.id, { resolve, reject });
689
- });
704
+ let result;
705
+ try {
706
+ result = await new Promise((resolve, reject) => {
707
+ this.promises.set(message.id, { resolve, reject });
708
+ });
709
+ }
710
+ catch (err) {
711
+ if (err instanceof types.RPCError && err.errorMessage == "AUTH_KEY_UNREGISTERED") {
712
+ await this.propagateAuthorizationState(false);
713
+ }
714
+ throw err;
715
+ }
690
716
  if (result instanceof types.BadServerSalt) {
691
717
  return await this.invoke(function_);
692
718
  }
@@ -1002,7 +1028,28 @@ export class Client extends ClientAbstract {
1002
1028
  }
1003
1029
  }
1004
1030
  }
1031
+ async getUserAccessHash(userId) {
1032
+ const users = await this.invoke(new functions.UsersGetUsers({ id: [new types.InputUser({ userId, accessHash: 0n })] }));
1033
+ return users[0][as](types.User).accessHash ?? 0n;
1034
+ }
1035
+ async getChannelAccessHash(channelId) {
1036
+ const channels = await this.invoke(new functions.ChannelsGetChannels({ id: [new types.InputChannel({ channelId, accessHash: 0n })] }));
1037
+ return channels.chats[0][as](types.Channel).accessHash ?? 0n;
1038
+ }
1005
1039
  async getInputPeer(id) {
1040
+ const inputPeer = await this.getInputPeerInner(id);
1041
+ if (inputPeer instanceof types.InputPeerUser || inputPeer instanceof types.InputPeerChannel && inputPeer.accessHash == 0n && await this.storage.getAccountType() == "bot") {
1042
+ if ("channelId" in inputPeer) {
1043
+ inputPeer.accessHash = await this.getChannelAccessHash(inputPeer.channelId);
1044
+ }
1045
+ else {
1046
+ inputPeer.accessHash = await this.getUserAccessHash(inputPeer.userId);
1047
+ await this.storage.setUserAccessHash(inputPeer.userId, inputPeer.accessHash);
1048
+ }
1049
+ }
1050
+ return inputPeer;
1051
+ }
1052
+ async getInputPeerInner(id) {
1006
1053
  if (typeof id === "string") {
1007
1054
  if (!id.startsWith("@")) {
1008
1055
  throw new Error("Expected username to start with @");
@@ -1107,9 +1154,13 @@ export class Client extends ClientAbstract {
1107
1154
  result instanceof types.ChatlistsExportedInvites ||
1108
1155
  result instanceof types.ChatlistsChatlistInviteAlready ||
1109
1156
  result instanceof types.ChatlistsChatlistInvite ||
1110
- result instanceof types.ChatlistsChatlistUpdates) {
1157
+ result instanceof types.ChatlistsChatlistUpdates ||
1158
+ result instanceof types.MessagesChats ||
1159
+ result instanceof types.MessagesChatsSlice) {
1111
1160
  await this.processChats(result.chats);
1112
- await this.processUsers(result.users);
1161
+ if ("users" in result) {
1162
+ await this.processUsers(result.users);
1163
+ }
1113
1164
  }
1114
1165
  if (result instanceof types.MessagesMessages) {
1115
1166
  for (const message of result.messages) {
@@ -1486,9 +1537,7 @@ export class Client extends ClientAbstract {
1486
1537
  });
1487
1538
  };
1488
1539
  }
1489
- on(
1490
- // deno-lint-ignore no-explicit-any
1491
- filter, handler) {
1540
+ on(filter, handler) {
1492
1541
  const type = typeof filter === "string" ? filter : filter[0];
1493
1542
  const keys = Array.isArray(filter) ? filter.slice(1) : [];
1494
1543
  this.use((update, next) => {
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
6
6
  export declare const INITIAL_DC: DC;
7
7
  export declare const LAYER = 161;
8
- export declare const APP_VERSION = "MTKruto 0.0.990";
8
+ export declare const APP_VERSION = "MTKruto 0.0.991";
9
9
  export declare const DEVICE_MODEL: string;
10
10
  export declare const LANG_CODE: string;
11
11
  export declare const LANG_PACK = "";
package/esm/constants.js CHANGED
@@ -54,7 +54,7 @@ export const PUBLIC_KEYS = Object.freeze([
54
54
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
55
55
  export const INITIAL_DC = "2-test";
56
56
  export const LAYER = 161;
57
- export const APP_VERSION = "MTKruto 0.0.990";
57
+ export const APP_VERSION = "MTKruto 0.0.991";
58
58
  // @ts-ignore: lib
59
59
  export const DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
60
60
  export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -37,6 +37,8 @@ export interface Message {
37
37
  date?: Date;
38
38
  /** Conversation the message belongs to */
39
39
  chat: Chat;
40
+ /** A link to the message */
41
+ link?: string;
40
42
  /** For forwarded messages, sender of the original message */
41
43
  forwardFrom?: User;
42
44
  /** For messages forwarded from channels or from anonymous administrators, information about the original sender chat */
@@ -185,6 +185,7 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
185
185
  if (!(message_ instanceof types.Message) && !(message_ instanceof types.MessageService)) {
186
186
  UNREACHABLE();
187
187
  }
188
+ let link;
188
189
  let chat_ = null;
189
190
  if (message_.peerId instanceof types.PeerUser) {
190
191
  const entity = await getEntity(message_.peerId);
@@ -205,6 +206,7 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
205
206
  }
206
207
  }
207
208
  else if (message_.peerId instanceof types.PeerChannel) {
209
+ link = `https://t.me/c/${message_.peerId.channelId}/${message_.id}`;
208
210
  const entity = await getEntity(message_.peerId);
209
211
  if (entity) {
210
212
  chat_ = constructChat(entity);
@@ -223,6 +225,7 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
223
225
  out: message_.out ?? false,
224
226
  id: message_.id,
225
227
  chat: chat_,
228
+ link,
226
229
  date: new Date(message_.date * 1000),
227
230
  views: message_.views,
228
231
  isTopicMessage: false,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.0.990",
5
+ "version": "0.0.991",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -194,6 +194,8 @@ export declare class Client extends ClientAbstract {
194
194
  private connectionInited;
195
195
  disconnect(): Promise<void>;
196
196
  private initConnection;
197
+ private lastPropagatedAuthorizationState;
198
+ private propagateAuthorizationState;
197
199
  /**
198
200
  * Calls [initConnection](1) and authorizes the client with one of the following:
199
201
  *
@@ -243,7 +245,10 @@ export declare class Client extends ClientAbstract {
243
245
  private getLocalState;
244
246
  private recoverUpdateGap;
245
247
  private recoverChannelUpdateGap;
248
+ private getUserAccessHash;
249
+ private getChannelAccessHash;
246
250
  getInputPeer(id: ChatID): Promise<types.InputPeerChat | types.InputPeerUser | types.InputPeerChannel>;
251
+ private getInputPeerInner;
247
252
  [getEntity](peer: types.PeerUser): Promise<types.User | null>;
248
253
  [getEntity](peer: types.PeerChat): Promise<types.Chat | null>;
249
254
  [getEntity](peer: types.PeerChannel): Promise<types.Channel | null>;
@@ -309,16 +314,21 @@ export declare class Client extends ClientAbstract {
309
314
  private handleUpdate;
310
315
  handler: Handler;
311
316
  use(middleware: Handler): void;
312
- on<U extends keyof Update, K extends keyof Update[U]>(filter: Update[U] extends string ? U : Update[U] extends Array<any> ? U : U | [U, ...K[]], handler: Handler<Pick<{
317
+ on<U extends keyof Update, K extends keyof Update[U]>(filter: U extends FilterableUpdates ? U | [U, K, ...K[]] : U, handler: Handler<Pick<{
313
318
  [P in U]: With<Update[U], K>;
314
319
  }, U>>): void;
315
320
  }
316
321
  type With<T, K extends keyof T> = T & Required<Pick<T, K>>;
317
322
  export type ConnectionState = "not-connected" | "updating" | "ready";
323
+ export type AuthorizationState = {
324
+ authorized: boolean;
325
+ };
326
+ type FilterableUpdates = "message" | "editedMessage";
318
327
  export interface Update {
319
328
  message: Message;
320
329
  editedMessage: Message;
321
330
  connectionState: ConnectionState;
331
+ authorizationState: AuthorizationState;
322
332
  deletedMessages: [Message, ...Message[]];
323
333
  }
324
334
  export interface Handler<U extends Partial<Update> = Partial<Update>> {
@@ -230,6 +230,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
230
230
  writable: true,
231
231
  value: false
232
232
  });
233
+ Object.defineProperty(this, "lastPropagatedAuthorizationState", {
234
+ enumerable: true,
235
+ configurable: true,
236
+ writable: true,
237
+ value: null
238
+ });
233
239
  Object.defineProperty(this, "autoStarted", {
234
240
  enumerable: true,
235
241
  configurable: true,
@@ -304,11 +310,11 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
304
310
  * Before establishing the connection, the session is saved.
305
311
  */
306
312
  async connect() {
313
+ if (this.connected) {
314
+ return;
315
+ }
307
316
  const release = await this.connectMutex.acquire();
308
317
  try {
309
- if (this.connected) {
310
- return;
311
- }
312
318
  if (!this.storageInited) {
313
319
  await this.storage.init();
314
320
  this.storageInited = true;
@@ -388,6 +394,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
388
394
  d("connection inited");
389
395
  }
390
396
  }
397
+ async propagateAuthorizationState(authorized) {
398
+ if (this.lastPropagatedAuthorizationState != authorized) {
399
+ await this.handler({ authorizationState: { authorized } }, resolve);
400
+ this.lastPropagatedAuthorizationState = authorized;
401
+ }
402
+ }
391
403
  /**
392
404
  * Calls [initConnection](1) and authorizes the client with one of the following:
393
405
  *
@@ -425,6 +437,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
425
437
  await this.initConnection();
426
438
  try {
427
439
  await this.fetchState("authorize");
440
+ await this.propagateAuthorizationState(true);
428
441
  d("already authorized");
429
442
  return;
430
443
  }
@@ -458,6 +471,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
458
471
  }
459
472
  }
460
473
  dAuth("authorized as bot");
474
+ await this.propagateAuthorizationState(true);
461
475
  await this.fetchState("authorize");
462
476
  return;
463
477
  }
@@ -519,6 +533,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
519
533
  }));
520
534
  await this.storage.setAccountType("user");
521
535
  dAuth("authorized as user");
536
+ await this.propagateAuthorizationState(true);
522
537
  await this.fetchState("authorize");
523
538
  return;
524
539
  }
@@ -546,6 +561,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
546
561
  await this.invoke(new functions.AuthCheckPassword({ password: input }));
547
562
  await this.storage.setAccountType("user");
548
563
  dAuth("authorized as user");
564
+ await this.propagateAuthorizationState(true);
549
565
  await this.fetchState("authorize");
550
566
  break;
551
567
  }
@@ -568,6 +584,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
568
584
  try {
569
585
  await this.fetchState("authorize");
570
586
  d("already authorized");
587
+ await this.propagateAuthorizationState(true);
571
588
  return;
572
589
  }
573
590
  catch (err) {
@@ -710,9 +727,18 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
710
727
  if (noWait) {
711
728
  return;
712
729
  }
713
- const result = await new Promise((resolve, reject) => {
714
- this.promises.set(message.id, { resolve, reject });
715
- });
730
+ let result;
731
+ try {
732
+ result = await new Promise((resolve, reject) => {
733
+ this.promises.set(message.id, { resolve, reject });
734
+ });
735
+ }
736
+ catch (err) {
737
+ if (err instanceof types.RPCError && err.errorMessage == "AUTH_KEY_UNREGISTERED") {
738
+ await this.propagateAuthorizationState(false);
739
+ }
740
+ throw err;
741
+ }
716
742
  if (result instanceof types.BadServerSalt) {
717
743
  return await this.invoke(function_);
718
744
  }
@@ -1028,7 +1054,28 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1028
1054
  }
1029
1055
  }
1030
1056
  }
1057
+ async getUserAccessHash(userId) {
1058
+ const users = await this.invoke(new functions.UsersGetUsers({ id: [new types.InputUser({ userId, accessHash: 0n })] }));
1059
+ return users[0][_1_tl_object_js_1.as](types.User).accessHash ?? 0n;
1060
+ }
1061
+ async getChannelAccessHash(channelId) {
1062
+ const channels = await this.invoke(new functions.ChannelsGetChannels({ id: [new types.InputChannel({ channelId, accessHash: 0n })] }));
1063
+ return channels.chats[0][_1_tl_object_js_1.as](types.Channel).accessHash ?? 0n;
1064
+ }
1031
1065
  async getInputPeer(id) {
1066
+ const inputPeer = await this.getInputPeerInner(id);
1067
+ if (inputPeer instanceof types.InputPeerUser || inputPeer instanceof types.InputPeerChannel && inputPeer.accessHash == 0n && await this.storage.getAccountType() == "bot") {
1068
+ if ("channelId" in inputPeer) {
1069
+ inputPeer.accessHash = await this.getChannelAccessHash(inputPeer.channelId);
1070
+ }
1071
+ else {
1072
+ inputPeer.accessHash = await this.getUserAccessHash(inputPeer.userId);
1073
+ await this.storage.setUserAccessHash(inputPeer.userId, inputPeer.accessHash);
1074
+ }
1075
+ }
1076
+ return inputPeer;
1077
+ }
1078
+ async getInputPeerInner(id) {
1032
1079
  if (typeof id === "string") {
1033
1080
  if (!id.startsWith("@")) {
1034
1081
  throw new Error("Expected username to start with @");
@@ -1133,9 +1180,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1133
1180
  result instanceof types.ChatlistsExportedInvites ||
1134
1181
  result instanceof types.ChatlistsChatlistInviteAlready ||
1135
1182
  result instanceof types.ChatlistsChatlistInvite ||
1136
- result instanceof types.ChatlistsChatlistUpdates) {
1183
+ result instanceof types.ChatlistsChatlistUpdates ||
1184
+ result instanceof types.MessagesChats ||
1185
+ result instanceof types.MessagesChatsSlice) {
1137
1186
  await this.processChats(result.chats);
1138
- await this.processUsers(result.users);
1187
+ if ("users" in result) {
1188
+ await this.processUsers(result.users);
1189
+ }
1139
1190
  }
1140
1191
  if (result instanceof types.MessagesMessages) {
1141
1192
  for (const message of result.messages) {
@@ -1512,9 +1563,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1512
1563
  });
1513
1564
  };
1514
1565
  }
1515
- on(
1516
- // deno-lint-ignore no-explicit-any
1517
- filter, handler) {
1566
+ on(filter, handler) {
1518
1567
  const type = typeof filter === "string" ? filter : filter[0];
1519
1568
  const keys = Array.isArray(filter) ? filter.slice(1) : [];
1520
1569
  this.use((update, next) => {
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
6
6
  export declare const INITIAL_DC: DC;
7
7
  export declare const LAYER = 161;
8
- export declare const APP_VERSION = "MTKruto 0.0.990";
8
+ export declare const APP_VERSION = "MTKruto 0.0.991";
9
9
  export declare const DEVICE_MODEL: string;
10
10
  export declare const LANG_CODE: string;
11
11
  export declare const LANG_PACK = "";
@@ -80,7 +80,7 @@ exports.PUBLIC_KEYS = Object.freeze([
80
80
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
81
81
  exports.INITIAL_DC = "2-test";
82
82
  exports.LAYER = 161;
83
- exports.APP_VERSION = "MTKruto 0.0.990";
83
+ exports.APP_VERSION = "MTKruto 0.0.991";
84
84
  // @ts-ignore: lib
85
85
  exports.DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
86
86
  exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -37,6 +37,8 @@ export interface Message {
37
37
  date?: Date;
38
38
  /** Conversation the message belongs to */
39
39
  chat: Chat;
40
+ /** A link to the message */
41
+ link?: string;
40
42
  /** For forwarded messages, sender of the original message */
41
43
  forwardFrom?: User;
42
44
  /** For messages forwarded from channels or from anonymous administrators, information about the original sender chat */
@@ -211,6 +211,7 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
211
211
  if (!(message_ instanceof types.Message) && !(message_ instanceof types.MessageService)) {
212
212
  (0, _0_control_js_1.UNREACHABLE)();
213
213
  }
214
+ let link;
214
215
  let chat_ = null;
215
216
  if (message_.peerId instanceof types.PeerUser) {
216
217
  const entity = await getEntity(message_.peerId);
@@ -231,6 +232,7 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
231
232
  }
232
233
  }
233
234
  else if (message_.peerId instanceof types.PeerChannel) {
235
+ link = `https://t.me/c/${message_.peerId.channelId}/${message_.id}`;
234
236
  const entity = await getEntity(message_.peerId);
235
237
  if (entity) {
236
238
  chat_ = (0, _1_chat_js_1.constructChat)(entity);
@@ -249,6 +251,7 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
249
251
  out: message_.out ?? false,
250
252
  id: message_.id,
251
253
  chat: chat_,
254
+ link,
252
255
  date: new Date(message_.date * 1000),
253
256
  views: message_.views,
254
257
  isTopicMessage: false,