本文整理汇总了Golang中github.com/tucnak/telebot.Bot.SendPhoto方法的典型用法代码示例。如果您正苦于以下问题:Golang Bot.SendPhoto方法的具体用法?Golang Bot.SendPhoto怎么用?Golang Bot.SendPhoto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tucnak/telebot.Bot
的用法示例。
在下文中一共展示了Bot.SendPhoto方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Send
func (img *Image) Send(bot *telebot.Bot, msg telebot.Message) (err error) {
if img == nil {
warning := "You are trying to call a method of inexistent object :-)"
bot.SendMessage(msg.Chat, warning, nil)
return errors.New(warning)
}
img.Filename = fmt.Sprint("assets/", msg.ID, img.Ext)
if img.Filename == "" {
bot.SendMessage(msg.Chat, "There's any filename associated to this query.", nil)
return errors.New("There's any filename associated to this query.")
}
i, err := telebot.NewFile(img.Filename)
if err != nil {
return err
}
caption := img.Caption[:int(math.Min(float64(len(img.Caption)), MaxCaption))]
photo := telebot.Photo{Thumbnail: telebot.Thumbnail{File: i, Width: img.Width, Height: img.Height}, Caption: caption}
err = bot.SendPhoto(msg.Chat, &photo, &telebot.SendOptions{ReplyTo: msg})
if err != nil {
return err
}
return nil
}
示例2: SendPhoto
func SendPhoto(url string, message telebot.Message, bot *telebot.Bot) error {
imagefile, err := SaveImage(url)
if err != nil {
log.Println("Error fetching ")
log.Println(err)
bot.SendMessage(message.Chat, url, nil)
return err
}
defer os.Remove(imagefile)
var photo = telebot.Photo{}
photo.Thumbnail.File, err = telebot.NewFile(imagefile)
if err != nil {
log.Println("Error creating the new file ")
log.Println(err)
bot.SendMessage(message.Chat, url, nil)
return err
}
//photo.filename=imagefile
err = bot.SendPhoto(message.Chat, &photo, nil)
if err != nil {
log.Println("Error sending photo")
log.Println(err)
bot.SendMessage(message.Chat, url, nil)
return err
}
return err
}