diff --git a/markup.go b/markup.go index 67ad30e..79be3f2 100644 --- a/markup.go +++ b/markup.go @@ -15,16 +15,31 @@ type WebAppInfo struct { URL string `json:"url"` } +// KeyboardButtonStyle defines the visual style of an inline keyboard button. +type KeyboardButtonStyle struct { + BgPrimary bool `json:"bg_primary,omitempty"` + BgDanger bool `json:"bg_danger,omitempty"` + BgSuccess bool `json:"bg_success,omitempty"` + Icon *int64 `json:"icon,omitempty"` +} + // InlineKeyboardButton is one button of an inline keyboard. Exactly one of the // optional action fields should be set. type InlineKeyboardButton struct { - Text string `json:"text"` - URL string `json:"url,omitempty"` - CallbackData string `json:"callback_data,omitempty"` - WebApp *WebAppInfo `json:"web_app,omitempty"` - SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` - SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` - Pay bool `json:"pay,omitempty"` + Text string `json:"text"` + URL string `json:"url,omitempty"` + CallbackData string `json:"callback_data,omitempty"` + WebApp *WebAppInfo `json:"web_app,omitempty"` + Style *KeyboardButtonStyle `json:"style,omitempty"` + SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` + SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` + Pay bool `json:"pay,omitempty"` +} + +func (s *InlineKeyboardButton) Styled(style *KeyboardButtonStyle) InlineKeyboardButton { + s.Style = style + + return *s } // InlineKeyboardMarkup is an inline keyboard that appears beneath a message. diff --git a/markup_to_tg.go b/markup_to_tg.go index 13ab22f..316182a 100644 --- a/markup_to_tg.go +++ b/markup_to_tg.go @@ -71,19 +71,40 @@ func replyMarkupToTg(m ReplyMarkup) (tg.ReplyMarkupClass, error) { } func inlineButtonToTg(btn InlineKeyboardButton) (tg.KeyboardButtonClass, error) { + var opts []markup.StyleOption + + if btn.Style != nil { + s := btn.Style + if s.Icon != nil { + opts = append(opts, markup.StyleIcon(*s.Icon)) + } + + if s.BgDanger { + opts = append(opts, markup.StyleBgDanger()) + } + + if s.BgPrimary { + opts = append(opts, markup.StyleBgPrimary()) + } + + if s.BgSuccess { + opts = append(opts, markup.StyleBgSuccess()) + } + } + switch { case btn.URL != "": - return markup.URL(btn.Text, btn.URL), nil + return markup.URL(btn.Text, btn.URL, opts...), nil case btn.CallbackData != "": - return markup.Callback(btn.Text, []byte(btn.CallbackData)), nil + return markup.Callback(btn.Text, []byte(btn.CallbackData), opts...), nil case btn.WebApp != nil: - return markup.WebView(btn.Text, btn.WebApp.URL), nil + return markup.WebView(btn.Text, btn.WebApp.URL, opts...), nil case btn.SwitchInlineQuery != nil: - return markup.SwitchInline(btn.Text, *btn.SwitchInlineQuery, false), nil + return markup.SwitchInline(btn.Text, *btn.SwitchInlineQuery, false, opts...), nil case btn.SwitchInlineQueryCurrentChat != nil: - return markup.SwitchInline(btn.Text, *btn.SwitchInlineQueryCurrentChat, true), nil + return markup.SwitchInline(btn.Text, *btn.SwitchInlineQueryCurrentChat, true, opts...), nil case btn.Pay: - return markup.Buy(btn.Text), nil + return markup.Buy(btn.Text, opts...), nil default: return nil, &Error{Code: 400, Description: "Bad Request: text buttons are unallowed in the inline keyboard"} }