From 94c96cef29cd83bc60b2eabb8bb89c9fd8c7059b Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Fri, 9 Aug 2019 02:02:05 +0300 Subject: 0.1.8 Release --- keyboard.go | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 keyboard.go (limited to 'keyboard.go') diff --git a/keyboard.go b/keyboard.go new file mode 100644 index 0000000..7d79042 --- /dev/null +++ b/keyboard.go @@ -0,0 +1,77 @@ +// Package tamtam implements TamTam Bot API +// Copyright (c) 2019 Alexander Kiryukhin +package tamtam + +type KeyboardBuilder struct { + rows []*KeyboardRow +} + +func (k *KeyboardBuilder) AddRow() *KeyboardRow { + kr := &KeyboardRow{} + k.rows = append(k.rows, kr) + return kr +} + +func (k *KeyboardBuilder) Build() Keyboard { + buttons := make([][]ButtonInterface, 0, len(k.rows)) + for _, r := range k.rows { + buttons = append(buttons, r.Build()) + } + return Keyboard{Buttons: buttons} +} + +type KeyboardRow struct { + cols []ButtonInterface +} + +func (k *KeyboardRow) Build() []ButtonInterface { + return k.cols +} + +func (k *KeyboardRow) AddLink(text string, intent Intent, url string) *KeyboardRow { + b := LinkButton{ + Url: url, + Button: Button{ + Text: text, + Type: LINK, + }, + } + k.cols = append(k.cols, b) + return k +} + +func (k *KeyboardRow) AddCallback(text string, intent Intent, payload string) *KeyboardRow { + b := CallbackButton{ + Payload: payload, + Intent: intent, + Button: Button{ + Text: text, + Type: CALLBACK, + }, + } + k.cols = append(k.cols, b) + return k +} + +func (k *KeyboardRow) AddContact(text string) *KeyboardRow { + b := RequestContactButton{ + Button: Button{ + Text: text, + Type: CONTACT, + }, + } + k.cols = append(k.cols, b) + return k +} + +func (k *KeyboardRow) AddGeolocation(text string, quick bool) *KeyboardRow { + b := RequestGeoLocationButton{ + Quick: quick, + Button: Button{ + Text: text, + Type: GEOLOCATION, + }, + } + k.cols = append(k.cols, b) + return k +} -- cgit v1.2.3