Created
August 24, 2018 18:44
-
-
Save reaganmcf/3487f3bcf662435d0c200199654c5276 to your computer and use it in GitHub Desktop.
AddChoreIntentHandler updated
This file contains 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
/** | |
* 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