In Telegram it’s possible to modify an already sent message in the chat history, even a message with buttons. This example flow sends the user a message with two buttons “Yes” and “No” and when one of them is clicked, the buttons are replace by a “Clicked!” button.

Edit Buttons

Edit Buttons

The first Buttons node just sends out the two buttons, see Buttons node for more detail.

The Function node prepares the payload for the the next Conversation node and Buttons node

var chat = msg.chat();
var messageId = chat.get('messageId');
var chatId = chat.get('chatId');
msg.payload = {  
	chatId: chatId,  
	messageId: messageId,  
	buttons: [
		{ type: 'postback', value: 'clicked', label: 'Clicked!' }
	]
};
return msg;

The Conversation node requires a mandatory chatId and an optional messageId to target a specific message in the chat history: in this way the message sent in this conversation will replace the message in the history rather than creating a new one.

The chat context always contains the current chatId and the id of the the last send message (messageId).

The buttons key is the payload for the Buttons node : the button “Clicked!” will then replace the two previous buttons.

Clicked button

Clicked button