@mtcute/core 0.29.5 → 0.29.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/client.cjs +4 -0
  2. package/client.js +4 -0
  3. package/highlevel/client.d.cts +30 -0
  4. package/highlevel/client.d.ts +30 -0
  5. package/highlevel/methods/files/normalize-input-media.cjs +21 -1
  6. package/highlevel/methods/files/normalize-input-media.js +21 -1
  7. package/highlevel/methods/messages/create-streaming-draft.cjs +57 -0
  8. package/highlevel/methods/messages/create-streaming-draft.d.cts +36 -0
  9. package/highlevel/methods/messages/create-streaming-draft.d.ts +36 -0
  10. package/highlevel/methods/messages/create-streaming-draft.js +52 -0
  11. package/highlevel/methods/messages/send-common.cjs +2 -1
  12. package/highlevel/methods/messages/send-common.d.cts +4 -0
  13. package/highlevel/methods/messages/send-common.d.ts +4 -0
  14. package/highlevel/methods/messages/send-common.js +2 -1
  15. package/highlevel/methods/messages/send-media.cjs +1 -1
  16. package/highlevel/methods/messages/send-media.d.cts +3 -0
  17. package/highlevel/methods/messages/send-media.d.ts +3 -0
  18. package/highlevel/methods/messages/send-media.js +1 -1
  19. package/highlevel/methods/messages/send-text.cjs +1 -1
  20. package/highlevel/methods/messages/send-text.d.cts +3 -0
  21. package/highlevel/methods/messages/send-text.d.ts +3 -0
  22. package/highlevel/methods/messages/send-text.js +1 -1
  23. package/highlevel/methods.d.cts +2 -0
  24. package/highlevel/methods.d.ts +2 -0
  25. package/highlevel/types/media/input-media/types.d.cts +14 -0
  26. package/highlevel/types/media/input-media/types.d.ts +14 -0
  27. package/highlevel/types/media/photo.cjs +8 -0
  28. package/highlevel/types/media/photo.d.cts +2 -0
  29. package/highlevel/types/media/photo.d.ts +2 -0
  30. package/highlevel/types/media/photo.js +8 -0
  31. package/highlevel/types/media/poll.cjs +44 -4
  32. package/highlevel/types/media/poll.d.cts +19 -1
  33. package/highlevel/types/media/poll.d.ts +19 -1
  34. package/highlevel/types/media/poll.js +44 -4
  35. package/highlevel/types/messages/message-media.cjs +6 -1
  36. package/highlevel/types/messages/message-media.js +6 -1
  37. package/highlevel/types/messages/replied-message.cjs +4 -0
  38. package/highlevel/types/messages/replied-message.d.cts +2 -0
  39. package/highlevel/types/messages/replied-message.d.ts +2 -0
  40. package/highlevel/types/messages/replied-message.js +4 -0
  41. package/highlevel/types/messages/search-filters.cjs +2 -1
  42. package/highlevel/types/messages/search-filters.d.cts +4 -0
  43. package/highlevel/types/messages/search-filters.d.ts +4 -0
  44. package/highlevel/types/messages/search-filters.js +2 -1
  45. package/methods.cjs +2 -0
  46. package/methods.js +2 -0
  47. package/network/network-manager.cjs +1 -1
  48. package/network/network-manager.js +1 -1
  49. package/package.json +1 -1
package/client.cjs CHANGED
@@ -158,6 +158,7 @@ const iterInviteLinks = require("./highlevel/methods/invite-links/iter-invite-li
158
158
  const revokeInviteLink = require("./highlevel/methods/invite-links/revoke-invite-link.cjs");
159
159
  const appendTodoList = require("./highlevel/methods/messages/append-todo-list.cjs");
160
160
  const closePoll = require("./highlevel/methods/messages/close-poll.cjs");
161
+ const createStreamingDraft = require("./highlevel/methods/messages/create-streaming-draft.cjs");
161
162
  const deleteMessages = require("./highlevel/methods/messages/delete-messages.cjs");
162
163
  const deleteScheduledMessages = require("./highlevel/methods/messages/delete-scheduled-messages.cjs");
163
164
  const editInlineMessage = require("./highlevel/methods/messages/edit-inline-message.cjs");
@@ -922,6 +923,9 @@ TelegramClient.prototype.appendTodoList = function(...args) {
922
923
  TelegramClient.prototype.closePoll = function(...args) {
923
924
  return closePoll.closePoll(this._client, ...args);
924
925
  };
926
+ TelegramClient.prototype.createStreamingDraft = function(...args) {
927
+ return createStreamingDraft.createStreamingDraft(this._client, ...args);
928
+ };
925
929
  TelegramClient.prototype.deleteMessagesById = function(...args) {
926
930
  return deleteMessages.deleteMessagesById(this._client, ...args);
927
931
  };
package/client.js CHANGED
@@ -151,6 +151,7 @@ import { iterInviteLinks } from "./highlevel/methods/invite-links/iter-invite-li
151
151
  import { revokeInviteLink } from "./highlevel/methods/invite-links/revoke-invite-link.js";
152
152
  import { appendTodoList } from "./highlevel/methods/messages/append-todo-list.js";
153
153
  import { closePoll } from "./highlevel/methods/messages/close-poll.js";
154
+ import { createStreamingDraft } from "./highlevel/methods/messages/create-streaming-draft.js";
154
155
  import { deleteMessagesById, deleteMessages } from "./highlevel/methods/messages/delete-messages.js";
155
156
  import { deleteScheduledMessages } from "./highlevel/methods/messages/delete-scheduled-messages.js";
156
157
  import { editInlineMessage } from "./highlevel/methods/messages/edit-inline-message.js";
@@ -915,6 +916,9 @@ TelegramClient.prototype.appendTodoList = function(...args) {
915
916
  TelegramClient.prototype.closePoll = function(...args) {
916
917
  return closePoll(this._client, ...args);
917
918
  };
919
+ TelegramClient.prototype.createStreamingDraft = function(...args) {
920
+ return createStreamingDraft(this._client, ...args);
921
+ };
918
922
  TelegramClient.prototype.deleteMessagesById = function(...args) {
919
923
  return deleteMessagesById(this._client, ...args);
920
924
  };
@@ -10,6 +10,7 @@ import { GetForumTopicsOffset, getForumTopics } from './methods/forums/get-forum
10
10
  import { InputStarGiftAttributeIds, ResaleStarGiftsMeta } from './methods/gifts/get-resale-star-gifts.js';
11
11
  import { StarGiftUpgradeOptions } from './methods/gifts/get-star-gift-upgrade-options.js';
12
12
  import { GetInviteLinksOffset, getInviteLinks } from './methods/invite-links/get-invite-links.js';
13
+ import { StreamingDraft } from './methods/messages/create-streaming-draft.js';
13
14
  import { DeleteMessagesParams } from './methods/messages/delete-messages.js';
14
15
  import { ForwardMessageOptions } from './methods/messages/forward-messages.js';
15
16
  import { GetHistoryOffset, getHistory } from './methods/messages/get-history.js';
@@ -3077,6 +3078,31 @@ export interface TelegramClient extends ITelegramClient {
3077
3078
  */
3078
3079
  shouldDispatch?: true;
3079
3080
  }): Promise<Poll>;
3081
+ /**
3082
+ * Create a streaming text message draft
3083
+ *
3084
+ * **Available**: 👤 users only
3085
+ *
3086
+ * @param chatId Chat ID
3087
+ * @param params
3088
+ */
3089
+ createStreamingDraft(chatId: InputPeerLike, params?: {
3090
+ /**
3091
+ * Unique identifier of the business connection on behalf of which the action will be sent
3092
+ */
3093
+ businessConnectionId?: string;
3094
+ /**
3095
+ * For comment threads, ID of the thread (i.e. top message)
3096
+ */
3097
+ threadId?: number;
3098
+ /**
3099
+ * Mode of the draft's `send` method
3100
+ *
3101
+ * - `append` - appends the text to the previous draft
3102
+ * - `replace` - replaces the previous draft with the new one
3103
+ */
3104
+ mode?: 'append' | 'replace';
3105
+ }): Promise<StreamingDraft>;
3080
3106
  /**
3081
3107
  * Delete messages by their IDs
3082
3108
  *
@@ -3949,6 +3975,8 @@ export interface TelegramClient extends ITelegramClient {
3949
3975
  * @link InputMedia
3950
3976
  */
3951
3977
  sendMedia(chatId: InputPeerLike, media: InputMediaLike | string, params?: CommonSendParams & {
3978
+ /** Override the default random ID, for streaming drafts */
3979
+ randomId?: Long;
3952
3980
  /**
3953
3981
  * For bots: inline or reply markup or an instruction
3954
3982
  * to hide a reply keyboard or to force a reply.
@@ -4072,6 +4100,8 @@ export interface TelegramClient extends ITelegramClient {
4072
4100
  * @param params Additional sending parameters
4073
4101
  */
4074
4102
  sendText(chatId: InputPeerLike, text: InputText, params?: CommonSendParams & {
4103
+ /** Override the default random ID, for streaming drafts */
4104
+ randomId?: Long;
4075
4105
  /**
4076
4106
  * For bots: inline or reply markup or an instruction
4077
4107
  * to hide a reply keyboard or to force a reply.
@@ -10,6 +10,7 @@ import { GetForumTopicsOffset, getForumTopics } from './methods/forums/get-forum
10
10
  import { InputStarGiftAttributeIds, ResaleStarGiftsMeta } from './methods/gifts/get-resale-star-gifts.js';
11
11
  import { StarGiftUpgradeOptions } from './methods/gifts/get-star-gift-upgrade-options.js';
12
12
  import { GetInviteLinksOffset, getInviteLinks } from './methods/invite-links/get-invite-links.js';
13
+ import { StreamingDraft } from './methods/messages/create-streaming-draft.js';
13
14
  import { DeleteMessagesParams } from './methods/messages/delete-messages.js';
14
15
  import { ForwardMessageOptions } from './methods/messages/forward-messages.js';
15
16
  import { GetHistoryOffset, getHistory } from './methods/messages/get-history.js';
@@ -3077,6 +3078,31 @@ export interface TelegramClient extends ITelegramClient {
3077
3078
  */
3078
3079
  shouldDispatch?: true;
3079
3080
  }): Promise<Poll>;
3081
+ /**
3082
+ * Create a streaming text message draft
3083
+ *
3084
+ * **Available**: 👤 users only
3085
+ *
3086
+ * @param chatId Chat ID
3087
+ * @param params
3088
+ */
3089
+ createStreamingDraft(chatId: InputPeerLike, params?: {
3090
+ /**
3091
+ * Unique identifier of the business connection on behalf of which the action will be sent
3092
+ */
3093
+ businessConnectionId?: string;
3094
+ /**
3095
+ * For comment threads, ID of the thread (i.e. top message)
3096
+ */
3097
+ threadId?: number;
3098
+ /**
3099
+ * Mode of the draft's `send` method
3100
+ *
3101
+ * - `append` - appends the text to the previous draft
3102
+ * - `replace` - replaces the previous draft with the new one
3103
+ */
3104
+ mode?: 'append' | 'replace';
3105
+ }): Promise<StreamingDraft>;
3080
3106
  /**
3081
3107
  * Delete messages by their IDs
3082
3108
  *
@@ -3949,6 +3975,8 @@ export interface TelegramClient extends ITelegramClient {
3949
3975
  * @link InputMedia
3950
3976
  */
3951
3977
  sendMedia(chatId: InputPeerLike, media: InputMediaLike | string, params?: CommonSendParams & {
3978
+ /** Override the default random ID, for streaming drafts */
3979
+ randomId?: Long;
3952
3980
  /**
3953
3981
  * For bots: inline or reply markup or an instruction
3954
3982
  * to hide a reply keyboard or to force a reply.
@@ -4072,6 +4100,8 @@ export interface TelegramClient extends ITelegramClient {
4072
4100
  * @param params Additional sending parameters
4073
4101
  */
4074
4102
  sendText(chatId: InputPeerLike, text: InputText, params?: CommonSendParams & {
4103
+ /** Override the default random ID, for streaming drafts */
4104
+ randomId?: Long;
4075
4105
  /**
4076
4106
  * For bots: inline or reply markup or an instruction
4077
4107
  * to hide a reply keyboard or to force a reply.
@@ -135,6 +135,10 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
135
135
  let correct;
136
136
  let solution;
137
137
  let solutionEntities;
138
+ const [attachedMedia, solutionMedia] = await Promise.all([
139
+ media.attachedMedia ? _normalizeInputMedia(client, media.attachedMedia, params, true) : void 0,
140
+ media.type === "quiz" && media.solutionMedia ? _normalizeInputMedia(client, media.solutionMedia, params, true) : void 0
141
+ ]);
138
142
  if (media.type === "quiz") {
139
143
  let input2 = media.correct;
140
144
  if (!Array.isArray(input2)) input2 = [input2];
@@ -145,6 +149,8 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
145
149
  }
146
150
  return {
147
151
  _: "inputMediaPoll",
152
+ attachedMedia,
153
+ solutionMedia,
148
154
  poll: {
149
155
  _: "poll",
150
156
  closed: media.closed,
@@ -156,6 +162,10 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
156
162
  answers,
157
163
  closePeriod: media.closePeriod,
158
164
  closeDate: miscUtils.normalizeDate(media.closeDate),
165
+ openAnswers: media.openAnswers,
166
+ revotingDisabled: media.disableRevoting,
167
+ shuffleAnswers: media.shuffleAnswers,
168
+ hideResultsUntilClose: media.hideResultsUntilClose,
159
169
  hash: Long.ZERO
160
170
  },
161
171
  correctAnswers: correct,
@@ -238,6 +248,12 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
238
248
  typeAssertions.assertTypeIs("uploadMediaIfNeeded", inputMedia, "inputMediaPhoto");
239
249
  videoCover = inputMedia.id;
240
250
  }
251
+ let livePhotoVideo;
252
+ if (media.type === "photo" && media.livePhotoVideo) {
253
+ const inputMedia = await _normalizeInputMedia(client, media.livePhotoVideo, params, true);
254
+ typeAssertions.assertTypeIs("uploadMediaIfNeeded", inputMedia, "inputMediaDocument");
255
+ livePhotoVideo = inputMedia.id;
256
+ }
241
257
  const uploadPeer = params.uploadPeer ?? { _: "inputPeerSelf" };
242
258
  const uploadMediaIfNeeded = async (inputMedia, photo) => {
243
259
  if (!uploadMedia) return inputMedia;
@@ -259,7 +275,9 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
259
275
  fileReference: res.photo.fileReference
260
276
  },
261
277
  ttlSeconds: media.ttlSeconds,
262
- spoiler: media.type === "video" && media.spoiler
278
+ spoiler: media.type === "video" && media.spoiler,
279
+ livePhoto: Boolean(livePhotoVideo),
280
+ video: livePhotoVideo
263
281
  };
264
282
  }
265
283
  typeAssertions.assertTypeIs("normalizeInputMedia (@ messages.uploadMedia)", res, "messageMediaDocument");
@@ -336,6 +354,8 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
336
354
  {
337
355
  _: "inputMediaUploadedPhoto",
338
356
  file: inputFile,
357
+ livePhoto: Boolean(livePhotoVideo),
358
+ video: livePhotoVideo,
339
359
  ttlSeconds: media.ttlSeconds,
340
360
  spoiler: media.spoiler
341
361
  },
@@ -128,6 +128,10 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
128
128
  let correct;
129
129
  let solution;
130
130
  let solutionEntities;
131
+ const [attachedMedia, solutionMedia] = await Promise.all([
132
+ media.attachedMedia ? _normalizeInputMedia(client, media.attachedMedia, params, true) : void 0,
133
+ media.type === "quiz" && media.solutionMedia ? _normalizeInputMedia(client, media.solutionMedia, params, true) : void 0
134
+ ]);
131
135
  if (media.type === "quiz") {
132
136
  let input2 = media.correct;
133
137
  if (!Array.isArray(input2)) input2 = [input2];
@@ -138,6 +142,8 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
138
142
  }
139
143
  return {
140
144
  _: "inputMediaPoll",
145
+ attachedMedia,
146
+ solutionMedia,
141
147
  poll: {
142
148
  _: "poll",
143
149
  closed: media.closed,
@@ -149,6 +155,10 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
149
155
  answers,
150
156
  closePeriod: media.closePeriod,
151
157
  closeDate: normalizeDate(media.closeDate),
158
+ openAnswers: media.openAnswers,
159
+ revotingDisabled: media.disableRevoting,
160
+ shuffleAnswers: media.shuffleAnswers,
161
+ hideResultsUntilClose: media.hideResultsUntilClose,
152
162
  hash: Long.ZERO
153
163
  },
154
164
  correctAnswers: correct,
@@ -231,6 +241,12 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
231
241
  assertTypeIs("uploadMediaIfNeeded", inputMedia, "inputMediaPhoto");
232
242
  videoCover = inputMedia.id;
233
243
  }
244
+ let livePhotoVideo;
245
+ if (media.type === "photo" && media.livePhotoVideo) {
246
+ const inputMedia = await _normalizeInputMedia(client, media.livePhotoVideo, params, true);
247
+ assertTypeIs("uploadMediaIfNeeded", inputMedia, "inputMediaDocument");
248
+ livePhotoVideo = inputMedia.id;
249
+ }
234
250
  const uploadPeer = params.uploadPeer ?? { _: "inputPeerSelf" };
235
251
  const uploadMediaIfNeeded = async (inputMedia, photo) => {
236
252
  if (!uploadMedia) return inputMedia;
@@ -252,7 +268,9 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
252
268
  fileReference: res.photo.fileReference
253
269
  },
254
270
  ttlSeconds: media.ttlSeconds,
255
- spoiler: media.type === "video" && media.spoiler
271
+ spoiler: media.type === "video" && media.spoiler,
272
+ livePhoto: Boolean(livePhotoVideo),
273
+ video: livePhotoVideo
256
274
  };
257
275
  }
258
276
  assertTypeIs("normalizeInputMedia (@ messages.uploadMedia)", res, "messageMediaDocument");
@@ -329,6 +347,8 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
329
347
  {
330
348
  _: "inputMediaUploadedPhoto",
331
349
  file: inputFile,
350
+ livePhoto: Boolean(livePhotoVideo),
351
+ video: livePhotoVideo,
332
352
  ttlSeconds: media.ttlSeconds,
333
353
  spoiler: media.spoiler
334
354
  },
@@ -0,0 +1,57 @@
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 typeAssertions = require("../../../utils/type-assertions.cjs");
10
+ const entities = require("../../utils/entities.cjs");
11
+ const normalizeText = require("../misc/normalize-text.cjs");
12
+ const resolvePeer = require("../users/resolve-peer.cjs");
13
+ async function createStreamingDraft(client, chatId, params) {
14
+ const {
15
+ mode = "replace",
16
+ threadId,
17
+ businessConnectionId
18
+ } = params ?? {};
19
+ const randomId = longUtils.randomLong();
20
+ const peer = await resolvePeer.resolvePeer(client, chatId);
21
+ let previousText;
22
+ const sendDraft = async (text) => {
23
+ if (typeof text === "string") {
24
+ text = { text };
25
+ }
26
+ if (mode === "append" && previousText) {
27
+ text = entities.joinTextWithEntities([previousText, text]);
28
+ }
29
+ previousText = text;
30
+ const [_text, entities$1 = []] = await normalizeText._normalizeInputText(client, text);
31
+ const r = await client.call({
32
+ _: "messages.setTyping",
33
+ peer,
34
+ action: {
35
+ _: "sendMessageTextDraftAction",
36
+ text: {
37
+ _: "textWithEntities",
38
+ text: _text,
39
+ entities: entities$1
40
+ },
41
+ randomId
42
+ },
43
+ topMsgId: threadId
44
+ }, {
45
+ businessConnectionId
46
+ });
47
+ typeAssertions.assertTrue("messages.setTyping", r);
48
+ };
49
+ return {
50
+ randomId,
51
+ send: sendDraft,
52
+ get finalText() {
53
+ return previousText ?? { text: "", entities: [] };
54
+ }
55
+ };
56
+ }
57
+ exports.createStreamingDraft = createStreamingDraft;
@@ -0,0 +1,36 @@
1
+ import { default as Long } from 'long';
2
+ import { ITelegramClient } from '../../client.types.js';
3
+ import { InputPeerLike, InputText, TextWithEntities } from '../../types/index.js';
4
+ export interface StreamingDraft {
5
+ /** Random ID of the draft */
6
+ readonly randomId: Long;
7
+ /** Depending on the `mode`, this method will either append or replace the draft */
8
+ send(text: InputText): Promise<void>;
9
+ /** Final text of the draft, for convenience */
10
+ get finalText(): TextWithEntities;
11
+ }
12
+ /**
13
+ * Create a streaming text message draft
14
+ *
15
+ * @param chatId Chat ID
16
+ * @param params
17
+ */
18
+ export declare function createStreamingDraft(client: ITelegramClient, chatId: InputPeerLike, params?: {
19
+ /**
20
+ * Unique identifier of the business connection on behalf of which the action will be sent
21
+ */
22
+ businessConnectionId?: string;
23
+ /**
24
+ * For comment threads, ID of the thread (i.e. top message)
25
+ */
26
+ threadId?: number;
27
+ /**
28
+ * Mode of the draft's `send` method
29
+ *
30
+ * - `append` - appends the text to the previous draft
31
+ * - `replace` - replaces the previous draft with the new one
32
+ *
33
+ * @default `replace`
34
+ */
35
+ mode?: 'append' | 'replace';
36
+ }): Promise<StreamingDraft>;
@@ -0,0 +1,36 @@
1
+ import { default as Long } from 'long';
2
+ import { ITelegramClient } from '../../client.types.js';
3
+ import { InputPeerLike, InputText, TextWithEntities } from '../../types/index.js';
4
+ export interface StreamingDraft {
5
+ /** Random ID of the draft */
6
+ readonly randomId: Long;
7
+ /** Depending on the `mode`, this method will either append or replace the draft */
8
+ send(text: InputText): Promise<void>;
9
+ /** Final text of the draft, for convenience */
10
+ get finalText(): TextWithEntities;
11
+ }
12
+ /**
13
+ * Create a streaming text message draft
14
+ *
15
+ * @param chatId Chat ID
16
+ * @param params
17
+ */
18
+ export declare function createStreamingDraft(client: ITelegramClient, chatId: InputPeerLike, params?: {
19
+ /**
20
+ * Unique identifier of the business connection on behalf of which the action will be sent
21
+ */
22
+ businessConnectionId?: string;
23
+ /**
24
+ * For comment threads, ID of the thread (i.e. top message)
25
+ */
26
+ threadId?: number;
27
+ /**
28
+ * Mode of the draft's `send` method
29
+ *
30
+ * - `append` - appends the text to the previous draft
31
+ * - `replace` - replaces the previous draft with the new one
32
+ *
33
+ * @default `replace`
34
+ */
35
+ mode?: 'append' | 'replace';
36
+ }): Promise<StreamingDraft>;
@@ -0,0 +1,52 @@
1
+ import { randomLong } from "../../../utils/long-utils.js";
2
+ import { assertTrue } from "../../../utils/type-assertions.js";
3
+ import { joinTextWithEntities } from "../../utils/entities.js";
4
+ import { _normalizeInputText } from "../misc/normalize-text.js";
5
+ import { resolvePeer } from "../users/resolve-peer.js";
6
+ async function createStreamingDraft(client, chatId, params) {
7
+ const {
8
+ mode = "replace",
9
+ threadId,
10
+ businessConnectionId
11
+ } = params ?? {};
12
+ const randomId = randomLong();
13
+ const peer = await resolvePeer(client, chatId);
14
+ let previousText;
15
+ const sendDraft = async (text) => {
16
+ if (typeof text === "string") {
17
+ text = { text };
18
+ }
19
+ if (mode === "append" && previousText) {
20
+ text = joinTextWithEntities([previousText, text]);
21
+ }
22
+ previousText = text;
23
+ const [_text, entities = []] = await _normalizeInputText(client, text);
24
+ const r = await client.call({
25
+ _: "messages.setTyping",
26
+ peer,
27
+ action: {
28
+ _: "sendMessageTextDraftAction",
29
+ text: {
30
+ _: "textWithEntities",
31
+ text: _text,
32
+ entities
33
+ },
34
+ randomId
35
+ },
36
+ topMsgId: threadId
37
+ }, {
38
+ businessConnectionId
39
+ });
40
+ assertTrue("messages.setTyping", r);
41
+ };
42
+ return {
43
+ randomId,
44
+ send: sendDraft,
45
+ get finalText() {
46
+ return previousText ?? { text: "", entities: [] };
47
+ }
48
+ };
49
+ }
50
+ export {
51
+ createStreamingDraft
52
+ };
@@ -57,7 +57,8 @@ async function _processCommonSendParameters(client, chatId, params) {
57
57
  quoteEntities: params.quote?.entities,
58
58
  quoteOffset: params.quoteOffset,
59
59
  monoforumPeerId: params.toMonoforumPeer ? await resolvePeer.resolvePeer(client, params.toMonoforumPeer) : void 0,
60
- todoItemId: params.replyToTodoItem
60
+ todoItemId: params.replyToTodoItem,
61
+ pollOption: params.replyToPollOption
61
62
  };
62
63
  } else if (params.toMonoforumPeer) {
63
64
  tlReplyTo = {
@@ -16,6 +16,10 @@ export interface CommonSendParams {
16
16
  * If this is a reply to a specific todo item, ID of that item
17
17
  */
18
18
  replyToTodoItem?: number;
19
+ /**
20
+ * If this is a reply to a specific poll option, ID of that option
21
+ */
22
+ replyToPollOption?: Uint8Array;
19
23
  /**
20
24
  * When the chat is a monoforum you are an admin of, you **must** pass an
21
25
  * ID of a peer you are sending the message to.
@@ -16,6 +16,10 @@ export interface CommonSendParams {
16
16
  * If this is a reply to a specific todo item, ID of that item
17
17
  */
18
18
  replyToTodoItem?: number;
19
+ /**
20
+ * If this is a reply to a specific poll option, ID of that option
21
+ */
22
+ replyToPollOption?: Uint8Array;
19
23
  /**
20
24
  * When the chat is a monoforum you are an admin of, you **must** pass an
21
25
  * ID of a peer you are sending the message to.
@@ -50,7 +50,8 @@ async function _processCommonSendParameters(client, chatId, params) {
50
50
  quoteEntities: params.quote?.entities,
51
51
  quoteOffset: params.quoteOffset,
52
52
  monoforumPeerId: params.toMonoforumPeer ? await resolvePeer(client, params.toMonoforumPeer) : void 0,
53
- todoItemId: params.replyToTodoItem
53
+ todoItemId: params.replyToTodoItem,
54
+ pollOption: params.replyToPollOption
54
55
  };
55
56
  } else if (params.toMonoforumPeer) {
56
57
  tlReplyTo = {
@@ -37,7 +37,7 @@ async function sendMedia(client, chatId, media, params) {
37
37
  params.caption || media.caption
38
38
  );
39
39
  const replyMarkup = factories._convertToTl(params.replyMarkup);
40
- const randomId = longUtils.randomLong();
40
+ const randomId = params.randomId ?? longUtils.randomLong();
41
41
  const res = await client.call(
42
42
  {
43
43
  _: "messages.sendMedia",
@@ -1,3 +1,4 @@
1
+ import { default as Long } from 'long';
1
2
  import { ITelegramClient } from '../../client.types.js';
2
3
  import { ReplyMarkup } from '../../types/bots/keyboards/index.js';
3
4
  import { InputMediaLike } from '../../types/media/input-media/types.js';
@@ -17,6 +18,8 @@ import { CommonSendParams } from './send-common.js';
17
18
  * @link InputMedia
18
19
  */
19
20
  export declare function sendMedia(client: ITelegramClient, chatId: InputPeerLike, media: InputMediaLike | string, params?: CommonSendParams & {
21
+ /** Override the default random ID, for streaming drafts */
22
+ randomId?: Long;
20
23
  /**
21
24
  * For bots: inline or reply markup or an instruction
22
25
  * to hide a reply keyboard or to force a reply.
@@ -1,3 +1,4 @@
1
+ import { default as Long } from 'long';
1
2
  import { ITelegramClient } from '../../client.types.js';
2
3
  import { ReplyMarkup } from '../../types/bots/keyboards/index.js';
3
4
  import { InputMediaLike } from '../../types/media/input-media/types.js';
@@ -17,6 +18,8 @@ import { CommonSendParams } from './send-common.js';
17
18
  * @link InputMedia
18
19
  */
19
20
  export declare function sendMedia(client: ITelegramClient, chatId: InputPeerLike, media: InputMediaLike | string, params?: CommonSendParams & {
21
+ /** Override the default random ID, for streaming drafts */
22
+ randomId?: Long;
20
23
  /**
21
24
  * For bots: inline or reply markup or an instruction
22
25
  * to hide a reply keyboard or to force a reply.
@@ -30,7 +30,7 @@ async function sendMedia(client, chatId, media, params) {
30
30
  params.caption || media.caption
31
31
  );
32
32
  const replyMarkup = _convertToTl(params.replyMarkup);
33
- const randomId = randomLong();
33
+ const randomId = params.randomId ?? randomLong();
34
34
  const res = await client.call(
35
35
  {
36
36
  _: "messages.sendMedia",
@@ -27,7 +27,7 @@ async function sendText(client, chatId, text, params) {
27
27
  chatId,
28
28
  params
29
29
  );
30
- const randomId = longUtils.randomLong();
30
+ const randomId = params.randomId ?? longUtils.randomLong();
31
31
  const res = await client.call(
32
32
  {
33
33
  _: "messages.sendMessage",
@@ -1,3 +1,4 @@
1
+ import { default as Long } from 'long';
1
2
  import { ITelegramClient } from '../../client.types.js';
2
3
  import { ReplyMarkup } from '../../types/bots/keyboards/index.js';
3
4
  import { InputText } from '../../types/misc/entities.js';
@@ -12,6 +13,8 @@ import { Message } from '../../types/messages/message.js';
12
13
  * @param params Additional sending parameters
13
14
  */
14
15
  export declare function sendText(client: ITelegramClient, chatId: InputPeerLike, text: InputText, params?: CommonSendParams & {
16
+ /** Override the default random ID, for streaming drafts */
17
+ randomId?: Long;
15
18
  /**
16
19
  * For bots: inline or reply markup or an instruction
17
20
  * to hide a reply keyboard or to force a reply.
@@ -1,3 +1,4 @@
1
+ import { default as Long } from 'long';
1
2
  import { ITelegramClient } from '../../client.types.js';
2
3
  import { ReplyMarkup } from '../../types/bots/keyboards/index.js';
3
4
  import { InputText } from '../../types/misc/entities.js';
@@ -12,6 +13,8 @@ import { Message } from '../../types/messages/message.js';
12
13
  * @param params Additional sending parameters
13
14
  */
14
15
  export declare function sendText(client: ITelegramClient, chatId: InputPeerLike, text: InputText, params?: CommonSendParams & {
16
+ /** Override the default random ID, for streaming drafts */
17
+ randomId?: Long;
15
18
  /**
16
19
  * For bots: inline or reply markup or an instruction
17
20
  * to hide a reply keyboard or to force a reply.
@@ -20,7 +20,7 @@ async function sendText(client, chatId, text, params) {
20
20
  chatId,
21
21
  params
22
22
  );
23
- const randomId = randomLong();
23
+ const randomId = params.randomId ?? randomLong();
24
24
  const res = await client.call(
25
25
  {
26
26
  _: "messages.sendMessage",
@@ -160,6 +160,8 @@ export { iterInviteLinks } from './methods/invite-links/iter-invite-links.js';
160
160
  export { revokeInviteLink } from './methods/invite-links/revoke-invite-link.js';
161
161
  export { appendTodoList } from './methods/messages/append-todo-list.js';
162
162
  export { closePoll } from './methods/messages/close-poll.js';
163
+ export { createStreamingDraft } from './methods/messages/create-streaming-draft.js';
164
+ export type { StreamingDraft } from './methods/messages/create-streaming-draft.js';
163
165
  export { deleteMessagesById } from './methods/messages/delete-messages.js';
164
166
  export { deleteMessages } from './methods/messages/delete-messages.js';
165
167
  export type { DeleteMessagesParams } from './methods/messages/delete-messages.js';
@@ -160,6 +160,8 @@ export { iterInviteLinks } from './methods/invite-links/iter-invite-links.js';
160
160
  export { revokeInviteLink } from './methods/invite-links/revoke-invite-link.js';
161
161
  export { appendTodoList } from './methods/messages/append-todo-list.js';
162
162
  export { closePoll } from './methods/messages/close-poll.js';
163
+ export { createStreamingDraft } from './methods/messages/create-streaming-draft.js';
164
+ export type { StreamingDraft } from './methods/messages/create-streaming-draft.js';
163
165
  export { deleteMessagesById } from './methods/messages/delete-messages.js';
164
166
  export { deleteMessages } from './methods/messages/delete-messages.js';
165
167
  export type { DeleteMessagesParams } from './methods/messages/delete-messages.js';