- Newest
- Most votes
- Most comments
How I Solved Integrating Lex without Sample Utterances or Initial Response
1. Lambda Function Integration
First, integrate an "Invoke AWS Lambda function" block before the "Get customer input" block in your Amazon Connect flow.
2. Initiate a Text Request
Initiate a RecognizeTextCommand from inside your Lambda function. Ensure the text sent does not include any Sample Utterances from your Lex intent, to prevent unintended triggering of the initial response or first slot. Example implementation in Node.js:
try { const command = new RecognizeTextCommand({ botId: "your_bot_id", botAliasId: "your_bot_alias_id", localeId: "ja_JP", sessionId: "your_session_id", text: "BYPASS_LEX_INITIAL_RESPONSE" }); const response = await client.send(command); console.log("Lex response:", response); return response; } catch(error) { console.error("Error communicating with Lex:", error); throw error; }
3. Dynamic Integration of Slot Prompt Text
Lambda Function and Session Attributes
When the Lambda function processes the RecognizeTextCommand, it generates a response containing attributes such as messages and sessionState. These include sessionAttributes that are sent back to Amazon Connect. Here's an example of how you might structure the Lambda's JSON response:
return { lexSlotPrompt: response.messages?.[0]?.content, lexStep: response.sessionState?.sessionAttributes?.step }
Accessing Data in Amazon Connect
Within Amazon Connect, dynamically access the attributes received from the Lambda response in the External Namespace (lexSlotPrompt and lexStep in this example). These attributes can be utilized to guide the interaction with the customer in subsequent steps.
Dynamically Setting Prompts in "Get Customer Input" Block
Utilize the lexSlotPrompt text retrieved from the External Namespace to dynamically populate the "Get customer input" block in Amazon Connect. Configure this block to employ the Text-to-speech or chat text option. Set the source to Set dynamically, specify the Namespace as External, and the Key as lexSlotPrompt. The user will be prompted accurately with the message sent back from Lex. See the below image for reference:
4. Continuation of Dialogue Handling by Lex
After the user responds in the "Get customer input" block, Lex takes over control of the interaction. It manages the dialogue, progressing through slots and intents based on the user's input. When Lex completes the interaction, it sends back a response that includes session attributes under the Lex Namespace, which can be utilized in the Amazon Connect flow as needed. (Assumes that Lex is properly connected to the "Get customer input" block and attached to the Connect instance)
By adhering to these steps, you ensure a seamless function of the setup, with Lex and Lambda configurations effectively managing and processing user inputs based on dynamically incorporated prompts.
Chris, thanks so much for sharing this. The first part does seem to align with what OP was asking and what was suggested by Aurelien, but step 4 seems to go down a different direction. First, you didn't pass a matching utterance, so the bot response is more than likely "I didn't understand that." Second, the OP seems to want to jump the initial Lex intro and go straight to perhaps a second level menu within the same bot. So going back toy our example, if Lambda sends "Sales", then what the caller could hear next for example is "Great sales, would you like to buy a car?" Am I understanding your example and the OP correctly? If I can make some free time I would love to test this myself as it opens up some interesting use cases.
Hi Selva,
You can. You would need to use Lambda to "warm" your Lex bot. In this scenario, your Lambda would act as the entity initiating the conversation with Lex. Assuming you are using Lex V2, use Lambda to call the "RecognizeUtterance" API. You will need to pass obvious parameters (botId, botAliasId, localeId, etc), along with a sessionId and the inputStream. The inputStream must match an utterance that is configured on the intent you want to start the conversation with. The sessionId will be used to keep the conversation context for the end-user Lex is interacting with.
Happy to assist further if needed.
When using this with Amazon Connect, Lex sessionId is Amazon Connect's ContactID which you can get in Contact Flow $.ContactId
Hi Aurelien, Thanks for details. We are using Lex V2. But in V2, Lambda can be invoked inside the intent. It means that Do we need to call Lambda before calling Get user Input in AC call flow? In this case, how can we find out sessionId for Lex? I will appreciate your feedback. Thanks, Selva
To make sure I understand the contact flow: Lambda to the RecognizeUtterance end point with parameter botId, botAlias, sessionId = contactId, inputStream=utterance. Then if successful go to a Get Customer Input node to send the call to Lex?
That is correct. The output of the RecognizeUtterance API call is to be used into a Get Customer Input.
I don't see a way. You could use conditional branching (assuming v2), but you need that initial utterance to start the whole process to be able to branch. What are you trying to accomplish? Are you looking to have a single bot instead of a bunch of different smaller bots?
david
Thanks David. We want to use single bot with multiple intents and want to call the Lex bot multiple times in same call flow.
In order to give better customer experience, we want to pass utterance from call flow / Lambda.
Thanks, Selva
Is this still the case that I have to use a Lambda API to set this? Similarly, I have a lex bot in Connect Flow that gets invoked twice but on the second go I already know the intent, I just want to re-elicit the slot variable for the already fulfilled intent. I was hoping for a way tell the Lex bot through a variable setting what intent it is...i.e. SIMPLE versus API call.
Hi, I wonder if it possible to trigger the intent without the need to use a Lambda. if that intent doesn't have utterances assigned to it?
Relevant content
- asked 2 years ago
- AWS OFFICIALUpdated 4 years ago

If I understand your question correctly you're attempting to set some state without prompting the user first?
If so you could use the PutSession API to set the conversation state: https://docs.aws.amazon.com/lex/latest/dg/API_runtime_PutSession.html