From b4beeba33c15a2032a482a35dcb2b1c695f9480e Mon Sep 17 00:00:00 2001 From: teidesu <86301490+teidesu@users.noreply.github.com> Date: Mon, 9 May 2022 17:32:42 +0300 Subject: [PATCH] feat(client): support user profile button this one does not automatically do resolvePeer because i'm too lazy to make an intermediate type just for this type of buttons. once there are more of them, maybe i will... --- packages/client/src/types/bots/keyboards.ts | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/client/src/types/bots/keyboards.ts b/packages/client/src/types/bots/keyboards.ts index 6eba9b24..c22e09ea 100644 --- a/packages/client/src/types/bots/keyboards.ts +++ b/packages/client/src/types/bots/keyboards.ts @@ -1,6 +1,8 @@ import { assertNever } from '@mtcute/core' import { tl } from '@mtcute/tl' import { BotKeyboardBuilder } from './keyboard-builder' +import { normalizeToInputUser } from '../../utils/peer-utils' +import { MtInvalidPeerTypeError } from '../errors' /** * Reply keyboard markup @@ -353,6 +355,28 @@ export namespace BotKeyboard { } } + /** + * Button to open user profile + * + * @param text Text of the button + * @param user User to be opened (use {@link TelegramClient.resolvePeer}) + */ + export function userProfile( + text: string, + user: tl.TypeInputPeer + ): tl.RawInputKeyboardButtonUserProfile { + const userId = normalizeToInputUser(user) + if (!userId) { + throw new MtInvalidPeerTypeError(user, 'user') + } + + return { + _: 'inputKeyboardButtonUserProfile', + text, + userId, + } + } + /** * Find a button in the keyboard by its text or by predicate *