Last active
January 10, 2019 02:07
-
-
Save dmennis/5f476e044be1194bd1cb613ae4bf5d5b to your computer and use it in GitHub Desktop.
This is the source code for the EchoMe Lex Chatbot 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
'use strict'; | |
/** | |
* This code sample demonstrates an implementation of the Amazon Lex Code Hook Interface | |
* to echo back what the user says | |
* Written by: Dennis Hills | |
* Date: Jan 9, 2019 | |
* Amazon Lex Bot setup requires only a single slot | |
* Usage: "repeat after me I am the boss" or "repeat after me the quick brown fox jumped over the lazy dog" | |
*/ | |
// --------------- Main handler ----------------------- | |
// Route the incoming request based on intent. | |
// The JSON body of the request is provided in the event slot. | |
exports.handler = (event, context, callback) => { | |
try { | |
console.log('Received event:', JSON.stringify(event, null, 2)); | |
echoBack(event, (response) => callback(null, response)); | |
} catch (err) { | |
callback(err); | |
} | |
}; | |
/* | |
* Return echoed text back to user | |
*/ | |
function echoBack(intentRequest, callback) { | |
// Strip "repeat after me" intent off before responding | |
var echoResponse = intentRequest.inputTranscript.toLowerCase().replace("repeat after me", "").trim(); | |
callback(close(null, 'Fulfilled', { contentType: 'PlainText', content: echoResponse })); | |
return; | |
} | |
function close(sessionAttributes, fulfillmentState, message, responseCard) { | |
return { | |
sessionAttributes, | |
dialogAction: { | |
type: 'Close', | |
fulfillmentState, | |
message, | |
responseCard, | |
}, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment