-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanswer_webapp.go
More file actions
51 lines (41 loc) · 1.29 KB
/
Copy pathanswer_webapp.go
File metadata and controls
51 lines (41 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package botapi
import (
"context"
"github.com/gotd/td/tg"
)
// SentWebAppMessage describes an inline message sent by a Web App on behalf of a
// user.
type SentWebAppMessage struct {
// InlineMessageID is the identifier of the sent inline message, present only
// if the message has a reply markup with at least one callback or inline
// query button.
InlineMessageID string `json:"inline_message_id,omitempty"`
}
// AnswerWebAppQuery sets the result of an interaction with a Web App and sends a
// corresponding message on behalf of the user to the chat from which the query
// originated. webAppQueryID is the query id from the Web App.
func (b *Bot) AnswerWebAppQuery(ctx context.Context, webAppQueryID string, result InlineQueryResult) (*SentWebAppMessage, error) {
if result == nil {
return nil, errNilInlineResult()
}
converted, err := result.toTg(ctx, b)
if err != nil {
return nil, err
}
res, err := b.raw.MessagesSendWebViewResultMessage(ctx, &tg.MessagesSendWebViewResultMessageRequest{
BotQueryID: webAppQueryID,
Result: converted,
})
if err != nil {
return nil, asAPIError(err)
}
out := &SentWebAppMessage{}
if id, ok := res.GetMsgID(); ok {
enc, err := encodeInlineMessageID(id)
if err != nil {
return nil, err
}
out.InlineMessageID = enc
}
return out, nil
}