From e51fe7f41938d0ad7ce9f67d78c17131f1be26c6 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Thu, 13 Dec 2018 13:41:58 +0100 Subject: [PATCH] Add edit media support --- command.go | 14 ++++++++++++++ telegram.go | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/command.go b/command.go index b5f3fcd..107be53 100644 --- a/command.go +++ b/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 @@ -96,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 diff --git a/telegram.go b/telegram.go index 896ea4f..ae279d8 100644 --- a/telegram.go +++ b/telegram.go @@ -213,6 +213,29 @@ func (t Telegram) AnswerCallback(data ClientCallbackQueryData) { 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)