forked from max-messenger/max-bot-api-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyboard.go
More file actions
127 lines (105 loc) · 2.51 KB
/
keyboard.go
File metadata and controls
127 lines (105 loc) · 2.51 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package maxbot
import "github.com/max-messenger/max-bot-api-client-go/schemes"
// Keyboard implements a builder for the inline keyboard.
type Keyboard struct {
rows []*KeyboardRow
}
// AddRow adds a row to the inline keyboard.
func (k *Keyboard) AddRow() *KeyboardRow {
kr := &KeyboardRow{}
k.rows = append(k.rows, kr)
return kr
}
// Build returns the keyboard.
func (k *Keyboard) Build() schemes.Keyboard {
buttons := make([][]schemes.ButtonInterface, 0, len(k.rows))
for _, r := range k.rows {
buttons = append(buttons, r.Build())
}
return schemes.Keyboard{Buttons: buttons}
}
// KeyboardRow represents a button row.
type KeyboardRow struct {
cols []schemes.ButtonInterface
}
// Build returns keyboard rows.
func (k *KeyboardRow) Build() []schemes.ButtonInterface {
return k.cols
}
func (k *KeyboardRow) AddButton(b schemes.ButtonInterface) *KeyboardRow {
k.cols = append(k.cols, b)
return k
}
// AddLink button.
func (k *KeyboardRow) AddLink(text string, _ schemes.Intent, url string) *KeyboardRow {
b := schemes.LinkButton{
Url: url,
Button: schemes.Button{
Text: text,
Type: schemes.LINK,
},
}
k.cols = append(k.cols, b)
return k
}
// AddCallback button.
func (k *KeyboardRow) AddCallback(text string, intent schemes.Intent, payload string) *KeyboardRow {
b := schemes.CallbackButton{
Payload: payload,
Intent: intent,
Button: schemes.Button{
Text: text,
Type: schemes.CALLBACK,
},
}
k.cols = append(k.cols, b)
return k
}
// AddContact button.
func (k *KeyboardRow) AddContact(text string) *KeyboardRow {
b := schemes.RequestContactButton{
Button: schemes.Button{
Text: text,
Type: schemes.CONTACT,
},
}
k.cols = append(k.cols, b)
return k
}
// AddGeolocation button.
func (k *KeyboardRow) AddGeolocation(text string, quick bool) *KeyboardRow {
b := schemes.RequestGeoLocationButton{
Quick: quick,
Button: schemes.Button{
Text: text,
Type: schemes.GEOLOCATION,
},
}
k.cols = append(k.cols, b)
return k
}
// AddOpenApp button.
func (k *KeyboardRow) AddOpenApp(text string, app, payload string, contactId int64) *KeyboardRow {
b := schemes.OpenAppButton{
WebApp: app,
Payload: payload,
ContactId: contactId,
Button: schemes.Button{
Text: text,
Type: schemes.OPEN_APP,
},
}
k.cols = append(k.cols, b)
return k
}
// AddMessage button.
func (k *KeyboardRow) AddMessage(text string) *KeyboardRow {
b := schemes.MessageButton{
Button: schemes.Button{
Text: text,
Type: schemes.MESSAGE,
},
}
k.cols = append(k.cols, b)
return k
}