Bot Menu: Support commands update (#5864)

This commit is contained in:
zubiden 2025-04-23 18:59:47 +02:00 committed by Alexander Zinchuk
parent a63d4b7687
commit b3c6ae2089
4 changed files with 38 additions and 4 deletions

View File

@ -398,7 +398,7 @@ export function buildBotAppSettings(settings: GramJs.BotAppSettings): ApiBotAppS
};
}
function buildApiBotCommand(botId: string, command: GramJs.BotCommand): ApiBotCommand {
export function buildApiBotCommand(botId: string, command: GramJs.BotCommand): ApiBotCommand {
return {
botId,
...omitVirtualClassFields(command),

View File

@ -12,7 +12,7 @@ import {
omit, pick,
} from '../../../util/iteratees';
import { getServerTimeOffset, setServerTimeOffset } from '../../../util/serverTime';
import { buildApiBotMenuButton } from '../apiBuilders/bots';
import { buildApiBotCommand, buildApiBotMenuButton } from '../apiBuilders/bots';
import {
buildApiGroupCall,
buildApiGroupCallParticipant,
@ -953,6 +953,19 @@ export function updater(update: Update) {
botId: id,
button: buildApiBotMenuButton(button),
});
} else if (update instanceof GramJs.UpdateBotCommands) {
const {
botId,
commands,
} = update;
const id = buildApiPeerId(botId, 'user');
const commandsArray = commands.map((command) => buildApiBotCommand(id, command));
sendApiUpdate({
'@type': 'updateBotCommands',
botId: id,
commands: commandsArray.length ? commandsArray : undefined,
});
} else if (update instanceof GramJs.UpdateTranscribedAudio) {
sendApiUpdate({
'@type': 'updateTranscribedAudio',

View File

@ -8,7 +8,7 @@ import type {
} from '../../lib/secret-sauce';
import type { ThreadId } from '../../types';
import type { RegularLangFnParameters } from '../../util/localization';
import type { ApiBotMenuButton } from './bots';
import type { ApiBotCommand, ApiBotMenuButton } from './bots';
import type {
ApiGroupCall, ApiPhoneCall,
} from './calls';
@ -826,6 +826,12 @@ export type ApiUpdateLangPack = {
keysToRemove: string[];
};
export type ApiUpdateBotCommands = {
'@type': 'updateBotCommands';
botId: string;
commands?: ApiBotCommand[];
};
export type ApiUpdate = (
ApiUpdateReady | ApiUpdateSession | ApiUpdateWebAuthTokenFailed | ApiUpdateRequestUserUpdate |
ApiUpdateAuthorizationState | ApiUpdateAuthorizationError | ApiUpdateConnectionState | ApiUpdateCurrentUser |
@ -857,7 +863,7 @@ export type ApiUpdate = (
ApiRequestReconnectApi | ApiRequestSync | ApiUpdateFetchingDifference | ApiUpdateChannelMessages |
ApiUpdateStealthMode | ApiUpdateAttachMenuBots | ApiUpdateNewAuthorization | ApiUpdateGroupInvitePrivacyForbidden |
ApiUpdateViewForumAsMessages | ApiUpdateSavedDialogPinned | ApiUpdatePinnedSavedDialogIds | ApiUpdateChatLastMessage |
ApiUpdateDeleteSavedHistory | ApiUpdatePremiumFloodWait | ApiUpdateStarsBalance |
ApiUpdateDeleteSavedHistory | ApiUpdatePremiumFloodWait | ApiUpdateStarsBalance | ApiUpdateBotCommands |
ApiUpdateQuickReplyMessage | ApiUpdateQuickReplies | ApiDeleteQuickReply | ApiUpdateDeleteQuickReplyMessages |
ApiUpdateDeleteProfilePhoto | ApiUpdateNewProfilePhoto | ApiUpdateEntities | ApiUpdatePaidReactionPrivacy |
ApiUpdateLangPackTooLong | ApiUpdateLangPack | ApiUpdateNotSupportedInFrozenAccountError

View File

@ -107,6 +107,21 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
});
}
case 'updateBotCommands': {
const { botId, commands } = update;
const targetUserFullInfo = selectUserFullInfo(global, botId);
if (!targetUserFullInfo?.botInfo) {
return undefined;
}
return updateUserFullInfo(global, botId, {
botInfo: {
...targetUserFullInfo.botInfo,
commands,
},
});
}
case 'updatePeerSettings': {
const { id, settings } = update;