From 43b3f0ace1456e6cc16a5a5f237c80d3338a2b45 Mon Sep 17 00:00:00 2001 From: Sergey Date: Fri, 6 Sep 2019 16:41:36 +0300 Subject: [PATCH] Add helper for InlineKeyboardButtonLoginURL --- helpers.go | 11 ++++++++++- helpers_test.go | 17 +++++++++++++++++ types.go | 6 +++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/helpers.go b/helpers.go index b97aa2a..a7a7613 100644 --- a/helpers.go +++ b/helpers.go @@ -679,7 +679,16 @@ func NewInlineKeyboardButtonData(text, data string) InlineKeyboardButton { } } -// NewInlineKeyboardButtonURL creates an inline keyboard button with text +// NewInlineKeyboardButtonLoginURL creates an inline keyboard button with text +// which goes to a LoginURL. +func NewInlineKeyboardButtonLoginURL(text string, loginUrl LoginURL) InlineKeyboardButton { + return InlineKeyboardButton{ + Text: text, + LoginURL: &loginUrl, + } +} + +// NewInlineKeyboardButtonLoginURL creates an inline keyboard button with text // which goes to a URL. func NewInlineKeyboardButtonURL(text, url string) InlineKeyboardButton { return InlineKeyboardButton{ diff --git a/helpers_test.go b/helpers_test.go index 8e4508b..47c5d98 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -136,6 +136,23 @@ func TestNewInlineQueryResultLocation(t *testing.T) { } } +func TestNewInlineKeyboardButtonLoginURL(t *testing.T) { + result := NewInlineKeyboardButtonLoginURL("text", LoginURL{ + URL: "url", + ForwardText: "ForwardText", + BotUsername: "username", + RequestWriteAccess: false, + }) + + if result.Text != "text" || + result.LoginURL.URL != "url" || + result.LoginURL.ForwardText != "ForwardText" || + result.LoginURL.BotUsername != "username" || + result.LoginURL.RequestWriteAccess != false { + t.Fail() + } +} + func TestNewEditMessageText(t *testing.T) { edit := NewEditMessageText(ChatID, ReplyToMessageID, "new text") diff --git a/types.go b/types.go index 78ebcf3..347d4b8 100644 --- a/types.go +++ b/types.go @@ -476,9 +476,9 @@ type InlineKeyboardButton struct { // LoginURL is the parameters for the login inline keyboard button type. type LoginURL struct { URL string `json:"url"` - ForwardText string `json:"forward_text"` - BotUsername string `json:"bot_username"` - RequestWriteAccess bool `json:"request_write_access"` + ForwardText string `json:"forward_text,omitempty"` + BotUsername string `json:"bot_username,omitempty"` + RequestWriteAccess bool `json:"request_write_access,omitempty"` } // CallbackQuery is data sent when a keyboard button with callback data