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...
This commit is contained in:
teidesu 2022-05-09 17:32:42 +03:00
parent 63d0ea2ddf
commit b4beeba33c

View file

@ -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
*