diff --git a/bot.go b/bot.go index f2dccb2..b69c628 100644 --- a/bot.go +++ b/bot.go @@ -218,30 +218,33 @@ func (bot *BotAPI) UploadFile(endpoint string, params Params, fieldname string, ms.SetupRequest(req) - res, err := bot.Client.Do(req) + resp, err := bot.Client.Do(req) if err != nil { return APIResponse{}, err } - defer res.Body.Close() + defer resp.Body.Close() - bytes, err := ioutil.ReadAll(res.Body) + var apiResp APIResponse + bytes, err := bot.decodeAPIResponse(resp.Body, &apiResp) if err != nil { - return APIResponse{}, err + return apiResp, err } if bot.Debug { log.Printf("Endpoint: %s, response: %s\n", endpoint, string(bytes)) } - var apiResp APIResponse - - err = json.Unmarshal(bytes, &apiResp) - if err != nil { - return APIResponse{}, err - } - if !apiResp.Ok { - return APIResponse{}, errors.New(apiResp.Description) + var parameters ResponseParameters + + if apiResp.Parameters != nil { + parameters = *apiResp.Parameters + } + + return apiResp, Error{ + Message: apiResp.Description, + ResponseParameters: parameters, + } } return apiResp, nil diff --git a/configs.go b/configs.go index 4c5846e..997022f 100644 --- a/configs.go +++ b/configs.go @@ -1421,7 +1421,9 @@ func (config UploadStickerConfig) getFile() interface{} { } func (config UploadStickerConfig) useExistingFile() bool { - return false + _, ok := config.PNGSticker.(string) + + return ok } // NewStickerSetConfig allows creating a new sticker set. @@ -1527,7 +1529,9 @@ func (config AddStickerConfig) getFile() interface{} { } func (config AddStickerConfig) useExistingFile() bool { - return false + _, ok := config.PNGSticker.(string) + + return ok } // SetStickerPositionConfig allows you to change the position of a sticker in a set.