Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper for InlineKeyboardButtonLoginURL #267

Merged
merged 4 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
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