Skip to content

Instantly share code, notes, and snippets.

@reaganmcf
Created August 26, 2018 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reaganmcf/c0d9814435688ffca46a81a83b05b14e to your computer and use it in GitHub Desktop.
Save reaganmcf/c0d9814435688ffca46a81a83b05b14e to your computer and use it in GitHub Desktop.
RemoveChoreIntentHandler updated
/**
* Handler for the RemoveChoreIntent
*/
const RemoveChoreIntentHandler = {
canHandle(handlerInput) {
const { request } = handlerInput.requestEnvelope;
return (
request.type === Requests.INTENT_REQUEST &&
request.intent.name === Intents.REMOVE_CHORE_INTENT
);
},
async handle(handlerInput) {
const { request } = handlerInput.requestEnvelope;
const choreSlot = request.intent.slots.choreName;
let choreName;
if (choreSlot && choreSlot.value) {
choreName = choreSlot.value.toLowerCase();
}
let speakOutput = Messages.ERROR_NO_CHORE_SLOT;
if (choreName) {
const success = await API.removeChore(choreName);
speakOutput = Messages.ERROR_REMOVING_CHORE;
if (success) {
speakOutput = `Successfully removed ${choreName}`;
}
}
return handlerInput.responseBuilder.speak(speakOutput).getResponse();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment