Last active
January 7, 2019 07:15
-
-
Save surajsau/d45d0a7429e0921d41f37665b6e9ef9c to your computer and use it in GitHub Desktop.
rounds_preference intent DailyRounds Assistant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This handles when the user has said his/her speciality preference. | |
* This intent can be reached either from 'cases' intent (cases-followup context), | |
* when the speciality preference hasn't been mentioned and assistant asks for it. | |
* Or, when the user says 'Change my speciality preference'. | |
* | |
* In the first case, 'cases-followup' context has exhausted only 1 lifespan until now, | |
* i.e., in answering "Yes" for the question "Would you like us to save your preference?". | |
* So, when 'cases-followup' context exists, it means that it has come from the initial | |
* intent of "Latest 10 cases" and so, we need to proceed with fetching the cases after | |
* saving the speciality preference. | |
* If 'cases-followup' context doesn't exist means it has come from the second case, | |
* where we just save the speciality preference and show him suggestions. | |
*/ | |
app.intent('rounds_preference', (conv, {rounds_pref}) => { | |
//either get it from the users selection from the suggestions given | |
//or from the users input speech/text | |
const roundsPref = conv.arguments.get('OPTION') || rounds_pref; | |
conv.user.storage.rounds = rounds_map[roundsPref]; | |
conv.ask(`We'll remember that for you. You can always ask for cases from any other speciality though or even change your preference anytime.`); | |
if(conv.contexts.get('cases-followup')) { | |
const skipCount = conv.contexts.get('cases-followup').parameters.cases; | |
return fetchCasesAndDisplay(conv.user.storage.rounds, skipCount, conv); | |
} else { | |
conv.ask('So, how can we help you today?'); | |
return conv.ask(new Suggestions(`Today's top 5 cases`)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment