@imessaging/telegram-mtproto 0.8.11 → 0.8.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imessaging/telegram-mtproto",
3
- "version": "0.8.11",
3
+ "version": "0.8.12",
4
4
  "description": "Telegram MTProto user-account transport for imessaging",
5
5
  "keywords": [
6
6
  "messaging",
@@ -31,7 +31,7 @@
31
31
  "test": "bun test"
32
32
  },
33
33
  "dependencies": {
34
- "@imessaging/core": "^0.8.9",
34
+ "@imessaging/core": "^0.8.10",
35
35
  "big-integer": "^1.6.52"
36
36
  },
37
37
  "peerDependencies": {
@@ -1,4 +1,6 @@
1
1
  import type {
2
+ ChannelCommand,
3
+ CommandMenuTransport,
2
4
  ContactCard,
3
5
  ContactTransport,
4
6
  PhoneLookupOptions,
@@ -114,6 +116,14 @@ function inputPeerChatId(peer: Api.TypeInputPeer): string {
114
116
  throw new Error(`Unsupported input peer: ${peer.className}`);
115
117
  }
116
118
 
119
+ /** Разметка отправки: кнопки, а без них — снятие постоянной клавиатуры по `removeKeyboard`. */
120
+ function sendMarkup(message: OutboundMessage) {
121
+ return (
122
+ toGramJsButtons(message.buttons) ??
123
+ (message.removeKeyboard ? new Api.ReplyKeyboardHide({}) : undefined)
124
+ );
125
+ }
126
+
117
127
  function toGramJsButtons(buttons?: OutboundButton[][]) {
118
128
  if (!buttons || buttons.length === 0) return undefined;
119
129
  return buttons.map((row) =>
@@ -127,6 +137,7 @@ function toGramJsButtons(buttons?: OutboundButton[][]) {
127
137
 
128
138
  export class TelegramMtprotoTransport
129
139
  implements
140
+ CommandMenuTransport,
130
141
  ContactTransport,
131
142
  DraftTransport,
132
143
  EditableMessageTransport,
@@ -707,6 +718,20 @@ export class TelegramMtprotoTransport
707
718
  this.lastActivityAt = new Date();
708
719
  }
709
720
 
721
+ /** Меню команд бота. Сессия обычной учётки получит отказ Telegram: меню бывает только у бота. */
722
+ async setCommands(commands: ChannelCommand[]): Promise<void> {
723
+ this.assertConnected();
724
+ await this.client.invoke(
725
+ new Api.bots.SetBotCommands({
726
+ scope: new Api.BotCommandScopeDefault(),
727
+ langCode: "",
728
+ commands: commands.map(
729
+ (c) => new Api.BotCommand({ command: c.command, description: c.description }),
730
+ ),
731
+ }),
732
+ );
733
+ }
734
+
710
735
  async disconnect(): Promise<void> {
711
736
  await this.client.disconnect();
712
737
  this.connected = false;
@@ -869,7 +894,7 @@ export class TelegramMtprotoTransport
869
894
  parseMode,
870
895
  formattingEntities,
871
896
  replyTo: message.replyToMessageId ?? message.threadId,
872
- buttons: toGramJsButtons(message.buttons),
897
+ buttons: sendMarkup(message),
873
898
  });
874
899
  this.rememberOwn(this.ownSent, peer, sent.id);
875
900
  for (const document of message.documents ?? []) {