Skip to content

Commit 43b3f0a

Browse files
committed
Add helper for InlineKeyboardButtonLoginURL
1 parent ffe77fb commit 43b3f0a

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

helpers.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,16 @@ func NewInlineKeyboardButtonData(text, data string) InlineKeyboardButton {
679679
}
680680
}
681681

682-
// NewInlineKeyboardButtonURL creates an inline keyboard button with text
682+
// NewInlineKeyboardButtonLoginURL creates an inline keyboard button with text
683+
// which goes to a LoginURL.
684+
func NewInlineKeyboardButtonLoginURL(text string, loginUrl LoginURL) InlineKeyboardButton {
685+
return InlineKeyboardButton{
686+
Text: text,
687+
LoginURL: &loginUrl,
688+
}
689+
}
690+
691+
// NewInlineKeyboardButtonLoginURL creates an inline keyboard button with text
683692
// which goes to a URL.
684693
func NewInlineKeyboardButtonURL(text, url string) InlineKeyboardButton {
685694
return InlineKeyboardButton{

helpers_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,23 @@ func TestNewInlineQueryResultLocation(t *testing.T) {
136136
}
137137
}
138138

139+
func TestNewInlineKeyboardButtonLoginURL(t *testing.T) {
140+
result := NewInlineKeyboardButtonLoginURL("text", LoginURL{
141+
URL: "url",
142+
ForwardText: "ForwardText",
143+
BotUsername: "username",
144+
RequestWriteAccess: false,
145+
})
146+
147+
if result.Text != "text" ||
148+
result.LoginURL.URL != "url" ||
149+
result.LoginURL.ForwardText != "ForwardText" ||
150+
result.LoginURL.BotUsername != "username" ||
151+
result.LoginURL.RequestWriteAccess != false {
152+
t.Fail()
153+
}
154+
}
155+
139156
func TestNewEditMessageText(t *testing.T) {
140157
edit := NewEditMessageText(ChatID, ReplyToMessageID, "new text")
141158

types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,9 @@ type InlineKeyboardButton struct {
476476
// LoginURL is the parameters for the login inline keyboard button type.
477477
type LoginURL struct {
478478
URL string `json:"url"`
479-
ForwardText string `json:"forward_text"`
480-
BotUsername string `json:"bot_username"`
481-
RequestWriteAccess bool `json:"request_write_access"`
479+
ForwardText string `json:"forward_text,omitempty"`
480+
BotUsername string `json:"bot_username,omitempty"`
481+
RequestWriteAccess bool `json:"request_write_access,omitempty"`
482482
}
483483

484484
// CallbackQuery is data sent when a keyboard button with callback data

0 commit comments

Comments
 (0)