Maybe this will fix things

This commit is contained in:
Hamcha 2016-02-20 22:49:50 +01:00
parent f1e09612cb
commit f15f8dcef2
4 changed files with 15 additions and 11 deletions

View File

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

View File

@ -167,7 +167,7 @@ func memegen(broker *tg.Broker, update tg.APIMessage) {
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @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)
})
}
}

View File

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

View File

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