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

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

How upload an image? #550

Closed ghost closed 2 years ago

ghost commented 2 years ago

How can I upload an image? In older versions , it could be done like this:

msg := tgbotapi.NewImageUpload(update.Message.Chat.ID, "./io.jpg")
bot.Send(msg)
Gatvik commented 2 years ago

Tag me pls when a solution is found

nicourrrn commented 2 years ago

In new version (5) you need use struct that implements interface RequestFileData. For example FilePath.

photo := tgbotapi.NewPhoto(update.Message.From.ID, tgbotapi.FilePath("maxresdefault.jpg"))
if _, err = bot.Send(photo); err != nil {
    log.Fatalln(err)
}