Fix message parsing from requests

This commit is contained in:
Hamcha 2019-08-26 10:40:36 +02:00
parent 91c6b62afb
commit 27464fcee7
Signed by: hamcha
GPG key ID: 44AD3571EB09A39E
2 changed files with 16 additions and 6 deletions

10
api.go
View file

@ -233,3 +233,13 @@ type APICallbackQuery struct {
ChatID string `json:"chat_instance"` ChatID string `json:"chat_instance"`
Data *string `json:"data,omitempty"` Data *string `json:"data,omitempty"`
} }
type apiMessageResponse struct {
Ok bool `json:"ok"`
Result APIMessage `json:"result"`
}
type apiAlbumResponse struct {
Ok bool `json:"ok"`
Result []APIMessage `json:"result"`
}

View file

@ -101,10 +101,10 @@ func (t Telegram) SendTextMessage(data ClientTextMessageData) (APIMessage, error
} }
defer resp.Body.Close() defer resp.Body.Close()
var out APIMessage var out apiMessageResponse
err = json.NewDecoder(resp.Body).Decode(&out) err = json.NewDecoder(resp.Body).Decode(&out)
checkerr("SendTextMessage/json.Decode", err) checkerr("SendTextMessage/json.Decode", err)
return out, err return out.Result, err
} }
// SendPhoto sends a picture to a chat as a photo // SendPhoto sends a picture to a chat as a photo
@ -157,10 +157,10 @@ func (t Telegram) SendPhoto(data ClientPhotoData) (APIMessage, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
var out APIMessage var out apiMessageResponse
err = json.NewDecoder(resp.Body).Decode(&out) err = json.NewDecoder(resp.Body).Decode(&out)
checkerr("SendPhoto/json.Decode", err) checkerr("SendPhoto/json.Decode", err)
return out, err return out.Result, err
} }
// SendAlbum sends an album of photos or videos // SendAlbum sends an album of photos or videos
@ -187,10 +187,10 @@ func (t Telegram) SendAlbum(data ClientAlbumData) ([]APIMessage, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
var out []APIMessage var out apiAlbumResponse
err = json.NewDecoder(resp.Body).Decode(&out) err = json.NewDecoder(resp.Body).Decode(&out)
checkerr("SendAlbum/json.Decode", err) checkerr("SendAlbum/json.Decode", err)
return out, err return out.Result, err
} }
// ForwardMessage forwards an existing message to a chat // ForwardMessage forwards an existing message to a chat