aboutsummaryrefslogtreecommitdiff
path: root/keyboard.go
blob: 5259b7a076e87db9542516ef55faed3dc2de5fa8 (plain) (blame)
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
package tamtam

import "github.com/neonxp/tamtam/schemes"

//Keyboard implements builder for inline keyboard
type Keyboard struct {
	rows []*KeyboardRow
}

//AddRow adds row to inline keyboard
func (k *Keyboard) AddRow() *KeyboardRow {
	kr := &KeyboardRow{}
	k.rows = append(k.rows, kr)
	return kr
}

//Build returns result 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 buttons row
type KeyboardRow struct {
	cols []schemes.ButtonInterface
}

//Build returns result keyboard row
func (k *KeyboardRow) Build() []schemes.ButtonInterface {
	return k.cols
}

//AddLink button
func (k *KeyboardRow) AddLink(text string, intent 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
}