telegram-bot-api
telegram-bot-api copied to clipboard
Edit functions for text and image messages
Hello! There is possibility to edit already sent messages both text and image, but I cannot found details in documentation, please help.
You must create a EditMessageTextConfig and pass it to the bot.Send(..) method:
msg := tgbotapi.NewEditMessageText(chatId, messageID, "new edited text")
msg.Image = .....
if _, err = bot.Send(msg); err != nil {
panic(err)
}
bot.Send(...) is able to determine the type of action you're doing (send, edit, etc.) and act accordingly.
Unfortunately, there is no such metod "Image" in msg
photoBytesF, err := ioutil.ReadFile("../../pics/picF0M100.jpg") _=err msgM, err := bot.Send(tgbotapi.NewPhoto(update.Message.Chat.ID, photoFileBytesM)) //sent ok time.Sleep(3 * time.Second) msgME := tgbotapi.NewEditMessageText(update.Message.Chat.ID, msgM.MessageID, "msgME") msgME.Image = photoFileBytesM
msgME.Image undefined (type tgbotapi.EditMessageTextConfig has no field or method Image) (exit status 2)
Looking into it as well... Any inputs on this?
anyone solved this?
You must create a
EditMessageTextConfigand pass it to thebot.Send(..)method:msg := tgbotapi.NewEditMessageText(chatId, messageID, "new edited text") msg.Image = ..... if _, err = bot.Send(msg); err != nil { panic(err) }
bot.Send(...)is able to determine the type of action you're doing (send, edit, etc.) and act accordingly.
Thanks!
Thanks!
Actually, as already said, my first solution doesn't allow changing the Image.
It seems that to change the image you must send an editMessageMedia command https://core.telegram.org/bots/api#editmessagemedia. This command seems to be composed through the EditMessageMediaConfig structure, here a totally UNTESTED code:
msg := tgbotapi.EditMessageMediaConfig{
BaseEdit: tgbotapi.BaseEdit{
ChatID: 1,
MessageID: 3,
},
Media: image,
}
if _, err = bot.Send(msg); err != nil {
panic(err)
}