@mtcute/core 0.29.4 → 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 (102) hide show
  1. package/client.cjs +4 -0
  2. package/client.js +4 -0
  3. package/highlevel/base.cjs +0 -1
  4. package/highlevel/base.js +0 -1
  5. package/highlevel/client.d.cts +30 -0
  6. package/highlevel/client.d.ts +30 -0
  7. package/highlevel/methods/chats/get-creator-after-leave.cjs +4 -14
  8. package/highlevel/methods/chats/get-creator-after-leave.js +5 -15
  9. package/highlevel/methods/files/normalize-input-media.cjs +37 -15
  10. package/highlevel/methods/files/normalize-input-media.js +37 -15
  11. package/highlevel/methods/messages/close-poll.cjs +2 -1
  12. package/highlevel/methods/messages/close-poll.js +2 -1
  13. package/highlevel/methods/messages/create-streaming-draft.cjs +57 -0
  14. package/highlevel/methods/messages/create-streaming-draft.d.cts +36 -0
  15. package/highlevel/methods/messages/create-streaming-draft.d.ts +36 -0
  16. package/highlevel/methods/messages/create-streaming-draft.js +52 -0
  17. package/highlevel/methods/messages/send-common.cjs +2 -1
  18. package/highlevel/methods/messages/send-common.d.cts +4 -0
  19. package/highlevel/methods/messages/send-common.d.ts +4 -0
  20. package/highlevel/methods/messages/send-common.js +2 -1
  21. package/highlevel/methods/messages/send-media.cjs +1 -1
  22. package/highlevel/methods/messages/send-media.d.cts +3 -0
  23. package/highlevel/methods/messages/send-media.d.ts +3 -0
  24. package/highlevel/methods/messages/send-media.js +1 -1
  25. package/highlevel/methods/messages/send-text.cjs +1 -1
  26. package/highlevel/methods/messages/send-text.d.cts +3 -0
  27. package/highlevel/methods/messages/send-text.d.ts +3 -0
  28. package/highlevel/methods/messages/send-text.js +1 -1
  29. package/highlevel/methods/messages/send-vote.cjs +3 -1
  30. package/highlevel/methods/messages/send-vote.js +4 -2
  31. package/highlevel/methods.d.cts +2 -0
  32. package/highlevel/methods.d.ts +2 -0
  33. package/highlevel/storage/service/peers.cjs +1 -0
  34. package/highlevel/storage/service/peers.js +1 -0
  35. package/highlevel/types/media/input-media/types.d.cts +23 -12
  36. package/highlevel/types/media/input-media/types.d.ts +23 -12
  37. package/highlevel/types/media/photo.cjs +8 -0
  38. package/highlevel/types/media/photo.d.cts +2 -0
  39. package/highlevel/types/media/photo.d.ts +2 -0
  40. package/highlevel/types/media/photo.js +8 -0
  41. package/highlevel/types/media/poll.cjs +48 -5
  42. package/highlevel/types/media/poll.d.cts +21 -3
  43. package/highlevel/types/media/poll.d.ts +21 -3
  44. package/highlevel/types/media/poll.js +48 -5
  45. package/highlevel/types/messages/dialog.cjs +4 -0
  46. package/highlevel/types/messages/dialog.d.cts +2 -0
  47. package/highlevel/types/messages/dialog.d.ts +2 -0
  48. package/highlevel/types/messages/dialog.js +4 -0
  49. package/highlevel/types/messages/message-action.cjs +18 -0
  50. package/highlevel/types/messages/message-action.d.cts +19 -1
  51. package/highlevel/types/messages/message-action.d.ts +19 -1
  52. package/highlevel/types/messages/message-action.js +18 -0
  53. package/highlevel/types/messages/message-media.cjs +6 -1
  54. package/highlevel/types/messages/message-media.js +6 -1
  55. package/highlevel/types/messages/replied-message.cjs +4 -0
  56. package/highlevel/types/messages/replied-message.d.cts +2 -0
  57. package/highlevel/types/messages/replied-message.d.ts +2 -0
  58. package/highlevel/types/messages/replied-message.js +4 -0
  59. package/highlevel/types/messages/search-filters.cjs +2 -1
  60. package/highlevel/types/messages/search-filters.d.cts +4 -0
  61. package/highlevel/types/messages/search-filters.d.ts +4 -0
  62. package/highlevel/types/messages/search-filters.js +2 -1
  63. package/highlevel/types/peers/forum-topic.cjs +4 -0
  64. package/highlevel/types/peers/forum-topic.d.cts +2 -0
  65. package/highlevel/types/peers/forum-topic.d.ts +2 -0
  66. package/highlevel/types/peers/forum-topic.js +4 -0
  67. package/highlevel/types/peers/full-user.cjs +8 -0
  68. package/highlevel/types/peers/full-user.d.cts +4 -0
  69. package/highlevel/types/peers/full-user.d.ts +4 -0
  70. package/highlevel/types/peers/full-user.js +8 -0
  71. package/highlevel/types/peers/user.cjs +4 -0
  72. package/highlevel/types/peers/user.d.cts +2 -0
  73. package/highlevel/types/peers/user.d.ts +2 -0
  74. package/highlevel/types/peers/user.js +4 -0
  75. package/highlevel/types/updates/poll-update.cjs +8 -2
  76. package/highlevel/types/updates/poll-update.js +8 -2
  77. package/highlevel/updates/manager.cjs +7 -0
  78. package/highlevel/updates/manager.js +7 -0
  79. package/highlevel/worker/worker.cjs +6 -1
  80. package/highlevel/worker/worker.d.cts +2 -1
  81. package/highlevel/worker/worker.d.ts +2 -1
  82. package/highlevel/worker/worker.js +6 -1
  83. package/methods.cjs +2 -0
  84. package/methods.js +2 -0
  85. package/network/middlewares/flood-waiter.cjs +2 -1
  86. package/network/middlewares/flood-waiter.js +2 -1
  87. package/network/network-manager.cjs +1 -1
  88. package/network/network-manager.js +1 -1
  89. package/package.json +1 -1
  90. package/tl/api-schema.json +1 -1
  91. package/tl/binary/reader.cjs +86 -39
  92. package/tl/binary/reader.js +86 -39
  93. package/tl/binary/writer.cjs +308 -32
  94. package/tl/binary/writer.js +308 -32
  95. package/tl/compat/reader.cjs +34 -0
  96. package/tl/compat/reader.js +34 -0
  97. package/tl/index.d.cts +295 -25
  98. package/tl/index.d.ts +295 -25
  99. package/tl/inner-tl.cjs +16 -8
  100. package/tl/inner-tl.js +16 -8
  101. package/utils/binary/compat.cjs +41 -0
  102. package/utils/binary/compat.js +41 -0
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
  };
@@ -44,7 +44,6 @@ class BaseTelegramClient {
44
44
  });
45
45
  if (!params.disableUpdates && params.updates !== false) {
46
46
  this.updates = new manager.UpdatesManager(this, params.updates);
47
- this.onServerUpdate.add(this.updates.handleUpdate.bind(this.updates));
48
47
  this.updates.onCatchingUp((catchingUp) => {
49
48
  this.onConnectionState.emit(catchingUp ? "updating" : "connected");
50
49
  });
package/highlevel/base.js CHANGED
@@ -37,7 +37,6 @@ class BaseTelegramClient {
37
37
  });
38
38
  if (!params.disableUpdates && params.updates !== false) {
39
39
  this.updates = new UpdatesManager(this, params.updates);
40
- this.onServerUpdate.add(this.updates.handleUpdate.bind(this.updates));
41
40
  this.updates.onCatchingUp((catchingUp) => {
42
41
  this.onConnectionState.emit(catchingUp ? "updating" : "connected");
43
42
  });
@@ -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.
@@ -14,20 +14,10 @@ async function getCreatorAfterLeave(client, chatId) {
14
14
  if (peerUtils.isInputPeerUser(peer)) {
15
15
  throw new errors.MtInvalidPeerTypeError(chatId, "chat or channel");
16
16
  }
17
- let res;
18
- if (peerUtils.isInputPeerChannel(peer)) {
19
- res = await client.call({
20
- _: "channels.getFutureCreatorAfterLeave",
21
- channel: peerUtils.toInputChannel(peer)
22
- });
23
- } else if (peerUtils.isInputPeerChat(peer)) {
24
- res = await client.call({
25
- _: "messages.getFutureChatCreatorAfterLeave",
26
- peer
27
- });
28
- } else {
29
- throw new errors.MtInvalidPeerTypeError(chatId, "chat or channel");
30
- }
17
+ const res = await client.call({
18
+ _: "messages.getFutureChatCreatorAfterLeave",
19
+ peer
20
+ });
31
21
  if (res._ === "userEmpty") return null;
32
22
  return new user.User(res);
33
23
  }
@@ -1,26 +1,16 @@
1
1
  import { MtInvalidPeerTypeError } from "../../types/errors.js";
2
2
  import { User as User$2 } from "../../types/peers/user.js";
3
- import { isInputPeerUser, isInputPeerChannel, toInputChannel, isInputPeerChat } from "../../utils/peer-utils.js";
3
+ import { isInputPeerUser } from "../../utils/peer-utils.js";
4
4
  import { resolvePeer } from "../users/resolve-peer.js";
5
5
  async function getCreatorAfterLeave(client, chatId) {
6
6
  const peer = await resolvePeer(client, chatId);
7
7
  if (isInputPeerUser(peer)) {
8
8
  throw new MtInvalidPeerTypeError(chatId, "chat or channel");
9
9
  }
10
- let res;
11
- if (isInputPeerChannel(peer)) {
12
- res = await client.call({
13
- _: "channels.getFutureCreatorAfterLeave",
14
- channel: toInputChannel(peer)
15
- });
16
- } else if (isInputPeerChat(peer)) {
17
- res = await client.call({
18
- _: "messages.getFutureChatCreatorAfterLeave",
19
- peer
20
- });
21
- } else {
22
- throw new MtInvalidPeerTypeError(chatId, "chat or channel");
23
- }
10
+ const res = await client.call({
11
+ _: "messages.getFutureChatCreatorAfterLeave",
12
+ peer
13
+ });
24
14
  if (res._ === "userEmpty") return null;
25
15
  return new User$2(res);
26
16
  }
@@ -117,33 +117,40 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
117
117
  };
118
118
  }
119
119
  if (media.type === "poll" || media.type === "quiz") {
120
- const answers = media.answers.map((ans, idx) => {
121
- if (typeof ans === "object" && innerTl.isAnyPollAnswer(ans)) return ans;
120
+ const answers = await Promise.all(media.answers.map((ans) => {
121
+ if (typeof ans === "string") return { _: "inputPollAnswer", text: entities.inputTextToTl(ans) };
122
+ if (innerTl.isAnyPollAnswer(ans)) return ans;
123
+ if ("media" in ans && ans.media) {
124
+ return _normalizeInputMedia(client, ans.media, params, true).then((m) => ({
125
+ _: "inputPollAnswer",
126
+ text: entities.inputTextToTl(ans.text),
127
+ media: m
128
+ }));
129
+ }
122
130
  return {
123
- _: "pollAnswer",
124
- text: entities.inputTextToTl(ans),
125
- // emulate the behaviour of most implementations
126
- option: new Uint8Array([48 + idx])
131
+ _: "inputPollAnswer",
132
+ text: entities.inputTextToTl(ans.text)
127
133
  };
128
- });
134
+ }));
129
135
  let correct;
130
136
  let solution;
131
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
+ ]);
132
142
  if (media.type === "quiz") {
133
143
  let input2 = media.correct;
134
144
  if (!Array.isArray(input2)) input2 = [input2];
135
- correct = input2.map((it) => {
136
- if (typeof it === "number") {
137
- return answers[it].option;
138
- }
139
- return it;
140
- });
145
+ correct = input2;
141
146
  if (media.solution) {
142
147
  [solution, solutionEntities] = await normalizeText._normalizeInputText(client, media.solution);
143
148
  }
144
149
  }
145
150
  return {
146
151
  _: "inputMediaPoll",
152
+ attachedMedia,
153
+ solutionMedia,
147
154
  poll: {
148
155
  _: "poll",
149
156
  closed: media.closed,
@@ -154,7 +161,12 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
154
161
  question: entities.inputTextToTl(media.question),
155
162
  answers,
156
163
  closePeriod: media.closePeriod,
157
- closeDate: miscUtils.normalizeDate(media.closeDate)
164
+ closeDate: miscUtils.normalizeDate(media.closeDate),
165
+ openAnswers: media.openAnswers,
166
+ revotingDisabled: media.disableRevoting,
167
+ shuffleAnswers: media.shuffleAnswers,
168
+ hideResultsUntilClose: media.hideResultsUntilClose,
169
+ hash: Long.ZERO
158
170
  },
159
171
  correctAnswers: correct,
160
172
  solution,
@@ -236,6 +248,12 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
236
248
  typeAssertions.assertTypeIs("uploadMediaIfNeeded", inputMedia, "inputMediaPhoto");
237
249
  videoCover = inputMedia.id;
238
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
+ }
239
257
  const uploadPeer = params.uploadPeer ?? { _: "inputPeerSelf" };
240
258
  const uploadMediaIfNeeded = async (inputMedia, photo) => {
241
259
  if (!uploadMedia) return inputMedia;
@@ -257,7 +275,9 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
257
275
  fileReference: res.photo.fileReference
258
276
  },
259
277
  ttlSeconds: media.ttlSeconds,
260
- spoiler: media.type === "video" && media.spoiler
278
+ spoiler: media.type === "video" && media.spoiler,
279
+ livePhoto: Boolean(livePhotoVideo),
280
+ video: livePhotoVideo
261
281
  };
262
282
  }
263
283
  typeAssertions.assertTypeIs("normalizeInputMedia (@ messages.uploadMedia)", res, "messageMediaDocument");
@@ -334,6 +354,8 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
334
354
  {
335
355
  _: "inputMediaUploadedPhoto",
336
356
  file: inputFile,
357
+ livePhoto: Boolean(livePhotoVideo),
358
+ video: livePhotoVideo,
337
359
  ttlSeconds: media.ttlSeconds,
338
360
  spoiler: media.spoiler
339
361
  },
@@ -110,33 +110,40 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
110
110
  };
111
111
  }
112
112
  if (media.type === "poll" || media.type === "quiz") {
113
- const answers = media.answers.map((ans, idx) => {
114
- if (typeof ans === "object" && isAnyPollAnswer(ans)) return ans;
113
+ const answers = await Promise.all(media.answers.map((ans) => {
114
+ if (typeof ans === "string") return { _: "inputPollAnswer", text: inputTextToTl(ans) };
115
+ if (isAnyPollAnswer(ans)) return ans;
116
+ if ("media" in ans && ans.media) {
117
+ return _normalizeInputMedia(client, ans.media, params, true).then((m) => ({
118
+ _: "inputPollAnswer",
119
+ text: inputTextToTl(ans.text),
120
+ media: m
121
+ }));
122
+ }
115
123
  return {
116
- _: "pollAnswer",
117
- text: inputTextToTl(ans),
118
- // emulate the behaviour of most implementations
119
- option: new Uint8Array([48 + idx])
124
+ _: "inputPollAnswer",
125
+ text: inputTextToTl(ans.text)
120
126
  };
121
- });
127
+ }));
122
128
  let correct;
123
129
  let solution;
124
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
+ ]);
125
135
  if (media.type === "quiz") {
126
136
  let input2 = media.correct;
127
137
  if (!Array.isArray(input2)) input2 = [input2];
128
- correct = input2.map((it) => {
129
- if (typeof it === "number") {
130
- return answers[it].option;
131
- }
132
- return it;
133
- });
138
+ correct = input2;
134
139
  if (media.solution) {
135
140
  [solution, solutionEntities] = await _normalizeInputText(client, media.solution);
136
141
  }
137
142
  }
138
143
  return {
139
144
  _: "inputMediaPoll",
145
+ attachedMedia,
146
+ solutionMedia,
140
147
  poll: {
141
148
  _: "poll",
142
149
  closed: media.closed,
@@ -147,7 +154,12 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
147
154
  question: inputTextToTl(media.question),
148
155
  answers,
149
156
  closePeriod: media.closePeriod,
150
- closeDate: normalizeDate(media.closeDate)
157
+ closeDate: normalizeDate(media.closeDate),
158
+ openAnswers: media.openAnswers,
159
+ revotingDisabled: media.disableRevoting,
160
+ shuffleAnswers: media.shuffleAnswers,
161
+ hideResultsUntilClose: media.hideResultsUntilClose,
162
+ hash: Long.ZERO
151
163
  },
152
164
  correctAnswers: correct,
153
165
  solution,
@@ -229,6 +241,12 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
229
241
  assertTypeIs("uploadMediaIfNeeded", inputMedia, "inputMediaPhoto");
230
242
  videoCover = inputMedia.id;
231
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
+ }
232
250
  const uploadPeer = params.uploadPeer ?? { _: "inputPeerSelf" };
233
251
  const uploadMediaIfNeeded = async (inputMedia, photo) => {
234
252
  if (!uploadMedia) return inputMedia;
@@ -250,7 +268,9 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
250
268
  fileReference: res.photo.fileReference
251
269
  },
252
270
  ttlSeconds: media.ttlSeconds,
253
- spoiler: media.type === "video" && media.spoiler
271
+ spoiler: media.type === "video" && media.spoiler,
272
+ livePhoto: Boolean(livePhotoVideo),
273
+ video: livePhotoVideo
254
274
  };
255
275
  }
256
276
  assertTypeIs("normalizeInputMedia (@ messages.uploadMedia)", res, "messageMediaDocument");
@@ -327,6 +347,8 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
327
347
  {
328
348
  _: "inputMediaUploadedPhoto",
329
349
  file: inputFile,
350
+ livePhoto: Boolean(livePhotoVideo),
351
+ video: livePhotoVideo,
330
352
  ttlSeconds: media.ttlSeconds,
331
353
  spoiler: media.spoiler
332
354
  },
@@ -26,7 +26,8 @@ async function closePoll(client, params) {
26
26
  id: Long.ZERO,
27
27
  closed: true,
28
28
  question: { _: "textWithEntities", text: "", entities: [] },
29
- answers: []
29
+ answers: [],
30
+ hash: Long.ZERO
30
31
  }
31
32
  }
32
33
  });
@@ -19,7 +19,8 @@ async function closePoll(client, params) {
19
19
  id: Long.ZERO,
20
20
  closed: true,
21
21
  question: { _: "textWithEntities", text: "", entities: [] },
22
- answers: []
22
+ answers: [],
23
+ hash: Long.ZERO
23
24
  }
24
25
  }
25
26
  });
@@ -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.