1 | import { InlineKeyboardButton, KeyboardButton } from './core/types/typegram'
|
2 |
|
3 | type Hideable<B> = B & { hide: boolean }
|
4 |
|
5 | export function text(
|
6 | text: string,
|
7 | hide = false
|
8 | ): Hideable<KeyboardButton.CommonButton> {
|
9 | return { text, hide }
|
10 | }
|
11 |
|
12 | export function contactRequest(
|
13 | text: string,
|
14 | hide = false
|
15 | ): Hideable<KeyboardButton.RequestContactButton> {
|
16 | return { text, request_contact: true, hide }
|
17 | }
|
18 |
|
19 | export function locationRequest(
|
20 | text: string,
|
21 | hide = false
|
22 | ): Hideable<KeyboardButton.RequestLocationButton> {
|
23 | return { text, request_location: true, hide }
|
24 | }
|
25 |
|
26 | export function pollRequest(
|
27 | text: string,
|
28 | type?: 'quiz' | 'regular',
|
29 | hide = false
|
30 | ): Hideable<KeyboardButton.RequestPollButton> {
|
31 | return { text, request_poll: { type }, hide }
|
32 | }
|
33 |
|
34 | export function url(
|
35 | text: string,
|
36 | url: string,
|
37 | hide = false
|
38 | ): Hideable<InlineKeyboardButton.UrlButton> {
|
39 | return { text, url, hide }
|
40 | }
|
41 |
|
42 | export function callback(
|
43 | text: string,
|
44 | data: string,
|
45 | hide = false
|
46 | ): Hideable<InlineKeyboardButton.CallbackButton> {
|
47 | return { text, callback_data: data, hide }
|
48 | }
|
49 |
|
50 | export function switchToChat(
|
51 | text: string,
|
52 | value: string,
|
53 | hide = false
|
54 | ): Hideable<InlineKeyboardButton.SwitchInlineButton> {
|
55 | return { text, switch_inline_query: value, hide }
|
56 | }
|
57 |
|
58 | export function switchToCurrentChat(
|
59 | text: string,
|
60 | value: string,
|
61 | hide = false
|
62 | ): Hideable<InlineKeyboardButton.SwitchInlineCurrentChatButton> {
|
63 | return { text, switch_inline_query_current_chat: value, hide }
|
64 | }
|
65 |
|
66 | export function game(
|
67 | text: string,
|
68 | hide = false
|
69 | ): Hideable<InlineKeyboardButton.GameButton> {
|
70 | return { text, callback_game: {}, hide }
|
71 | }
|
72 |
|
73 | export function pay(
|
74 | text: string,
|
75 | hide = false
|
76 | ): Hideable<InlineKeyboardButton.PayButton> {
|
77 | return { text, pay: true, hide }
|
78 | }
|
79 |
|
80 | export function login(
|
81 | text: string,
|
82 | url: string,
|
83 | opts: {
|
84 | forward_text?: string
|
85 | bot_username?: string
|
86 | request_write_access?: boolean
|
87 | } = {},
|
88 | hide = false
|
89 | ): Hideable<InlineKeyboardButton.LoginButton> {
|
90 | return {
|
91 | text,
|
92 | login_url: { ...opts, url },
|
93 | hide,
|
94 | }
|
95 | }
|