-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboard.go
56 lines (45 loc) · 1.43 KB
/
keyboard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package keyboard
import "github.com/PaulSonOfLars/gotgbot/v2"
type keyboard [][]gotgbot.KeyboardButton
type Keyboard struct {
keyboard
}
// Adds a button.
func (k *Keyboard) Add(buttons ...gotgbot.KeyboardButton) *Keyboard {
if len(k.keyboard) == 0 {
k.keyboard = append(k.keyboard, []gotgbot.KeyboardButton{})
}
k.keyboard[len(k.keyboard)-1] = append(k.keyboard[len(k.keyboard)-1], buttons...)
return k
}
// Creates a row for the upcoming buttons.
func (k *Keyboard) Row() *Keyboard {
k.keyboard = append(k.keyboard, []gotgbot.KeyboardButton{})
return k
}
// Adds a text button.
func (k *Keyboard) Text(text string) *Keyboard {
k.Add(gotgbot.KeyboardButton{Text: text})
return k
}
// Adds a request contact button.
func (k *Keyboard) RequestContact(text string) *Keyboard {
k.Add(gotgbot.KeyboardButton{Text: text, RequestContact: true})
return k
}
// Adds a request location button.
func (k *Keyboard) RequestLocation(text string) *Keyboard {
k.Add(gotgbot.KeyboardButton{Text: text, RequestLocation: true})
return k
}
// Adds a request poll button.
func (k *Keyboard) RequestPoll(text string, pollType string) *Keyboard {
k.Add(gotgbot.KeyboardButton{Text: text, RequestPoll: &gotgbot.KeyboardButtonPollType{Type: pollType}})
return k
}
// Builds the reply keyboard markup. This should be called in the end only.
func (k *Keyboard) Build() *gotgbot.ReplyKeyboardMarkup {
return &gotgbot.ReplyKeyboardMarkup{
Keyboard: k.keyboard,
}
}