Skip to content

Instantly share code, notes, and snippets.

@surajsau
Last active January 7, 2019 06:48
Show Gist options
  • Save surajsau/491bb715dcc8caeda40552128ba671cf to your computer and use it in GitHub Desktop.
Save surajsau/491bb715dcc8caeda40552128ba671cf to your computer and use it in GitHub Desktop.
Cases Intent (Dailyrounds Assitant)
/**
* This handles 'Latest 10 cases in Radiology' from the user. It receives
* $rounds_pref (from rounds_preference entity) as in which speciality is being asked for,
* $cases tells total number of cases asked for
* $is_best_cases tells whether the user wants 'Top' or 'Best' cases
*/
app.intent('cases', (conv, {rounds_pref, cases, is_best_cases}) => {
//default 5 cases
if(!cases)
cases = 5;
//choose 'best' from rounds_map if 'Top' or 'Best' cases
//are asked for
if(is_best_cases)
rounds_pref = 'best';
const savedRoundsPref = conv.user.storage.rounds;
//$rounds_pref was not found and also the user hasn't saved his preference
if(!conv.contexts.get('name_permission-followup') && !rounds_pref && !savedRoundsPref) {
conv.ask(`We don't seem to know your preference of speciality. Would you like us to remember that for you?`);
return conv.ask(new Suggestions('Yes', 'No'));
} else {
const rounds = (!rounds_pref) ? ((!savedRoundsPref) ? rounds_map['primary'] : savedRoundsPref) : rounds_map[rounds_pref];
/**
* Check whether the current platform on which Google Assistant is running
* has a display capability.
*/
if(!conv.surface.capabilities.has('actions.capability.SCREEN_OUTPUT'))
return conv.close('Sorry we cannot run on Google Home at the moment');
return fetchCasesAndDisplay(rounds, cases, conv);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment