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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,11 +50,12 @@ 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,
|
||||||
|
Filename: filename,
|
||||||
Bytes: base64.StdEncoding.EncodeToString(data),
|
Bytes: base64.StdEncoding.EncodeToString(data),
|
||||||
Caption: caption,
|
Caption: caption,
|
||||||
ReplyID: original,
|
ReplyID: original,
|
||||||
|
|
|
@ -48,6 +48,7 @@ type ClientTextMessageData struct {
|
||||||
type ClientPhotoData struct {
|
type ClientPhotoData struct {
|
||||||
ChatID int
|
ChatID int
|
||||||
Bytes string
|
Bytes string
|
||||||
|
Filename string
|
||||||
Caption *string `json:",omitempty"`
|
Caption *string `json:",omitempty"`
|
||||||
ReplyID *int `json:",omitempty"`
|
ReplyID *int `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue