Initial support for callback queries
This commit is contained in:
parent
487ffb1bf7
commit
462f289121
3 changed files with 50 additions and 7 deletions
12
api.go
12
api.go
|
@ -138,6 +138,7 @@ type APIUpdate struct {
|
|||
UpdateID int64 `json:"update_id"`
|
||||
Message *APIMessage `json:"message"`
|
||||
Inline *APIInlineQuery `json:"inline_query,omitempty"`
|
||||
Callback *APICallbackQuery `json:"callback_query,omitempty"`
|
||||
}
|
||||
|
||||
// APIFile represents the "File" JSON structure
|
||||
|
@ -187,6 +188,7 @@ type APIInlineKeyboardMarkup struct {
|
|||
type APIInlineKeyboardButton struct {
|
||||
Text string `json:"text"`
|
||||
URL string `json:"url,omitempty"`
|
||||
CallbackData string `json:"callback_data,omitempty"`
|
||||
}
|
||||
|
||||
// APIInputMediaPhoto is a media photo element (already on telegram servers or via HTTP URL) for albums and other cached pictures
|
||||
|
@ -196,3 +198,13 @@ type APIInputMediaPhoto struct {
|
|||
Caption string `json:"caption,omitempty"`
|
||||
ParseMode string `json:"parse_mode,omitempty"`
|
||||
}
|
||||
|
||||
// APICallbackQuery is a callback query triggered by an inline button
|
||||
type APICallbackQuery struct {
|
||||
ID string `json:"id"`
|
||||
User APIAudio `json:"from"`
|
||||
Message *APIMessage `json:"message,omitempty"`
|
||||
InlineID *string `json:"inline_message_id,omitempty"`
|
||||
ChatID string `json:"chat_instance"`
|
||||
Data *string `json:"data,omitempty"`
|
||||
}
|
||||
|
|
|
@ -79,6 +79,15 @@ type ClientChatActionData struct {
|
|||
Action ChatAction
|
||||
}
|
||||
|
||||
// ClientCallbackQueryData is the required data for a CmdAnswerCallback request
|
||||
type ClientCallbackQueryData struct {
|
||||
QueryID string
|
||||
Text string
|
||||
ShowAlert bool
|
||||
URL string
|
||||
CacheTime int64
|
||||
}
|
||||
|
||||
// ClientAlbumData is the required data for a CmdSendAlbum request
|
||||
type ClientAlbumData struct {
|
||||
ChatID int64
|
||||
|
|
26
telegram.go
26
telegram.go
|
@ -158,10 +158,10 @@ func (t Telegram) SendAlbum(data ClientAlbumData) {
|
|||
"media": {string(jsonmedia)},
|
||||
}
|
||||
if data.Silent {
|
||||
postdata["disable_notification"] = []string{"true"}
|
||||
postdata.Set("disable_notification", "true")
|
||||
}
|
||||
if data.ReplyID != nil {
|
||||
postdata["reply_to_message_id"] = []string{strconv.FormatInt(*(data.ReplyID), 10)}
|
||||
postdata.Set("reply_to_message_id", strconv.FormatInt(*(data.ReplyID), 10))
|
||||
}
|
||||
|
||||
_, err = http.PostForm(t.apiURL("sendMediaGroup"), postdata)
|
||||
|
@ -191,6 +191,28 @@ func (t Telegram) SendChatAction(data ClientChatActionData) {
|
|||
checkerr("SendChatAction/http.PostForm", err)
|
||||
}
|
||||
|
||||
// AnswerCallback stops the progress bar after a callback query is initiated
|
||||
func (t Telegram) AnswerCallback(data ClientCallbackQueryData) {
|
||||
postdata := url.Values{
|
||||
"callback_query_id": {data.QueryID},
|
||||
}
|
||||
if data.Text != "" {
|
||||
postdata.Set("text", data.Text)
|
||||
}
|
||||
if data.URL != "" {
|
||||
postdata.Set("url", data.URL)
|
||||
}
|
||||
if data.ShowAlert {
|
||||
postdata.Set("show_alert", "true")
|
||||
}
|
||||
if data.CacheTime != 0 {
|
||||
postdata.Set("cache_time", strconv.FormatInt(data.CacheTime, 10))
|
||||
}
|
||||
|
||||
_, err := http.PostForm(t.apiURL("answerCallbackQuery"), postdata)
|
||||
checkerr("AnswerCallback/http.PostForm", err)
|
||||
}
|
||||
|
||||
// AnswerInlineQuery replies to an inline query
|
||||
func (t Telegram) AnswerInlineQuery(data InlineQueryResponse) error {
|
||||
jsonresults, err := json.Marshal(data.Results)
|
||||
|
|
Loading…
Reference in a new issue