Skip to content

Commit

Permalink
Adaptive Cards sample - Process Submit Action
Browse files Browse the repository at this point in the history
  • Loading branch information
pcostantini committed Jun 9, 2017
1 parent 47557d8 commit 851e953
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions Node/cards-AdaptiveCards/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,9 @@ server.post('/api/messages', connector.listen());
var bot = new builder.UniversalBot(connector, function (session) {

if (session.message && session.message.value) {
// receiving a card submit action
var value = session.message.value;

// Search, vlaidate parameters
if (value.type === 'hotelSearch') {
if (validateHotelSearch(session.message.value)) {
// proceed to search
return session.beginDialog('hotels-search', session.message.value);
}
}

// Hotel selection
if (value.type === 'hotelSelection') {
return sendHotelSelection(session, session.message.value);
}

// A form data was recieved, invalid or incomplete since the previous validation did not pass
return session.send('Please complete all the search parameters');
// A Card's Submit Action obj was received
processSubmitAction(session, session.message.value);
return;
}

// Display Welcome card with Hotels and Flights search options
Expand Down Expand Up @@ -189,6 +174,30 @@ bot.on('error', function (e) {
console.log('And error ocurred', e);
});

function processSubmitAction(session, value) {
var defaultErrorMessage = 'Please complete all the search parameters';
switch (value.type) {
case 'hotelSearch':
// Search, validate parameters
if (validateHotelSearch(value)) {
// proceed to search
session.beginDialog('hotels-search', value);
} else {
session.send(defaultErrorMessage);
}
break;

case 'hotelSelection':
// Hotel selection
sendHotelSelection(session, value);
break;

default:
// A form data was received, invalid or incomplete since the previous validation did not pass
session.send(defaultErrorMessage);
}
}

function validateHotelSearch(hotelSearch) {
if (!hotelSearch) {
return false;
Expand Down

0 comments on commit 851e953

Please sign in to comment.