Last active
January 26, 2020 18:16
-
-
Save aldidoanta/0baae42b159a7e0035197ab57f7d8c70 to your computer and use it in GitHub Desktop.
checkinAlexaSkill Lambda function
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
exports.handler = (event, context, callback) => { | |
switch (event.request.type) { | |
case "LaunchRequest": | |
// Handles the launch of the skill. Example utterance: "Alexa, open check in." | |
context.succeed( | |
generateResponse(buildSpeechletResponse("Welcome to Checkin.", false)) | |
) | |
break; | |
case "IntentRequest": | |
// Handles intents after skill has been launched. Example utterance: "{name} is checking in." | |
if (event.request.intent.name === "RecordCheckin") { | |
const person = event.request.intent.slots["person"].value // Retrieves slot value. | |
const successfulResponse = `Hello, ${person}. Thank you for checking in.` | |
const failedResponse = "Sorry, I can not hear your name." | |
const response = person ? successfulResponse : failedResponse | |
context.succeed(generateResponse(buildSpeechletResponse(response, true))) | |
} | |
break; | |
} | |
} | |
// Helper functions for constructing responses | |
const buildSpeechletResponse = (outputText, shouldEndSession) => { | |
return { | |
outputSpeech: { | |
type: "PlainText", | |
text: outputText | |
}, | |
shouldEndSession: shouldEndSession | |
} | |
} | |
const generateResponse = (speechletResponse) => { | |
return { | |
version: "1.0", | |
response: speechletResponse | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment