Bot Menu: Support commands update (#5864)
This commit is contained in:
parent
a63d4b7687
commit
b3c6ae2089
@ -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 {
|
return {
|
||||||
botId,
|
botId,
|
||||||
...omitVirtualClassFields(command),
|
...omitVirtualClassFields(command),
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import {
|
|||||||
omit, pick,
|
omit, pick,
|
||||||
} from '../../../util/iteratees';
|
} from '../../../util/iteratees';
|
||||||
import { getServerTimeOffset, setServerTimeOffset } from '../../../util/serverTime';
|
import { getServerTimeOffset, setServerTimeOffset } from '../../../util/serverTime';
|
||||||
import { buildApiBotMenuButton } from '../apiBuilders/bots';
|
import { buildApiBotCommand, buildApiBotMenuButton } from '../apiBuilders/bots';
|
||||||
import {
|
import {
|
||||||
buildApiGroupCall,
|
buildApiGroupCall,
|
||||||
buildApiGroupCallParticipant,
|
buildApiGroupCallParticipant,
|
||||||
@ -953,6 +953,19 @@ export function updater(update: Update) {
|
|||||||
botId: id,
|
botId: id,
|
||||||
button: buildApiBotMenuButton(button),
|
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) {
|
} else if (update instanceof GramJs.UpdateTranscribedAudio) {
|
||||||
sendApiUpdate({
|
sendApiUpdate({
|
||||||
'@type': 'updateTranscribedAudio',
|
'@type': 'updateTranscribedAudio',
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import type {
|
|||||||
} from '../../lib/secret-sauce';
|
} from '../../lib/secret-sauce';
|
||||||
import type { ThreadId } from '../../types';
|
import type { ThreadId } from '../../types';
|
||||||
import type { RegularLangFnParameters } from '../../util/localization';
|
import type { RegularLangFnParameters } from '../../util/localization';
|
||||||
import type { ApiBotMenuButton } from './bots';
|
import type { ApiBotCommand, ApiBotMenuButton } from './bots';
|
||||||
import type {
|
import type {
|
||||||
ApiGroupCall, ApiPhoneCall,
|
ApiGroupCall, ApiPhoneCall,
|
||||||
} from './calls';
|
} from './calls';
|
||||||
@ -826,6 +826,12 @@ export type ApiUpdateLangPack = {
|
|||||||
keysToRemove: string[];
|
keysToRemove: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ApiUpdateBotCommands = {
|
||||||
|
'@type': 'updateBotCommands';
|
||||||
|
botId: string;
|
||||||
|
commands?: ApiBotCommand[];
|
||||||
|
};
|
||||||
|
|
||||||
export type ApiUpdate = (
|
export type ApiUpdate = (
|
||||||
ApiUpdateReady | ApiUpdateSession | ApiUpdateWebAuthTokenFailed | ApiUpdateRequestUserUpdate |
|
ApiUpdateReady | ApiUpdateSession | ApiUpdateWebAuthTokenFailed | ApiUpdateRequestUserUpdate |
|
||||||
ApiUpdateAuthorizationState | ApiUpdateAuthorizationError | ApiUpdateConnectionState | ApiUpdateCurrentUser |
|
ApiUpdateAuthorizationState | ApiUpdateAuthorizationError | ApiUpdateConnectionState | ApiUpdateCurrentUser |
|
||||||
@ -857,7 +863,7 @@ export type ApiUpdate = (
|
|||||||
ApiRequestReconnectApi | ApiRequestSync | ApiUpdateFetchingDifference | ApiUpdateChannelMessages |
|
ApiRequestReconnectApi | ApiRequestSync | ApiUpdateFetchingDifference | ApiUpdateChannelMessages |
|
||||||
ApiUpdateStealthMode | ApiUpdateAttachMenuBots | ApiUpdateNewAuthorization | ApiUpdateGroupInvitePrivacyForbidden |
|
ApiUpdateStealthMode | ApiUpdateAttachMenuBots | ApiUpdateNewAuthorization | ApiUpdateGroupInvitePrivacyForbidden |
|
||||||
ApiUpdateViewForumAsMessages | ApiUpdateSavedDialogPinned | ApiUpdatePinnedSavedDialogIds | ApiUpdateChatLastMessage |
|
ApiUpdateViewForumAsMessages | ApiUpdateSavedDialogPinned | ApiUpdatePinnedSavedDialogIds | ApiUpdateChatLastMessage |
|
||||||
ApiUpdateDeleteSavedHistory | ApiUpdatePremiumFloodWait | ApiUpdateStarsBalance |
|
ApiUpdateDeleteSavedHistory | ApiUpdatePremiumFloodWait | ApiUpdateStarsBalance | ApiUpdateBotCommands |
|
||||||
ApiUpdateQuickReplyMessage | ApiUpdateQuickReplies | ApiDeleteQuickReply | ApiUpdateDeleteQuickReplyMessages |
|
ApiUpdateQuickReplyMessage | ApiUpdateQuickReplies | ApiDeleteQuickReply | ApiUpdateDeleteQuickReplyMessages |
|
||||||
ApiUpdateDeleteProfilePhoto | ApiUpdateNewProfilePhoto | ApiUpdateEntities | ApiUpdatePaidReactionPrivacy |
|
ApiUpdateDeleteProfilePhoto | ApiUpdateNewProfilePhoto | ApiUpdateEntities | ApiUpdatePaidReactionPrivacy |
|
||||||
ApiUpdateLangPackTooLong | ApiUpdateLangPack | ApiUpdateNotSupportedInFrozenAccountError
|
ApiUpdateLangPackTooLong | ApiUpdateLangPack | ApiUpdateNotSupportedInFrozenAccountError
|
||||||
|
|||||||
@ -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': {
|
case 'updatePeerSettings': {
|
||||||
const { id, settings } = update;
|
const { id, settings } = update;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user