markup: add WebApp to the Btn

pull/558/head
Demian 2 years ago
parent d90e8974cc
commit b8cc28a9be

@ -89,6 +89,7 @@ type Btn struct {
Location bool `json:"request_location,omitempty"` Location bool `json:"request_location,omitempty"`
Poll PollType `json:"request_poll,omitempty"` Poll PollType `json:"request_poll,omitempty"`
Login *Login `json:"login_url,omitempty"` Login *Login `json:"login_url,omitempty"`
WebApp *WebApp `json:"web_app,omitempty"`
} }
// Row represents an array of buttons, a row. // Row represents an array of buttons, a row.
@ -193,6 +194,10 @@ func (r *ReplyMarkup) Login(text string, login *Login) Btn {
return Btn{Login: login, Text: text} return Btn{Login: login, Text: text}
} }
func (r *ReplyMarkup) WebApp(text string, app *WebApp) Btn {
return Btn{Text: text, WebApp: app}
}
// ReplyButton represents a button displayed in reply-keyboard. // ReplyButton represents a button displayed in reply-keyboard.
// //
// Set either Contact or Location to true in order to request // Set either Contact or Location to true in order to request
@ -230,8 +235,8 @@ type InlineButton struct {
Data string `json:"callback_data,omitempty"` Data string `json:"callback_data,omitempty"`
InlineQuery string `json:"switch_inline_query,omitempty"` InlineQuery string `json:"switch_inline_query,omitempty"`
InlineQueryChat string `json:"switch_inline_query_current_chat"` InlineQueryChat string `json:"switch_inline_query_current_chat"`
WebApp *WebApp `json:"web_app,omitempty"`
Login *Login `json:"login_url,omitempty"` Login *Login `json:"login_url,omitempty"`
WebApp *WebApp `json:"web_app,omitempty"`
} }
// MarshalJSON implements json.Marshaler interface. // MarshalJSON implements json.Marshaler interface.
@ -274,6 +279,7 @@ func (b Btn) Reply() *ReplyButton {
Contact: b.Contact, Contact: b.Contact,
Location: b.Location, Location: b.Location,
Poll: b.Poll, Poll: b.Poll,
WebApp: b.WebApp,
} }
} }
@ -286,6 +292,7 @@ func (b Btn) Inline() *InlineButton {
InlineQuery: b.InlineQuery, InlineQuery: b.InlineQuery,
InlineQueryChat: b.InlineQueryChat, InlineQueryChat: b.InlineQueryChat,
Login: b.Login, Login: b.Login,
WebApp: b.WebApp,
} }
} }

@ -22,6 +22,7 @@ func TestBtn(t *testing.T) {
assert.Equal(t, &InlineButton{Text: "T", InlineQuery: "q"}, r.Query("T", "q").Inline()) assert.Equal(t, &InlineButton{Text: "T", InlineQuery: "q"}, r.Query("T", "q").Inline())
assert.Equal(t, &InlineButton{Text: "T", InlineQueryChat: "q"}, r.QueryChat("T", "q").Inline()) assert.Equal(t, &InlineButton{Text: "T", InlineQueryChat: "q"}, r.QueryChat("T", "q").Inline())
assert.Equal(t, &InlineButton{Text: "T", Login: &Login{Text: "T"}}, r.Login("T", &Login{Text: "T"}).Inline()) assert.Equal(t, &InlineButton{Text: "T", Login: &Login{Text: "T"}}, r.Login("T", &Login{Text: "T"}).Inline())
assert.Equal(t, &InlineButton{Text: "T", WebApp: &WebApp{URL: "url"}}, r.WebApp("T", &WebApp{URL: "url"}).Inline())
} }
func TestOptions(t *testing.T) { func TestOptions(t *testing.T) {
Loading…
Cancel
Save