Created
January 8, 2018 16:43
-
-
Save divgo/d4d386e9cfb747242487ee99b13479ed to your computer and use it in GitHub Desktop.
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
console.log('Loading event'); | |
var AWS = require('aws-sdk'); | |
// Close dialog with the customer | |
function close(sessionAttributes, fulfillmentState, message) { | |
return { | |
sessionAttributes, | |
dialogAction: { | |
type: 'ElicitIntent', | |
message, | |
}, | |
}; | |
} | |
function buildResponse(intent, callback) { | |
console.log("buildResponse"); | |
let responseText = "Welcome to our service. Are you interested in registering? Reply REGISTER if interested, otherwise reply CANCEL or just ignore this message."; | |
callback(close(intent.sessionAttributes, 'Fulfilled', { | |
'contentType': 'PlainText', | |
'content': responseText | |
})); | |
}; | |
// --------------- 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(event); | |
console.log(`request received for userId=${event.userId}, intentName=${event.currentIntent.name}`); | |
buildResponse(event, | |
(response) => { | |
callback(null, response); | |
}); | |
} catch (err) { | |
callback(err); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment