Search code examples
node.jsevent-handlingbotframeworkbotkitadaptive-cards

Bot Framework Event for Postbacks?


My question:

I have an adaptive card with a postback button whose value is say "thisIsMyPostback". Now, I want to act on this postback as one would.

The problem is that this postback can also be typed out to reach the same result. In other words, clicking the button and also just messaging my bot "thisIsMyPostback" straight up result in the same thing.

Is there a way to separate a postback message from a 'message_received'? That way a user messaging "thisIsMyPostback" straight up would not result in the same thing as clicking the button.

Thanks!


Solution

  • The Adaptive Cards readme on the BotFramework WebChat GitHub repo GitHub repo states:

    The data property of the action may be a string or it may be an object. A string is passed back to your bot as a Bot Builder SDK imBack activity, and an object is passed as a postBack activity. Activities with imBack appear in the chat stream as a user-entered reply. The postBack activities are not displayed.

    "actions": [
              {
                "type": "Action.Submit",
                "title": "Next",
                "data": { "postBack": "thisIsMyPostback" }
              }
            ]
    

    If the value of the Activity doesn't have an object, then the user did not click the button.