Skip to content

Instantly share code, notes, and snippets.

@reaganmcf
Created August 24, 2018 18:44
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/3487f3bcf662435d0c200199654c5276 to your computer and use it in GitHub Desktop.
Save reaganmcf/3487f3bcf662435d0c200199654c5276 to your computer and use it in GitHub Desktop.
AddChoreIntentHandler updated
/**
* Handler for the AddChoreIntent
*/
const AddChoreIntentHandler = {
canHandle(handlerInput) {
const { request } = handlerInput.requestEnvelope;
return (
request.type === Requests.INTENT_REQUEST &&
request.intent.name === Intents.ADD_CHORE_INTENT
);
},
async handle(handlerInput) {
const { request } = handlerInput.requestEnvelope;
//Retrieve the chore said by the user
const choreSlot = request.intent.slots.Chore;
let choreName;
if (choreSlot && choreSlot.value) {
choreName = choreSlot.value.toLowerCase();
}
let speakOutput = Messages.ERROR_NO_CHORE_SLOT;
if (choreName) {
const success = await API.addChore(choreName);
if (!success) {
speakOutput = Messages.ERROR_ADDING_CHORE;
}
speakOutput = `Added ${choreName} to your chores list!`;
}
return handlerInput.responseBuilder.speak(speakOutput).getResponse();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment