Add edit media support

This commit is contained in:
Hamcha 2018-12-13 13:41:58 +01:00
parent 462f289121
commit e51fe7f419
Signed by: hamcha
GPG Key ID: A40413D21021EAEE
2 changed files with 37 additions and 0 deletions

View File

@ -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

View File

@ -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)