[Card Actions] How to generate action type to be processed by bot?
Hi, I am trying to find for HeroCard how to specify the Action.Submit type and string to be executed when a button is pressed. In AdaptiveCard this is done in the JSON:
"selectAction": {
"type": "Action.Submit",
"text": "Choose",
"data": {
"type": `edit-reservation-id-${id}`
}
}
Where edit-reservation-id-${id} is the "type" string that is then caught by the bot by following function:
function processSubmitAction(session, value) {
var defaultErrorMessage = 'Please complete all the search parameters';
var option = value.type;
session.userData.chosenOption = value.type;
option = option.substr(0,14);
switch (option) {
case 'reserve-option':
session.beginDialog('reservation');
break;
case 'edit-reservati':
session.beginDialog('editovatRezervaci');
break;
case 'cancel-reserva':
session.beginDialog('zrusitRezervaci');
break;
default:
session.send(defaultErrorMessage);
}
}
Or is there some other way how to specify what should happen once I press a button?
I have tried two possibilities according to this docs: https://github.com/Microsoft/BotBuilder/blob/7b70cfd/Node/core/lib/botbuilder.d.ts#L2136
1)
var action = new builder.CardAction(session)
.type(`reserve-option-${index}-room-${roomNo}`)
.title(`Z${roomNo}`)
.image(roomToImage[roomNo]);
2)
var action = builder.CardAction
.postBack(session,`reserve-option-${index}-room-${roomNo}`,`Z${roomNo}`);
Check out this documentation for more info. Generally how people handle this is with the imBack or postBack action. This contains a value parameter which you can set to any string you like then you can have logic to "catch" that message in your code and handle it however you need to. Since it looks like you are using a variable in the value field you may have to use some regex.
Thanks a lot
Also note that you can either use imBack which outputs the trigger string into dialog, or postBack which is silent