feat(client): support get/setBotMenuButton methods
This commit is contained in:
parent
d41bec9c73
commit
a0bfe2c075
3 changed files with 67 additions and 0 deletions
|
@ -79,6 +79,7 @@ import { start } from './methods/auth/start'
|
|||
import { answerCallbackQuery } from './methods/bots/answer-callback-query'
|
||||
import { answerInlineQuery } from './methods/bots/answer-inline-query'
|
||||
import { deleteMyCommands } from './methods/bots/delete-my-commands'
|
||||
import { getBotMenuButton } from './methods/bots/get-bot-menu-button'
|
||||
import { getCallbackAnswer } from './methods/bots/get-callback-answer'
|
||||
import {
|
||||
getGameHighScores,
|
||||
|
@ -86,6 +87,7 @@ import {
|
|||
} from './methods/bots/get-game-high-scores'
|
||||
import { getMyCommands } from './methods/bots/get-my-commands'
|
||||
import { _normalizeCommandScope } from './methods/bots/normalize-command-scope'
|
||||
import { setBotMenuButton } from './methods/bots/set-bot-menu-button'
|
||||
import { setGameScore, setInlineGameScore } from './methods/bots/set-game-score'
|
||||
import { setMyCommands } from './methods/bots/set-my-commands'
|
||||
import { setMyDefaultRights } from './methods/bots/set-my-default-rights'
|
||||
|
@ -809,6 +811,11 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
*/
|
||||
langCode?: string
|
||||
}): Promise<void>
|
||||
/**
|
||||
* Fetches the menu button set for the given user.
|
||||
*
|
||||
*/
|
||||
getBotMenuButton(user: InputPeerLike): Promise<tl.TypeBotMenuButton>
|
||||
/**
|
||||
* Request a callback answer from a bot,
|
||||
* i.e. click an inline button that contains data.
|
||||
|
@ -887,6 +894,14 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
*/
|
||||
langCode?: string
|
||||
}): Promise<tl.RawBotCommand[]>
|
||||
/**
|
||||
* Sets a menu button for the given user.
|
||||
*
|
||||
*/
|
||||
setBotMenuButton(
|
||||
user: InputPeerLike,
|
||||
button: tl.TypeBotMenuButton
|
||||
): Promise<void>
|
||||
/**
|
||||
* Set a score of a user in a game
|
||||
*
|
||||
|
@ -3698,11 +3713,13 @@ export class TelegramClient extends BaseTelegramClient {
|
|||
answerCallbackQuery = answerCallbackQuery
|
||||
answerInlineQuery = answerInlineQuery
|
||||
deleteMyCommands = deleteMyCommands
|
||||
getBotMenuButton = getBotMenuButton
|
||||
getCallbackAnswer = getCallbackAnswer
|
||||
getGameHighScores = getGameHighScores
|
||||
getInlineGameHighScores = getInlineGameHighScores
|
||||
getMyCommands = getMyCommands
|
||||
protected _normalizeCommandScope = _normalizeCommandScope
|
||||
setBotMenuButton = setBotMenuButton
|
||||
setGameScore = setGameScore
|
||||
setInlineGameScore = setInlineGameScore
|
||||
setMyCommands = setMyCommands
|
||||
|
|
24
packages/client/src/methods/bots/get-bot-menu-button.ts
Normal file
24
packages/client/src/methods/bots/get-bot-menu-button.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { TelegramClient } from '../../client'
|
||||
import { tl } from '@mtcute/tl'
|
||||
import { InputPeerLike, MtInvalidPeerTypeError } from "../../types";
|
||||
import { normalizeToInputUser } from "../../utils/peer-utils";
|
||||
|
||||
/**
|
||||
* Fetches the menu button set for the given user.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export async function getBotMenuButton(
|
||||
this: TelegramClient,
|
||||
user: InputPeerLike
|
||||
): Promise<tl.TypeBotMenuButton> {
|
||||
const userId = normalizeToInputUser(await this.resolvePeer(user))
|
||||
if (!userId) {
|
||||
throw new MtInvalidPeerTypeError(user, 'user')
|
||||
}
|
||||
|
||||
return await this.call({
|
||||
_: 'bots.getBotMenuButton',
|
||||
userId,
|
||||
})
|
||||
}
|
26
packages/client/src/methods/bots/set-bot-menu-button.ts
Normal file
26
packages/client/src/methods/bots/set-bot-menu-button.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { TelegramClient } from '../../client'
|
||||
import { tl } from '@mtcute/tl'
|
||||
import { InputPeerLike, MtInvalidPeerTypeError } from "../../types";
|
||||
import { normalizeToInputUser } from "../../utils/peer-utils";
|
||||
|
||||
/**
|
||||
* Sets a menu button for the given user.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export async function setBotMenuButton(
|
||||
this: TelegramClient,
|
||||
user: InputPeerLike,
|
||||
button: tl.TypeBotMenuButton
|
||||
): Promise<void> {
|
||||
const userId = normalizeToInputUser(await this.resolvePeer(user))
|
||||
if (!userId) {
|
||||
throw new MtInvalidPeerTypeError(user, 'user')
|
||||
}
|
||||
|
||||
await this.call({
|
||||
_: 'bots.setBotMenuButton',
|
||||
userId,
|
||||
button
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue