Skip to content

Instantly share code, notes, and snippets.

@aldidoanta
Last active January 26, 2020 18:16
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 aldidoanta/0baae42b159a7e0035197ab57f7d8c70 to your computer and use it in GitHub Desktop.
Save aldidoanta/0baae42b159a7e0035197ab57f7d8c70 to your computer and use it in GitHub Desktop.
checkinAlexaSkill Lambda function
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