Maybe this will fix things
This commit is contained in:
parent
f1e09612cb
commit
f15f8dcef2
4 changed files with 15 additions and 11 deletions
|
@ -79,7 +79,7 @@ func (t Telegram) SendPhoto(data tg.ClientPhotoData) {
|
||||||
// Write file into multipart buffer
|
// Write file into multipart buffer
|
||||||
body := new(bytes.Buffer)
|
body := new(bytes.Buffer)
|
||||||
writer := multipart.NewWriter(body)
|
writer := multipart.NewWriter(body)
|
||||||
part, err := writer.CreateFormFile("photo", "meme.jpg")
|
part, err := writer.CreateFormFile("photo", data.Filename)
|
||||||
if checkerr("SendPhoto/multipart.CreateFormFile", err) {
|
if checkerr("SendPhoto/multipart.CreateFormFile", err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,8 @@ func (t Telegram) SendPhoto(data tg.ClientPhotoData) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.Header.Add("Content-Type", writer.FormDataContentType())
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
checkerr("SendPhoto/http.Do", err)
|
checkerr("SendPhoto/http.Do", err)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
|
@ -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)
|
broker.SendTextMessage(update.Chat, "<b>ERRORE!</b> @hamcha controlla la console!", &update.MessageID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
broker.SendPhoto(update.Chat, buf.Bytes(), nil, &update.MessageID)
|
broker.SendPhoto(update.Chat, buf.Bytes(), "meme.jpg", nil, &update.MessageID)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
tg/broker.go
11
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.
|
// SendPhoto sends a photo with an optional caption to a chat.
|
||||||
// A reply_to message ID can be specified as optional parameter.
|
// 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{
|
b.sendCmd(ClientCommand{
|
||||||
Type: CmdSendPhoto,
|
Type: CmdSendPhoto,
|
||||||
PhotoData: &ClientPhotoData{
|
PhotoData: &ClientPhotoData{
|
||||||
ChatID: chat.ChatID,
|
ChatID: chat.ChatID,
|
||||||
Bytes: base64.StdEncoding.EncodeToString(data),
|
Filename: filename,
|
||||||
Caption: caption,
|
Bytes: base64.StdEncoding.EncodeToString(data),
|
||||||
ReplyID: original,
|
Caption: caption,
|
||||||
|
ReplyID: original,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,10 +46,11 @@ type ClientTextMessageData struct {
|
||||||
|
|
||||||
// ClientPhotoData is the required data for a CmdSendPhoto request
|
// ClientPhotoData is the required data for a CmdSendPhoto request
|
||||||
type ClientPhotoData struct {
|
type ClientPhotoData struct {
|
||||||
ChatID int
|
ChatID int
|
||||||
Bytes string
|
Bytes string
|
||||||
Caption *string `json:",omitempty"`
|
Filename string
|
||||||
ReplyID *int `json:",omitempty"`
|
Caption *string `json:",omitempty"`
|
||||||
|
ReplyID *int `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileRequestData is the required data for a CmdGetFile request
|
// FileRequestData is the required data for a CmdGetFile request
|
||||||
|
|
Reference in a new issue