AWS Lex Helpers
AWS Lex helper classes and functions to build responses
Response Types
- ElicitSlot - Informs Amazon Lex that the user is expected to provide a slot value in the response
- ElicitIntent - Informs Amazon Lex that the user is expected to respond with an utterance that includes an intent
- ConfirmIntent - Informs Amazon Lex that the user is expected to give a yes or no answer to confirm or deny the current intent
- Close - Informs Amazon Lex not to expect a response from the user
- Delegate - Directs Amazon Lex to choose the next course of action based on the bot configuration
View more details on Lex Documentation
Response Message Components
- PlainTextMessage
- ResponseCard
- ResponseCardAttachment
- AttachmentButton
- ResponseCardAttachment
Lambda Function Response Structure
Your lambda functions need to response in the following format
Using this module, you can easily generate the above response like below.
- Generate the dialog action content using message components (ResponseCard,ResponseCardAttachment,AttachmentButton,PlainTextMessage)
- Generate the lambda response using the message component generated in step 1
Usage
Installation
npm install aws-lex-helpers --save
Initialization
const AWSLexHelpers = ; // Response generatorconst Responses = AWSLexHelpersResponses; // Message componentsconst ResponseCardResponseCardAttachmentAttachmentButtonPlainTextMessageConstants = AWSLexHelpers;
Plain Text Message
let plainTextMessage = ;
Response Card
let firstAttachmentButton = ; let secondAttachmentButton = ; let responseCardAttachment = // Hosted url of the image // URL to be opened once click on the image ; let responseCard = // Response card attachments can be provided as an array ;
Generating lambda response
let sessionAttributes = YOUR_SESSION_ATTRIBUTES;let intentName = 'YOUR_INTENT_NAME';let slots = YOUR_SLOTS;
Elicit Slot
let slotToElicit = YOUR_SLOTS_TO_ELICIT; let response = Responses;
Elicit Intent
let response = Responses;
Confirm Intent
let response = Responses;
Close Intent
let fulfillmentState = ConstantsFULFILMENT_STATESFULFILLED; // or FAILED let response = Responses;
Delegate Intent
let response = Responses;
Return the response above from your lambda function
Additional Resources
Constants
-
FULFILMENT_STATES
- FULFILLED
- FAILED
-
INVOCATION_SOURCE
- DIALOG_CODE_HOOK
- FULFILMENT_CODE_HOOK