Initial support for callback queries
This commit is contained in:
parent
487ffb1bf7
commit
462f289121
3 changed files with 50 additions and 7 deletions
22
api.go
22
api.go
|
@ -135,9 +135,10 @@ type APILocation struct {
|
||||||
|
|
||||||
// APIUpdate represents the "Update" JSON structure
|
// APIUpdate represents the "Update" JSON structure
|
||||||
type APIUpdate struct {
|
type APIUpdate struct {
|
||||||
UpdateID int64 `json:"update_id"`
|
UpdateID int64 `json:"update_id"`
|
||||||
Message *APIMessage `json:"message"`
|
Message *APIMessage `json:"message"`
|
||||||
Inline *APIInlineQuery `json:"inline_query,omitempty"`
|
Inline *APIInlineQuery `json:"inline_query,omitempty"`
|
||||||
|
Callback *APICallbackQuery `json:"callback_query,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// APIFile represents the "File" JSON structure
|
// APIFile represents the "File" JSON structure
|
||||||
|
@ -185,8 +186,9 @@ type APIInlineKeyboardMarkup struct {
|
||||||
|
|
||||||
// APIInlineKeyboardButton is an inline message button
|
// APIInlineKeyboardButton is an inline message button
|
||||||
type APIInlineKeyboardButton struct {
|
type APIInlineKeyboardButton struct {
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
URL string `json:"url,omitempty"`
|
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
|
// 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"`
|
Caption string `json:"caption,omitempty"`
|
||||||
ParseMode string `json:"parse_mode,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
|
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
|
// ClientAlbumData is the required data for a CmdSendAlbum request
|
||||||
type ClientAlbumData struct {
|
type ClientAlbumData struct {
|
||||||
ChatID int64
|
ChatID int64
|
||||||
|
|
26
telegram.go
26
telegram.go
|
@ -158,10 +158,10 @@ func (t Telegram) SendAlbum(data ClientAlbumData) {
|
||||||
"media": {string(jsonmedia)},
|
"media": {string(jsonmedia)},
|
||||||
}
|
}
|
||||||
if data.Silent {
|
if data.Silent {
|
||||||
postdata["disable_notification"] = []string{"true"}
|
postdata.Set("disable_notification", "true")
|
||||||
}
|
}
|
||||||
if data.ReplyID != nil {
|
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)
|
_, err = http.PostForm(t.apiURL("sendMediaGroup"), postdata)
|
||||||
|
@ -191,6 +191,28 @@ func (t Telegram) SendChatAction(data ClientChatActionData) {
|
||||||
checkerr("SendChatAction/http.PostForm", err)
|
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
|
// AnswerInlineQuery replies to an inline query
|
||||||
func (t Telegram) AnswerInlineQuery(data InlineQueryResponse) error {
|
func (t Telegram) AnswerInlineQuery(data InlineQueryResponse) error {
|
||||||
jsonresults, err := json.Marshal(data.Results)
|
jsonresults, err := json.Marshal(data.Results)
|
||||||
|
|
Loading…
Reference in a new issue