Search code examples
botframeworkweb-chat

How to echo clicked button text from Rich cards in web chat


We've developed a bot and are sending rich cards to the client. When a user connects to our bot through web chat and clicks a button within those rich cards, the text of the buttons the user clicked on are not echoed to the chat window as if the user would have typed it himself, unlike messenger for example.

The problem with this is that if the user scrolls up in the conversation, all he sees is text written by the bot and it makes it hard for him to see what choices he's made (what buttons were clicked), and therefore what bot's answers correspond to what choice.


Solution

  • Make sure that the Type of your CardAction (your buttons) is set to imBack. Then fill the Value property with the text you want to show in the chat.

    Per the documentation:

    CardAction.Type: imBack

    CardAction.Value: Text of the message to send to the bot (from the user who clicked the button or tapped the card). This message (from user to bot) will be visible to all conversation participants via the client application that is hosting the conversation.