

# Use Amazon Lex and attribute values
<a name="attribs-cust-input-lex-bot"></a>

When you reference attributes in a **Get customer input** block, and choose Amazon Lex as the method of collecting the input, the attribute values are retrieved and stored from the output from the customer interaction with the Amazon Lex bot. You can use an attribute for each intent or slot used in the Amazon Lex bot, as well as the sessions attributes associated with the bot. An output branch is added to the block for each intent you include. When a customer chooses an intent when interacting with the bot, the branch associated with that intent is followed in the flow.

For a list of Amazon Lex attributes you can use and receive back from the Lex bot, see [Amazon Lex contact attributes](connect-attrib-list.md#attribs-lex-table).

# Using an Amazon Lex bot to get customer input


1. Open an existing or create a new flow.

1. Under **Interact**, drag a **Get customer input** block to the designer.

1. Choose the title of the block to display the block settings, then select **Text to speech (Ad hoc)**.

1. Choose **Enter text**, then enter text in the **Enter text to be spoken** field that is used as a message or greeting to your customers. For example, "Thank you for calling" followed by a request to enter information to fulfill the intents you defined in your Amazon Lex bot.

1. Choose the **Amazon Lex** tab, then from the drop-down menu, choose the Amazon Lex bot to use to get customer input.

1. By default, the **Alias** field is populated with \$1LATEST. To use a different alias of the bot, enter the alias value to use.
**Important**  
In a production environment, always use a different alias than **TestBotAlias** for Amazon Lex and **\$1LATEST** for Amazon Lex classic. **TestBotAlias** and **\$1LATEST** support a limited number of concurrent calls to an Amazon Lex bot. For more information, see [Runtime quotas](https://docs.aws.amazon.com/lexv2/latest/dg/quotas.html#quotas-service) or [Runtime Service Quotas (Amazon Lex Classic)](https://docs.aws.amazon.com/lex/latest/dg/gl-limits.html#gl-limits-runtime).

1. Optionally, to pass an attribute to Amazon Lex to use as a session attribute, choose **Add an attribute**. Specify the value to pass using either text or an attribute.

1. To create a branch from the block based on the customer intent, choose **Add an intent**, then enter the name of the intent exactly the same as the intent name in your bot.

1. Choose **Save**.

# Use alternate intent attributes in Amazon Lex
<a name="alternate-intent-attributes"></a>

Usually you configure flows to branch on the winning Lex intent. However, in some situations, you might want to branch on an alternate intent. That is, what the customer might have meant. 

The following image shows the **Properties** page of the **Check contact attributes** block. It is configured to check a Lex attribute. 

![\[The properties page of the Check contact attributes block.\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/check-contact-attributes-alternate-intents.png)


1. **Intent name** is the name of an alternate intent in Lex. It's case sensitive and must match what's in Lex exactly.

1. **Intent Attribute** is what Amazon Connect is going to check. In this example, it's going to check the **Intent Confidence Score**.

1. **Conditions to check**: If Lex is 70% certain the customer meant the alternate intent instead of the winning intent, branch.

# How flow blocks use Amazon Lex session attributes
<a name="how-to-use-session-attributes"></a>

When a customer starts a conversation with your bot, Amazon Lex creates a *session*. With *session attributes*, also known as *Lex attributes*, you can pass information between the bot and Amazon Connect during the session. For a list of Amazon Lex attributes that you can use, see [Amazon Lex contact attributes](connect-attrib-list.md#attribs-lex-table).

## Life cycle of session attributes
<a name="session-attribute-lifecycle"></a>

Each conversation contains one set of session attributes. In cases where an AWS Lambda function is invoked to do some processing, Amazon Lex runs the attributes in the following order:
+ Service defaults: These attributes are only used if no attributes are defined.
+ Session attributes provided by Amazon Connect: These attributes are defined in the [Get customer input](get-customer-input.md) block.
+ Session attributes provided by Lambda override everything prior: When an AWS Lambda function is invoked and it does some processing, it overrides any session attributes set in the [Get customer input](get-customer-input.md) block.

Let's say a customer utters that they want **a car**. That's the first session attribute to go through processing. When asked what kind of car, they say **luxury car**. This second utterance overrides any Lambda processing that took place on the first utterance. 

For an example of how to create a Lambda function that processes session attributes, see [Step 1: Create a Lambda Function](https://docs.aws.amazon.com/lex/latest/dg/gs2-prepare.html) in the *Amazon Lex Developer Guide*. For information about Amazon Lex V2, see [Setting session attributes](https://docs.aws.amazon.com/lexv2/latest/dg/context-mgmt-session-attribs.html). 

For the structure of the event data that Amazon Lex provides to a Lambda function, see [Lambda Function Input Event and Response Format](https://docs.aws.amazon.com/lex/latest/dg/lambda-input-response-format.html) in the *Amazon Lex Developer Guide*. For information about Amazon Lex V2, see [Interpreting the input event format](https://docs.aws.amazon.com/lexv2/latest/dg/lambda-input-format.html).

## Flow blocks that support Lex session attributes
<a name="blocks-support-lex-session-attributes"></a>

You can use Lex session attributes in the following flow blocks when a Lex bot is called:
+  [Change routing priority / age](change-routing-priority.md) 
+  [Check contact attributes](check-contact-attributes.md) 
+  [Get customer input](get-customer-input.md) 
+  [AWS Lambda function](invoke-lambda-function-block.md) 
+  [Loop](loop.md) 
+  [Set callback number](set-callback-number.md) 
+  [Set contact attributes](set-contact-attributes.md) 
+  [Set customer queue flow](set-customer-queue-flow.md) 
+  [Set disconnect flow](set-disconnect-flow.md) 
+  [Set hold flow](set-hold-flow.md) 
+  [Set logging behavior](set-logging-behavior.md) 
+  [Set whisper flow](set-whisper-flow.md) 
+  [Set working queue](set-working-queue.md) 
+  [Transfer to flow](transfer-to-flow.md) 
+  [Transfer to phone number](transfer-to-phone-number.md) 
+  [Wait](wait.md) 

### More information
<a name="more-info-attributes"></a>

For more information about using Amazon Lex session attributes, see [Managing Conversation Context](https://docs.aws.amazon.com/lex/latest/dg/context-mgmt.html) in the *Amazon Amazon Lex V1 Developer Guide*.

# How to use the same Amazon Lex bot for voice and chat
<a name="one-bot-voice-chat"></a>

You can use the same bot for voice and chat. However, you may want the bot to respond differently based on the channel. For example, you want to return SSML for voice so a number is read as a phone number, but you want to return normal text to chat. You can do this by passing the **Channel** attribute.

1. In the **Get customer input** block, choose the **Amazon Lex** tab.

1. Under **Session attributes**, choose **Add an attribute**. In the **Destination key** box, enter **phoneNumber**. Choose **Set dynamically**. In the **Namespace** box, choose **System**, and in the **Value** box, choose **Customer Number**, as shown in the following image.   
![\[The properties page of the Get customer input block, the Session attributes section.\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/session_attributes_customer_number.png)

1. Choose **Add an attribute** again.

1. Choose **Set dynamically**. In the **Destination key** box, enter **callType**. In the **Namespace** box, choose **System**, and in the **Value** box choose **Channel**, as shown in the following image.  
![\[The Set dynamically section.\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/session_attributes_call_type_channel.png)

1. Choose **Save**.

1. In your Lambda function, you can access this value in the `SessionAttributes` field in the incoming event.