telegram-bot-api icon indicating copy to clipboard operation
telegram-bot-api copied to clipboard

Edit functions for text and image messages

Open NikolayUvarov opened this issue 3 years ago • 6 comments

Hello! There is possibility to edit already sent messages both text and image, but I cannot found details in documentation, please help.

NikolayUvarov avatar Jan 15 '22 19:01 NikolayUvarov

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.

cmaglie avatar Apr 24 '22 12:04 cmaglie

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)

NikolayUvarov avatar May 01 '22 16:05 NikolayUvarov

Looking into it as well... Any inputs on this?

AdamRussak avatar Oct 21 '22 13:10 AdamRussak

anyone solved this?

selfmakeit avatar Aug 02 '23 10:08 selfmakeit

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.

Thanks!

drrainlab avatar Aug 09 '23 18:08 drrainlab

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)
	}

cmaglie avatar Aug 09 '23 18:08 cmaglie