2023-07-09 01:28:59 +03:00
|
|
|
package behx
|
|
|
|
|
|
|
|
import (
|
|
|
|
apix "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
// The type wraps Telegram API's button to provide Action functionality.
|
|
|
|
type Button struct {
|
2023-07-12 02:02:33 +03:00
|
|
|
Text string
|
|
|
|
Data string
|
|
|
|
Url string
|
2023-07-12 00:33:51 +03:00
|
|
|
Action Action
|
2023-07-09 01:28:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type ButtonMap map[string] *Button
|
|
|
|
|
|
|
|
// Represents the reply button row.
|
|
|
|
type ButtonRow []*Button
|
|
|
|
|
|
|
|
// Returns new button with specified text and action.
|
|
|
|
func NewButton(text string, action Action) *Button {
|
|
|
|
return &Button{
|
2023-07-12 02:02:33 +03:00
|
|
|
Text: text,
|
2023-07-09 01:28:59 +03:00
|
|
|
Action: action,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-12 02:02:33 +03:00
|
|
|
func NewButtonData(text string, data string, action Action) *Button {
|
|
|
|
return &Button{
|
|
|
|
Text: text,
|
|
|
|
Data: data,
|
|
|
|
Action: action,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewButtonUrl(text string, url string, action Action) *Button {
|
|
|
|
return &Button{
|
|
|
|
Text: text,
|
|
|
|
Url: url,
|
|
|
|
Action: action,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (btn *Button) ToTelegram() apix.KeyboardButton {
|
|
|
|
return apix.NewKeyboardButton(btn.Text)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (btn *Button) ToTelegramInline() apix.InlineKeyboardButton {
|
|
|
|
if btn.Data != "" {
|
|
|
|
return apix.NewInlineKeyboardButtonData(btn.Text, btn.Data)
|
|
|
|
}
|
|
|
|
|
|
|
|
if btn.Url != "" {
|
|
|
|
return apix.NewInlineKeyboardButtonURL(btn.Text, btn.Url)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no match then return the data one with data the same as the text.
|
|
|
|
return apix.NewInlineKeyboardButtonData(btn.Text, btn.Text)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-09 01:28:59 +03:00
|
|
|
func NewButtonRow(btns ...*Button) ButtonRow {
|
|
|
|
return btns
|
|
|
|
}
|
|
|
|
|