Merge pull request #55 from sschepens/master

Add AnswerCallbackQuery
pull/59/head
Ian Byrd 8 years ago committed by GitHub
commit 43fb1c544e

@ -592,3 +592,31 @@ func (b *Bot) AnswerInlineQuery(query *Query, response *QueryResponse) error {
return nil
}
// AnswerCallbackQuery sends a response for a given callback query. A callback can
// only be responded to once, subsequent attempts to respond to the same callback
// will result in an error.
func (b *Bot) AnswerCallbackQuery(callback *Callback, response *CallbackResponse) error {
response.CallbackID = callback.ID
responseJSON, err := sendCommand("answerCallbackQuery", b.Token, response)
if err != nil {
return err
}
var responseRecieved struct {
Ok bool
Description string
}
err = json.Unmarshal(responseJSON, &responseRecieved)
if err != nil {
return err
}
if !responseRecieved.Ok {
return fmt.Errorf("telebot: %s", responseRecieved.Description)
}
return nil
}

@ -177,6 +177,21 @@ type Callback struct {
Data string `json:"data"`
}
// CallbackResponse builds a response to an Callback query.
// See also: https://core.telegram.org/bots/api#answerCallbackQuery
type CallbackResponse struct {
// The ID of the callback to which this is a response.
// It is not necessary to specify this field manually.
CallbackID string `json:"callback_query_id"`
// Text of the notification. If not specified, nothing will be shown to the user.
Text string `json:"text,omitempty"`
// (Optional) If true, an alert will be shown by the client instead
// of a notification at the top of the chat screen. Defaults to false.
ShowAlert bool `json:"show_alert,omitempty"`
}
// Venue object represents a venue location with name, address and optional foursquare id.
type Venue struct {
Location Location `json:"location"`

Loading…
Cancel
Save