From b8cc28a9be80fce59d07f8ff724e6f8e892d8bcc Mon Sep 17 00:00:00 2001 From: Demian Date: Thu, 6 Oct 2022 01:00:11 +0300 Subject: [PATCH] markup: add WebApp to the Btn --- markup.go | 9 ++++++++- options_test.go => markup_test.go | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) rename options_test.go => markup_test.go (94%) diff --git a/markup.go b/markup.go index 8b71596..ae7ca0f 100644 --- a/markup.go +++ b/markup.go @@ -89,6 +89,7 @@ type Btn struct { Location bool `json:"request_location,omitempty"` Poll PollType `json:"request_poll,omitempty"` Login *Login `json:"login_url,omitempty"` + WebApp *WebApp `json:"web_app,omitempty"` } // 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} } +func (r *ReplyMarkup) WebApp(text string, app *WebApp) Btn { + return Btn{Text: text, WebApp: app} +} + // ReplyButton represents a button displayed in reply-keyboard. // // Set either Contact or Location to true in order to request @@ -230,8 +235,8 @@ type InlineButton struct { Data string `json:"callback_data,omitempty"` InlineQuery string `json:"switch_inline_query,omitempty"` InlineQueryChat string `json:"switch_inline_query_current_chat"` - WebApp *WebApp `json:"web_app,omitempty"` Login *Login `json:"login_url,omitempty"` + WebApp *WebApp `json:"web_app,omitempty"` } // MarshalJSON implements json.Marshaler interface. @@ -274,6 +279,7 @@ func (b Btn) Reply() *ReplyButton { Contact: b.Contact, Location: b.Location, Poll: b.Poll, + WebApp: b.WebApp, } } @@ -286,6 +292,7 @@ func (b Btn) Inline() *InlineButton { InlineQuery: b.InlineQuery, InlineQueryChat: b.InlineQueryChat, Login: b.Login, + WebApp: b.WebApp, } } diff --git a/options_test.go b/markup_test.go similarity index 94% rename from options_test.go rename to markup_test.go index 30029e4..fb5fbb4 100644 --- a/options_test.go +++ b/markup_test.go @@ -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", 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", WebApp: &WebApp{URL: "url"}}, r.WebApp("T", &WebApp{URL: "url"}).Inline()) } func TestOptions(t *testing.T) {