all repos — telegram-bot-api @ 43b3f0ace1456e6cc16a5a5f237c80d3338a2b45

Golang bindings for the Telegram Bot API

Add helper for InlineKeyboardButtonLoginURL
Sergey sergey@antsupov.xyz
Fri, 06 Sep 2019 16:41:36 +0300
commit

43b3f0ace1456e6cc16a5a5f237c80d3338a2b45

parent

ffe77fb717d3cda2df08269a6362c49ccab11ebf

3 files changed, 30 insertions(+), 4 deletions(-)

jump to
M helpers.gohelpers.go

@@ -679,7 +679,16 @@ CallbackData: &data,

} } -// 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{
M helpers_test.gohelpers_test.go

@@ -136,6 +136,23 @@ t.Fail()

} } +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")
M types.gotypes.go

@@ -476,9 +476,9 @@

// 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