@mtcute/core 0.29.7 → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.cjs +8 -0
- package/client.js +8 -0
- package/highlevel/client.d.cts +67 -7
- package/highlevel/client.d.ts +67 -7
- package/highlevel/methods/chats/join-chat.cjs +38 -16
- package/highlevel/methods/chats/join-chat.d.cts +20 -6
- package/highlevel/methods/chats/join-chat.d.ts +20 -6
- package/highlevel/methods/chats/join-chat.js +38 -16
- package/highlevel/methods/chats/save-draft.d.cts +4 -1
- package/highlevel/methods/chats/save-draft.d.ts +4 -1
- package/highlevel/methods/files/normalize-input-media.cjs +8 -0
- package/highlevel/methods/files/normalize-input-media.js +9 -1
- package/highlevel/methods/messages/create-rich-streaming-draft.cjs +39 -0
- package/highlevel/methods/messages/create-rich-streaming-draft.d.cts +42 -0
- package/highlevel/methods/messages/create-rich-streaming-draft.d.ts +42 -0
- package/highlevel/methods/messages/create-rich-streaming-draft.js +34 -0
- package/highlevel/methods/messages/normalize-rich-message.cjs +157 -0
- package/highlevel/methods/messages/normalize-rich-message.d.cts +10 -0
- package/highlevel/methods/messages/normalize-rich-message.d.ts +10 -0
- package/highlevel/methods/messages/normalize-rich-message.js +152 -0
- package/highlevel/methods/messages/send-rich-message.cjs +49 -0
- package/highlevel/methods/messages/send-rich-message.d.cts +38 -0
- package/highlevel/methods/messages/send-rich-message.d.ts +38 -0
- package/highlevel/methods/messages/send-rich-message.js +44 -0
- package/highlevel/methods.d.cts +5 -0
- package/highlevel/methods.d.ts +5 -0
- package/highlevel/storage/service/peers.cjs +1 -0
- package/highlevel/storage/service/peers.js +1 -0
- package/highlevel/types/bots/inline-message/factories.cjs +14 -0
- package/highlevel/types/bots/inline-message/factories.d.cts +9 -1
- package/highlevel/types/bots/inline-message/factories.d.ts +9 -1
- package/highlevel/types/bots/inline-message/factories.js +14 -0
- package/highlevel/types/bots/inline-message/types.d.cts +17 -1
- package/highlevel/types/bots/inline-message/types.d.ts +17 -1
- package/highlevel/types/files/utils.d.cts +1 -1
- package/highlevel/types/files/utils.d.ts +1 -1
- package/highlevel/types/media/input-media/types.d.cts +1 -1
- package/highlevel/types/media/input-media/types.d.ts +1 -1
- package/highlevel/types/messages/index.d.cts +1 -0
- package/highlevel/types/messages/index.d.ts +1 -0
- package/highlevel/types/messages/message.cjs +5 -0
- package/highlevel/types/messages/message.d.cts +3 -0
- package/highlevel/types/messages/message.d.ts +3 -0
- package/highlevel/types/messages/message.js +5 -0
- package/highlevel/types/messages/rich/index.d.cts +4 -0
- package/highlevel/types/messages/rich/index.d.ts +4 -0
- package/highlevel/types/messages/rich/inner.cjs +219 -0
- package/highlevel/types/messages/rich/inner.d.cts +127 -0
- package/highlevel/types/messages/rich/inner.d.ts +127 -0
- package/highlevel/types/messages/rich/inner.js +214 -0
- package/highlevel/types/messages/rich/rich-message.cjs +50 -0
- package/highlevel/types/messages/rich/rich-message.d.cts +18 -0
- package/highlevel/types/messages/rich/rich-message.d.ts +18 -0
- package/highlevel/types/messages/rich/rich-message.js +45 -0
- package/highlevel/types/messages/rich/types.d.cts +76 -0
- package/highlevel/types/messages/rich/types.d.ts +76 -0
- package/highlevel/types/peers/full-chat.cjs +6 -0
- package/highlevel/types/peers/full-chat.d.cts +2 -0
- package/highlevel/types/peers/full-chat.d.ts +2 -0
- package/highlevel/types/peers/full-chat.js +6 -0
- package/highlevel/types/peers/user.cjs +4 -0
- package/highlevel/types/peers/user.d.cts +2 -0
- package/highlevel/types/peers/user.d.ts +2 -0
- package/highlevel/types/peers/user.js +4 -0
- package/highlevel/types/updates/user-typing-update.cjs +2 -0
- package/highlevel/types/updates/user-typing-update.js +2 -0
- package/highlevel/updates/manager.cjs +195 -0
- package/highlevel/updates/manager.js +195 -0
- package/highlevel/utils/entities.cjs +176 -0
- package/highlevel/utils/entities.d.cts +18 -0
- package/highlevel/utils/entities.d.ts +18 -0
- package/highlevel/utils/entities.js +177 -1
- package/highlevel/utils/inspectable.cjs +1 -0
- package/highlevel/utils/inspectable.d.cts +1 -0
- package/highlevel/utils/inspectable.d.ts +1 -0
- package/highlevel/utils/inspectable.js +1 -0
- package/index.cjs +4 -0
- package/index.js +4 -0
- package/methods.cjs +4 -0
- package/methods.js +4 -0
- package/network/flood-control.cjs +149 -0
- package/network/flood-control.d.cts +79 -0
- package/network/flood-control.d.ts +79 -0
- package/network/flood-control.js +144 -0
- package/network/flood-control.test.d.cts +1 -0
- package/network/flood-control.test.d.ts +1 -0
- package/network/mtproto-session.cjs +1 -21
- package/network/mtproto-session.d.cts +1 -5
- package/network/mtproto-session.d.ts +1 -5
- package/network/mtproto-session.js +2 -22
- package/network/mtproxy/_fake-tls.cjs +169 -107
- package/network/mtproxy/_fake-tls.js +169 -107
- package/network/mtproxy/_fake-tls.test.d.cts +1 -0
- package/network/mtproxy/_fake-tls.test.d.ts +1 -0
- package/network/multi-session-connection.cjs +26 -16
- package/network/multi-session-connection.d.cts +1 -1
- package/network/multi-session-connection.d.ts +1 -1
- package/network/multi-session-connection.js +26 -16
- package/network/multi-session-connection.test.d.cts +1 -0
- package/network/multi-session-connection.test.d.ts +1 -0
- package/network/network-manager.cjs +3 -2
- package/network/network-manager.d.cts +12 -0
- package/network/network-manager.d.ts +12 -0
- package/network/network-manager.js +3 -2
- package/network/persistent-connection.cjs +25 -1
- package/network/persistent-connection.d.cts +5 -0
- package/network/persistent-connection.d.ts +5 -0
- package/network/persistent-connection.js +25 -1
- package/network/session-connection.cjs +5 -10
- package/network/session-connection.d.cts +0 -2
- package/network/session-connection.d.ts +0 -2
- package/network/session-connection.js +5 -10
- package/package.json +1 -1
- package/tl/api-schema.json +1 -1
- package/tl/binary/reader.cjs +182 -26
- package/tl/binary/reader.js +182 -26
- package/tl/binary/writer.cjs +437 -20
- package/tl/binary/writer.js +437 -20
- package/tl/compat/reader.cjs +23 -0
- package/tl/compat/reader.js +23 -0
- package/tl/index.d.cts +425 -14
- package/tl/index.d.ts +425 -14
- package/tl/inner-tl.cjs +22 -8
- package/tl/inner-tl.js +22 -8
- package/types/utils.d.cts +4 -0
- package/types/utils.d.ts +4 -0
- package/utils/binary/compat.cjs +79 -0
- package/utils/binary/compat.js +79 -0
- package/utils/index.d.cts +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/long-utils.cjs +10 -0
- package/utils/long-utils.js +10 -0
- package/utils.cjs +9 -0
- package/utils.js +11 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { default as Long } from 'long';
|
|
2
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
3
|
+
import { InputPeerLike } from '../../types/index.js';
|
|
4
|
+
import { InputRichMessage, RichMediaUploadCache } from '../../types/messages/rich/types.js';
|
|
5
|
+
export interface RichStreamingDraft {
|
|
6
|
+
/** Random ID of the draft */
|
|
7
|
+
readonly randomId: Long;
|
|
8
|
+
/** Replace the draft with the given rich message */
|
|
9
|
+
send(content: InputRichMessage): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Cache of media uploaded while streaming the draft (unless disabled).
|
|
12
|
+
*
|
|
13
|
+
* Pass it to the final {@link sendRichMessage} call to avoid re-uploading the media.
|
|
14
|
+
*/
|
|
15
|
+
readonly uploadCache?: RichMediaUploadCache;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a streaming rich message draft
|
|
19
|
+
*
|
|
20
|
+
* @param chatId Chat ID
|
|
21
|
+
* @param params
|
|
22
|
+
*/
|
|
23
|
+
export declare function createRichStreamingDraft(client: ITelegramClient, chatId: InputPeerLike, params?: {
|
|
24
|
+
/**
|
|
25
|
+
* Unique identifier of the business connection on behalf of which the action will be sent
|
|
26
|
+
*/
|
|
27
|
+
businessConnectionId?: string;
|
|
28
|
+
/** Whether to disable upload cache (exists to prevent uploading the same media multiple times) */
|
|
29
|
+
disableUploadCache?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* For comment threads, ID of the thread (i.e. top message)
|
|
32
|
+
*/
|
|
33
|
+
threadId?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Function that will be called after some part of the media has been uploaded.
|
|
36
|
+
*
|
|
37
|
+
* @param id ID of the file being uploaded
|
|
38
|
+
* @param uploaded Number of bytes already uploaded
|
|
39
|
+
* @param total Total file size
|
|
40
|
+
*/
|
|
41
|
+
progressCallback?: (id: string, uploaded: number, total: number) => void;
|
|
42
|
+
}): Promise<RichStreamingDraft>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { default as Long } from 'long';
|
|
2
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
3
|
+
import { InputPeerLike } from '../../types/index.js';
|
|
4
|
+
import { InputRichMessage, RichMediaUploadCache } from '../../types/messages/rich/types.js';
|
|
5
|
+
export interface RichStreamingDraft {
|
|
6
|
+
/** Random ID of the draft */
|
|
7
|
+
readonly randomId: Long;
|
|
8
|
+
/** Replace the draft with the given rich message */
|
|
9
|
+
send(content: InputRichMessage): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Cache of media uploaded while streaming the draft (unless disabled).
|
|
12
|
+
*
|
|
13
|
+
* Pass it to the final {@link sendRichMessage} call to avoid re-uploading the media.
|
|
14
|
+
*/
|
|
15
|
+
readonly uploadCache?: RichMediaUploadCache;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a streaming rich message draft
|
|
19
|
+
*
|
|
20
|
+
* @param chatId Chat ID
|
|
21
|
+
* @param params
|
|
22
|
+
*/
|
|
23
|
+
export declare function createRichStreamingDraft(client: ITelegramClient, chatId: InputPeerLike, params?: {
|
|
24
|
+
/**
|
|
25
|
+
* Unique identifier of the business connection on behalf of which the action will be sent
|
|
26
|
+
*/
|
|
27
|
+
businessConnectionId?: string;
|
|
28
|
+
/** Whether to disable upload cache (exists to prevent uploading the same media multiple times) */
|
|
29
|
+
disableUploadCache?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* For comment threads, ID of the thread (i.e. top message)
|
|
32
|
+
*/
|
|
33
|
+
threadId?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Function that will be called after some part of the media has been uploaded.
|
|
36
|
+
*
|
|
37
|
+
* @param id ID of the file being uploaded
|
|
38
|
+
* @param uploaded Number of bytes already uploaded
|
|
39
|
+
* @param total Total file size
|
|
40
|
+
*/
|
|
41
|
+
progressCallback?: (id: string, uploaded: number, total: number) => void;
|
|
42
|
+
}): Promise<RichStreamingDraft>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { randomLong } from "../../../utils/long-utils.js";
|
|
2
|
+
import { assertTrue } from "../../../utils/type-assertions.js";
|
|
3
|
+
import { resolvePeer } from "../users/resolve-peer.js";
|
|
4
|
+
import { _normalizeInputRichMessage } from "./normalize-rich-message.js";
|
|
5
|
+
async function createRichStreamingDraft(client, chatId, params) {
|
|
6
|
+
const { threadId, businessConnectionId, progressCallback } = params ?? {};
|
|
7
|
+
const randomId = randomLong();
|
|
8
|
+
const peer = await resolvePeer(client, chatId);
|
|
9
|
+
const uploadCache = params?.disableUploadCache ? void 0 : /* @__PURE__ */ new Map();
|
|
10
|
+
const sendDraft = async (content) => {
|
|
11
|
+
const richMessage = await _normalizeInputRichMessage(client, peer, content, { progressCallback, uploadCache });
|
|
12
|
+
const r = await client.call({
|
|
13
|
+
_: "messages.setTyping",
|
|
14
|
+
peer,
|
|
15
|
+
action: {
|
|
16
|
+
_: "inputSendMessageRichMessageDraftAction",
|
|
17
|
+
randomId,
|
|
18
|
+
richMessage
|
|
19
|
+
},
|
|
20
|
+
topMsgId: threadId
|
|
21
|
+
}, {
|
|
22
|
+
businessConnectionId
|
|
23
|
+
});
|
|
24
|
+
assertTrue("messages.setTyping", r);
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
randomId,
|
|
28
|
+
send: sendDraft,
|
|
29
|
+
uploadCache
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
createRichStreamingDraft
|
|
34
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
+
console.warn("[@mtcute/core] CommonJS bundles are deprecated. They will be removed completely in one of the upcoming releases. No support is provided for CommonJS users. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
4
|
+
console.warn("[@mtcute/core] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
5
|
+
}
|
|
6
|
+
"use strict";
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
const utils = require("@fuman/utils");
|
|
9
|
+
const errors = require("../../../types/errors.cjs");
|
|
10
|
+
const typeAssertions = require("../../../utils/type-assertions.cjs");
|
|
11
|
+
const normalizeInputMedia = require("../files/normalize-input-media.cjs");
|
|
12
|
+
function _richMediaCacheKey(media) {
|
|
13
|
+
if (typeof media === "string") return `auto:${media}`;
|
|
14
|
+
if ("_" in media) return void 0;
|
|
15
|
+
if (typeof media.file === "string") return `${media.type}:${media.file}`;
|
|
16
|
+
return media;
|
|
17
|
+
}
|
|
18
|
+
async function _uploadRichMedia(client, peer, id, media, params) {
|
|
19
|
+
const cacheKey = params.uploadCache != null ? _richMediaCacheKey(media) : void 0;
|
|
20
|
+
if (cacheKey !== void 0) {
|
|
21
|
+
const cached = params.uploadCache.get(cacheKey);
|
|
22
|
+
if (cached != null) return cached;
|
|
23
|
+
}
|
|
24
|
+
const input = typeof media === "string" ? { type: "auto", file: media } : media;
|
|
25
|
+
const normalized = await normalizeInputMedia._normalizeInputMedia(client, input, {
|
|
26
|
+
uploadPeer: peer,
|
|
27
|
+
abortSignal: params.abortSignal,
|
|
28
|
+
progressCallback: params.progressCallback?.bind(null, id)
|
|
29
|
+
}, true);
|
|
30
|
+
if (normalized._ !== "inputMediaPhoto" && normalized._ !== "inputMediaDocument") {
|
|
31
|
+
throw new errors.MtTypeAssertionError("sendRichMessage (upload)", "inputMediaDocument | inputMediaPhoto", normalized._);
|
|
32
|
+
}
|
|
33
|
+
if (cacheKey !== void 0) params.uploadCache.set(cacheKey, normalized);
|
|
34
|
+
return normalized;
|
|
35
|
+
}
|
|
36
|
+
async function _normalizeInputRichMessage(client, peer, input, params) {
|
|
37
|
+
if ("_" in input) return input;
|
|
38
|
+
if (input.type !== "blocks") {
|
|
39
|
+
let richFiles;
|
|
40
|
+
if (input.attachments) {
|
|
41
|
+
const medias = [...Object.entries(input.attachments)];
|
|
42
|
+
const normalized = await utils.parallelMap(
|
|
43
|
+
medias,
|
|
44
|
+
async ([id, media]) => [id, await _uploadRichMedia(client, peer, id, media, params)],
|
|
45
|
+
{ limit: 4, signal: params.abortSignal }
|
|
46
|
+
);
|
|
47
|
+
richFiles = normalized.map(
|
|
48
|
+
([id, media]) => media._ === "inputMediaDocument" ? { _: "inputRichFileDocument", id, document: media.id } : { _: "inputRichFilePhoto", id, photo: media.id }
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return input.type === "markdown" ? {
|
|
52
|
+
_: "inputRichMessageMarkdown",
|
|
53
|
+
rtl: input.rtl,
|
|
54
|
+
noautolink: input.skipEntityDetection,
|
|
55
|
+
files: richFiles,
|
|
56
|
+
markdown: input.content
|
|
57
|
+
} : {
|
|
58
|
+
_: "inputRichMessageHTML",
|
|
59
|
+
rtl: input.rtl,
|
|
60
|
+
noautolink: input.skipEntityDetection,
|
|
61
|
+
files: richFiles,
|
|
62
|
+
html: input.content
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const photos = [];
|
|
66
|
+
const documents = [];
|
|
67
|
+
const fileBlocks = [];
|
|
68
|
+
function processBlock(node) {
|
|
69
|
+
if ("file" in node) {
|
|
70
|
+
const block = processBlock(node.block);
|
|
71
|
+
fileBlocks.push({ block, media: node.file });
|
|
72
|
+
return block;
|
|
73
|
+
}
|
|
74
|
+
switch (node._) {
|
|
75
|
+
case "pageBlockCover":
|
|
76
|
+
return { ...node, cover: processBlock(node.cover) };
|
|
77
|
+
case "pageBlockCollage":
|
|
78
|
+
case "pageBlockSlideshow":
|
|
79
|
+
return { ...node, items: node.items.map(processBlock) };
|
|
80
|
+
case "pageBlockDetails":
|
|
81
|
+
case "pageBlockEmbedPost":
|
|
82
|
+
case "pageBlockBlockquoteBlocks":
|
|
83
|
+
return { ...node, blocks: node.blocks.map(processBlock) };
|
|
84
|
+
case "pageBlockList":
|
|
85
|
+
return {
|
|
86
|
+
...node,
|
|
87
|
+
items: node.items.map(
|
|
88
|
+
(item) => item._ === "pageListItemBlocks" ? {
|
|
89
|
+
...item,
|
|
90
|
+
blocks: item.blocks.map(processBlock)
|
|
91
|
+
} : item
|
|
92
|
+
)
|
|
93
|
+
};
|
|
94
|
+
case "pageBlockOrderedList":
|
|
95
|
+
return {
|
|
96
|
+
...node,
|
|
97
|
+
items: node.items.map(
|
|
98
|
+
(item) => item._ === "pageListOrderedItemBlocks" ? { ...item, blocks: item.blocks.map(processBlock) } : item
|
|
99
|
+
)
|
|
100
|
+
};
|
|
101
|
+
default:
|
|
102
|
+
return node;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const blocks = input.blocks.map(processBlock);
|
|
106
|
+
const uploaded = await utils.parallelMap(
|
|
107
|
+
fileBlocks,
|
|
108
|
+
async ({ block, media }, idx) => {
|
|
109
|
+
const uploaded2 = await _uploadRichMedia(client, peer, `block-${idx}`, media, params);
|
|
110
|
+
return { block, media: uploaded2 };
|
|
111
|
+
},
|
|
112
|
+
{ limit: 4, signal: params.abortSignal }
|
|
113
|
+
);
|
|
114
|
+
for (const { block, media } of uploaded) {
|
|
115
|
+
if (media._ === "inputMediaPhoto") {
|
|
116
|
+
const photo = media.id;
|
|
117
|
+
typeAssertions.assertTypeIs("sendRichMessage (upload)", photo, "inputPhoto");
|
|
118
|
+
photos.push(photo);
|
|
119
|
+
switch (block._) {
|
|
120
|
+
case "pageBlockPhoto":
|
|
121
|
+
block.photoId = photo.id;
|
|
122
|
+
break;
|
|
123
|
+
case "pageBlockEmbed":
|
|
124
|
+
block.posterPhotoId = photo.id;
|
|
125
|
+
break;
|
|
126
|
+
case "pageBlockEmbedPost":
|
|
127
|
+
block.authorPhotoId = photo.id;
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
throw new errors.MtArgumentError(`sendRichMessage: expected photo ${photo.id} to be used in a photo block, but got ${block._}`);
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
const document = media.id;
|
|
134
|
+
typeAssertions.assertTypeIs("sendRichMessage (upload)", document, "inputDocument");
|
|
135
|
+
documents.push(document);
|
|
136
|
+
switch (block._) {
|
|
137
|
+
case "pageBlockVideo":
|
|
138
|
+
block.videoId = document.id;
|
|
139
|
+
break;
|
|
140
|
+
case "pageBlockAudio":
|
|
141
|
+
block.audioId = document.id;
|
|
142
|
+
break;
|
|
143
|
+
default:
|
|
144
|
+
throw new errors.MtArgumentError(`sendRichMessage: expected document ${document.id} to be used in a document block, but got ${block._}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
_: "inputRichMessage",
|
|
150
|
+
rtl: input.rtl,
|
|
151
|
+
noautolink: input.skipEntityDetection,
|
|
152
|
+
blocks,
|
|
153
|
+
photos: photos.length ? photos : void 0,
|
|
154
|
+
documents: documents.length ? documents : void 0
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
exports._normalizeInputRichMessage = _normalizeInputRichMessage;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { tl } from '../../../tl/index.js';
|
|
2
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
3
|
+
import { InputRichMessage, RichMediaUploadCache } from '../../types/messages/rich/types.js';
|
|
4
|
+
interface NormalizeRichMessageParams {
|
|
5
|
+
abortSignal?: AbortSignal;
|
|
6
|
+
progressCallback?: (id: string, uploaded: number, total: number) => void;
|
|
7
|
+
uploadCache?: RichMediaUploadCache;
|
|
8
|
+
}
|
|
9
|
+
export declare function _normalizeInputRichMessage(client: ITelegramClient, peer: tl.TypeInputPeer, input: InputRichMessage, params: NormalizeRichMessageParams): Promise<tl.TypeInputRichMessage>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { tl } from '../../../tl/index.js';
|
|
2
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
3
|
+
import { InputRichMessage, RichMediaUploadCache } from '../../types/messages/rich/types.js';
|
|
4
|
+
interface NormalizeRichMessageParams {
|
|
5
|
+
abortSignal?: AbortSignal;
|
|
6
|
+
progressCallback?: (id: string, uploaded: number, total: number) => void;
|
|
7
|
+
uploadCache?: RichMediaUploadCache;
|
|
8
|
+
}
|
|
9
|
+
export declare function _normalizeInputRichMessage(client: ITelegramClient, peer: tl.TypeInputPeer, input: InputRichMessage, params: NormalizeRichMessageParams): Promise<tl.TypeInputRichMessage>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { parallelMap } from "@fuman/utils";
|
|
2
|
+
import { MtArgumentError, MtTypeAssertionError } from "../../../types/errors.js";
|
|
3
|
+
import { assertTypeIs } from "../../../utils/type-assertions.js";
|
|
4
|
+
import { _normalizeInputMedia } from "../files/normalize-input-media.js";
|
|
5
|
+
function _richMediaCacheKey(media) {
|
|
6
|
+
if (typeof media === "string") return `auto:${media}`;
|
|
7
|
+
if ("_" in media) return void 0;
|
|
8
|
+
if (typeof media.file === "string") return `${media.type}:${media.file}`;
|
|
9
|
+
return media;
|
|
10
|
+
}
|
|
11
|
+
async function _uploadRichMedia(client, peer, id, media, params) {
|
|
12
|
+
const cacheKey = params.uploadCache != null ? _richMediaCacheKey(media) : void 0;
|
|
13
|
+
if (cacheKey !== void 0) {
|
|
14
|
+
const cached = params.uploadCache.get(cacheKey);
|
|
15
|
+
if (cached != null) return cached;
|
|
16
|
+
}
|
|
17
|
+
const input = typeof media === "string" ? { type: "auto", file: media } : media;
|
|
18
|
+
const normalized = await _normalizeInputMedia(client, input, {
|
|
19
|
+
uploadPeer: peer,
|
|
20
|
+
abortSignal: params.abortSignal,
|
|
21
|
+
progressCallback: params.progressCallback?.bind(null, id)
|
|
22
|
+
}, true);
|
|
23
|
+
if (normalized._ !== "inputMediaPhoto" && normalized._ !== "inputMediaDocument") {
|
|
24
|
+
throw new MtTypeAssertionError("sendRichMessage (upload)", "inputMediaDocument | inputMediaPhoto", normalized._);
|
|
25
|
+
}
|
|
26
|
+
if (cacheKey !== void 0) params.uploadCache.set(cacheKey, normalized);
|
|
27
|
+
return normalized;
|
|
28
|
+
}
|
|
29
|
+
async function _normalizeInputRichMessage(client, peer, input, params) {
|
|
30
|
+
if ("_" in input) return input;
|
|
31
|
+
if (input.type !== "blocks") {
|
|
32
|
+
let richFiles;
|
|
33
|
+
if (input.attachments) {
|
|
34
|
+
const medias = [...Object.entries(input.attachments)];
|
|
35
|
+
const normalized = await parallelMap(
|
|
36
|
+
medias,
|
|
37
|
+
async ([id, media]) => [id, await _uploadRichMedia(client, peer, id, media, params)],
|
|
38
|
+
{ limit: 4, signal: params.abortSignal }
|
|
39
|
+
);
|
|
40
|
+
richFiles = normalized.map(
|
|
41
|
+
([id, media]) => media._ === "inputMediaDocument" ? { _: "inputRichFileDocument", id, document: media.id } : { _: "inputRichFilePhoto", id, photo: media.id }
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return input.type === "markdown" ? {
|
|
45
|
+
_: "inputRichMessageMarkdown",
|
|
46
|
+
rtl: input.rtl,
|
|
47
|
+
noautolink: input.skipEntityDetection,
|
|
48
|
+
files: richFiles,
|
|
49
|
+
markdown: input.content
|
|
50
|
+
} : {
|
|
51
|
+
_: "inputRichMessageHTML",
|
|
52
|
+
rtl: input.rtl,
|
|
53
|
+
noautolink: input.skipEntityDetection,
|
|
54
|
+
files: richFiles,
|
|
55
|
+
html: input.content
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const photos = [];
|
|
59
|
+
const documents = [];
|
|
60
|
+
const fileBlocks = [];
|
|
61
|
+
function processBlock(node) {
|
|
62
|
+
if ("file" in node) {
|
|
63
|
+
const block = processBlock(node.block);
|
|
64
|
+
fileBlocks.push({ block, media: node.file });
|
|
65
|
+
return block;
|
|
66
|
+
}
|
|
67
|
+
switch (node._) {
|
|
68
|
+
case "pageBlockCover":
|
|
69
|
+
return { ...node, cover: processBlock(node.cover) };
|
|
70
|
+
case "pageBlockCollage":
|
|
71
|
+
case "pageBlockSlideshow":
|
|
72
|
+
return { ...node, items: node.items.map(processBlock) };
|
|
73
|
+
case "pageBlockDetails":
|
|
74
|
+
case "pageBlockEmbedPost":
|
|
75
|
+
case "pageBlockBlockquoteBlocks":
|
|
76
|
+
return { ...node, blocks: node.blocks.map(processBlock) };
|
|
77
|
+
case "pageBlockList":
|
|
78
|
+
return {
|
|
79
|
+
...node,
|
|
80
|
+
items: node.items.map(
|
|
81
|
+
(item) => item._ === "pageListItemBlocks" ? {
|
|
82
|
+
...item,
|
|
83
|
+
blocks: item.blocks.map(processBlock)
|
|
84
|
+
} : item
|
|
85
|
+
)
|
|
86
|
+
};
|
|
87
|
+
case "pageBlockOrderedList":
|
|
88
|
+
return {
|
|
89
|
+
...node,
|
|
90
|
+
items: node.items.map(
|
|
91
|
+
(item) => item._ === "pageListOrderedItemBlocks" ? { ...item, blocks: item.blocks.map(processBlock) } : item
|
|
92
|
+
)
|
|
93
|
+
};
|
|
94
|
+
default:
|
|
95
|
+
return node;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const blocks = input.blocks.map(processBlock);
|
|
99
|
+
const uploaded = await parallelMap(
|
|
100
|
+
fileBlocks,
|
|
101
|
+
async ({ block, media }, idx) => {
|
|
102
|
+
const uploaded2 = await _uploadRichMedia(client, peer, `block-${idx}`, media, params);
|
|
103
|
+
return { block, media: uploaded2 };
|
|
104
|
+
},
|
|
105
|
+
{ limit: 4, signal: params.abortSignal }
|
|
106
|
+
);
|
|
107
|
+
for (const { block, media } of uploaded) {
|
|
108
|
+
if (media._ === "inputMediaPhoto") {
|
|
109
|
+
const photo = media.id;
|
|
110
|
+
assertTypeIs("sendRichMessage (upload)", photo, "inputPhoto");
|
|
111
|
+
photos.push(photo);
|
|
112
|
+
switch (block._) {
|
|
113
|
+
case "pageBlockPhoto":
|
|
114
|
+
block.photoId = photo.id;
|
|
115
|
+
break;
|
|
116
|
+
case "pageBlockEmbed":
|
|
117
|
+
block.posterPhotoId = photo.id;
|
|
118
|
+
break;
|
|
119
|
+
case "pageBlockEmbedPost":
|
|
120
|
+
block.authorPhotoId = photo.id;
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
throw new MtArgumentError(`sendRichMessage: expected photo ${photo.id} to be used in a photo block, but got ${block._}`);
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
const document = media.id;
|
|
127
|
+
assertTypeIs("sendRichMessage (upload)", document, "inputDocument");
|
|
128
|
+
documents.push(document);
|
|
129
|
+
switch (block._) {
|
|
130
|
+
case "pageBlockVideo":
|
|
131
|
+
block.videoId = document.id;
|
|
132
|
+
break;
|
|
133
|
+
case "pageBlockAudio":
|
|
134
|
+
block.audioId = document.id;
|
|
135
|
+
break;
|
|
136
|
+
default:
|
|
137
|
+
throw new MtArgumentError(`sendRichMessage: expected document ${document.id} to be used in a document block, but got ${block._}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
_: "inputRichMessage",
|
|
143
|
+
rtl: input.rtl,
|
|
144
|
+
noautolink: input.skipEntityDetection,
|
|
145
|
+
blocks,
|
|
146
|
+
photos: photos.length ? photos : void 0,
|
|
147
|
+
documents: documents.length ? documents : void 0
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
export {
|
|
151
|
+
_normalizeInputRichMessage
|
|
152
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
+
console.warn("[@mtcute/core] CommonJS bundles are deprecated. They will be removed completely in one of the upcoming releases. No support is provided for CommonJS users. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
4
|
+
console.warn("[@mtcute/core] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
5
|
+
}
|
|
6
|
+
"use strict";
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
const longUtils = require("../../../utils/long-utils.cjs");
|
|
9
|
+
const resolvePeer = require("../users/resolve-peer.cjs");
|
|
10
|
+
const findInUpdate = require("./find-in-update.cjs");
|
|
11
|
+
const normalizeRichMessage = require("./normalize-rich-message.cjs");
|
|
12
|
+
const sendCommon = require("./send-common.cjs");
|
|
13
|
+
const factories = require("../../types/bots/keyboards/factories.cjs");
|
|
14
|
+
async function sendRichMessage(client, chatId, params) {
|
|
15
|
+
const { peer, replyTo, scheduleDate, chainId, quickReplyShortcut } = await sendCommon._processCommonSendParameters(
|
|
16
|
+
client,
|
|
17
|
+
chatId,
|
|
18
|
+
params
|
|
19
|
+
);
|
|
20
|
+
const richMessage = await normalizeRichMessage._normalizeInputRichMessage(client, peer, params.content, params);
|
|
21
|
+
const randomId = params.randomId ?? longUtils.randomLong();
|
|
22
|
+
const res = await client.call(
|
|
23
|
+
{
|
|
24
|
+
_: "messages.sendMessage",
|
|
25
|
+
peer,
|
|
26
|
+
silent: params.silent,
|
|
27
|
+
replyTo,
|
|
28
|
+
randomId,
|
|
29
|
+
scheduleDate,
|
|
30
|
+
replyMarkup: factories._convertToTl(params.replyMarkup),
|
|
31
|
+
message: "",
|
|
32
|
+
clearDraft: params.clearDraft,
|
|
33
|
+
noforwards: params.forbidForwards,
|
|
34
|
+
sendAs: params.sendAs ? await resolvePeer.resolvePeer(client, params.sendAs) : void 0,
|
|
35
|
+
quickReplyShortcut,
|
|
36
|
+
effect: params.effect,
|
|
37
|
+
allowPaidFloodskip: params.allowPaidFloodskip,
|
|
38
|
+
allowPaidStars: params.allowPaidMessages,
|
|
39
|
+
richMessage
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
chainId,
|
|
43
|
+
abortSignal: params.abortSignal,
|
|
44
|
+
businessConnectionId: params.businessConnectionId
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
return findInUpdate._findMessageInUpdate(client, res, false, !params.shouldDispatch, false, randomId);
|
|
48
|
+
}
|
|
49
|
+
exports.sendRichMessage = sendRichMessage;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { default as Long } from 'long';
|
|
2
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
3
|
+
import { ReplyMarkup } from '../../types/bots/keyboards/index.js';
|
|
4
|
+
import { Message } from '../../types/messages/message.js';
|
|
5
|
+
import { InputRichMessage, RichMediaUploadCache } from '../../types/messages/rich/types.js';
|
|
6
|
+
import { InputPeerLike } from '../../types/peers/index.js';
|
|
7
|
+
import { CommonSendParams } from './send-common.js';
|
|
8
|
+
/**
|
|
9
|
+
* Send a rich message
|
|
10
|
+
*
|
|
11
|
+
* @param chatId ID of the chat, its username, phone or `"me"` or `"self"`
|
|
12
|
+
* @param params Rich message contents and additional sending parameters
|
|
13
|
+
*/
|
|
14
|
+
export declare function sendRichMessage(client: ITelegramClient, chatId: InputPeerLike, params: CommonSendParams & {
|
|
15
|
+
content: InputRichMessage;
|
|
16
|
+
/** Override the default random ID, for streaming drafts */
|
|
17
|
+
randomId?: Long;
|
|
18
|
+
/**
|
|
19
|
+
* For bots: inline or reply markup or an instruction
|
|
20
|
+
* to hide a reply keyboard or to force a reply.
|
|
21
|
+
*/
|
|
22
|
+
replyMarkup?: ReplyMarkup;
|
|
23
|
+
/**
|
|
24
|
+
* Function that will be called after some part has been uploaded.
|
|
25
|
+
*
|
|
26
|
+
* @param id ID of the file being uploaded
|
|
27
|
+
* @param uploaded Number of bytes already uploaded
|
|
28
|
+
* @param total Total file size
|
|
29
|
+
*/
|
|
30
|
+
progressCallback?: (id: string, uploaded: number, total: number) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Cache for uploaded media, used to avoid re-uploading the same media multiple times.
|
|
33
|
+
*
|
|
34
|
+
* Pass a (potentially shared) {@link RichMediaUploadCache} to reuse media uploaded
|
|
35
|
+
* by an earlier call (e.g. a streaming draft) instead of uploading it again.
|
|
36
|
+
*/
|
|
37
|
+
uploadCache?: RichMediaUploadCache;
|
|
38
|
+
}): Promise<Message>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { default as Long } from 'long';
|
|
2
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
3
|
+
import { ReplyMarkup } from '../../types/bots/keyboards/index.js';
|
|
4
|
+
import { Message } from '../../types/messages/message.js';
|
|
5
|
+
import { InputRichMessage, RichMediaUploadCache } from '../../types/messages/rich/types.js';
|
|
6
|
+
import { InputPeerLike } from '../../types/peers/index.js';
|
|
7
|
+
import { CommonSendParams } from './send-common.js';
|
|
8
|
+
/**
|
|
9
|
+
* Send a rich message
|
|
10
|
+
*
|
|
11
|
+
* @param chatId ID of the chat, its username, phone or `"me"` or `"self"`
|
|
12
|
+
* @param params Rich message contents and additional sending parameters
|
|
13
|
+
*/
|
|
14
|
+
export declare function sendRichMessage(client: ITelegramClient, chatId: InputPeerLike, params: CommonSendParams & {
|
|
15
|
+
content: InputRichMessage;
|
|
16
|
+
/** Override the default random ID, for streaming drafts */
|
|
17
|
+
randomId?: Long;
|
|
18
|
+
/**
|
|
19
|
+
* For bots: inline or reply markup or an instruction
|
|
20
|
+
* to hide a reply keyboard or to force a reply.
|
|
21
|
+
*/
|
|
22
|
+
replyMarkup?: ReplyMarkup;
|
|
23
|
+
/**
|
|
24
|
+
* Function that will be called after some part has been uploaded.
|
|
25
|
+
*
|
|
26
|
+
* @param id ID of the file being uploaded
|
|
27
|
+
* @param uploaded Number of bytes already uploaded
|
|
28
|
+
* @param total Total file size
|
|
29
|
+
*/
|
|
30
|
+
progressCallback?: (id: string, uploaded: number, total: number) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Cache for uploaded media, used to avoid re-uploading the same media multiple times.
|
|
33
|
+
*
|
|
34
|
+
* Pass a (potentially shared) {@link RichMediaUploadCache} to reuse media uploaded
|
|
35
|
+
* by an earlier call (e.g. a streaming draft) instead of uploading it again.
|
|
36
|
+
*/
|
|
37
|
+
uploadCache?: RichMediaUploadCache;
|
|
38
|
+
}): Promise<Message>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { randomLong } from "../../../utils/long-utils.js";
|
|
2
|
+
import { resolvePeer } from "../users/resolve-peer.js";
|
|
3
|
+
import { _findMessageInUpdate } from "./find-in-update.js";
|
|
4
|
+
import { _normalizeInputRichMessage } from "./normalize-rich-message.js";
|
|
5
|
+
import { _processCommonSendParameters } from "./send-common.js";
|
|
6
|
+
import { _convertToTl } from "../../types/bots/keyboards/factories.js";
|
|
7
|
+
async function sendRichMessage(client, chatId, params) {
|
|
8
|
+
const { peer, replyTo, scheduleDate, chainId, quickReplyShortcut } = await _processCommonSendParameters(
|
|
9
|
+
client,
|
|
10
|
+
chatId,
|
|
11
|
+
params
|
|
12
|
+
);
|
|
13
|
+
const richMessage = await _normalizeInputRichMessage(client, peer, params.content, params);
|
|
14
|
+
const randomId = params.randomId ?? randomLong();
|
|
15
|
+
const res = await client.call(
|
|
16
|
+
{
|
|
17
|
+
_: "messages.sendMessage",
|
|
18
|
+
peer,
|
|
19
|
+
silent: params.silent,
|
|
20
|
+
replyTo,
|
|
21
|
+
randomId,
|
|
22
|
+
scheduleDate,
|
|
23
|
+
replyMarkup: _convertToTl(params.replyMarkup),
|
|
24
|
+
message: "",
|
|
25
|
+
clearDraft: params.clearDraft,
|
|
26
|
+
noforwards: params.forbidForwards,
|
|
27
|
+
sendAs: params.sendAs ? await resolvePeer(client, params.sendAs) : void 0,
|
|
28
|
+
quickReplyShortcut,
|
|
29
|
+
effect: params.effect,
|
|
30
|
+
allowPaidFloodskip: params.allowPaidFloodskip,
|
|
31
|
+
allowPaidStars: params.allowPaidMessages,
|
|
32
|
+
richMessage
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
chainId,
|
|
36
|
+
abortSignal: params.abortSignal,
|
|
37
|
+
businessConnectionId: params.businessConnectionId
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
return _findMessageInUpdate(client, res, false, !params.shouldDispatch, false, randomId);
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
sendRichMessage
|
|
44
|
+
};
|
package/highlevel/methods.d.cts
CHANGED
|
@@ -64,6 +64,7 @@ export { getUser } from './methods/chats/get-user.js';
|
|
|
64
64
|
export { iterChatEventLog } from './methods/chats/iter-chat-event-log.js';
|
|
65
65
|
export { iterChatMembers } from './methods/chats/iter-chat-members.js';
|
|
66
66
|
export { joinChat } from './methods/chats/join-chat.js';
|
|
67
|
+
export type { JoinChatResult } from './methods/chats/join-chat.js';
|
|
67
68
|
export { kickChatMember } from './methods/chats/kick-chat-member.js';
|
|
68
69
|
export { leaveChat } from './methods/chats/leave-chat.js';
|
|
69
70
|
export { markChatUnread } from './methods/chats/mark-chat-unread.js';
|
|
@@ -72,6 +73,7 @@ export { closeChat } from './methods/chats/open-chat.js';
|
|
|
72
73
|
export { reorderUsernames } from './methods/chats/reorder-usernames.js';
|
|
73
74
|
export { restrictChatMember } from './methods/chats/restrict-chat-member.js';
|
|
74
75
|
export { saveDraft } from './methods/chats/save-draft.js';
|
|
76
|
+
export type { DraftMessageInput } from './methods/chats/save-draft.js';
|
|
75
77
|
export { setChatColor } from './methods/chats/set-chat-color.js';
|
|
76
78
|
export { setChatDefaultPermissions } from './methods/chats/set-chat-default-permissions.js';
|
|
77
79
|
export { setChatDescription } from './methods/chats/set-chat-description.js';
|
|
@@ -161,6 +163,8 @@ export { iterInviteLinks } from './methods/invite-links/iter-invite-links.js';
|
|
|
161
163
|
export { revokeInviteLink } from './methods/invite-links/revoke-invite-link.js';
|
|
162
164
|
export { appendTodoList } from './methods/messages/append-todo-list.js';
|
|
163
165
|
export { closePoll } from './methods/messages/close-poll.js';
|
|
166
|
+
export { createRichStreamingDraft } from './methods/messages/create-rich-streaming-draft.js';
|
|
167
|
+
export type { RichStreamingDraft } from './methods/messages/create-rich-streaming-draft.js';
|
|
164
168
|
export { createStreamingDraft } from './methods/messages/create-streaming-draft.js';
|
|
165
169
|
export type { StreamingDraft } from './methods/messages/create-streaming-draft.js';
|
|
166
170
|
export { deleteMessagesById } from './methods/messages/delete-messages.js';
|
|
@@ -228,6 +232,7 @@ export { sendReaction } from './methods/messages/send-reaction.js';
|
|
|
228
232
|
export { replyText } from './methods/messages/send-reply.js';
|
|
229
233
|
export { replyMedia } from './methods/messages/send-reply.js';
|
|
230
234
|
export { replyMediaGroup } from './methods/messages/send-reply.js';
|
|
235
|
+
export { sendRichMessage } from './methods/messages/send-rich-message.js';
|
|
231
236
|
export { sendScheduled } from './methods/messages/send-scheduled.js';
|
|
232
237
|
export { sendText } from './methods/messages/send-text.js';
|
|
233
238
|
export { sendTyping } from './methods/messages/send-typing.js';
|