Messages

Editing & deleting

Edit body, edit media, edit keyboard, delete. All four are one call each and accept the same flexible peer id forms as everything else.

Editing text

client.EditMessage(peerID, msgID, "updated body")
client.EditMessage(peerID, msgID, "updated body")

Or, if you held the original return value, edit through it — gogram already knows the peer and message id:

m, _ := client.SendMessage("me", "wait")
m.Edit("done")
m, _ := client.SendMessage("me", "wait")
m.Edit("done")

All SendOptions fields that make sense for an edit apply: ParseMode, LinkPreview, InvertMedia, ReplyMarkup, Entities.

Editing media

Replace a photo with another photo, swap a document for a different document, change a video. Pass the new media as Media on SendOptions:

client.EditMessage(peerID, msgID, "new caption", &telegram.SendOptions{
	Media: "./new-photo.jpg",
})
client.EditMessage(peerID, msgID, "new caption", &telegram.SendOptions{
	Media: "./new-photo.jpg",
})

The kind of media must match: you cannot edit a text message into a photo or vice versa. For that, delete the original and send a fresh one.

Editing the inline keyboard

Most common in callback handlers: the user clicked a button, you want to change the row to show a new state.

client.EditMessage(peerID, msgID, "voted!", &telegram.SendOptions{
	ReplyMarkup: telegram.NewKeyboard().Row(
		telegram.Button.Data("Undo", "undo:"+strconv.Itoa(int(msgID))),
	).Build(),
})
client.EditMessage(peerID, msgID, "voted!", &telegram.SendOptions{
	ReplyMarkup: telegram.NewKeyboard().Row(
		telegram.Button.Data("Undo", "undo:"+strconv.Itoa(int(msgID))),
	).Build(),
})

Pass the new ReplyMarkup; an empty markup clears the keyboard.

Deleting

client.DeleteMessages(peerID, []int32{msgID})

// or via the helper:
m.Delete()
client.DeleteMessages(peerID, []int32{msgID})

// or via the helper:
m.Delete()

DeleteMessages takes a slice so you can clear up to 100 in one round-trip. The server will silently skip messages that do not exist (already deleted, wrong peer).

Server-side limits

  • Edits are allowed for 48 hours after a message is sent — longer for the message author in private chats. Past that, you get MESSAGE_EDIT_TIME_EXPIRED.
  • Bots can only edit messages they sent themselves.
  • Bots can delete any message in a chat where they are admins with delete permission; otherwise only messages they sent within the last 48 hours.
  • Editing rate is roughly 5 edits/second per chat across all messages before flood waits kick in.