Added AnswerWebApp for using in a Handle method

pull/509/head
Mikhail Borovikov 2 years ago
parent c4abfac25d
commit 2c2e8dcff1

@ -409,6 +409,10 @@ func (b *Bot) ProcessUpdate(u Update) {
return
}
if m.WebAppData != nil {
b.handle(OnWebApp, c)
}
if m.ProximityAlert != nil {
b.handle(OnProximityAlert, c)
return
@ -1087,6 +1091,29 @@ func (b *Bot) Respond(c *Callback, resp ...*CallbackResponse) error {
return err
}
// AnswerWebApp sends a response for a query from Web App and returns
// information about an inline message sent by a Web App on behalf of a user
func (b *Bot) AnswerWebApp(query *Query, resp *WebAppQueryResponse) (SentWebAppMessage, error) {
resp.WebAppQueryID = query.ID
resp.Result.Process(b)
data, err := b.Raw("answerWebAppQuery", resp)
if err != nil {
return SentWebAppMessage{}, err
}
var response struct {
Result SentWebAppMessage
}
if err := json.Unmarshal(data, &response); err != nil {
return SentWebAppMessage{}, wrapError(err)
}
return response.Result, err
}
// FileByID returns full file object including File.FilePath, allowing you to
// download the file from the server.
//

@ -145,6 +145,10 @@ type Context interface {
// See Respond from bot.go.
Respond(resp ...*CallbackResponse) error
// AnswerWebApp sends a response to the Web App query.
// See AnswerWebApp from bot.go.
AnswerWebApp(resp *WebAppQueryResponse) error
// Get retrieves data from the context.
Get(key string) interface{}
@ -454,6 +458,14 @@ func (c *nativeContext) Respond(resp ...*CallbackResponse) error {
return c.b.Respond(c.u.Callback, resp...)
}
func (c *nativeContext) AnswerWebApp(resp *WebAppQueryResponse) error {
if c.u.Query == nil {
return errors.New("telebot: context inline query is nil")
}
_, err := c.b.AnswerWebApp(c.u.Query, resp)
return err
}
func (c *nativeContext) Set(key string, value interface{}) {
c.lock.Lock()
defer c.lock.Unlock()

@ -137,3 +137,15 @@ func inferIQR(result Result) error {
return nil
}
// WebAppQueryResponse builds a response to an web app query.
type WebAppQueryResponse struct {
// (Required) Unique identifier for the query to be answered
WebAppQueryID string `json:"web_app_query_id"`
// (Required) A object describing the message to be sent
Result Result `json:"result"`
}
type SentWebAppMessage struct {
InlineMessageID string `json:"inline_message_id"`
}

@ -134,6 +134,9 @@ const (
// Will fire on auto delete timer set.
OnAutoDeleteTimer = "\amessage_auto_delete_timer_changed"
// Will fire on the web app data.
OnWebApp = "\aweb_app"
)
// ChatAction is a client-side status indicating bot activity.

Loading…
Cancel
Save