Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,15 @@ func NewInlineKeyboardButtonData(text, data string) InlineKeyboardButton {
}
}

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

// NewInlineKeyboardButtonURL creates an inline keyboard button with text
// which goes to a URL.
func NewInlineKeyboardButtonURL(text, url string) InlineKeyboardButton {
Expand Down
17 changes: 17 additions & 0 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
6 changes: 3 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down