go-telegram-bot-api / telegram-bot-api

Golang bindings for the Telegram Bot API
https://go-telegram-bot-api.dev
MIT License
5.58k stars 863 forks source link

FileID of Photo #623

Closed Maestrodesu closed 1 year ago

Maestrodesu commented 1 year ago

Why is there update.Message.Video.FileID and update.Message.Document.FileID but no update.Message.Photo.FileID? How can i get photo file id?

realtemirov commented 1 year ago

if you want to get user photos use bot.GetUserProfilePhotos(), pass tg.UserProfilePhotosConfig as parameter, respone will return as update.Message.Photo and TotalCount. This type has a Photos [][]PhotoSize json:"photos" field, of which [1][2] 1) number of pictures by index 2) size of pictures (the size you want) recommended =>

    p := Photos
    fileID := p[0][len(p) - 1].FileID

fileID := update.Message.Photo[0].FileID The highest size is taken

Maestrodesu commented 1 year ago

It's working, thanks!

Maestrodesu commented 1 year ago

Example below will download the highest size of picture, which user sent to you

if update.Message.Photo != nil {
    p := update.Message.Photo
    fileID := p[len(p)-1].FileID
    bot.GetFileDirectURL(fileID)
}