@mtcute/core 0.12.2 → 0.13.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/cjs/highlevel/client.d.ts +83 -2
- package/cjs/highlevel/client.js +20 -1
- package/cjs/highlevel/client.js.map +1 -1
- package/cjs/highlevel/methods/_imports.js.map +1 -1
- package/cjs/highlevel/methods/_init.js +1 -1
- package/cjs/highlevel/methods/_init.js.map +1 -1
- package/cjs/highlevel/methods/bots/get-callback-answer.d.ts +11 -0
- package/cjs/highlevel/methods/bots/get-callback-answer.js +10 -2
- package/cjs/highlevel/methods/bots/get-callback-answer.js.map +1 -1
- package/cjs/highlevel/methods/chats/archive-chats.js +2 -1
- package/cjs/highlevel/methods/chats/archive-chats.js.map +1 -1
- package/cjs/highlevel/methods/dialogs/find-dialogs.d.ts +12 -0
- package/cjs/highlevel/methods/dialogs/find-dialogs.js +88 -0
- package/cjs/highlevel/methods/dialogs/find-dialogs.js.map +1 -0
- package/cjs/highlevel/methods/dialogs/get-peer-dialogs.js +2 -1
- package/cjs/highlevel/methods/dialogs/get-peer-dialogs.js.map +1 -1
- package/cjs/highlevel/methods/dialogs/iter-dialogs.js +3 -1
- package/cjs/highlevel/methods/dialogs/iter-dialogs.js.map +1 -1
- package/cjs/highlevel/methods/messages/_business-connection.d.ts +2 -1
- package/cjs/highlevel/methods/messages/_business-connection.js.map +1 -1
- package/cjs/highlevel/methods/messages/get-available-effects.d.ts +6 -0
- package/cjs/highlevel/methods/messages/get-available-effects.js +26 -0
- package/cjs/highlevel/methods/messages/get-available-effects.js.map +1 -0
- package/cjs/highlevel/methods/messages/get-fact-check.d.ts +11 -0
- package/cjs/highlevel/methods/messages/get-fact-check.js +27 -0
- package/cjs/highlevel/methods/messages/get-fact-check.js.map +1 -0
- package/cjs/highlevel/methods/messages/search-hashtag.d.ts +44 -0
- package/cjs/highlevel/methods/messages/search-hashtag.js +75 -0
- package/cjs/highlevel/methods/messages/search-hashtag.js.map +1 -0
- package/cjs/highlevel/methods/messages/send-common.d.ts +5 -0
- package/cjs/highlevel/methods/messages/send-common.js.map +1 -1
- package/cjs/highlevel/methods/messages/send-media-group.js +1 -0
- package/cjs/highlevel/methods/messages/send-media-group.js.map +1 -1
- package/cjs/highlevel/methods/messages/send-media.js +1 -0
- package/cjs/highlevel/methods/messages/send-media.js.map +1 -1
- package/cjs/highlevel/methods/messages/send-text.js +1 -0
- package/cjs/highlevel/methods/messages/send-text.js.map +1 -1
- package/cjs/highlevel/methods/misc/normalize-privacy-rules.js +2 -1
- package/cjs/highlevel/methods/misc/normalize-privacy-rules.js.map +1 -1
- package/cjs/highlevel/methods/users/resolve-peer-many.d.ts +6 -2
- package/cjs/highlevel/methods/users/resolve-peer-many.js +22 -6
- package/cjs/highlevel/methods/users/resolve-peer-many.js.map +1 -1
- package/cjs/highlevel/methods/users/resolve-peer.js +30 -11
- package/cjs/highlevel/methods/users/resolve-peer.js.map +1 -1
- package/cjs/highlevel/methods.d.ts +6 -0
- package/cjs/highlevel/methods.js +15 -4
- package/cjs/highlevel/methods.js.map +1 -1
- package/cjs/highlevel/types/conversation.js +1 -1
- package/cjs/highlevel/types/conversation.js.map +1 -1
- package/cjs/highlevel/types/messages/dialog.d.ts +2 -2
- package/cjs/highlevel/types/messages/dialog.js +2 -3
- package/cjs/highlevel/types/messages/dialog.js.map +1 -1
- package/cjs/highlevel/types/messages/fact-check.d.ts +30 -0
- package/cjs/highlevel/types/messages/fact-check.js +56 -0
- package/cjs/highlevel/types/messages/fact-check.js.map +1 -0
- package/cjs/highlevel/types/messages/index.d.ts +2 -0
- package/cjs/highlevel/types/messages/index.js +2 -0
- package/cjs/highlevel/types/messages/index.js.map +1 -1
- package/cjs/highlevel/types/messages/message-effect.d.ts +20 -0
- package/cjs/highlevel/types/messages/message-effect.js +69 -0
- package/cjs/highlevel/types/messages/message-effect.js.map +1 -0
- package/cjs/highlevel/types/messages/message-entity.d.ts +4 -1
- package/cjs/highlevel/types/messages/message-entity.js +1 -1
- package/cjs/highlevel/types/messages/message-entity.js.map +1 -1
- package/cjs/highlevel/types/messages/message.d.ts +12 -0
- package/cjs/highlevel/types/messages/message.js +23 -0
- package/cjs/highlevel/types/messages/message.js.map +1 -1
- package/cjs/network/client.d.ts +1 -2
- package/cjs/network/client.js +3 -3
- package/cjs/network/client.js.map +1 -1
- package/cjs/network/network-manager.js +1 -1
- package/cjs/network/session-connection.js +1 -1
- package/cjs/network/session-connection.js.map +1 -1
- package/cjs/platform.js +3 -7
- package/cjs/platform.js.map +1 -1
- package/esm/highlevel/client.d.ts +83 -2
- package/esm/highlevel/client.js +20 -1
- package/esm/highlevel/client.js.map +1 -1
- package/esm/highlevel/methods/_imports.js.map +1 -1
- package/esm/highlevel/methods/_init.js +1 -1
- package/esm/highlevel/methods/_init.js.map +1 -1
- package/esm/highlevel/methods/bots/get-callback-answer.d.ts +11 -0
- package/esm/highlevel/methods/bots/get-callback-answer.js +10 -2
- package/esm/highlevel/methods/bots/get-callback-answer.js.map +1 -1
- package/esm/highlevel/methods/chats/archive-chats.js +2 -1
- package/esm/highlevel/methods/chats/archive-chats.js.map +1 -1
- package/esm/highlevel/methods/dialogs/find-dialogs.d.ts +12 -0
- package/esm/highlevel/methods/dialogs/find-dialogs.js +84 -0
- package/esm/highlevel/methods/dialogs/find-dialogs.js.map +1 -0
- package/esm/highlevel/methods/dialogs/get-peer-dialogs.js +2 -1
- package/esm/highlevel/methods/dialogs/get-peer-dialogs.js.map +1 -1
- package/esm/highlevel/methods/dialogs/iter-dialogs.js +3 -1
- package/esm/highlevel/methods/dialogs/iter-dialogs.js.map +1 -1
- package/esm/highlevel/methods/messages/_business-connection.d.ts +2 -1
- package/esm/highlevel/methods/messages/_business-connection.js.map +1 -1
- package/esm/highlevel/methods/messages/get-available-effects.d.ts +6 -0
- package/esm/highlevel/methods/messages/get-available-effects.js +22 -0
- package/esm/highlevel/methods/messages/get-available-effects.js.map +1 -0
- package/esm/highlevel/methods/messages/get-fact-check.d.ts +11 -0
- package/esm/highlevel/methods/messages/get-fact-check.js +23 -0
- package/esm/highlevel/methods/messages/get-fact-check.js.map +1 -0
- package/esm/highlevel/methods/messages/search-hashtag.d.ts +44 -0
- package/esm/highlevel/methods/messages/search-hashtag.js +70 -0
- package/esm/highlevel/methods/messages/search-hashtag.js.map +1 -0
- package/esm/highlevel/methods/messages/send-common.d.ts +5 -0
- package/esm/highlevel/methods/messages/send-common.js.map +1 -1
- package/esm/highlevel/methods/messages/send-media-group.js +1 -0
- package/esm/highlevel/methods/messages/send-media-group.js.map +1 -1
- package/esm/highlevel/methods/messages/send-media.js +1 -0
- package/esm/highlevel/methods/messages/send-media.js.map +1 -1
- package/esm/highlevel/methods/messages/send-text.js +1 -0
- package/esm/highlevel/methods/messages/send-text.js.map +1 -1
- package/esm/highlevel/methods/misc/normalize-privacy-rules.js +2 -1
- package/esm/highlevel/methods/misc/normalize-privacy-rules.js.map +1 -1
- package/esm/highlevel/methods/users/resolve-peer-many.d.ts +6 -2
- package/esm/highlevel/methods/users/resolve-peer-many.js +22 -6
- package/esm/highlevel/methods/users/resolve-peer-many.js.map +1 -1
- package/esm/highlevel/methods/users/resolve-peer.js +30 -11
- package/esm/highlevel/methods/users/resolve-peer.js.map +1 -1
- package/esm/highlevel/methods.d.ts +6 -0
- package/esm/highlevel/methods.js +5 -0
- package/esm/highlevel/methods.js.map +1 -1
- package/esm/highlevel/types/conversation.js +1 -1
- package/esm/highlevel/types/conversation.js.map +1 -1
- package/esm/highlevel/types/messages/dialog.d.ts +2 -2
- package/esm/highlevel/types/messages/dialog.js +2 -3
- package/esm/highlevel/types/messages/dialog.js.map +1 -1
- package/esm/highlevel/types/messages/fact-check.d.ts +30 -0
- package/esm/highlevel/types/messages/fact-check.js +53 -0
- package/esm/highlevel/types/messages/fact-check.js.map +1 -0
- package/esm/highlevel/types/messages/index.d.ts +2 -0
- package/esm/highlevel/types/messages/index.js +2 -0
- package/esm/highlevel/types/messages/index.js.map +1 -1
- package/esm/highlevel/types/messages/message-effect.d.ts +20 -0
- package/esm/highlevel/types/messages/message-effect.js +66 -0
- package/esm/highlevel/types/messages/message-effect.js.map +1 -0
- package/esm/highlevel/types/messages/message-entity.d.ts +4 -1
- package/esm/highlevel/types/messages/message-entity.js +1 -1
- package/esm/highlevel/types/messages/message-entity.js.map +1 -1
- package/esm/highlevel/types/messages/message.d.ts +12 -0
- package/esm/highlevel/types/messages/message.js +23 -0
- package/esm/highlevel/types/messages/message.js.map +1 -1
- package/esm/network/client.d.ts +1 -2
- package/esm/network/client.js +3 -3
- package/esm/network/client.js.map +1 -1
- package/esm/network/network-manager.js +1 -1
- package/esm/network/session-connection.js +1 -1
- package/esm/network/session-connection.js.map +1 -1
- package/esm/platform.js +3 -7
- package/esm/platform.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fact-check.js","sourceRoot":"","sources":["../../../../../src/highlevel/types/messages/fact-check.ts"],"names":[],"mappings":";;;AAEA,+DAA4D;AAC5D,uDAAuD;AACvD,2DAAmD;AAEnD;;GAEG;AACH,MAAa,SAAS;IACG;IAArB,YAAqB,GAAoB;QAApB,QAAG,GAAH,GAAG,CAAiB;IAAG,CAAC;IAE7C;;OAEG;IACH,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,CAAA;IACpC,CAAC;IAED;;OAEG;IACH,IAAI,QAAQ;QACR,MAAM,QAAQ,GAAoB,EAAE,CAAA;QAEpC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC;YAC1B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACvC,QAAQ,CAAC,IAAI,CAAC,IAAI,iCAAa,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;YAC7D,CAAC;QACL,CAAC;QAED,OAAO,QAAQ,CAAA;IACnB,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,IAAI,CAAA;IACnC,CAAC;IAED;;;OAGG;IACH,IAAI,aAAa;QACb,OAAO,IAAI,CAAC,GAAG,CAAC,SAAU,CAAA;IAC9B,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAA;IACxB,CAAC;CACJ;AA9CD,8BA8CC;AAED,IAAA,2BAAc,EAAC,SAAS,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA;AACvC,IAAA,gCAAe,EAAC,SAAS,CAAC,CAAA","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { makeInspectable } from '../../utils/inspectable.js'\nimport { memoizeGetters } from '../../utils/memoize.js'\nimport { MessageEntity } from './message-entity.js'\n\n/**\n * Describes a fact-check added to the message by an independent checker\n */\nexport class FactCheck {\n constructor(readonly raw: tl.RawFactCheck) {}\n\n /**\n * Text of the fact-check\n */\n get text(): string {\n return this.raw.text?.text ?? ''\n }\n\n /**\n * Entities contained in the fact-check text\n */\n get entities(): MessageEntity[] {\n const entities: MessageEntity[] = []\n\n if (this.raw.text?.entities) {\n for (const ent of this.raw.text.entities) {\n entities.push(new MessageEntity(ent, this.raw.text.text))\n }\n }\n\n return entities\n }\n\n /**\n * Country for which the fact-check is relevant\n */\n get country(): string | null {\n return this.raw.country ?? null\n }\n\n /**\n * Whether this information might be outdated\n * and should be re-fetched manually\n */\n get shouldRecheck(): boolean {\n return this.raw.needCheck!\n }\n\n /**\n * Hash of the fact-check\n */\n get hash(): tl.Long {\n return this.raw.hash\n }\n}\n\nmemoizeGetters(FactCheck, ['entities'])\nmakeInspectable(FactCheck)\n"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export * from './dialog.js';
|
|
2
2
|
export * from './draft-message.js';
|
|
3
|
+
export * from './fact-check.js';
|
|
3
4
|
export * from './input-message-id.js';
|
|
4
5
|
export * from './message.js';
|
|
5
6
|
export * from './message-action.js';
|
|
7
|
+
export * from './message-effect.js';
|
|
6
8
|
export * from './message-entity.js';
|
|
7
9
|
export * from './message-forward.js';
|
|
8
10
|
export * from './message-media.js';
|
|
@@ -16,9 +16,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./dialog.js"), exports);
|
|
18
18
|
__exportStar(require("./draft-message.js"), exports);
|
|
19
|
+
__exportStar(require("./fact-check.js"), exports);
|
|
19
20
|
__exportStar(require("./input-message-id.js"), exports);
|
|
20
21
|
__exportStar(require("./message.js"), exports);
|
|
21
22
|
__exportStar(require("./message-action.js"), exports);
|
|
23
|
+
__exportStar(require("./message-effect.js"), exports);
|
|
22
24
|
__exportStar(require("./message-entity.js"), exports);
|
|
23
25
|
__exportStar(require("./message-forward.js"), exports);
|
|
24
26
|
__exportStar(require("./message-media.js"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/highlevel/types/messages/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,qDAAkC;AAClC,wDAAqC;AACrC,+CAA4B;AAC5B,sDAAmC;AACnC,sDAAmC;AACnC,uDAAoC;AACpC,qDAAkC;AAClC,yDAAsC;AACtC,uDAAoC;AACpC,uDAAoC;AACpC,sDAAmC","sourcesContent":["export * from './dialog.js'\nexport * from './draft-message.js'\nexport * from './input-message-id.js'\nexport * from './message.js'\nexport * from './message-action.js'\nexport * from './message-entity.js'\nexport * from './message-forward.js'\nexport * from './message-media.js'\nexport * from './message-reactions.js'\nexport * from './message-replies.js'\nexport * from './replied-message.js'\nexport * from './search-filters.js'\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/highlevel/types/messages/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,qDAAkC;AAClC,kDAA+B;AAC/B,wDAAqC;AACrC,+CAA4B;AAC5B,sDAAmC;AACnC,sDAAmC;AACnC,sDAAmC;AACnC,uDAAoC;AACpC,qDAAkC;AAClC,yDAAsC;AACtC,uDAAoC;AACpC,uDAAoC;AACpC,sDAAmC","sourcesContent":["export * from './dialog.js'\nexport * from './draft-message.js'\nexport * from './fact-check.js'\nexport * from './input-message-id.js'\nexport * from './message.js'\nexport * from './message-action.js'\nexport * from './message-effect.js'\nexport * from './message-entity.js'\nexport * from './message-forward.js'\nexport * from './message-media.js'\nexport * from './message-reactions.js'\nexport * from './message-replies.js'\nexport * from './replied-message.js'\nexport * from './search-filters.js'\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { tl } from '@mtcute/tl';
|
|
2
|
+
import { LongMap } from '../../../utils/long-utils.js';
|
|
3
|
+
import { Sticker } from '../media/sticker.js';
|
|
4
|
+
export declare class MessageEffect {
|
|
5
|
+
readonly raw: tl.RawAvailableEffect;
|
|
6
|
+
readonly documentsMap: LongMap<tl.RawDocument>;
|
|
7
|
+
constructor(raw: tl.RawAvailableEffect, documentsMap: LongMap<tl.RawDocument>);
|
|
8
|
+
/** Whether Telegram Premium is required to use this effect */
|
|
9
|
+
get isPremiumRequired(): boolean;
|
|
10
|
+
/** ID of this effect */
|
|
11
|
+
get id(): tl.Long;
|
|
12
|
+
/** Emoji representint this reaction */
|
|
13
|
+
get emoji(): string;
|
|
14
|
+
/** Sticker representing a static icon for this effect (if any) */
|
|
15
|
+
get staticIcon(): Sticker | null;
|
|
16
|
+
/** Animated icon representing the effect */
|
|
17
|
+
get icon(): Sticker;
|
|
18
|
+
/** The animation itself */
|
|
19
|
+
get animation(): Sticker | null;
|
|
20
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageEffect = void 0;
|
|
4
|
+
const errors_js_1 = require("../../../types/errors.js");
|
|
5
|
+
const inspectable_js_1 = require("../../utils/inspectable.js");
|
|
6
|
+
const memoize_js_1 = require("../../utils/memoize.js");
|
|
7
|
+
const document_utils_js_1 = require("../media/document-utils.js");
|
|
8
|
+
class MessageEffect {
|
|
9
|
+
raw;
|
|
10
|
+
documentsMap;
|
|
11
|
+
constructor(raw, documentsMap) {
|
|
12
|
+
this.raw = raw;
|
|
13
|
+
this.documentsMap = documentsMap;
|
|
14
|
+
}
|
|
15
|
+
/** Whether Telegram Premium is required to use this effect */
|
|
16
|
+
get isPremiumRequired() {
|
|
17
|
+
return this.raw.premiumRequired;
|
|
18
|
+
}
|
|
19
|
+
/** ID of this effect */
|
|
20
|
+
get id() {
|
|
21
|
+
return this.raw.id;
|
|
22
|
+
}
|
|
23
|
+
/** Emoji representint this reaction */
|
|
24
|
+
get emoji() {
|
|
25
|
+
return this.raw.emoticon;
|
|
26
|
+
}
|
|
27
|
+
/** Sticker representing a static icon for this effect (if any) */
|
|
28
|
+
get staticIcon() {
|
|
29
|
+
if (!this.raw.staticIconId)
|
|
30
|
+
return null;
|
|
31
|
+
const document = this.documentsMap.get(this.raw.staticIconId);
|
|
32
|
+
if (!document)
|
|
33
|
+
return null;
|
|
34
|
+
const parsed = (0, document_utils_js_1.parseSticker)(document);
|
|
35
|
+
if (!parsed) {
|
|
36
|
+
throw new errors_js_1.MtTypeAssertionError('MessageEffect.staticIcon', 'sticker', 'null');
|
|
37
|
+
}
|
|
38
|
+
return parsed;
|
|
39
|
+
}
|
|
40
|
+
/** Animated icon representing the effect */
|
|
41
|
+
get icon() {
|
|
42
|
+
const document = this.documentsMap.get(this.raw.effectStickerId);
|
|
43
|
+
if (!document) {
|
|
44
|
+
throw new errors_js_1.MtTypeAssertionError('MessageEffect.effect', 'document', 'null');
|
|
45
|
+
}
|
|
46
|
+
const parsed = (0, document_utils_js_1.parseSticker)(document);
|
|
47
|
+
if (!parsed) {
|
|
48
|
+
throw new errors_js_1.MtTypeAssertionError('MessageEffect.effect', 'sticker', 'null');
|
|
49
|
+
}
|
|
50
|
+
return parsed;
|
|
51
|
+
}
|
|
52
|
+
/** The animation itself */
|
|
53
|
+
get animation() {
|
|
54
|
+
if (!this.raw.effectAnimationId)
|
|
55
|
+
return null;
|
|
56
|
+
const document = this.documentsMap.get(this.raw.effectAnimationId);
|
|
57
|
+
if (!document)
|
|
58
|
+
return null;
|
|
59
|
+
const parsed = (0, document_utils_js_1.parseSticker)(document);
|
|
60
|
+
if (!parsed) {
|
|
61
|
+
throw new errors_js_1.MtTypeAssertionError('MessageEffect.effectAnimation', 'sticker', 'null');
|
|
62
|
+
}
|
|
63
|
+
return parsed;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.MessageEffect = MessageEffect;
|
|
67
|
+
(0, memoize_js_1.memoizeGetters)(MessageEffect, ['staticIcon', 'icon', 'animation']);
|
|
68
|
+
(0, inspectable_js_1.makeInspectable)(MessageEffect);
|
|
69
|
+
//# sourceMappingURL=message-effect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-effect.js","sourceRoot":"","sources":["../../../../../src/highlevel/types/messages/message-effect.ts"],"names":[],"mappings":";;;AAEA,wDAA+D;AAE/D,+DAA4D;AAC5D,uDAAuD;AACvD,kEAAyD;AAGzD,MAAa,aAAa;IAET;IACA;IAFb,YACa,GAA0B,EAC1B,YAAqC;QADrC,QAAG,GAAH,GAAG,CAAuB;QAC1B,iBAAY,GAAZ,YAAY,CAAyB;IAC/C,CAAC;IAEJ,8DAA8D;IAC9D,IAAI,iBAAiB;QACjB,OAAO,IAAI,CAAC,GAAG,CAAC,eAAgB,CAAA;IACpC,CAAC;IAED,wBAAwB;IACxB,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;IACtB,CAAC;IAED,uCAAuC;IACvC,IAAI,KA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CAAC,CAAA;QAClE,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAA;QAE1B,MAAM,MAAM,GAAG,IAAA,gCAAY,EAAC,QAAQ,CAAC,CAAA;QAErC,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,MAAM,IAAI,gCAAoB,CAAC,+BAA+B,EAAE,SAAS,EAAE,MAAM,CAAC,CAAA;QACtF,CAAC;QAED,OAAO,MAAM,CAAA;IACjB,CAAC;CACJ;AArED,sCAqEC;AAED,IAAA,2BAAc,EAAC,aAAa,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAA;AAClE,IAAA,gCAAe,EAAC,aAAa,CAAC,CAAA","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { MtTypeAssertionError } from '../../../types/errors.js'\nimport { LongMap } from '../../../utils/long-utils.js'\nimport { makeInspectable } from '../../utils/inspectable.js'\nimport { memoizeGetters } from '../../utils/memoize.js'\nimport { parseSticker } from '../media/document-utils.js'\nimport { Sticker } from '../media/sticker.js'\n\nexport class MessageEffect {\n constructor(\n readonly raw: tl.RawAvailableEffect,\n readonly documentsMap: LongMap<tl.RawDocument>,\n ) {}\n\n /** Whether Telegram Premium is required to use this effect */\n get isPremiumRequired(): boolean {\n return this.raw.premiumRequired!\n }\n\n /** ID of this effect */\n get id(): tl.Long {\n return this.raw.id\n }\n\n /** Emoji representint this reaction */\n get emoji(): string {\n return this.raw.emoticon\n }\n\n /** Sticker representing a static icon for this effect (if any) */\n get staticIcon(): Sticker | null {\n if (!this.raw.staticIconId) return null\n\n const document = this.documentsMap.get(this.raw.staticIconId)\n if (!document) return null\n\n const parsed = parseSticker(document)\n\n if (!parsed) {\n throw new MtTypeAssertionError('MessageEffect.staticIcon', 'sticker', 'null')\n }\n\n return parsed\n }\n\n /** Animated icon representing the effect */\n get icon(): Sticker {\n const document = this.documentsMap.get(this.raw.effectStickerId)\n\n if (!document) {\n throw new MtTypeAssertionError('MessageEffect.effect', 'document', 'null')\n }\n\n const parsed = parseSticker(document)\n\n if (!parsed) {\n throw new MtTypeAssertionError('MessageEffect.effect', 'sticker', 'null')\n }\n\n return parsed\n }\n\n /** The animation itself */\n get animation(): Sticker | null {\n if (!this.raw.effectAnimationId) return null\n\n const document = this.documentsMap.get(this.raw.effectAnimationId)\n if (!document) return null\n\n const parsed = parseSticker(document)\n\n if (!parsed) {\n throw new MtTypeAssertionError('MessageEffect.effectAnimation', 'sticker', 'null')\n }\n\n return parsed\n }\n}\n\nmemoizeGetters(MessageEffect, ['staticIcon', 'icon', 'animation'])\nmakeInspectable(MessageEffect)\n"]}
|
|
@@ -20,7 +20,10 @@ import { tl } from '@mtcute/tl';
|
|
|
20
20
|
* - 'emoji': A custom emoji. `.emojiId` contains the emoji ID.
|
|
21
21
|
*/
|
|
22
22
|
export type MessageEntityParams = {
|
|
23
|
-
kind: 'mention' | 'hashtag' | 'cashtag' | 'bot_command' | 'url' | 'email' | 'phone_number' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler' | 'code' | '
|
|
23
|
+
kind: 'mention' | 'hashtag' | 'cashtag' | 'bot_command' | 'url' | 'email' | 'phone_number' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'spoiler' | 'code' | 'bank_card' | 'unknown';
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'blockquote';
|
|
26
|
+
collapsible: boolean;
|
|
24
27
|
} | {
|
|
25
28
|
kind: 'pre';
|
|
26
29
|
language?: string;
|
|
@@ -73,7 +73,7 @@ class MessageEntity {
|
|
|
73
73
|
case 'messageEntityMentionName':
|
|
74
74
|
return { kind: 'text_mention', userId: this.raw.userId };
|
|
75
75
|
case 'messageEntityBlockquote':
|
|
76
|
-
return { kind: 'blockquote' };
|
|
76
|
+
return { kind: 'blockquote', collapsible: this.raw.collapsed };
|
|
77
77
|
case 'messageEntityCustomEmoji':
|
|
78
78
|
return { kind: 'emoji', emojiId: this.raw.documentId };
|
|
79
79
|
case 'messageEntityBankCard':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-entity.js","sourceRoot":"","sources":["../../../../../src/highlevel/types/messages/message-entity.ts"],"names":[],"mappings":";;;AAEA,mDAAsD;AACtD,uDAAuD;AAoDvD;;GAEG;AACH,MAAa,aAAa;IAET;IACA;IAFb,YACa,GAAyB,EACzB,KAAc;QADd,QAAG,GAAH,GAAG,CAAsB;QACzB,UAAK,GAAL,KAAK,CAAS;IACxB,CAAC;IAEJ;;;;OAIG;IACH,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAA;IAC1B,CAAC;IAED;;;;OAIG;IACH,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAA;IAC1B,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAA;IAC3B,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACN,QAAQ,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACjB,KAAK,sBAAsB;gBACvB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;YAC9B,KAAK,sBAAsB;gBACvB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;YAC9B,KAAK,sBAAsB;gBACvB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;YAC9B,KAAK,yBAAyB;gBAC1B,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAA;YAClC,KAAK,kBAAkB;gBACnB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;YAC1B,KAAK,oBAAoB;gBACrB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;YAC5B,KAAK,oBAAoB;gBACrB,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAA;YACnC,KAAK,mBAAmB;gBACpB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;YAC3B,KAAK,qBAAqB;gBACtB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;YAC7B,KAAK,wBAAwB;gBACzB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAA;YAChC,KAAK,qBAAqB;gBACtB,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAA;YACpC,KAAK,sBAAsB;gBACvB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;YAC9B,KAAK,mBAAmB;gBACpB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;YAC3B,KAAK,kBAAkB;gBACnB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAA;YACvD,KAAK,sBAAsB;gBACvB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;YACnD,KAAK,0BAA0B;gBAC3B,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAA;YAC5D,KAAK,yBAAyB;gBAC1B,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"message-entity.js","sourceRoot":"","sources":["../../../../../src/highlevel/types/messages/message-entity.ts"],"names":[],"mappings":";;;AAEA,mDAAsD;AACtD,uDAAuD;AAoDvD;;GAEG;AACH,MAAa,aAAa;IAET;IACA;IAFb,YACa,GAAyB,EACzB,KAAc;QADd,QAAG,GAAH,GAAG,CAAsB;QACzB,UAAK,GAAL,KAAK,CAAS;IACxB,CAAC;IAEJ;;;;OAIG;IACH,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAA;IAC1B,CAAC;IAED;;;;OAIG;IACH,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAA;IAC1B,CAAC;IAED;;OAEG;I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O,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;YACnD,KAAK,0BAA0B;gBAC3B,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAA;YAC5D,KAAK,yBAAyB;gBAC1B,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,SAAU,EAAE,CAAA;YACnE,KAAK,0BAA0B;gBAC3B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAA;YAC1D,KAAK,uBAAuB;gBACxB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAA;QACpC,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;IAC9B,CAAC;IAED;;;;;OAKG;IACH,IAAI,IAAI;QACJ,IAAI,CAAC,IAAI,CAAC,KAAK;YAAE,OAAO,EAAE,CAAA;QAE1B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAC/E,CAAC;IAED;;;;OAIG;IACH,EAAE,CACE,IAAO;QAEP,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAAA;IACpC,CAAC;CACJ;AArGD,sCAqGC;AAED,IAAA,2BAAc,EAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;AACzC,IAAA,0BAAe,EAAC,aAAa,CAAC,CAAA","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { makeInspectable } from '../../utils/index.js'\nimport { memoizeGetters } from '../../utils/memoize.js'\n\n/**\n * Params of the entity. `.kind` can be:\n * - 'mention': `@username`.\n * - 'hashtag': `#hashtag`.\n * - 'cashtag': `$USD`.\n * - 'bot_command': `/start`.\n * - 'url': `https://example.com`\n * - 'email': `example@example.com`.\n * - 'phone_number': `+42000`.\n * - 'bold': **bold text**.\n * - 'italic': *italic text*.\n * - 'underline': <u>underlined</u> text.\n * - 'strikethrough': <s>strikethrough</s> text.\n * - 'code': `monospaced` string.\n * - 'pre': `monospaced` block. `.language` contains the language of the block (if available).\n * - 'text_link': for clickable text URLs.\n * - 'text_mention': for user mention by name. `.userId` contains the ID of the mentioned user.\n * - 'blockquote': A blockquote\n * - 'emoji': A custom emoji. `.emojiId` contains the emoji ID.\n */\nexport type MessageEntityParams =\n | {\n kind:\n | 'mention'\n | 'hashtag'\n | 'cashtag'\n | 'bot_command'\n | 'url'\n | 'email'\n | 'phone_number'\n | 'bold'\n | 'italic'\n | 'underline'\n | 'strikethrough'\n | 'spoiler'\n | 'code'\n | 'bank_card'\n | 'unknown'\n }\n | { kind: 'blockquote'; collapsible: boolean }\n | { kind: 'pre'; language?: string }\n | { kind: 'text_link'; url: string }\n | { kind: 'text_mention'; userId: number }\n | { kind: 'emoji'; emojiId: tl.Long }\n\n/**\n * Kind of the entity. For more information, see {@link MessageEntityParams}\n */\nexport type MessageEntityKind = MessageEntityParams['kind']\n\n/**\n * One special entity in a text message (like mention, hashtag, URL, etc.)\n */\nexport class MessageEntity {\n constructor(\n readonly raw: tl.TypeMessageEntity,\n readonly _text?: string,\n ) {}\n\n /**\n * Offset in UTF-16 code units to the start of the entity.\n *\n * Since JS strings are UTF-16, you can use this as-is\n */\n get offset() {\n return this.raw.offset\n }\n\n /**\n * Length of the entity in UTF-16 code units.\n *\n * Since JS strings are UTF-16, you can use this as-is\n */\n get length() {\n return this.raw.length\n }\n\n /**\n * Kind of the entity (see {@link MessageEntityParams})\n */\n get kind(): MessageEntityKind {\n return this.params.kind\n }\n\n /**\n * Params of the entity\n */\n get params(): MessageEntityParams {\n switch (this.raw._) {\n case 'messageEntityMention':\n return { kind: 'mention' }\n case 'messageEntityHashtag':\n return { kind: 'hashtag' }\n case 'messageEntityCashtag':\n return { kind: 'cashtag' }\n case 'messageEntityBotCommand':\n return { kind: 'bot_command' }\n case 'messageEntityUrl':\n return { kind: 'url' }\n case 'messageEntityEmail':\n return { kind: 'email' }\n case 'messageEntityPhone':\n return { kind: 'phone_number' }\n case 'messageEntityBold':\n return { kind: 'bold' }\n case 'messageEntityItalic':\n return { kind: 'italic' }\n case 'messageEntityUnderline':\n return { kind: 'underline' }\n case 'messageEntityStrike':\n return { kind: 'strikethrough' }\n case 'messageEntitySpoiler':\n return { kind: 'spoiler' }\n case 'messageEntityCode':\n return { kind: 'code' }\n case 'messageEntityPre':\n return { kind: 'pre', language: this.raw.language }\n case 'messageEntityTextUrl':\n return { kind: 'text_link', url: this.raw.url }\n case 'messageEntityMentionName':\n return { kind: 'text_mention', userId: this.raw.userId }\n case 'messageEntityBlockquote':\n return { kind: 'blockquote', collapsible: this.raw.collapsed! }\n case 'messageEntityCustomEmoji':\n return { kind: 'emoji', emojiId: this.raw.documentId }\n case 'messageEntityBankCard':\n return { kind: 'bank_card' }\n }\n\n return { kind: 'unknown' }\n }\n\n /**\n * Text contained in this entity.\n *\n * > **Note**: This does not take into account that entities may overlap,\n * > and is only useful for simple cases.\n */\n get text(): string {\n if (!this._text) return ''\n\n return this._text.slice(this.raw.offset, this.raw.offset + this.raw.length)\n }\n\n /**\n * Checks if this entity is of the given type, and adjusts the type accordingly.\n * @param kind\n * @returns\n */\n is<const T extends MessageEntityKind>(\n kind: T,\n ): this is MessageEntity & { params: Extract<MessageEntityParams, { kind: T }>; kind: T } {\n return this.params.kind === kind\n }\n}\n\nmemoizeGetters(MessageEntity, ['params'])\nmakeInspectable(MessageEntity)\n"]}
|
|
@@ -5,6 +5,7 @@ import { Chat } from '../peers/chat.js';
|
|
|
5
5
|
import { Peer } from '../peers/peer.js';
|
|
6
6
|
import { PeersIndex } from '../peers/peers-index.js';
|
|
7
7
|
import { User } from '../peers/user.js';
|
|
8
|
+
import { FactCheck } from './fact-check.js';
|
|
8
9
|
import { MessageAction } from './message-action.js';
|
|
9
10
|
import { MessageEntity } from './message-entity.js';
|
|
10
11
|
import { MessageForwardInfo } from './message-forward.js';
|
|
@@ -226,7 +227,18 @@ export declare class Message {
|
|
|
226
227
|
* `false` for service mesasges and private restricted chats/chanenls
|
|
227
228
|
*/
|
|
228
229
|
get canBeForwarded(): boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Reactions added to this message, if any
|
|
232
|
+
*/
|
|
229
233
|
get reactions(): MessageReactions | null;
|
|
234
|
+
/**
|
|
235
|
+
* Information about fact-check added to the message, if any
|
|
236
|
+
*/
|
|
237
|
+
get factCheck(): FactCheck | null;
|
|
238
|
+
/**
|
|
239
|
+
* If this message was sent with a message effect, ID of the effect
|
|
240
|
+
*/
|
|
241
|
+
get effectId(): tl.Long | null;
|
|
230
242
|
/**
|
|
231
243
|
* Generated permalink to this message, only for groups and channels
|
|
232
244
|
*
|
|
@@ -11,6 +11,7 @@ const index_js_2 = require("../bots/keyboards/index.js");
|
|
|
11
11
|
const chat_js_1 = require("../peers/chat.js");
|
|
12
12
|
const peer_js_1 = require("../peers/peer.js");
|
|
13
13
|
const user_js_1 = require("../peers/user.js");
|
|
14
|
+
const fact_check_js_1 = require("./fact-check.js");
|
|
14
15
|
const message_action_js_1 = require("./message-action.js");
|
|
15
16
|
const message_entity_js_1 = require("./message-entity.js");
|
|
16
17
|
const message_forward_js_1 = require("./message-forward.js");
|
|
@@ -402,12 +403,33 @@ class Message {
|
|
|
402
403
|
get canBeForwarded() {
|
|
403
404
|
return this.raw._ === 'message' && !this.raw.noforwards;
|
|
404
405
|
}
|
|
406
|
+
/**
|
|
407
|
+
* Reactions added to this message, if any
|
|
408
|
+
*/
|
|
405
409
|
get reactions() {
|
|
406
410
|
if (this.raw._ === 'messageService' || !this.raw.reactions) {
|
|
407
411
|
return null;
|
|
408
412
|
}
|
|
409
413
|
return new message_reactions_js_1.MessageReactions(this.raw.id, (0, peer_utils_js_1.getMarkedPeerId)(this.raw.peerId), this.raw.reactions, this._peers);
|
|
410
414
|
}
|
|
415
|
+
/**
|
|
416
|
+
* Information about fact-check added to the message, if any
|
|
417
|
+
*/
|
|
418
|
+
get factCheck() {
|
|
419
|
+
if (this.raw._ === 'messageService')
|
|
420
|
+
return null;
|
|
421
|
+
if (!this.raw.factcheck || this.raw.factcheck.hash.isZero())
|
|
422
|
+
return null;
|
|
423
|
+
return new fact_check_js_1.FactCheck(this.raw.factcheck);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* If this message was sent with a message effect, ID of the effect
|
|
427
|
+
*/
|
|
428
|
+
get effectId() {
|
|
429
|
+
if (this.raw._ === 'messageService')
|
|
430
|
+
return null;
|
|
431
|
+
return this.raw.effect ?? null;
|
|
432
|
+
}
|
|
411
433
|
/**
|
|
412
434
|
* Generated permalink to this message, only for groups and channels
|
|
413
435
|
*
|
|
@@ -435,6 +457,7 @@ exports.Message = Message;
|
|
|
435
457
|
'media',
|
|
436
458
|
'markup',
|
|
437
459
|
'reactions',
|
|
460
|
+
'factCheck',
|
|
438
461
|
]);
|
|
439
462
|
(0, index_js_1.makeInspectable)(Message, ['isScheduled'], ['link']);
|
|
440
463
|
//# sourceMappingURL=message.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../../../src/highlevel/types/messages/message.ts"],"names":[],"mappings":";;;AAEA,wDAA0D;AAC1D,sDAAqD;AACrD,gEAAmF;AACnF,0EAAmE;AACnE,mDAAsD;AACtD,uDAAuD;AACvD,yDAAqE;AAErE,8CAAuC;AACvC,8CAAkD;AAElD,8CAAuC;AACvC,2DAAyE;AACzE,2DAAmD;AACnD,6DAAyD;AACzD,yDAAsE;AACtE,iEAAyD;AACzD,6DAAyD;AACzD,6DAAyD;AAEzD;;GAEG;AACH,MAAa,OAAO;IAQH;IAKA;IAZb;;OAEG;IACM,GAAG,C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AC,MAAM,CAAC,CAAA;IAC/G,CAAC;IAED;;;;OAIG;IACH,IAAI,IAAI;QACJ,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,YAAY,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC1E,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACrB,OAAO,gBAAgB,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,EAAE,EAAE,CAAA;YAC1D,CAAC;YAED,OAAO,kBAAkB,IAAA,mCAAmB,EAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,CAAA;QAC3E,CAAC;QAED,MAAM,IAAI,2BAAe,CAAC,oCAAoC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;IACvF,CAAC;CACJ;AA/cD,0BA+cC;AAED,IAAA,2BAAc,EAAC,OAAO,EAAE;IACpB,QAAQ;IACR,MAAM;IACN,SAAS;IACT,SAAS;IACT,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,WAAW;CACd,CAAC,CAAA;AACF,IAAA,0BAAe,EAAC,OAAO,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { MtArgumentError } from '../../../types/errors.js'\nimport { assertNever } from '../../../types/utils.js'\nimport { getMarkedPeerId, toggleChannelIdMark } from '../../../utils/peer-utils.js'\nimport { assertTypeIsNot } from '../../../utils/type-assertions.js'\nimport { makeInspectable } from '../../utils/index.js'\nimport { memoizeGetters } from '../../utils/memoize.js'\nimport { BotKeyboard, ReplyMarkup } from '../bots/keyboards/index.js'\nimport { TextWithEntities } from '../misc/index.js'\nimport { Chat } from '../peers/chat.js'\nimport { parsePeer, Peer } from '../peers/peer.js'\nimport { PeersIndex } from '../peers/peers-index.js'\nimport { User } from '../peers/user.js'\nimport { _messageActionFromTl, MessageAction } from './message-action.js'\nimport { MessageEntity } from './message-entity.js'\nimport { MessageForwardInfo } from './message-forward.js'\nimport { _messageMediaFromTl, MessageMedia } from './message-media.js'\nimport { MessageReactions } from './message-reactions.js'\nimport { MessageRepliesInfo } from './message-replies.js'\nimport { RepliedMessageInfo } from './replied-message.js'\n\n/**\n * A Telegram message.\n */\nexport class Message {\n /**\n * Raw TL object.\n */\n readonly raw: tl.RawMessage | tl.RawMessageService\n\n constructor(\n raw: tl.TypeMessage,\n readonly _peers: PeersIndex,\n /**\n * Whether the message is scheduled.\n * If it is, then its {@link date} is set to future.\n */\n readonly isScheduled = false,\n ) {\n assertTypeIsNot('Message#ctor', raw, 'messageEmpty')\n\n this.raw = raw\n }\n\n /** Unique message identifier inside this chat */\n get id(): number {\n return this.raw.id\n }\n\n /**\n * For channel posts, number of views\n *\n * `null` for service messages and non-post messages.\n */\n get views(): number | null {\n return this.raw._ === 'message' ? this.raw.views ?? null : null\n }\n\n /**\n * For channel posts, number of forwards\n *\n * `null` for service messages and non-post messages, or\n * if the current user is not an admin in the channel\n */\n get forwards(): number | null {\n return this.raw._ === 'message' ? this.raw.forwards ?? null : null\n }\n\n /**\n * For channel posts with signatures enabled, name of the post author\n */\n get signature(): string | null {\n return this.raw._ === 'message' ? this.raw.postAuthor ?? null : null\n }\n\n /**\n * Whether the message is incoming or outgoing:\n * - Messages received from other chats are incoming (`outgoing = false`)\n * - Messages sent by you to other chats are outgoing (`outgoing = true`)\n * - Messages to yourself (i.e. *Saved Messages*) are incoming (`outgoing = false`)\n */\n get isOutgoing(): boolean {\n return this.raw.out!\n }\n\n /**\n * Whether this message is a service message\n */\n get isService(): boolean {\n return this.raw._ === 'messageService'\n }\n\n /** Whether this message has content protection (i.e. disabled forwards) */\n get isContentProtected(): boolean {\n return this.raw._ === 'message' && this.raw.noforwards!\n }\n\n /**\n * Whether the message was sent by an implicit action, for example,\n * as an away or a greeting business message, or as a scheduled message\n */\n get isFromOffline(): boolean {\n return this.raw._ === 'message' && this.raw.offline!\n }\n\n /** Whether this is a silent message (no notification triggered) */\n get isSilent(): boolean {\n return this.raw.silent!\n }\n\n /** Whether there are unread media attachments in this message */\n get hasUnreadMedia(): boolean {\n return this.raw.mediaUnread!\n }\n\n /** Whether this is a broadcast channel post */\n get isChannelPost(): boolean {\n return this.raw._ === 'message' && this.raw.post!\n }\n\n /**\n * Whether this message was automatically sent from a scheduled message.\n *\n * **Note**: for messages sent by other users, this is always `false`.\n */\n get isFromScheduled(): boolean {\n return this.raw._ === 'message' && this.raw.fromScheduled!\n }\n\n /** Whether the message is pinned in the current chat */\n get isPinned(): boolean {\n return this.raw._ === 'message' && this.raw.pinned!\n }\n\n /** Whether the message should be considered unedited, even if {@link editDate} ≠ null */\n get hideEditMark(): boolean {\n return this.raw._ === 'message' && this.raw.editHide!\n }\n\n /**\n * If set, any eventual webpage preview should be shown on top of\n * the message instead of at the bottom.\n */\n get invertMedia(): boolean {\n return this.raw._ === 'message' && this.raw.invertMedia!\n }\n\n /**\n * Multiple media messages with the same grouped ID\n * indicate an album or media group\n *\n * `null` for service messages and non-grouped messages\n */\n get groupedId(): tl.Long | null {\n return this.raw._ === 'message' ? this.raw.groupedId ?? null : null\n }\n\n /**\n * Same as {@link groupedId}, but is globally unique across chats.\n */\n get groupedIdUnique(): string | null {\n if (!(this.raw._ === 'message' && this.raw.groupedId !== undefined)) return null\n\n return `${this.raw.groupedId.low}|${this.raw.groupedId.high}|${getMarkedPeerId(this.raw.peerId)}`\n }\n\n /**\n * Message sender.\n *\n * Usually is a {@link User}, but can be a {@link Chat}\n * in case the message was sent by an anonymous admin, anonymous premium user,\n * or if the message is a forwarded channel post.\n *\n * If the message was sent by an anonymous admin,\n * sender will equal to {@link chat}.\n *\n * If the message is a forwarded channel post,\n * sender is the channel itself.\n */\n get sender(): Peer {\n const from = this.raw.fromId\n\n if (!from) {\n if (this.raw.peerId._ === 'peerUser') {\n return new User(this._peers.user(this.raw.peerId.userId))\n }\n\n // anon admin, return the chat\n return this.chat\n }\n\n return parsePeer(from, this._peers)\n }\n\n /**\n * Number of boosts applied to this {@link chat} by the sender\n */\n get senderBoostCount(): number {\n if (this.raw._ !== 'message') return 0\n\n return this.raw.fromBoostsApplied ?? 0\n }\n\n /**\n * Conversation the message belongs to\n */\n get chat(): Chat {\n return Chat._parseFromMessage(this.raw, this._peers)\n }\n\n /**\n * Date when the message was sent\n */\n get date(): Date {\n return new Date(this.raw.date * 1000)\n }\n\n /**\n * Date when the message was last edited\n */\n get editDate(): Date | null {\n if (this.raw._ === 'messageService') return null\n\n return this.raw.editDate ? new Date(this.raw.editDate * 1000) : null\n }\n\n /**\n * If this message is a forward, contains info about it.\n */\n get forward(): MessageForwardInfo | null {\n if (this.raw._ !== 'message' || !this.raw.fwdFrom) {\n return null\n }\n\n return new MessageForwardInfo(this.raw.fwdFrom, this._peers)\n }\n\n /**\n * Whether the message is a channel post that was\n * automatically forwarded to the connected discussion group\n */\n get isAutomaticForward(): boolean {\n if (this.raw._ === 'messageService' || !this.raw.fwdFrom) return false\n\n const fwd = this.raw.fwdFrom\n\n return Boolean(\n this.chat.chatType === 'supergroup' &&\n fwd.savedFromMsgId &&\n fwd.savedFromPeer?._ === 'peerChannel' &&\n getMarkedPeerId(fwd.savedFromPeer) !== getMarkedPeerId(this.raw.peerId),\n )\n }\n\n /**\n * Information about comments (for channels) or replies (for groups)\n */\n get replies(): MessageRepliesInfo | null {\n if (this.raw._ !== 'message' || !this.raw.replies) return null\n\n return new MessageRepliesInfo(this.raw.replies, this._peers)\n }\n\n /**\n * For replies, information about the that is being replied to.\n *\n * Mutually exclusive with {@link replyToStory}\n */\n get replyToMessage(): RepliedMessageInfo | null {\n if (this.raw.replyTo?._ !== 'messageReplyHeader') return null\n\n return new RepliedMessageInfo(this.raw.replyTo, this._peers)\n }\n\n /**\n * For replies, information about the story that is being replied to\n *\n * Mutually exclusive with {@link replyToMessage}\n */\n get replyToStory(): tl.RawMessageReplyStoryHeader | null {\n if (this.raw.replyTo?._ !== 'messageReplyStoryHeader') return null\n\n return this.raw.replyTo\n }\n\n /** Whether this message is in a forum topic */\n get isTopicMessage(): boolean {\n if (this.raw.replyTo?._ !== 'messageReplyHeader') return false\n\n return this.raw.replyTo.forumTopic!\n }\n\n /**\n * Whether this message contains mention of the current user\n */\n get isMention(): boolean {\n return this.raw.mentioned!\n }\n\n /**\n * If non-null, this message is not actually sent, and is\n * instead inside a group of \"quick reply\" messages\n * under the given shortcut ID\n */\n get quickReplyShortcutId(): number | null {\n if (this.raw._ === 'messageService') return null\n\n return this.raw.quickReplyShortcutId ?? null\n }\n\n /**\n * If this message is generated from an inline query,\n * information about the bot which generated it\n */\n get viaBot(): User | null {\n if (this.raw._ === 'messageService' || !this.raw.viaBotId) {\n return null\n }\n\n return new User(this._peers.user(this.raw.viaBotId))\n }\n\n /**\n * If this message was sent by a business bot on behalf of {@link sender},\n * information about the business bot.\n *\n * **Note**: only available to the business account and the bot itself.\n */\n get viaBusinessBot(): User | null {\n if (this.raw._ === 'messageService' || !this.raw.viaBusinessBotId) {\n return null\n }\n\n return new User(this._peers.user(this.raw.viaBusinessBotId))\n }\n\n /**\n * Message text or media caption.\n *\n * Empty string for service messages\n * (you should handle i18n yourself)\n */\n get text(): string {\n return this.raw._ === 'messageService' ? '' : this.raw.message\n }\n\n /**\n * Message text/caption entities (may be empty)\n */\n get entities(): ReadonlyArray<MessageEntity> {\n const entities: MessageEntity[] = []\n\n if (this.raw._ === 'message' && this.raw.entities?.length) {\n for (const ent of this.raw.entities) {\n entities.push(new MessageEntity(ent, this.raw.message))\n }\n }\n\n return entities\n }\n\n get textWithEntities(): TextWithEntities {\n if (this.raw._ === 'messageService') return { text: '', entities: [] }\n\n return {\n text: this.raw.message,\n entities: this.raw.entities,\n }\n }\n\n /**\n * Message action. `null` for non-service messages\n * or for unsupported events.\n *\n * For unsupported events, use `.raw.action` directly.\n */\n get action(): MessageAction | null {\n if (this.raw._ === 'message') {\n return null\n }\n\n return _messageActionFromTl.call(this, this.raw.action)\n }\n\n /**\n * Message media. `null` for text-only and service messages\n * and for unsupported media types.\n *\n * For unsupported media types, use `.raw.media` directly.\n */\n get media(): MessageMedia {\n if (this.raw._ === 'messageService' || !this.raw.media || this.raw.media._ === 'messageMediaEmpty') {\n return null\n }\n\n return _messageMediaFromTl(this._peers, this.raw.media)\n }\n\n /**\n * Whether this is a premium media\n * (e.g. >2gb file or fullscreen sticker)\n * that was forwarded without author by a non-premium user\n */\n get isForwardedPremiumMedia(): boolean {\n return this.raw._ === 'message' && this.raw.media?._ === 'messageMediaDocument' && this.raw.media.nopremium!\n }\n\n /**\n * TTL period of the message, in seconds.\n */\n get ttlPeriod(): number | null {\n return this.raw.ttlPeriod ?? null\n }\n\n /**\n * Reply markup provided with this message, if any.\n */\n get markup(): ReplyMarkup | null {\n if (this.raw._ === 'messageService' || !this.raw.replyMarkup) {\n return null\n }\n\n const rm = this.raw.replyMarkup\n\n switch (rm._) {\n case 'replyKeyboardHide':\n return {\n type: 'reply_hide',\n selective: rm.selective,\n }\n case 'replyKeyboardForceReply':\n return {\n type: 'force_reply',\n singleUse: rm.singleUse,\n selective: rm.selective,\n }\n case 'replyKeyboardMarkup':\n return {\n type: 'reply',\n resize: rm.resize,\n singleUse: rm.singleUse,\n selective: rm.selective,\n buttons: BotKeyboard._rowsTo2d(rm.rows),\n }\n case 'replyInlineMarkup':\n return {\n type: 'inline',\n buttons: BotKeyboard._rowsTo2d(rm.rows),\n }\n default:\n assertNever(rm)\n }\n }\n\n /**\n * Whether this message can be forwarded\n *\n * `false` for service mesasges and private restricted chats/chanenls\n */\n get canBeForwarded(): boolean {\n return this.raw._ === 'message' && !this.raw.noforwards\n }\n\n get reactions(): MessageReactions | null {\n if (this.raw._ === 'messageService' || !this.raw.reactions) {\n return null\n }\n\n return new MessageReactions(this.raw.id, getMarkedPeerId(this.raw.peerId), this.raw.reactions, this._peers)\n }\n\n /**\n * Generated permalink to this message, only for groups and channels\n *\n * @throws MtArgumentError In case the chat does not support message links\n */\n get link(): string {\n if (this.chat.chatType === 'supergroup' || this.chat.chatType === 'channel') {\n if (this.chat.username) {\n return `https://t.me/${this.chat.username}/${this.id}`\n }\n\n return `https://t.me/c/${toggleChannelIdMark(this.chat.id)}/${this.id}`\n }\n\n throw new MtArgumentError(`Cannot generate message link for ${this.chat.chatType}`)\n }\n}\n\nmemoizeGetters(Message, [\n 'sender',\n 'chat',\n 'forward',\n 'replies',\n 'viaBot',\n 'entities',\n 'action',\n 'media',\n 'markup',\n 'reactions',\n])\nmakeInspectable(Message, ['isScheduled'], ['link'])\n"]}
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../../../src/highlevel/types/messages/message.ts"],"names":[],"mappings":";;;AAEA,wDAA0D;AAC1D,sDAAqD;AACrD,gEAAmF;AACnF,0EAAmE;AACnE,mDAAsD;AACtD,uDAAuD;AACvD,yDAAqE;AAErE,8CAAuC;AACvC,8CAAkD;AAElD,8CAAuC;AACvC,mDAA2C;AAC3C,2DAAyE;AACzE,2DAAmD;AACnD,6DAAyD;AACzD,yDAAsE;AACtE,iEAAyD;AACzD,6DAAyD;AACzD,6DAAyD;AAEzD;;GAEG;AACH,MAAa,OAAO;IAQH;IAKA;IAZb;;OAEG;IACM,GAAG,CAAsC;IAElD,YACI,GAAmB,EACV,MAAkB;IAC3B;;;OAGG;IACM,cAAc,KAAK;QALnB,WAAM,GAAN,MAAM,CAAY;QAKlB,gBAAW,GAAX,WAAW,CAAQ;QAE5B,IAAA,oCAAe,EAAC,cAAc,EAAE,GAAG,EAAE,cAAc,CAAC,CAAA;QAEpD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAClB,CAAC;IAED,iDAAiD;IACjD,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;IACtB,CAAC;IAED;;;;OAIG;IACH,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,GAA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AAQ;QACR,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,gBAAgB;YAAE,OAAO,IAAI,CAAA;QAEhD,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,CAAA;IAClC,CAAC;IAED;;;;OAIG;IACH,IAAI,IAAI;QACJ,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,YAAY,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC1E,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACrB,OAAO,gBAAgB,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,EAAE,EAAE,CAAA;YAC1D,CAAC;YAED,OAAO,kBAAkB,IAAA,mCAAmB,EAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,CAAA;QAC3E,CAAC;QAED,MAAM,IAAI,2BAAe,CAAC,oCAAoC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;IACvF,CAAC;CACJ;AAreD,0BAqeC;AAED,IAAA,2BAAc,EAAC,OAAO,EAAE;IACpB,QAAQ;IACR,MAAM;IACN,SAAS;IACT,SAAS;IACT,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,WAAW;IACX,WAAW;CACd,CAAC,CAAA;AACF,IAAA,0BAAe,EAAC,OAAO,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { MtArgumentError } from '../../../types/errors.js'\nimport { assertNever } from '../../../types/utils.js'\nimport { getMarkedPeerId, toggleChannelIdMark } from '../../../utils/peer-utils.js'\nimport { assertTypeIsNot } from '../../../utils/type-assertions.js'\nimport { makeInspectable } from '../../utils/index.js'\nimport { memoizeGetters } from '../../utils/memoize.js'\nimport { BotKeyboard, ReplyMarkup } from '../bots/keyboards/index.js'\nimport { TextWithEntities } from '../misc/index.js'\nimport { Chat } from '../peers/chat.js'\nimport { parsePeer, Peer } from '../peers/peer.js'\nimport { PeersIndex } from '../peers/peers-index.js'\nimport { User } from '../peers/user.js'\nimport { FactCheck } from './fact-check.js'\nimport { _messageActionFromTl, MessageAction } from './message-action.js'\nimport { MessageEntity } from './message-entity.js'\nimport { MessageForwardInfo } from './message-forward.js'\nimport { _messageMediaFromTl, MessageMedia } from './message-media.js'\nimport { MessageReactions } from './message-reactions.js'\nimport { MessageRepliesInfo } from './message-replies.js'\nimport { RepliedMessageInfo } from './replied-message.js'\n\n/**\n * A Telegram message.\n */\nexport class Message {\n /**\n * Raw TL object.\n */\n readonly raw: tl.RawMessage | tl.RawMessageService\n\n constructor(\n raw: tl.TypeMessage,\n readonly _peers: PeersIndex,\n /**\n * Whether the message is scheduled.\n * If it is, then its {@link date} is set to future.\n */\n readonly isScheduled = false,\n ) {\n assertTypeIsNot('Message#ctor', raw, 'messageEmpty')\n\n this.raw = raw\n }\n\n /** Unique message identifier inside this chat */\n get id(): number {\n return this.raw.id\n }\n\n /**\n * For channel posts, number of views\n *\n * `null` for service messages and non-post messages.\n */\n get views(): number | null {\n return this.raw._ === 'message' ? this.raw.views ?? null : null\n }\n\n /**\n * For channel posts, number of forwards\n *\n * `null` for service messages and non-post messages, or\n * if the current user is not an admin in the channel\n */\n get forwards(): number | null {\n return this.raw._ === 'message' ? this.raw.forwards ?? null : null\n }\n\n /**\n * For channel posts with signatures enabled, name of the post author\n */\n get signature(): string | null {\n return this.raw._ === 'message' ? this.raw.postAuthor ?? null : null\n }\n\n /**\n * Whether the message is incoming or outgoing:\n * - Messages received from other chats are incoming (`outgoing = false`)\n * - Messages sent by you to other chats are outgoing (`outgoing = true`)\n * - Messages to yourself (i.e. *Saved Messages*) are incoming (`outgoing = false`)\n */\n get isOutgoing(): boolean {\n return this.raw.out!\n }\n\n /**\n * Whether this message is a service message\n */\n get isService(): boolean {\n return this.raw._ === 'messageService'\n }\n\n /** Whether this message has content protection (i.e. disabled forwards) */\n get isContentProtected(): boolean {\n return this.raw._ === 'message' && this.raw.noforwards!\n }\n\n /**\n * Whether the message was sent by an implicit action, for example,\n * as an away or a greeting business message, or as a scheduled message\n */\n get isFromOffline(): boolean {\n return this.raw._ === 'message' && this.raw.offline!\n }\n\n /** Whether this is a silent message (no notification triggered) */\n get isSilent(): boolean {\n return this.raw.silent!\n }\n\n /** Whether there are unread media attachments in this message */\n get hasUnreadMedia(): boolean {\n return this.raw.mediaUnread!\n }\n\n /** Whether this is a broadcast channel post */\n get isChannelPost(): boolean {\n return this.raw._ === 'message' && this.raw.post!\n }\n\n /**\n * Whether this message was automatically sent from a scheduled message.\n *\n * **Note**: for messages sent by other users, this is always `false`.\n */\n get isFromScheduled(): boolean {\n return this.raw._ === 'message' && this.raw.fromScheduled!\n }\n\n /** Whether the message is pinned in the current chat */\n get isPinned(): boolean {\n return this.raw._ === 'message' && this.raw.pinned!\n }\n\n /** Whether the message should be considered unedited, even if {@link editDate} ≠ null */\n get hideEditMark(): boolean {\n return this.raw._ === 'message' && this.raw.editHide!\n }\n\n /**\n * If set, any eventual webpage preview should be shown on top of\n * the message instead of at the bottom.\n */\n get invertMedia(): boolean {\n return this.raw._ === 'message' && this.raw.invertMedia!\n }\n\n /**\n * Multiple media messages with the same grouped ID\n * indicate an album or media group\n *\n * `null` for service messages and non-grouped messages\n */\n get groupedId(): tl.Long | null {\n return this.raw._ === 'message' ? this.raw.groupedId ?? null : null\n }\n\n /**\n * Same as {@link groupedId}, but is globally unique across chats.\n */\n get groupedIdUnique(): string | null {\n if (!(this.raw._ === 'message' && this.raw.groupedId !== undefined)) return null\n\n return `${this.raw.groupedId.low}|${this.raw.groupedId.high}|${getMarkedPeerId(this.raw.peerId)}`\n }\n\n /**\n * Message sender.\n *\n * Usually is a {@link User}, but can be a {@link Chat}\n * in case the message was sent by an anonymous admin, anonymous premium user,\n * or if the message is a forwarded channel post.\n *\n * If the message was sent by an anonymous admin,\n * sender will equal to {@link chat}.\n *\n * If the message is a forwarded channel post,\n * sender is the channel itself.\n */\n get sender(): Peer {\n const from = this.raw.fromId\n\n if (!from) {\n if (this.raw.peerId._ === 'peerUser') {\n return new User(this._peers.user(this.raw.peerId.userId))\n }\n\n // anon admin, return the chat\n return this.chat\n }\n\n return parsePeer(from, this._peers)\n }\n\n /**\n * Number of boosts applied to this {@link chat} by the sender\n */\n get senderBoostCount(): number {\n if (this.raw._ !== 'message') return 0\n\n return this.raw.fromBoostsApplied ?? 0\n }\n\n /**\n * Conversation the message belongs to\n */\n get chat(): Chat {\n return Chat._parseFromMessage(this.raw, this._peers)\n }\n\n /**\n * Date when the message was sent\n */\n get date(): Date {\n return new Date(this.raw.date * 1000)\n }\n\n /**\n * Date when the message was last edited\n */\n get editDate(): Date | null {\n if (this.raw._ === 'messageService') return null\n\n return this.raw.editDate ? new Date(this.raw.editDate * 1000) : null\n }\n\n /**\n * If this message is a forward, contains info about it.\n */\n get forward(): MessageForwardInfo | null {\n if (this.raw._ !== 'message' || !this.raw.fwdFrom) {\n return null\n }\n\n return new MessageForwardInfo(this.raw.fwdFrom, this._peers)\n }\n\n /**\n * Whether the message is a channel post that was\n * automatically forwarded to the connected discussion group\n */\n get isAutomaticForward(): boolean {\n if (this.raw._ === 'messageService' || !this.raw.fwdFrom) return false\n\n const fwd = this.raw.fwdFrom\n\n return Boolean(\n this.chat.chatType === 'supergroup' &&\n fwd.savedFromMsgId &&\n fwd.savedFromPeer?._ === 'peerChannel' &&\n getMarkedPeerId(fwd.savedFromPeer) !== getMarkedPeerId(this.raw.peerId),\n )\n }\n\n /**\n * Information about comments (for channels) or replies (for groups)\n */\n get replies(): MessageRepliesInfo | null {\n if (this.raw._ !== 'message' || !this.raw.replies) return null\n\n return new MessageRepliesInfo(this.raw.replies, this._peers)\n }\n\n /**\n * For replies, information about the that is being replied to.\n *\n * Mutually exclusive with {@link replyToStory}\n */\n get replyToMessage(): RepliedMessageInfo | null {\n if (this.raw.replyTo?._ !== 'messageReplyHeader') return null\n\n return new RepliedMessageInfo(this.raw.replyTo, this._peers)\n }\n\n /**\n * For replies, information about the story that is being replied to\n *\n * Mutually exclusive with {@link replyToMessage}\n */\n get replyToStory(): tl.RawMessageReplyStoryHeader | null {\n if (this.raw.replyTo?._ !== 'messageReplyStoryHeader') return null\n\n return this.raw.replyTo\n }\n\n /** Whether this message is in a forum topic */\n get isTopicMessage(): boolean {\n if (this.raw.replyTo?._ !== 'messageReplyHeader') return false\n\n return this.raw.replyTo.forumTopic!\n }\n\n /**\n * Whether this message contains mention of the current user\n */\n get isMention(): boolean {\n return this.raw.mentioned!\n }\n\n /**\n * If non-null, this message is not actually sent, and is\n * instead inside a group of \"quick reply\" messages\n * under the given shortcut ID\n */\n get quickReplyShortcutId(): number | null {\n if (this.raw._ === 'messageService') return null\n\n return this.raw.quickReplyShortcutId ?? null\n }\n\n /**\n * If this message is generated from an inline query,\n * information about the bot which generated it\n */\n get viaBot(): User | null {\n if (this.raw._ === 'messageService' || !this.raw.viaBotId) {\n return null\n }\n\n return new User(this._peers.user(this.raw.viaBotId))\n }\n\n /**\n * If this message was sent by a business bot on behalf of {@link sender},\n * information about the business bot.\n *\n * **Note**: only available to the business account and the bot itself.\n */\n get viaBusinessBot(): User | null {\n if (this.raw._ === 'messageService' || !this.raw.viaBusinessBotId) {\n return null\n }\n\n return new User(this._peers.user(this.raw.viaBusinessBotId))\n }\n\n /**\n * Message text or media caption.\n *\n * Empty string for service messages\n * (you should handle i18n yourself)\n */\n get text(): string {\n return this.raw._ === 'messageService' ? '' : this.raw.message\n }\n\n /**\n * Message text/caption entities (may be empty)\n */\n get entities(): ReadonlyArray<MessageEntity> {\n const entities: MessageEntity[] = []\n\n if (this.raw._ === 'message' && this.raw.entities?.length) {\n for (const ent of this.raw.entities) {\n entities.push(new MessageEntity(ent, this.raw.message))\n }\n }\n\n return entities\n }\n\n get textWithEntities(): TextWithEntities {\n if (this.raw._ === 'messageService') return { text: '', entities: [] }\n\n return {\n text: this.raw.message,\n entities: this.raw.entities,\n }\n }\n\n /**\n * Message action. `null` for non-service messages\n * or for unsupported events.\n *\n * For unsupported events, use `.raw.action` directly.\n */\n get action(): MessageAction | null {\n if (this.raw._ === 'message') {\n return null\n }\n\n return _messageActionFromTl.call(this, this.raw.action)\n }\n\n /**\n * Message media. `null` for text-only and service messages\n * and for unsupported media types.\n *\n * For unsupported media types, use `.raw.media` directly.\n */\n get media(): MessageMedia {\n if (this.raw._ === 'messageService' || !this.raw.media || this.raw.media._ === 'messageMediaEmpty') {\n return null\n }\n\n return _messageMediaFromTl(this._peers, this.raw.media)\n }\n\n /**\n * Whether this is a premium media\n * (e.g. >2gb file or fullscreen sticker)\n * that was forwarded without author by a non-premium user\n */\n get isForwardedPremiumMedia(): boolean {\n return this.raw._ === 'message' && this.raw.media?._ === 'messageMediaDocument' && this.raw.media.nopremium!\n }\n\n /**\n * TTL period of the message, in seconds.\n */\n get ttlPeriod(): number | null {\n return this.raw.ttlPeriod ?? null\n }\n\n /**\n * Reply markup provided with this message, if any.\n */\n get markup(): ReplyMarkup | null {\n if (this.raw._ === 'messageService' || !this.raw.replyMarkup) {\n return null\n }\n\n const rm = this.raw.replyMarkup\n\n switch (rm._) {\n case 'replyKeyboardHide':\n return {\n type: 'reply_hide',\n selective: rm.selective,\n }\n case 'replyKeyboardForceReply':\n return {\n type: 'force_reply',\n singleUse: rm.singleUse,\n selective: rm.selective,\n }\n case 'replyKeyboardMarkup':\n return {\n type: 'reply',\n resize: rm.resize,\n singleUse: rm.singleUse,\n selective: rm.selective,\n buttons: BotKeyboard._rowsTo2d(rm.rows),\n }\n case 'replyInlineMarkup':\n return {\n type: 'inline',\n buttons: BotKeyboard._rowsTo2d(rm.rows),\n }\n default:\n assertNever(rm)\n }\n }\n\n /**\n * Whether this message can be forwarded\n *\n * `false` for service mesasges and private restricted chats/chanenls\n */\n get canBeForwarded(): boolean {\n return this.raw._ === 'message' && !this.raw.noforwards\n }\n\n /**\n * Reactions added to this message, if any\n */\n get reactions(): MessageReactions | null {\n if (this.raw._ === 'messageService' || !this.raw.reactions) {\n return null\n }\n\n return new MessageReactions(this.raw.id, getMarkedPeerId(this.raw.peerId), this.raw.reactions, this._peers)\n }\n\n /**\n * Information about fact-check added to the message, if any\n */\n get factCheck(): FactCheck | null {\n if (this.raw._ === 'messageService') return null\n if (!this.raw.factcheck || this.raw.factcheck.hash.isZero()) return null\n\n return new FactCheck(this.raw.factcheck)\n }\n\n /**\n * If this message was sent with a message effect, ID of the effect\n */\n get effectId(): tl.Long | null {\n if (this.raw._ === 'messageService') return null\n\n return this.raw.effect ?? null\n }\n\n /**\n * Generated permalink to this message, only for groups and channels\n *\n * @throws MtArgumentError In case the chat does not support message links\n */\n get link(): string {\n if (this.chat.chatType === 'supergroup' || this.chat.chatType === 'channel') {\n if (this.chat.username) {\n return `https://t.me/${this.chat.username}/${this.id}`\n }\n\n return `https://t.me/c/${toggleChannelIdMark(this.chat.id)}/${this.id}`\n }\n\n throw new MtArgumentError(`Cannot generate message link for ${this.chat.chatType}`)\n }\n}\n\nmemoizeGetters(Message, [\n 'sender',\n 'chat',\n 'forward',\n 'replies',\n 'viaBot',\n 'entities',\n 'action',\n 'media',\n 'markup',\n 'reactions',\n 'factCheck',\n])\nmakeInspectable(Message, ['isScheduled'], ['link'])\n"]}
|
package/cjs/network/client.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ import { ConfigManager } from './config-manager.js';
|
|
|
9
9
|
import { NetworkManager, NetworkManagerExtraParams, RpcCallOptions } from './network-manager.js';
|
|
10
10
|
import { PersistentConnectionParams } from './persistent-connection.js';
|
|
11
11
|
import { ReconnectionStrategy } from './reconnection.js';
|
|
12
|
-
import { SessionConnection } from './session-connection.js';
|
|
13
12
|
import { TransportFactory } from './transports/index.js';
|
|
14
13
|
/** Options for {@link MtClient} */
|
|
15
14
|
export interface MtClientOptions {
|
|
@@ -196,7 +195,7 @@ export declare class MtClient extends EventEmitter {
|
|
|
196
195
|
readonly log: Logger;
|
|
197
196
|
readonly network: NetworkManager;
|
|
198
197
|
constructor(params: MtClientOptions);
|
|
199
|
-
emitError(err: unknown
|
|
198
|
+
emitError(err: unknown): void;
|
|
200
199
|
private _prepare;
|
|
201
200
|
/**
|
|
202
201
|
* **ADVANCED**
|
package/cjs/network/client.js
CHANGED
|
@@ -102,9 +102,9 @@ class MtClient extends events_1.default {
|
|
|
102
102
|
...params.network,
|
|
103
103
|
}, this._config);
|
|
104
104
|
}
|
|
105
|
-
emitError(err
|
|
105
|
+
emitError(err) {
|
|
106
106
|
if (this._emitError) {
|
|
107
|
-
this._emitError(err
|
|
107
|
+
this._emitError(err);
|
|
108
108
|
}
|
|
109
109
|
else {
|
|
110
110
|
this.log.error('unhandled error:', err);
|
|
@@ -176,7 +176,7 @@ class MtClient extends events_1.default {
|
|
|
176
176
|
* @param handler Error handler.
|
|
177
177
|
*/
|
|
178
178
|
onError(handler) {
|
|
179
|
-
this.
|
|
179
|
+
this._emitError = handler;
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
exports.MtClient = MtClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/network/client.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAuD;AACvD,oDAAiC;AAEjC,mCAA+B;AAC/B,2DAA+E;AAC/E,2DAA+E;AAI/E,sDAAkF;AAElF,gDAU0B;AAC1B,2DAAmD;AACnD,6DAAgG;AAkLhG;;;;GAIG;AACH,MAAa,QAAS,SAAQ,gBAAY;IAmCjB;IAlCrB;;OAEG;IACM,MAAM,CAAiB;IAEhC,sBAAsB;IACb,OAAO,CAAgB;IAEhC;;OAEG;IACgB,SAAS,CAAS;IAErC;;;OAGG;IACH,WAAW,CAAW;IAEd,WAAW,CAAS;IAC5B,kCAAkC;IACzB,MAAM,CAAQ;IACvB,wCAAwC;IAC/B,UAAU,CAAa;IAChC,wCAAwC;IAC/B,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AAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;IAEF;;;;;OAKG;IACH,KAAK,CAAC,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAA;IAC9B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACP,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;QACtB,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;QAE5B,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;QACzB,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAA;QAE9B,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;QACrB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IACzB,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,IAAI,CACN,OAAmC,EACnC,MAAuB;QAEvB,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;QAE9D,+DAA+D;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;IACpD,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,OAA+B;QACnC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAA;IAC5B,CAAC;CACJ;AA9LD,4BA8LC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport EventEmitter from 'events'\n\nimport { tl } from '@mtcute/tl'\nimport { __tlReaderMap as defaultReaderMap } from '@mtcute/tl/binary/reader.js'\nimport { __tlWriterMap as defaultWriterMap } from '@mtcute/tl/binary/writer.js'\nimport { TlReaderMap, TlWriterMap } from '@mtcute/tl-runtime'\n\nimport { IMtStorageProvider } from '../storage/provider.js'\nimport { StorageManager, StorageManagerExtraOptions } from '../storage/storage.js'\nimport { MustEqual } from '../types/index.js'\nimport {\n asyncResettable,\n DcOptions,\n defaultProductionDc,\n defaultProductionIpv6Dc,\n defaultTestDc,\n defaultTestIpv6Dc,\n ICryptoProvider,\n Logger,\n LogManager,\n} from '../utils/index.js'\nimport { ConfigManager } from './config-manager.js'\nimport { NetworkManager, NetworkManagerExtraParams, RpcCallOptions } from './network-manager.js'\nimport { PersistentConnectionParams } from './persistent-connection.js'\nimport { ReconnectionStrategy } from './reconnection.js'\nimport { SessionConnection } from './session-connection.js'\nimport { TransportFactory } from './transports/index.js'\n\n/** Options for {@link MtClient} */\nexport interface MtClientOptions {\n /**\n * API ID from my.telegram.org\n */\n apiId: number\n /**\n * API hash from my.telegram.org\n */\n apiHash: string\n\n /**\n * Storage to use for this client.\n */\n storage: IMtStorageProvider\n\n /** Additional options for the storage manager */\n storageOptions?: StorageManagerExtraOptions\n\n /**\n * Cryptography provider to allow delegating\n * crypto to native addon, worker, etc.\n */\n crypto: ICryptoProvider\n\n /**\n * Whether to use IPv6 datacenters\n * (IPv6 will be preferred when choosing a DC by id)\n * (default: false)\n */\n useIpv6?: boolean\n\n /**\n * Primary DC to use for initial connection.\n * This does not mean this will be the only DC used,\n * nor that this DC will actually be primary, this only\n * determines the first DC the library will try to connect to.\n * Can be used to connect to other networks (like test DCs).\n *\n * When session already contains primary DC, this parameter is ignored.\n *\n * @default Production DC 2.\n */\n defaultDcs?: DcOptions\n\n /**\n * Whether to connect to test servers.\n *\n * If passed, {@link defaultDc} defaults to Test DC 2.\n *\n * **Must** be passed if using test servers, even if\n * you passed custom {@link defaultDc}\n */\n testMode?: boolean\n\n /**\n * Additional options for initConnection call.\n * `apiId` and `query` are not available and will be ignored.\n * Omitted values will be filled with defaults\n */\n initConnectionOptions?: Partial<Omit<tl.RawInitConnectionRequest, 'apiId' | 'query'>>\n\n /**\n * Transport factory to use in the client.\n *\n * @default platform-specific transport: WebSocket on the web, TCP in node\n */\n transport: TransportFactory\n\n /**\n * Reconnection strategy.\n *\n * @default simple reconnection strategy: first 0ms, then up to 5s (increasing by 1s)\n */\n reconnectionStrategy?: ReconnectionStrategy<PersistentConnectionParams>\n\n /**\n * Maximum duration of a flood_wait that will be waited automatically.\n * Flood waits above this threshold will throw a FloodWaitError.\n * Set to 0 to disable. Can be overridden with `throwFlood` parameter in call() params\n *\n * @default 10000\n */\n floodSleepThreshold?: number\n\n /**\n * Maximum number of retries when calling RPC methods.\n * Call is retried when InternalError or FloodWaitError is encountered.\n * Can be set to Infinity.\n *\n * @default 5\n */\n maxRetryCount?: number\n\n /**\n * If true, all API calls will be wrapped with `tl.invokeWithoutUpdates`,\n * effectively disabling the server-sent events for the clients.\n * May be useful in some cases.\n *\n * @default false\n */\n disableUpdates?: boolean\n\n /**\n * mtcute can send all unknown RPC errors to [danog](https://github.com/danog)'s\n * [error reporting service](https://rpc.pwrtelegram.xyz/).\n *\n * This is fully anonymous (except maybe IP) and is only used to improve the library\n * and developer experience for everyone working with MTProto. This is fully opt-in,\n * and if you're too paranoid, you can disable it by manually passing `enableErrorReporting: false` to the client.\n *\n * @default false\n */\n enableErrorReporting?: boolean\n\n /**\n * If true, RPC errors will have a stack trace of the initial `.call()`\n * or `.sendForResult()` call position, which drastically improves\n * debugging experience.<br>\n * If false, they will have a stack trace of mtcute internals.\n *\n * Internally this creates a stack capture before every RPC call\n * and stores it until the result is received. This might\n * use a lot more memory than normal, thus can be disabled here.\n *\n * @default true\n */\n niceStacks?: boolean\n\n /**\n * Extra parameters for {@link NetworkManager}\n */\n network?: NetworkManagerExtraParams\n\n /**\n * Logger instance for the client.\n * If not passed, a new one will be created.\n */\n logger?: Logger\n\n /**\n * Set logging level for the client.\n * Shorthand for `client.log.level = level`.\n *\n * See static members of {@link LogManager} for possible values.\n */\n logLevel?: number\n\n /**\n * **EXPERT USE ONLY!**\n *\n * Override TL layer used for the connection.\n *\n * **Does not** change the schema used.\n */\n overrideLayer?: number\n\n /**\n * **EXPERT USE ONLY**\n *\n * Override reader map used for the connection.\n */\n readerMap?: TlReaderMap\n\n /**\n * **EXPERT USE ONLY**\n *\n * Override writer map used for the connection.\n */\n writerMap?: TlWriterMap\n}\n\n/**\n * Basic MTProto client implementation, only doing the bare minimum\n * to make RPC calls and receive low-level updates, as well as providing\n * some APIs to manage that.\n */\nexport class MtClient extends EventEmitter {\n /**\n * Crypto provider taken from {@link MtClientOptions.crypto}\n */\n readonly crypto: ICryptoProvider\n\n /** Storage manager */\n readonly storage: StorageManager\n\n /**\n * \"Test mode\" taken from {@link MtClientOptions.testMode}\n */\n protected readonly _testMode: boolean\n\n /**\n * Primary DCs taken from {@link MtClientOptions.defaultDcs},\n * loaded from session or changed by other means (like redirecting).\n */\n _defaultDcs: DcOptions\n\n private _niceStacks: boolean\n /** TL layer used by the client */\n readonly _layer: number\n /** TL readers map used by the client */\n readonly _readerMap: TlReaderMap\n /** TL writers map used by the client */\n readonly _writerMap: TlWriterMap\n\n readonly _config = new ConfigManager(() => this.call({ _: 'help.getConfig' }))\n\n private _emitError?: (err: unknown, connection?: SessionConnection) => void\n\n readonly log: Logger\n readonly network: NetworkManager\n\n constructor(readonly params: MtClientOptions) {\n super()\n\n this.log = params.logger ?? new LogManager()\n\n if (params.logLevel !== undefined) {\n this.log.mgr.level = params.logLevel\n }\n\n this.crypto = params.crypto\n this._testMode = Boolean(params.testMode)\n\n let dc = params.defaultDcs\n\n if (!dc) {\n if (params.testMode) {\n dc = params.useIpv6 ? defaultTestIpv6Dc : defaultTestDc\n } else {\n dc = params.useIpv6 ? defaultProductionIpv6Dc : defaultProductionDc\n }\n }\n\n this._defaultDcs = dc\n this._niceStacks = params.niceStacks ?? true\n\n this._layer = params.overrideLayer ?? tl.LAYER\n this._readerMap = params.readerMap ?? defaultReaderMap\n this._writerMap = params.writerMap ?? defaultWriterMap\n\n this.storage = new StorageManager({\n provider: params.storage,\n log: this.log,\n readerMap: this._readerMap,\n writerMap: this._writerMap,\n ...params.storageOptions,\n })\n\n this.network = new NetworkManager(\n {\n apiId: params.apiId,\n crypto: this.crypto,\n disableUpdates: params.disableUpdates ?? false,\n initConnectionOptions: params.initConnectionOptions,\n layer: this._layer,\n log: this.log,\n readerMap: this._readerMap,\n writerMap: this._writerMap,\n reconnectionStrategy: params.reconnectionStrategy,\n storage: this.storage,\n testMode: Boolean(params.testMode),\n transport: params.transport,\n emitError: this.emitError.bind(this),\n floodSleepThreshold: params.floodSleepThreshold ?? 10000,\n maxRetryCount: params.maxRetryCount ?? 5,\n isPremium: false,\n useIpv6: Boolean(params.useIpv6),\n enableErrorReporting: params.enableErrorReporting ?? false,\n onUsable: () => this.emit('usable'),\n onConnecting: () => this.emit('connecting'),\n onNetworkChanged: (connected) => this.emit('networkChanged', connected),\n onUpdate: (upd) => this.emit('update', upd),\n ...params.network,\n },\n this._config,\n )\n }\n\n emitError(err: unknown, connection?: SessionConnection): void {\n if (this._emitError) {\n this._emitError(err, connection)\n } else {\n this.log.error('unhandled error:', err)\n }\n }\n\n private _prepare = asyncResettable(async () => {\n await this.crypto.initialize?.()\n await this.storage.load()\n\n const primaryDc = await this.storage.dcs.fetch()\n if (primaryDc !== null) this._defaultDcs = primaryDc\n })\n\n /**\n * **ADVANCED**\n *\n * Do all the preparations, but don't connect just yet.\n * Useful when you want to do some preparations before\n * connecting, like setting up session.\n *\n * Call {@link connect} to actually connect.\n */\n prepare() {\n return this._prepare.run()\n }\n\n private _connect = asyncResettable(async () => {\n await this._prepare.run()\n await this.network.connect(this._defaultDcs)\n })\n\n /**\n * Initialize the connection to the primary DC.\n *\n * You shouldn't usually call this method directly as it is called\n * implicitly the first time you call {@link call}.\n */\n async connect(): Promise<void> {\n return this._connect.run()\n }\n\n /**\n * Close all connections and finalize the client.\n */\n async close(): Promise<void> {\n this._config.destroy()\n await this.network.destroy()\n\n await this.storage.save()\n await this.storage.destroy?.()\n\n this._prepare.reset()\n this._connect.reset()\n }\n\n /**\n * Make an RPC call.\n *\n * The connection must have been {@link connect}-ed\n * before calling this method.\n *\n * This method is still quite low-level and you shouldn't use this\n * when using high-level API provided by `@mtcute/client`.\n *\n * @param message RPC method to call\n * @param params Additional call parameters\n */\n async call<T extends tl.RpcMethod>(\n message: MustEqual<T, tl.RpcMethod>,\n params?: RpcCallOptions,\n ): Promise<tl.RpcCallReturn[T['_']]> {\n const stack = this._niceStacks ? new Error().stack : undefined\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.network.call(message, params, stack)\n }\n\n /**\n * Register an error handler for the client\n *\n * @param handler Error handler.\n */\n onError(handler: (err: unknown) => void): void {\n this.emitError = handler\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/network/client.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAuD;AACvD,oDAAiC;AAEjC,mCAA+B;AAC/B,2DAA+E;AAC/E,2DAA+E;AAI/E,sDAAkF;AAElF,gDAU0B;AAC1B,2DAAmD;AACnD,6DAAgG;AAiLhG;;;;GAIG;AACH,MAAa,QAAS,SAAQ,gBAAY;IAmCjB;IAlCrB;;OAEG;IACM,MAAM,CAAiB;IAEhC,sBAAsB;IACb,OAAO,CAAgB;IAEhC;;OAEG;IACgB,SAAS,CAAS;IAErC;;;OAGG;IACH,WAAW,CAAW;IAEd,WAAW,CAAS;IAC5B,kCAAkC;IACzB,MAAM,CAAQ;IACvB,wCAAwC;IAC/B,UAAU,CAAa;IAChC,wCAAwC;IAC/B,UAAU,CAAa;IAEvB,OAAO,GAAG,IAAI,iCAAa,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAA;IAEtE,UAAU,CAAyB;IAElC,GAAG,CAAQ;IACX,OAAO,CAAgB;IAEhC,YAAqB,MAAuB;QACxC,KAAK,EAAE,CAAA;QADU,WAAM,GAAN,MAAM,CAAiB;QAGxC,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,IA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AE,CAAA;QACzB,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAA;QAE9B,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;QACrB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAA;IACzB,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,IAAI,CACN,OAAmC,EACnC,MAAuB;QAEvB,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;QAE9D,+DAA+D;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;IACpD,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,OAA+B;QACnC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAA;IAC7B,CAAC;CACJ;AA9LD,4BA8LC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport EventEmitter from 'events'\n\nimport { tl } from '@mtcute/tl'\nimport { __tlReaderMap as defaultReaderMap } from '@mtcute/tl/binary/reader.js'\nimport { __tlWriterMap as defaultWriterMap } from '@mtcute/tl/binary/writer.js'\nimport { TlReaderMap, TlWriterMap } from '@mtcute/tl-runtime'\n\nimport { IMtStorageProvider } from '../storage/provider.js'\nimport { StorageManager, StorageManagerExtraOptions } from '../storage/storage.js'\nimport { MustEqual } from '../types/index.js'\nimport {\n asyncResettable,\n DcOptions,\n defaultProductionDc,\n defaultProductionIpv6Dc,\n defaultTestDc,\n defaultTestIpv6Dc,\n ICryptoProvider,\n Logger,\n LogManager,\n} from '../utils/index.js'\nimport { ConfigManager } from './config-manager.js'\nimport { NetworkManager, NetworkManagerExtraParams, RpcCallOptions } from './network-manager.js'\nimport { PersistentConnectionParams } from './persistent-connection.js'\nimport { ReconnectionStrategy } from './reconnection.js'\nimport { TransportFactory } from './transports/index.js'\n\n/** Options for {@link MtClient} */\nexport interface MtClientOptions {\n /**\n * API ID from my.telegram.org\n */\n apiId: number\n /**\n * API hash from my.telegram.org\n */\n apiHash: string\n\n /**\n * Storage to use for this client.\n */\n storage: IMtStorageProvider\n\n /** Additional options for the storage manager */\n storageOptions?: StorageManagerExtraOptions\n\n /**\n * Cryptography provider to allow delegating\n * crypto to native addon, worker, etc.\n */\n crypto: ICryptoProvider\n\n /**\n * Whether to use IPv6 datacenters\n * (IPv6 will be preferred when choosing a DC by id)\n * (default: false)\n */\n useIpv6?: boolean\n\n /**\n * Primary DC to use for initial connection.\n * This does not mean this will be the only DC used,\n * nor that this DC will actually be primary, this only\n * determines the first DC the library will try to connect to.\n * Can be used to connect to other networks (like test DCs).\n *\n * When session already contains primary DC, this parameter is ignored.\n *\n * @default Production DC 2.\n */\n defaultDcs?: DcOptions\n\n /**\n * Whether to connect to test servers.\n *\n * If passed, {@link defaultDc} defaults to Test DC 2.\n *\n * **Must** be passed if using test servers, even if\n * you passed custom {@link defaultDc}\n */\n testMode?: boolean\n\n /**\n * Additional options for initConnection call.\n * `apiId` and `query` are not available and will be ignored.\n * Omitted values will be filled with defaults\n */\n initConnectionOptions?: Partial<Omit<tl.RawInitConnectionRequest, 'apiId' | 'query'>>\n\n /**\n * Transport factory to use in the client.\n *\n * @default platform-specific transport: WebSocket on the web, TCP in node\n */\n transport: TransportFactory\n\n /**\n * Reconnection strategy.\n *\n * @default simple reconnection strategy: first 0ms, then up to 5s (increasing by 1s)\n */\n reconnectionStrategy?: ReconnectionStrategy<PersistentConnectionParams>\n\n /**\n * Maximum duration of a flood_wait that will be waited automatically.\n * Flood waits above this threshold will throw a FloodWaitError.\n * Set to 0 to disable. Can be overridden with `throwFlood` parameter in call() params\n *\n * @default 10000\n */\n floodSleepThreshold?: number\n\n /**\n * Maximum number of retries when calling RPC methods.\n * Call is retried when InternalError or FloodWaitError is encountered.\n * Can be set to Infinity.\n *\n * @default 5\n */\n maxRetryCount?: number\n\n /**\n * If true, all API calls will be wrapped with `tl.invokeWithoutUpdates`,\n * effectively disabling the server-sent events for the clients.\n * May be useful in some cases.\n *\n * @default false\n */\n disableUpdates?: boolean\n\n /**\n * mtcute can send all unknown RPC errors to [danog](https://github.com/danog)'s\n * [error reporting service](https://rpc.pwrtelegram.xyz/).\n *\n * This is fully anonymous (except maybe IP) and is only used to improve the library\n * and developer experience for everyone working with MTProto. This is fully opt-in,\n * and if you're too paranoid, you can disable it by manually passing `enableErrorReporting: false` to the client.\n *\n * @default false\n */\n enableErrorReporting?: boolean\n\n /**\n * If true, RPC errors will have a stack trace of the initial `.call()`\n * or `.sendForResult()` call position, which drastically improves\n * debugging experience.<br>\n * If false, they will have a stack trace of mtcute internals.\n *\n * Internally this creates a stack capture before every RPC call\n * and stores it until the result is received. This might\n * use a lot more memory than normal, thus can be disabled here.\n *\n * @default true\n */\n niceStacks?: boolean\n\n /**\n * Extra parameters for {@link NetworkManager}\n */\n network?: NetworkManagerExtraParams\n\n /**\n * Logger instance for the client.\n * If not passed, a new one will be created.\n */\n logger?: Logger\n\n /**\n * Set logging level for the client.\n * Shorthand for `client.log.level = level`.\n *\n * See static members of {@link LogManager} for possible values.\n */\n logLevel?: number\n\n /**\n * **EXPERT USE ONLY!**\n *\n * Override TL layer used for the connection.\n *\n * **Does not** change the schema used.\n */\n overrideLayer?: number\n\n /**\n * **EXPERT USE ONLY**\n *\n * Override reader map used for the connection.\n */\n readerMap?: TlReaderMap\n\n /**\n * **EXPERT USE ONLY**\n *\n * Override writer map used for the connection.\n */\n writerMap?: TlWriterMap\n}\n\n/**\n * Basic MTProto client implementation, only doing the bare minimum\n * to make RPC calls and receive low-level updates, as well as providing\n * some APIs to manage that.\n */\nexport class MtClient extends EventEmitter {\n /**\n * Crypto provider taken from {@link MtClientOptions.crypto}\n */\n readonly crypto: ICryptoProvider\n\n /** Storage manager */\n readonly storage: StorageManager\n\n /**\n * \"Test mode\" taken from {@link MtClientOptions.testMode}\n */\n protected readonly _testMode: boolean\n\n /**\n * Primary DCs taken from {@link MtClientOptions.defaultDcs},\n * loaded from session or changed by other means (like redirecting).\n */\n _defaultDcs: DcOptions\n\n private _niceStacks: boolean\n /** TL layer used by the client */\n readonly _layer: number\n /** TL readers map used by the client */\n readonly _readerMap: TlReaderMap\n /** TL writers map used by the client */\n readonly _writerMap: TlWriterMap\n\n readonly _config = new ConfigManager(() => this.call({ _: 'help.getConfig' }))\n\n private _emitError?: (err: unknown) => void\n\n readonly log: Logger\n readonly network: NetworkManager\n\n constructor(readonly params: MtClientOptions) {\n super()\n\n this.log = params.logger ?? new LogManager()\n\n if (params.logLevel !== undefined) {\n this.log.mgr.level = params.logLevel\n }\n\n this.crypto = params.crypto\n this._testMode = Boolean(params.testMode)\n\n let dc = params.defaultDcs\n\n if (!dc) {\n if (params.testMode) {\n dc = params.useIpv6 ? defaultTestIpv6Dc : defaultTestDc\n } else {\n dc = params.useIpv6 ? defaultProductionIpv6Dc : defaultProductionDc\n }\n }\n\n this._defaultDcs = dc\n this._niceStacks = params.niceStacks ?? true\n\n this._layer = params.overrideLayer ?? tl.LAYER\n this._readerMap = params.readerMap ?? defaultReaderMap\n this._writerMap = params.writerMap ?? defaultWriterMap\n\n this.storage = new StorageManager({\n provider: params.storage,\n log: this.log,\n readerMap: this._readerMap,\n writerMap: this._writerMap,\n ...params.storageOptions,\n })\n\n this.network = new NetworkManager(\n {\n apiId: params.apiId,\n crypto: this.crypto,\n disableUpdates: params.disableUpdates ?? false,\n initConnectionOptions: params.initConnectionOptions,\n layer: this._layer,\n log: this.log,\n readerMap: this._readerMap,\n writerMap: this._writerMap,\n reconnectionStrategy: params.reconnectionStrategy,\n storage: this.storage,\n testMode: Boolean(params.testMode),\n transport: params.transport,\n emitError: this.emitError.bind(this),\n floodSleepThreshold: params.floodSleepThreshold ?? 10000,\n maxRetryCount: params.maxRetryCount ?? 5,\n isPremium: false,\n useIpv6: Boolean(params.useIpv6),\n enableErrorReporting: params.enableErrorReporting ?? false,\n onUsable: () => this.emit('usable'),\n onConnecting: () => this.emit('connecting'),\n onNetworkChanged: (connected) => this.emit('networkChanged', connected),\n onUpdate: (upd) => this.emit('update', upd),\n ...params.network,\n },\n this._config,\n )\n }\n\n emitError(err: unknown): void {\n if (this._emitError) {\n this._emitError(err)\n } else {\n this.log.error('unhandled error:', err)\n }\n }\n\n private _prepare = asyncResettable(async () => {\n await this.crypto.initialize?.()\n await this.storage.load()\n\n const primaryDc = await this.storage.dcs.fetch()\n if (primaryDc !== null) this._defaultDcs = primaryDc\n })\n\n /**\n * **ADVANCED**\n *\n * Do all the preparations, but don't connect just yet.\n * Useful when you want to do some preparations before\n * connecting, like setting up session.\n *\n * Call {@link connect} to actually connect.\n */\n prepare() {\n return this._prepare.run()\n }\n\n private _connect = asyncResettable(async () => {\n await this._prepare.run()\n await this.network.connect(this._defaultDcs)\n })\n\n /**\n * Initialize the connection to the primary DC.\n *\n * You shouldn't usually call this method directly as it is called\n * implicitly the first time you call {@link call}.\n */\n async connect(): Promise<void> {\n return this._connect.run()\n }\n\n /**\n * Close all connections and finalize the client.\n */\n async close(): Promise<void> {\n this._config.destroy()\n await this.network.destroy()\n\n await this.storage.save()\n await this.storage.destroy?.()\n\n this._prepare.reset()\n this._connect.reset()\n }\n\n /**\n * Make an RPC call.\n *\n * The connection must have been {@link connect}-ed\n * before calling this method.\n *\n * This method is still quite low-level and you shouldn't use this\n * when using high-level API provided by `@mtcute/client`.\n *\n * @param message RPC method to call\n * @param params Additional call parameters\n */\n async call<T extends tl.RpcMethod>(\n message: MustEqual<T, tl.RpcMethod>,\n params?: RpcCallOptions,\n ): Promise<tl.RpcCallReturn[T['_']]> {\n const stack = this._niceStacks ? new Error().stack : undefined\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.network.call(message, params, stack)\n }\n\n /**\n * Register an error handler for the client\n *\n * @param handler Error handler.\n */\n onError(handler: (err: unknown) => void): void {\n this._emitError = handler\n }\n}\n"]}
|
|
@@ -1096,7 +1096,7 @@ class SessionConnection extends persistent_connection_js_1.PersistentConnection
|
|
|
1096
1096
|
return pending.promise;
|
|
1097
1097
|
}
|
|
1098
1098
|
if (timeout) {
|
|
1099
|
-
pending.timeout = setTimeout(this._cancelRpc
|
|
1099
|
+
pending.timeout = setTimeout(() => this._cancelRpc(pending, true), timeout);
|
|
1100
1100
|
}
|
|
1101
1101
|
if (abortSignal) {
|
|
1102
1102
|
abortSignal.addEventListener('abort', () => this._cancelRpc(pending, false, abortSignal));
|