Maybe this is explained somewhere else but using the Bot Framework it took me several days to actually understand that the Action.Submit response was supposed to be parsed and analyzed inside the very same dialog step that called the Action.Submit action.
The documentation is very broad on this and just says that the originator will get the response.
Thanks for the feedback, we definitely want to make sure our docs are approachable especially for common scenarios like handling actions.
I can add action handling to our Getting Started page as well.
@danmarshall is this scenario documented in BF somewhere that I should link to from Adaptive Cards docs?
@matthidinger That would be great. Please take it as constructive criticism as I love BT and AC too. But sometimes it feels the docs assume a lot of background knowledge like restify, middleware chains, events, etc. Apologize if this is a too simple question but it drove me mad several days.
BT does not have this particular scenario handled either. I haven't seen any example at least that handles input data like this.
I am leaving my code here just in case it either helps understanding the issue or just for somebody in the future visiting the issue (Check the first IF):
bot.dialog("requestLocation", [
function(session, args, next){
//This is the snippet that took me a while to find and understand this is where you are supposed to capture the Submit.Action response, I was assuming the Submit will skip to the next middleware chain instead of waiting in the same dialog step.
if (session.message && session.message.value) {
session.endDialogWithResult({location: session.message.value});
return; //Without this, the dialog kept repeating even after the endDialog
}
let dropdown = {};
let attachments = [];
let attachment = {};
attachment.contentType = "application/vnd.microsoft.card.adaptive";
attachment.content = {
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Input.ChoiceSet",
"id": "location",
"style": "compact",
"placeholder": "Choose your zone",
"value": "-1",
"choices": [
{
"title": "Zone 1",
"value": "1"
},
{
"title": "Zone 2",
"value": "2"
},
[...]
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Send"
}
]
};
attachments.push(attachment);
dropdown.type = "message";
dropdown.text = "What is your zone?";
dropdown.attachments = attachments;
session.send(dropdown);
}
]);
@sfratini thanks for working this out, and thanks for letting us know.
@matthidinger - I've let our docs team know, maybe you will want to add links to BotBuilder samples:
@danmarshall Excellent. I might have seen that example some weeks ago and I "fixed" my code by memory.
Only one question/comment about this: "When using the Submit method, the Bot Framework will handle the submission and your bot will receive a new message with its value field filled with the form data as a JSON object."
So, in the example link the message is received by the default/root dialog and in my case I am trapping it in another child dialog. I am assuming that the activity is sent to the current middleware chain step (if the dialogs are handled like that) and not to the root dialog. Meaning that the current dialog step will wait for the user response.
Thanks both!
@danmarshall @matthidinger Just a FYI, this is related: https://github.com/Microsoft/BotBuilder/issues/2715
It seems confusing that the action response from AdaptiveCards is taken from session.message.value and the response from HeroCards is from session.message.text.
But now I understand this is the correct way of handling action responses.
@sfratini yes, this behavior stems from the fact that AC can pass a complex object and "legacy" BotBuilder used only strings.
@sfratini , now response from AdaptiveCards is taken from session.message.text.
@hardlin3r Do you have a link for that? I need to remember not to update the modules then.
@sfratini , i have these dependencies:
"dependencies": {
"@types/restify": "^5.0.6",
"adaptivecards": "^1.0.0-beta2",
"botbuilder": "^3.11.0",
"restify": "^6.2.3",
"typescript": "^2.6.1"
},
"devDependencies": {
"@types/chai": "^4.0.5",
"@types/mocha": "^2.2.44",
"@types/node": "^8.0.53",
"bot-tester": "^3.2.2",
"chai": "^4.1.2",
"mocha": "^4.0.1",
"ts-node": "^3.3.0"
}
and i get response from Action.Submit in session.message.text.