Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Last active March 1, 2017 01:03
Show Gist options
  • Select an option

  • Save ajcrites/3dbb77998f33ef9f0700bd4f5f748b07 to your computer and use it in GitHub Desktop.

Select an option

Save ajcrites/3dbb77998f33ef9f0700bd4f5f748b07 to your computer and use it in GitHub Desktop.
app.launch(function(request, response) {
return Promise.resolve().then(() => {
const accessTokenReceived = request.sessionDetails.accessToken;
if (accessTokenReceived === undefined) {
throw 'no_access_token';
}
return user.getUserFromAccessTokenPromise(accessTokenReceived);
}).catch(() => {
throw 'not_good_access_token';
}).then(user => stuff.getStuffFromUserPromise(user).then(stuff => ({stuff, user, userId: user.id})))
.catch(() => {
throw 'no_stuff';
}).then(({userId}) => helper.getStaffUserIdPromise(userId))
.catch(() => {
throw 'error_retrieving_staff';
}).then(() => {
if (numberOfStaff !== 0) {
return response.say(config.dialog.onLaunchIntent.case13.say)
.reprompt(config.dialog.onLaunchIntent.case13.reprompt)
.card(config.dialog.onLaunchIntent.case13.cardTitle, config.dialog.onLaunchIntent.case12.card)
.shouldEndSession(config.dialog.onLaunchIntent.case13.end);
}
throw "no_staff";
})
.catch(err => {
switch (err) {
case "no_access_token":
response.say(config.dialog.onLaunchIntent.case10.say)
.reprompt(config.dialog.onLaunchIntent.case10.reprompt)
.linkAccount()
.shouldEndSession(config.dialog.onLaunchIntent.end);
break;
case "not_good_access_token":
response.say(config.dialog.onLaunchIntent.case10.say)
.reprompt(config.dialog.onLaunchIntent.case10.reprompt)
.linkAccount()
.shouldEndSession(config.dialog.onLaunchIntent.case10.end);
break;
case "no_stuff":
response.say(config.dialog.onLaunchIntent.case11.say)
.reprompt(config.dialog.onLaunchIntent.case11.reprompt)
.card(config.dialog.onLaunchIntent.case11.cardTitle, config.dialog.onLaunchIntent.case11.card)
.shouldEndSession(config.dialog.onLaunchIntent.case11.end);
break;
case "no_staff":
response.say(config.dialog.onLaunchIntent.case12.say)
.reprompt(config.dialog.onLaunchIntent.case12.reprompt)
.card(config.dialog.onLaunchIntent.case12.cardTitle, config.dialog.onLaunchIntent.case12.card)
.shouldEndSession(config.dialog.onLaunchIntent.case12.end);
break;
default:
response.say(config.dialog.onLaunchIntent.case6.say)
.reprompt(config.dialog.onLaunchIntent.case6.reprompt)
.card(config.dialog.onLaunchIntent.case6.cardTitle, config.dialog.onLaunchIntent.case6.card)
.shouldEndSession(config.dialog.onLaunchIntent.case6.end);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment