Skip to content

fix add sticker to stickerset uploads by url and fileId #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,30 +208,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
if !apiResp.Ok {
var parameters ResponseParameters

err = json.Unmarshal(bytes, &apiResp)
if err != nil {
return APIResponse{}, err
}
if apiResp.Parameters != nil {
parameters = *apiResp.Parameters
}

if !apiResp.Ok {
return APIResponse{}, errors.New(apiResp.Description)
return apiResp, Error{
Message: apiResp.Description,
ResponseParameters: parameters,
}
}

return apiResp, nil
Expand Down
8 changes: 6 additions & 2 deletions configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,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.
Expand Down Expand Up @@ -1417,7 +1419,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.
Expand Down