Compare commits
2 commits
487ffb1bf7
...
e51fe7f419
Author | SHA1 | Date | |
---|---|---|---|
e51fe7f419 | |||
462f289121 |
3 changed files with 87 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"`
|
||||
}
|
||||
|
|
23
command.go
23
command.go
|
@ -47,6 +47,12 @@ const (
|
|||
|
||||
// CmdSendAlbum requests the broker sends an album of photos or videos
|
||||
CmdSendAlbum ClientCommandType = "sendAlbum"
|
||||
|
||||
// CmdAnswerCallback requests the broker to reply to a incoming callback query
|
||||
CmdAnswerCallback ClientCommandType = "answerCallback"
|
||||
|
||||
// CmdEditMedia requests to broker to replace the media contents of a message
|
||||
CmdEditMedia ClientCommandType = "editMedia"
|
||||
)
|
||||
|
||||
// ClientTextMessageData is the required data for a CmdSendTextMessage request
|
||||
|
@ -79,6 +85,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
|
||||
|
@ -87,6 +102,14 @@ type ClientAlbumData struct {
|
|||
ReplyID *int64 `json:",omitempty"`
|
||||
}
|
||||
|
||||
// ClientEditMediaData is the required data for a CmdEditMedia request
|
||||
type ClientEditMediaData struct {
|
||||
ChatID int64
|
||||
MessageID int64
|
||||
Media interface{}
|
||||
ReplyMarkup interface{} `json:",omitempty"`
|
||||
}
|
||||
|
||||
// ChatAction is the action name for CmdSendChatAction requests
|
||||
type ChatAction string
|
||||
|
||||
|
|
49
telegram.go
49
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,51 @@ 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)
|
||||
}
|
||||
|
||||
// EditMedia modifies the media content (like photo) of a message
|
||||
func (t Telegram) EditMedia(data ClientEditMediaData) {
|
||||
jsonmedia, err := json.Marshal(data.Media)
|
||||
if err != nil {
|
||||
checkerr("SendAlbum/json.Marshal", err)
|
||||
}
|
||||
postdata := url.Values{
|
||||
"chat_id": {strconv.FormatInt(data.ChatID, 10)},
|
||||
"message_id": {strconv.FormatInt(data.MessageID, 10)},
|
||||
"media": {string(jsonmedia)},
|
||||
}
|
||||
if data.ReplyMarkup != nil {
|
||||
replyjson, err := json.Marshal(data.ReplyMarkup)
|
||||
if !checkerr("SendTextMessage/json.Marshal", err) {
|
||||
return
|
||||
}
|
||||
postdata["reply_markup"] = []string{string(replyjson)}
|
||||
}
|
||||
|
||||
_, err = http.PostForm(t.apiURL("editMessageMedia"), postdata)
|
||||
checkerr("EditMedia/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