|
|
|
@ -99,6 +99,8 @@ type Update struct {
|
|
|
|
|
Query *Query `json:"inline_query,omitempty"`
|
|
|
|
|
|
|
|
|
|
ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"`
|
|
|
|
|
|
|
|
|
|
PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ChosenInlineResult represents a result of an inline query that was chosen
|
|
|
|
@ -113,6 +115,14 @@ type ChosenInlineResult struct {
|
|
|
|
|
Location *Location `json:"location,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PreCheckoutQuery struct {
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
Sender *User `json:"from"`
|
|
|
|
|
Currency string `json:"currency"`
|
|
|
|
|
Total int `json:"total_amount"`
|
|
|
|
|
Payload string `json:"invoice_payload"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle lets you set the handler for some command name or
|
|
|
|
|
// one of the supported endpoints.
|
|
|
|
|
//
|
|
|
|
@ -379,6 +389,24 @@ func (b *Bot) incomingUpdate(upd *Update) {
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if upd.PreCheckoutQuery != nil {
|
|
|
|
|
if handler, ok := b.handlers[OnCheckout]; ok {
|
|
|
|
|
if handler, ok := handler.(func(*PreCheckoutQuery)); ok {
|
|
|
|
|
// i'm not 100% sure that any of the values
|
|
|
|
|
// won't be cached, so I pass them all in:
|
|
|
|
|
go func(b *Bot, handler func(*PreCheckoutQuery),
|
|
|
|
|
r *PreCheckoutQuery) {
|
|
|
|
|
defer b.deferDebug()
|
|
|
|
|
handler(r)
|
|
|
|
|
}(b, handler, upd.PreCheckoutQuery)
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
panic("telebot: checkout handler is bad")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Bot) handle(end string, m *Message) bool {
|
|
|
|
@ -747,6 +775,27 @@ func (b *Bot) Notify(recipient Recipient, action ChatAction) error {
|
|
|
|
|
return extractOkResponse(respJSON)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Accept finalizes the deal.
|
|
|
|
|
func (b *Bot) Accept(query *PreCheckoutQuery, errorMessage ...string) error {
|
|
|
|
|
params := map[string]string{
|
|
|
|
|
"pre_checkout_query_id": query.ID,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(errorMessage) == 0 {
|
|
|
|
|
params["ok"] = "True"
|
|
|
|
|
} else {
|
|
|
|
|
params["ok"] = "False"
|
|
|
|
|
params["error_message"] = errorMessage[0]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
respJSON, err := b.Raw("answerPreCheckoutQuery", params)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return extractOkResponse(respJSON)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Answer sends a response for a given inline query. A query can only
|
|
|
|
|
// be responded to once, subsequent attempts to respond to the same query
|
|
|
|
|
// will result in an error.
|
|
|
|
|