Sushanth
Sushanth

Reputation: 2342

How to invoke lambda when lex does not process the intent automatically?

My Lex bot has four intents. Suppose a user asks a question at the very beginning of the conversation and this question is not allotted to any of the four intents. Hence no intent will be established. When this happens, I want to call lambda to run an "intent suggestion model" (built using topic modeling) to suggest the user about what the intent of the question might be. Also, lambda will have to store such queries in a database (s3 or RDB) so that if such queries are repetitive, then that intent can eventually be added to the bot and for other analytical solutions.

Upvotes: 2

Views: 743

Answers (1)

sid8491
sid8491

Reputation: 6800

What you need is a fallback intent but Lex does not support fallback intents as of now.
You can still achieve this if you use a bridge between your chat client and Lex.

Setup an API Gateway and Lambda function in between your chat-client and the Lex.

enter image description here

Your chat-client will send a request to API Gateway, API Gateway will forward this to Lambda function which will be used to call Lex and get response from it. Lex will have one more lambda function as a webhook.
In the Lambda function you used to call Lex, we can check if any intent was matched or we got an error message, if it's an error message and trigger some action like intent suggestion model.

You need to use boto library to call Lex and use post_text() method.

Hope it helps.

Upvotes: 4

Related Questions