diff --git a/broker/telegram.go b/broker/telegram.go index 529363d..76cf437 100644 --- a/broker/telegram.go +++ b/broker/telegram.go @@ -79,7 +79,7 @@ func (t Telegram) SendPhoto(data tg.ClientPhotoData) { // Write file into multipart buffer body := new(bytes.Buffer) writer := multipart.NewWriter(body) - part, err := writer.CreateFormFile("photo", "meme.jpg") + part, err := writer.CreateFormFile("photo", data.Filename) if checkerr("SendPhoto/multipart.CreateFormFile", err) { return } @@ -104,6 +104,8 @@ func (t Telegram) SendPhoto(data tg.ClientPhotoData) { return } + req.Header.Add("Content-Type", writer.FormDataContentType()) + resp, err := client.Do(req) checkerr("SendPhoto/http.Do", err) defer resp.Body.Close() diff --git a/mods/memegen.go b/mods/memegen.go index 3b68784..dab843c 100644 --- a/mods/memegen.go +++ b/mods/memegen.go @@ -167,7 +167,7 @@ func memegen(broker *tg.Broker, update tg.APIMessage) { broker.SendTextMessage(update.Chat, "ERRORE! @hamcha controlla la console!", &update.MessageID) return } - broker.SendPhoto(update.Chat, buf.Bytes(), nil, &update.MessageID) + broker.SendPhoto(update.Chat, buf.Bytes(), "meme.jpg", nil, &update.MessageID) }) } } diff --git a/tg/broker.go b/tg/broker.go index 6da6804..cc86467 100644 --- a/tg/broker.go +++ b/tg/broker.go @@ -50,14 +50,15 @@ func (b *Broker) SendTextMessage(chat *APIChat, text string, original *int) { // SendPhoto sends a photo with an optional caption to a chat. // A reply_to message ID can be specified as optional parameter. -func (b *Broker) SendPhoto(chat *APIChat, data []byte, caption *string, original *int) { +func (b *Broker) SendPhoto(chat *APIChat, data []byte, filename string, caption *string, original *int) { b.sendCmd(ClientCommand{ Type: CmdSendPhoto, PhotoData: &ClientPhotoData{ - ChatID: chat.ChatID, - Bytes: base64.StdEncoding.EncodeToString(data), - Caption: caption, - ReplyID: original, + ChatID: chat.ChatID, + Filename: filename, + Bytes: base64.StdEncoding.EncodeToString(data), + Caption: caption, + ReplyID: original, }, }) } diff --git a/tg/command.go b/tg/command.go index 452cb4c..c97f7ef 100644 --- a/tg/command.go +++ b/tg/command.go @@ -46,10 +46,11 @@ type ClientTextMessageData struct { // ClientPhotoData is the required data for a CmdSendPhoto request type ClientPhotoData struct { - ChatID int - Bytes string - Caption *string `json:",omitempty"` - ReplyID *int `json:",omitempty"` + ChatID int + Bytes string + Filename string + Caption *string `json:",omitempty"` + ReplyID *int `json:",omitempty"` } // FileRequestData is the required data for a CmdGetFile request