

# Deploying bots from Lex V2 for your production environment


After creating and testing your bot, it is ready for deployment to interact with your customers. In this section, learn to create *versions* of your bot when you have made an update. Use *aliases* to point to different versions of your bot when they are ready for deployment. Learn how to integrate your bots with messaging platforms, mobile applications, and websites.

**Topics**
+ [

# Versioning and aliases with your Lex V2 bot
](versions-aliases.md)
+ [

# Using a Java application to interact with an Amazon Lex V2 bot
](deploy-java.md)
+ [

# Use Global Resiliency to deploy bots to other Regions
](global-resiliency.md)
+ [

# Integrating an Amazon Lex V2 bot with a messaging platform
](deploying-messaging-platform.md)
+ [

# Integrating an Amazon Lex V2 bot with a contact center
](contact-center.md)

# Versioning and aliases with your Lex V2 bot


Amazon Lex V2 supports creating versions and aliases of bots and bot networks so that you can control the implementation that your client applications use. A version acts as a numbered snapshot of your work. You can point an alias to the version of your bot that you want to be available to your customers. In between creating versions, you can continue to update the `Draft` version of your bot without affecting the user experience.

## Versions


Amazon Lex V2 supports creating versions of bots so that you can control the implementation that your client applications use. A *version* is a numbered snapshot of your work that you can create for use in different parts of your workflow, such as development, beta deployment, and production.

### The Draft version of your Lex V2 bot


When you create an Amazon Lex V2 bot there is only one version, the `Draft` version. 

`Draft` is the working copy of your bot. You can update only the `Draft` version and until you create your first version, `Draft` is the only version of the bot that you have. 

The `Draft` version of your bot is associated with the `TestBotAlias`. The `TestBotAlias` should only be used for manual testing. Amazon Lex V2 limits the number of runtime requests that you can make to the `TestBotAlias` alias of the bot.

### Creating a version for your Lex V2 bot


When you version an Amazon Lex V2 bot you create a numbered snapshot of the bot so that you can use the bot as it existed when the version was made. Once you've created a numeric version it will stay the same while you continue to work on the draft version of your application.

When you create a version, you can choose the locales to include in the version. You don't need to choose all of the locales in a bot. Also, when you create a version you can choose a locale from a previous version. For example, if you have three versions of a bot, you can choose one locale from the `Draft` version and one from version two when you create version four.

If you delete a locale from the `Draft` version, it is not deleted from a numbered version.

If a bot version is not used for six months, Amazon Lex V2 will mark the version inactive. When a version is inactive, you can't use runtime operations with the bot. To make the bot active, rebuild all the languages associated with the version.

### Updating an Amazon Lex V2 bot


You can update only the `Draft` version of an Amazon Lex V2 bot. Versions can't be changed. You can create a new version any time after you update a resource in the console or with the [CreateBotVersion](https://docs.aws.amazon.com/lexv2/latest/APIReference/API_CreateBotVersion.html) operation.

### Deleting an Amazon Lex V2 bot or version


Amazon Lex V2 supports deleting a bot or version using the console or one of the API operations:
+  [DeleteBot](https://docs.aws.amazon.com/lexv2/latest/APIReference/API_DeleteBot.html) 
+  [DeleteBotVersion](https://docs.aws.amazon.com/lexv2/latest/APIReference/API_DeleteBotVersion.html) 

## Aliases for your Lex V2 bot


Amazon Lex V2 bots support aliases. An *alias* is a pointer to a specific version of a bot. With an alias, you can easily update the version that your client applications are using. For example, you can point an alias to version 1 of your bot. When you are ready to update the bot, you create version 2 and change the alias to point to the new version. Because your applications use the alias instead of a specific version, all of your clients get the new functionality without needing to be updated.

An alias is a pointer to a specific version of an Amazon Lex V2 bot. Use an alias to allow client applications to use a specific version of the bot without requiring the application to track which version that is.

When you create a bot, Amazon Lex V2 creates an alias called `TestBotAlias` that you can use for testing your bot. The `TestBotAlias` alias is always associated with the `Draft` version of your bot. You should only use the `TestBotAlias` alias for testing, Amazon Lex V2 limits the number of runtime requests that you can make to the alias.

The following example shows two versions of an Amazon Lex V2 bot, version 1 and version 2. Each of these bot versions has an associated alias, BETA and PROD, respectively. Client applications use the PROD alias to access the bot.

![\[Point a client application to a version by using an alias.\]](http://docs.aws.amazon.com/lexv2/latest/dg/images/lex-publish-alias-bot.png) 

When you create a second version of the bot, you can update the alias to point to the new version of the bot using the console or the [UpdateBotAlias](https://docs.aws.amazon.com/lexv2/latest/APIReference/API_UpdateBotAlias.html) operation. When you change the alias, all of your client applications use the new version. If there is a problem with the new version, you can roll back to the previous version by simply changing the alias to point to that version.

![\[Updating an alias changes the version used by client applications.\]](http://docs.aws.amazon.com/lexv2/latest/dg/images/lex-publish-alias-bot-v2.png) 

When you set up your client applications to call the [Amazon Lex Runtime V2](https://docs.aws.amazon.com/lexv2/latest/APIReference/API_Operations_Amazon_Lex_Runtime_V2.html) APIs to let customers interact with your bot, you use the alias that points the version that you want your customers to use.

**Note**  
Although you can test the `Draft` version of a bot in the console, we recommend that when you integrate a bot with your client application, you first create a version and create an alias that points to that version. Use the alias in your client application for the reasons explained in this section. When you update an alias, Amazon Lex V2 will use the current version for all in-progress sessions. New sessions use the new version.

# Using a Java application to interact with an Amazon Lex V2 bot
Integrating with a Java application

The [AWS SDK for Java 2.0](https://github.com/aws/aws-sdk-java-v2) provides an interface that you can use from your Java applications to interact with your bots. Use the SDK for Java to build client applications for users. 

The following application interacts with the OrderFlowers bot that you created in [Exercise 1: Create a chatbot from a template](exercise-1.md). It uses the `LexRuntimeV2Client` from the SDK for Java SDK to call the [RecognizeText](https://docs.aws.amazon.com/lexv2/latest/APIReference/API_runtime_RecognizeText.html) operation to conduct a conversation with the bot. 

The output from the conversation looks like this:

```
User : I would like to order flowers
Bot  : What type of flowers would you like to order?
User : 1 dozen roses
Bot  : What day do you want the dozen roses to be picked up?
User : Next Monday
Bot  : At what time do you want the dozen roses to be picked up?
User : 5 in the evening
Bot  : Okay, your dozen roses will be ready for pickup by 17:00 on 2021-01-04.  Does this sound okay?
User : Yes
Bot  : Thanks.
```

For the JSON structures that are sent between the client application and the Amazon Lex V2 bot, see [Exercise 2: Review the conversation flow](exercise-2.md).

To run the application, you must provide the following information:
+ botId – The identifier assigned to the bot when you created it. You can see the bot ID in the Amazon Lex V2 console on the bot **Settings** page.
+ botAliasId – The identifier assigned to the bot alias when you created it. You can see the bot alias ID in the Amazon Lex V2 console on the **Aliases** page. If you can't see the alias ID in the list, choose the gear icon on the upper right and turn on **Alias ID**.
+ localeId – The identifier of the locale that you used for your bot. For a list of locales, see [Languages and locales supported by Amazon Lex V2](how-languages.md).
+ accessKey and secretKey – The authentication keys for your account. If you don't have a set of keys, create them using the AWS Identity and Access Management console.
+ sessionId – An identifier for the session with the Amazon Lex V2 bot. In this case, the code uses a random UUID.
+ region – If your bot is not in the US East (N. Virginia) Region, make sure that you change the Region.

The applications uses a function called `getRecognizeTextRequest` to create individual requests to the bot. The function builds a request with the required parameters to send to Amazon Lex V2.

```
package com.lex.recognizetext.sample;

import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.lexruntimev2.LexRuntimeV2Client;
import software.amazon.awssdk.services.lexruntimev2.model.RecognizeTextRequest;
import software.amazon.awssdk.services.lexruntimev2.model.RecognizeTextResponse;

import java.net.URISyntaxException;
import java.util.UUID;


/**
 * This is a sample application to interact with a bot using RecognizeText API.
 */
public class OrderFlowersSampleApplication {

    public static void main(String[] args) throws URISyntaxException, InterruptedException {
        String botId = "";
        String botAliasId = "";
        String localeId = "en_US";
        String accessKey = "";
        String secretKey = "";
        String sessionId = UUID.randomUUID().toString();
        Region region = Region.US_EAST_1; // pick an appropriate region

        AwsBasicCredentials awsCreds = AwsBasicCredentials.create(accessKey, secretKey);
        AwsCredentialsProvider awsCredentialsProvider = StaticCredentialsProvider.create(awsCreds);

        LexRuntimeV2Client lexV2Client = LexRuntimeV2Client
                .builder()
                .credentialsProvider(awsCredentialsProvider)
                .region(region)
                .build();

        // utterance 1
        String userInput = "I would like to order flowers";
        RecognizeTextRequest recognizeTextRequest = getRecognizeTextRequest(botId, botAliasId, localeId, sessionId, userInput);
        RecognizeTextResponse recognizeTextResponse = lexV2Client.recognizeText(recognizeTextRequest);

        System.out.println("User : " + userInput);
        recognizeTextResponse.messages().forEach(message -> {
            System.out.println("Bot : " + message.content());
        });

        // utterance 2
        userInput = "1 dozen roses";
        recognizeTextRequest = getRecognizeTextRequest(botId, botAliasId, localeId, sessionId, userInput);
        recognizeTextResponse = lexV2Client.recognizeText(recognizeTextRequest);

        System.out.println("User : " + userInput);
        recognizeTextResponse.messages().forEach(message -> {
            System.out.println("Bot : " + message.content());
        });

        // utterance 3
        userInput = "next monday";
        recognizeTextRequest = getRecognizeTextRequest(botId, botAliasId, localeId, sessionId, userInput);
        recognizeTextResponse = lexV2Client.recognizeText(recognizeTextRequest);

        System.out.println("User : " + userInput);
        recognizeTextResponse.messages().forEach(message -> {
            System.out.println("Bot : " + message.content());
        });

        // utterance 4
        userInput = "5 in evening";
        recognizeTextRequest = getRecognizeTextRequest(botId, botAliasId, localeId, sessionId, userInput);
        recognizeTextResponse = lexV2Client.recognizeText(recognizeTextRequest);

        System.out.println("User : " + userInput);
        recognizeTextResponse.messages().forEach(message -> {
            System.out.println("Bot : " + message.content());
        });

        // utterance 5
        userInput = "Yes";
        recognizeTextRequest = getRecognizeTextRequest(botId, botAliasId, localeId, sessionId, userInput);
        recognizeTextResponse = lexV2Client.recognizeText(recognizeTextRequest);

        System.out.println("User : " + userInput);
        recognizeTextResponse.messages().forEach(message -> {
            System.out.println("Bot : " + message.content());
        });
    }

    private static RecognizeTextRequest getRecognizeTextRequest(String botId, String botAliasId, String localeId, String sessionId, String userInput) {
        RecognizeTextRequest recognizeTextRequest = RecognizeTextRequest.builder()
                .botAliasId(botAliasId)
                .botId(botId)
                .localeId(localeId)
                .sessionId(sessionId)
                .text(userInput)
                .build();
        return recognizeTextRequest;
    }
}
```

# Use Global Resiliency to deploy bots to other Regions


Global Resiliency lets you replicate a bot in a secondary region. The secondary region can be made active with the automatic replication of the user’s bot in both regions. You will have a backup region in case of a regional outage. Once Global Resiliency is active, new bots created are replicated in a second AWS region.

**Note**  
This feature is available only for Amazon Connect and Amazon Lex V2 instances created in the US East (N. Virginia) and US West (Oregon) Regions, and the Europe West (London) and Europe Central (Frankfurt) Regions.  
To obtain access to this feature, contact your Amazon Connect Solutions Architect or Technical Account Manager.

After activating this feature, you can automate the replication of Amazon Lex V2 bots and their resources, versions, and aliases across a paired AWS region in near real-time. With this feature, you can monitor the version number of the original and replica bot to ensure that the bot replica remains in sync with the original bot. When you enable replication, you can activate the pre-determined AWS region you want the bot to be replicated in (regions are based on pre-determined pairs). Any updates to the source bot in the source region is automatically updated to the replicated bot in the second region. 

**Note**  
When Global Resiliency is enabled for a bot, all existing aliases and their associated versions get replicated in the replica region. Versions which are not associated to an alias before enabling replication are replicated when they get associated to an alias. Every version and alias created after enabling replication, is automatically replicated. Users can use `ListBotVersionReplicas` and `ListBotAliasReplicas` to review the status of replication of each individual version and alias. Bot mutations are uni-directional from bot to its replica. Users cannot modify the replica bot because it is always kept in sync with the bot. 

Additional information about using Global Resiliency:
+ Global Resiliency currently only works with pre-determined pairs of regions.    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/lexv2/latest/dg/global-resiliency.html)
+ When Global Resiliency is enabled for a bot, all existing aliases and their associated versions get replicated in the replica region. Versions which are not associated to an alias before enabling replication, are replicated when they are associated to an alias. Every version and alias created after enabling replication, gets automatically replicated. Users can use `ListBotVersionReplicas` and `ListBotAliasReplicas` to know the status of replication for each individual version and alias. Bot mutations are uni-directional from bot to its replica. Users cannot modify the replica bot, because it is always kept in sync with the bot.
+ Any Alias can be associated with any version. If the version is not replicated already, it will be replicated during the association with the Alias.

Limitations:
+ Global Resiliency does not replicate bots created with slots that use LLM such as CFAQ and Utterance Generation.
+ Global Resiliency does not replicate a Network of Bots, but any bot that is part of the Network of Bots can still be individually replicated. 

**Topics**
+ [

# Permissions to replicate bots and manage bot replicas in Lex V2
](gr-permissions.md)
+ [

# Deploying Global Resiliency with your Lex V2 bot
](navigation-gr.md)

# Permissions to replicate bots and manage bot replicas in Lex V2
Permissions

If an IAM role has the [AmazonLexFullAccess](security-iam-awsmanpol.md#security-iam-awsmanpol-AmazonLexFullAccess) policy attached, it can create and manage bot replicas.

If you prefer to create a role with minimal permissions for Global Resiliency, use the following policy, which contains the following statements.
+ Permissions to access the Amazon Lex V2 [service-linked role for bot replication](using-service-linked-roles.md#slr-replication).
+ Permissions to allow Amazon Lex V2 to create a [service-linked role for bot replication on your behalf](using-service-linked-roles.md#slr-replication).
+ Permissions to call the bot replication APIs.

You can restrict permissions further by modifying them as follows.
+ Replace *\$1* with specific bot or bot alias IDs to limit the permissions to specific bots or bot aliases.
+ Use a subset of the `lex BotReplica` actions to restrict the role to specific actions.

For an example, see [Allow users to create and view bot replicas, but not to delete them](security_iam_id-based-policy-examples.md#security_iam_id-based-policy-examples-gr-permissions).

# Deploying Global Resiliency with your Lex V2 bot


Global Resiliency lets you replicate a bot in a secondary region. The secondary region can be made active with the automatic replication of the user’s bot in both regions. You will have a backup region in case of a regional outage. Once Global Resiliency is active, new bots created are replicated in a second AWS region.

## Global Resiliency information panel displays details about your deployments


You can access the following information in the Global Resiliency panel:
+ **Source details** – Information about your bot's source region, replica type, replication enabled date, and last created version. Use this information to track iterations of your bot.
+ **Replication details** – After creating your bot replica, you can track the replicated region, replica type, last version synced date, and last replicated version. Use this information to track the sync of your bot replica.
+ **Source region** – The region where Global Resiliency is enabled. You can make changes in the source region to replicate the bot in both regions.
+ **Replica type** – Indicates if the bot is read only or able to read and write based on the region.
+ **Replica region** – The secondary region that is used to replicate your source bot for Global Resiliency. Global Resiliency currently only works with IAD/PDX and LDN/FRA regional pairs.
+ **Replication enabled date** – The date and time the bot replica was enabled.
+ **Last created version** – The last bot version associated with the replica in the source region.

## Enabling Global Resiliency for your Lex V2 bots


Before activating Global Resiliency in the Amazon Lex V2 console, you must ensure that the user that enables bot replication has permission to create Service Linked Roles (SLR). Global Resiliency will use these FAS credentials to create a SLR in the enabled account when CreateReplica is invoked. For more information on setting up the SLR for Global Resiliency in Amazon Lex V2, see [AWS managed policy: AmazonLexFullAccess](https://docs.aws.amazon.com/lexv2/latest/dg/security-iam-awsmanpol.html#security-iam-awsmanpol-AmazonLexFullAccess) . 

**Note**  
This feature is available only for Amazon Connect and Amazon Lex V2 instances created in the US East (N. Virginia) and US West (Oregon) Regions, and the Europe West (London) and Europe Central (Frankfurt) Regions.  
To obtain access to this feature, contact your Amazon Connect Solutions Architect or Technical Account Manager. 

Activate Global Resiliency and set up bot replication for a second region:

1. Sign in to the AWS Management Console and open the Amazon Lex console at [ https://console.aws.amazon.com/lex/](https://console.aws.amazon.com/lex/).

1. Choose the bot you want to replicate from the Bots navigation on the left side navigation panel.

1. Choose Deployment > Global Resiliency.

1. Select the **Create replica** button on the upper right corner of the window to create a draft version of your bot.
**Note**  
Check to make certain you do not have any bots in the secondary region with the same name as the bot you want to replicate. (Your bot must be uniquely named).

1. Go to **Global Resiliency**, Click **Create Replica** - This action creates a draft version of your bot. (you do not need to go back to the Global Resiliency tab except to review status or see details of future builds).
**Note**  
You can also create an Alias bot for replication in Global Resiliency by going to Alias and selecting **Create New Alias** for Global Resiliency enabled bot. All aliases will be replicated, even if created before replication was enabled.

1. Go to **Alias** - **Create New Alias** for the Global Resiliency enabled bot. All aliases will be replicated, even if they were created before replication was enabled.

1. Go to **Version** - **Create New Version** for the Global Resiliency enabled bot. Any version associated with an alias will be replicated, even if it was created before replication was enabled.

**Note**  
Customers still have full control of managing their resource based policies and tags for replicated bots. Lambda functions and CloudWatch Logs Groups will need to be deployed in both regions with the same identifiers. Users will not have to associate the lambda function again in the replica region.

## Disabling Global Resiliency


You can disable Global Resiliency at any time by selecting the **Disable Global Resiliency** button. This action stops your source bot and any aliases and versions associated with it from being replicated in other regions.

## Using APIs with Global Resiliency for your Lex V2 bots


You can make API calls in Global Resiliency using the following APIs. Additional information about Global Resiliency APIs and Amazon Lex V2 can be found in the [Amazon Lex V2 API Guide](https://docs.aws.amazon.com/lexv2/latest/dg/api_ref.html).
+ **CreateBotReplica**

  Enable Global Resiliency and creates a replicated bot. Requires `replicaRegion`.

  For more information, see [CreateBotReplica](https://docs.aws.amazon.com/lexv2/latest/APIReference/API_CreateBotReplica.html) in the Amazon Lex V2 API Guide.
+ **DeleteBotReplica**

  Disable Global Resiliency and delete the replicated bot. Requires `replicaRegion` and `botId`.

  For more information, see [DeleteBotReplica](https://docs.aws.amazon.com/lexv2/latest/APIReference/API_DeleteBotReplica.html) in the Amazon Lex V2 API Guide.
+ **ListBotReplicas**

  List the replicated bots in the secondary zone. Requires `botId`.

  For more information, see [ListBotReplicas](https://docs.aws.amazon.com/lexv2/latest/APIReference/API_ListBotReplicas.html) in the Amazon Lex V2 API Guide.
+ **DescribeBotReplica**

  Summary of information for the replicated bot. Requires `replicaRegion` and `botId`.

  For more information, see [DescribeBotReplica](https://docs.aws.amazon.com/lexv2/latest/APIReference/API_DescribeBotReplica.html) in the Amazon Lex V2 API Guide.

# Integrating an Amazon Lex V2 bot with a messaging platform
Integrating with messaging platforms

This section explains how to integrate Amazon Lex V2 bots with the Facebook, Slack, and Twilio messaging platforms. If you don't already have an Amazon Lex V2 bot, create one. In this topic, we assume that you are using the bot that you created in [Exercise 1: Create a chatbot from a template](exercise-1.md). However, you can use any bot. 

**Note**  
When storing your Facebook, Slack, or Twilio configurations, Amazon Lex V2 uses an AWS KMS key to encrypt information. The first time that you create a channel to one of these messaging platforms, Amazon Lex V2 creates a default customer managed key (`aws/lex`) in your AWS account or you can select your own customer managed key. Amazon Lex V2 supports only symmetric keys. For more information, see the [AWS Key Management Service Developer Guide](https://docs.aws.amazon.com/kms/latest/developerguide/).

When a messaging platform sends a request to Amazon Lex V2 it includes platform-specific information as a request attribute to you Lambda function. Use this attribute to customize the way that your bot behaves. For more information, see [Setting request attributes for your Lex V2 bot](context-mgmt-request-attribs.md).


**Common request attributes for messaging platforms**  

| Attribute | Description | 
| --- | --- | 
| x-amz-lex:channels:platform | One of the following values: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/lexv2/latest/dg/deploying-messaging-platform.html) | 

# Integrating an Amazon Lex V2 bot with Facebook Messenger
Integrating with Facebook

You can host your Amazon Lex V2 bot in Facebook Messenger. When you do, Facebook users can interact with your bot to fulfill intents. 

Before you start, you need to sign up for a Facebook developer account at [https://developers.facebook.com](https://developers.facebook.com).

You need to perform the following steps:

**Topics**
+ [

# Step 1: Create a Facebook application
](facebook-step-1.md)
+ [

# Step 2: Integrate Facebook Messenger with the Amazon Lex V2 bot
](facebook-step-2.md)
+ [

# Step 3: Complete Facebook integration with your Lex V2 bot
](facebook-step-3.md)
+ [

# Step 4: Test the integration with Facebook Messenger
](facebook-step-4.md)

# Step 1: Create a Facebook application


On the Facebook developer portal, create a Facebook application and a Facebook page. 

**To create a Facebook application**

1. Open [ https://developers.facebook.com/apps ](https://developers.facebook.com/apps) 

1. Choose **Create App**.

1. In the **Create an App** page, choose **Business**, then choose **Next**.

1. For the **Add on app name**, **App contact email**, and **Business Account** fields, make the appropriate choices for your app. Choose **Create App** to continue.

1. From **Add Products to Your App**, choose **Set Up** from the **Messenger** tile.

1. In the **Access Tokens** section, choose **Add or Remove pages**.

1. Choose a page to use with your app, then choose **Next**.

1. For **What is app allowed to do**, leave the defaults then choose **Done**.

1. On the confirmation page, choose **OK**.

1. In the **Access Tokens** section, choose **Generate Token**, then copy the token. You enter this token in the Amazon Lex V2 console.

1. From the left menu, choose ** Settings ** and then choose **Basic**.

1. For **App Secret**, choose **Show** and then copy the secret. You enter this token in the Amazon Lex V2 console.

## Next step


[Step 2: Integrate Facebook Messenger with the Amazon Lex V2 bot](facebook-step-2.md)

# Step 2: Integrate Facebook Messenger with the Amazon Lex V2 bot


In this step you link your Amazon Lex V2 bot with Facebook.

1. Sign in to the AWS Management Console and open the Amazon Lex console at [https://console.aws.amazon.com/lex/](https://console.aws.amazon.com/lex/).

1. From the list of bots, choose the Amazon Lex V2 bot that you created.

1. In the left menu, choose **Channel integrations** and then choose **Add channel**.

1. In **Create channel**, do the following:

   1. For **Platform**, choose **Facebook**.

   1. For **Identity policies**, choose the AWS KMS key to protect channel information. The default key is provided by Amazon Lex V2.

   1. For **Integration configuration**, give the channel a name and an optional description. Choose the alias that points to the version of the bot to use, and choose the language that the channel supports.

   1. For **Additional configuration**, enter the following:
      + **Alias** – A string that identifies the app that is calling Amazon Lex V2. You can use any string. Record this string, you enter it in the Facebook developer console.
      + **Page access token** – The page access token that you copied from the Facebook developer console.
      + **App secret key** – The secret key that you copied from the Facebook developer console.

   1. Choose **Create**

   1. Amazon Lex V2 shows the list of channels for your bot. From the list, choose the channel that you just created.

   1. From **Callback URL**, record the callback URL. You enter this URL in the Facebook developer console.

## Next step


[Step 3: Complete Facebook integration with your Lex V2 bot](facebook-step-3.md)

# Step 3: Complete Facebook integration with your Lex V2 bot


In this step, use the Facebook developer console to complete integration with Amazon Lex V2. 

**To complete Facebook Messenger integration**

1. Open [ https://developers.facebook.com/apps ](https://developers.facebook.com/apps) 

1. From the list of apps, choose the app that you are integrating with Facebook Messenger.

1. In the left menu, choose **Messenger**, then choose **Settings**.

1. In the **Webhooks** section:

   1. Choose **Add Callback URL**.

   1. In **Edit Callback URL**, enter the following:
      + **Callback URL** – Enter the callback URL that you recorded from the Amazon Lex V2 console.
      + **Verify Token** – Enter the alias that you entered in the Amazon Lex V2 console.

   1. Choose **Verify and Save**.

   1. Choose **Add subscriptions** under **Webhooks** next to your page.

   1. In the window that pops up, choose `messages` and then click **Save**.

## Next step


[Step 4: Test the integration with Facebook Messenger](facebook-step-4.md)

# Step 4: Test the integration with Facebook Messenger


You can now start a conversation from Facebook Messenger with your Amazon Lex V2 bot.

**To test the integration between Facebook Messenger and an Amazon Lex V2 bot**

1. Open the Facebook page that you associated with your bot in step 1.

1. In the Messenger window, use the test utterances provided in [Exercise 1: Create a chatbot from a template](exercise-1.md).

# Integrating an Amazon Lex V2 bot with Slack
Integrating with Slack

This topic provides instructions for integrating an Amazon Lex V2 bot with the Slack messaging application. You perform the following steps:

**Topics**
+ [

# Step 1: Sign up for Slack and create a Slack team
](slack-step-1.md)
+ [

# Step 2: Create a Slack application
](slack-step-2.md)
+ [

# Step 3: Integrate the Slack application with the Amazon Lex V2 bot
](slack-step-3.md)
+ [

# Step 4: Complete Slack integration with your Lex V2 bot
](slack-step-4.md)
+ [

# Step 5: Test the integration between your Lex V2 bot and Slack
](slack-step-5.md)

# Step 1: Sign up for Slack and create a Slack team


Sign up for a Slack account and create a Slack team. For instructions, see [Using Slack](https://get.slack.help/hc/en-us/articles/212675257-Creating-a-Slack-account). In the next section you create a Slack application, which any Slack team can install.

## Next step


[Step 2: Create a Slack application](slack-step-2.md)

# Step 2: Create a Slack application


In this section, you do the following: 

1. Create a Slack application in the Slack API Console.

1. Configure the application to add interactive messaging to your bot.

At the end of this section, you get application credentials (Client ID, Client Secret, and Verification Token). In the next step, you use this information to integrate the bot in the Amazon Lex V2 console.

**To create a Slack application**

1. Sign in to the Slack API Console at [https://api.slack.com ](https://api.slack.com).

1. Create an application. 

   After you have successfully created the application, Slack displays the **Basic Information** page for the application. 

1. Configure the application features as follows:

   1. In the left menu, choose **Interactivity & Shortcuts**.
     + Choose the toggle to turn interactive components on.
     + In the **Request URL** box, specify any valid URL. For example, you can use **https://slack.com**.
**Note**  
For now, enter any valid URL to get the verification token that you need in the next step. You will update this URL after you add the bot channel association in the Amazon Lex console. 
     + Choose **Save Changes**.

1. In the left menu, in **Settings**, choose **Basic Information**. Record the following application credentials:
   + Client ID 
   + Client Secret
   + Verification Token 

## Next step


[Step 3: Integrate the Slack application with the Amazon Lex V2 bot](slack-step-3.md)

# Step 3: Integrate the Slack application with the Amazon Lex V2 bot


 In this section, integrate the Slack application you created with the Amazon Lex V2 bot you created by using Channel integrations. 

1. Sign in to the AWS Management Console and open the Amazon Lex console at [https://console.aws.amazon.com/lex/](https://console.aws.amazon.com/lex/).

1. From the list of bots, choose the Amazon Lex V2 bot that you created.

1. In the left menu, choose **Channel integrations** and then choose **Add channel**.

1. In **Create channel**, do the following:

   1. For **Platform**, choose **Slack**.

   1. For **Identity policies**, choose the AWS KMS key to protect channel information. The default key is provided by Amazon Lex V2.

   1. For **Integration configuration**, give the channel a name and an optional description. Choose the alias that points to the version of the bot to use, and choose the language that the channel supports.
**Note**  
 If your bot is available in multiple languages, you must create a different channel and a different application for each language. 

   1. For **Additional configuration**, enter the following:
      + **Client ID** – enter the client ID from Slack. 
      + **Client secret** – enter the client secret from Slack. 
      + **Verification token** – enter the verification token from Slack.
      + **Success page URL** – The URL of the page that Slack should open when the user is authenticated. Typically you leave this blank.

1. Choose **Create** to create the channel.

1. Amazon Lex V2 shows the list of channels for your bot. From the list, choose the channel that you just created.

1. From **Callback URL**, record the endpoint and the OAuth endpoint.

## Next step


[Step 4: Complete Slack integration with your Lex V2 bot](slack-step-4.md)

# Step 4: Complete Slack integration with your Lex V2 bot


In this section, use the Slack API console to complete integration with the Slack application.

1. Sign in to the Slack API console at [https://api.slack.com](https://api.slack.com). Choose the app that you created in [Step 2: Create a Slack application](slack-step-2.md).

1. Update the **OAuth & Permissions** feature as follows:

   1. In the left menu, choose **OAuth & Permissions**.

   1. In the **Redirect URLs** section, add the OAuth endpoint that Amazon Lex provided in the preceding step. Choose **Add**, and then choose **Save URLs**.

   1. In the **Bot Token Scopes** section, add two permissions with the **Add an OAuth Scope** button. Filter the list with the following text:
      + **chat:write**
      + **team:read**

1. Update the **Interactivity & Shortcuts** feature by updating the **Request URL** value to the endpoint that Amazon Lex provided in the preceding step. Enter the endpoint that you saved in step 3, and then choose **Save Changes**.

1. Subscribe to the **Event Subscriptions** feature as follows:
   + Enable events by choosing the **On** option.
   + Set the **Request URL** value to the endpoint that Amazon Lex provided in the preceding step. 
   + In the **Subscribe to Bot Events** section, select **Add Bot User Event** and add the **message.im** bot event to enable direct messaging between the end user and the Slack bot.
   + Save the changes.

1. Enable sending messages from the messages tab as follows:
   + From the left menu, choose **App Home**.
   + In the **Show Tabs** section, choose **Allow users to send Slash commands and messages from the messages tab.**

1. Choose **Manage Distribution** under **Settings**. Choose **Add to Slack** to install the application. If you are authenticated to multiple workspaces, first choose the correct workspace in the upper right-hand corner from the drop-down list. Next, select **Allow** to authorize the bot to respond to messages. 
**Note**  
If you make any changes to your Slack application settings later, you must redo this substep.

## Next step


[Step 5: Test the integration between your Lex V2 bot and Slack](slack-step-5.md)

# Step 5: Test the integration between your Lex V2 bot and Slack


Now use a browser window to test the integration of Slack with your Amazon Lex V2 bot.

**To test your Slack application**

1. Launch Slack. From the left menu, in the **Direct Messages** section, choose your bot. If you don't see your bot, choose the plus icon (\$1) next to **Direct Messages** to search for it.

1. Engage in a chat with your Slack application. Your bot responds to messages.

   If you created the bot using [Exercise 1: Create a chatbot from a template](exercise-1.md), you can use the example conversations from that exercise.

# Integrating an Amazon Lex V2 bot with Twilio SMS
Integrating with Twilio SMS

This topic provides instructions for integrating an Amazon Lex V2 bot with the Twilio simple message service (SMS). You perform the following steps:

**Topics**
+ [

# Step 1: Create a Twilio SMS account
](twilio-step-1.md)
+ [

# Step 2: Integrate the Twilio message service endpoint with the Amazon Lex V2 bot
](twilio-step-2.md)
+ [

# Step 3: Complete Twilio integration between your Lex V2 bot and Twilio
](twilio-step-3.md)
+ [

# Step 4: Test the integration between your Lex V2 bot and Twilio
](twilio-step-4.md)

# Step 1: Create a Twilio SMS account


Sign up for a Twilio account and record the following account information: 
+ **ACCOUNT SID**
+ **AUTH TOKEN**

For sign-up instructions, see [ https://www.twilio.com/console ](https://www.twilio.com/console).

## Next step


[Step 2: Integrate the Twilio message service endpoint with the Amazon Lex V2 bot](twilio-step-2.md)

# Step 2: Integrate the Twilio message service endpoint with the Amazon Lex V2 bot


1. Sign in to the AWS Management Console and open the Amazon Lex console at [https://console.aws.amazon.com/lex/](https://console.aws.amazon.com/lex/).

1. From the list of bots, choose the Amazon Lex V2 bot that you created.

1. In the left menu, choose **Channel integrations** and then choose **Add channel**.

1. In **Create channel**, do the following:

   1. For **Platform**, choose **Twilio**.

   1. For **Identity policies**, choose the AWS KMS key to protect channel information. The default key is provided by Amazon Lex V2.

   1. For **Integration configuration**, give the channel a name and an optional description. Choose the alias that points to the version of the bot to use, and choose the language that the channel supports.

   1. For **Additional configuration**, enter the account SID and authentication token from the Twilio dashboard.

1. Choose **Create**.

1. From the list of channels, choose the channel that you just created.

1. Copy the **Callback URL**.

## Next step


[Step 3: Complete Twilio integration between your Lex V2 bot and Twilio](twilio-step-3.md)

# Step 3: Complete Twilio integration between your Lex V2 bot and Twilio


Use the Twilio console to complete the integration of your Amazon Lex V2 bot with Twilio SMS.

1. Open the Twilio console at [ https://www.twilio.com/console ](https://www.twilio.com/console).

1. From the left menu, choose **All Products & Services**, then choose **Phone Number**.

1. If you have a phone number, choose it. If you don't have a phone number, choose **Buy a Number** to get one.

1. In the **Messaging** section, in **A MESSAGE COMES IN**, enter the callback URL from the Amazon Lex V2 console.

1. Choose **Save**.

## Next step


[Step 4: Test the integration between your Lex V2 bot and Twilio](twilio-step-4.md)

# Step 4: Test the integration between your Lex V2 bot and Twilio


Use your mobile phone to test the integration between Twilio SMS and your bot. Using your mobile phone, send messages to the Twilio number.

If you created the bot using [Exercise 1: Create a chatbot from a template](exercise-1.md), you can use the example conversations from that exercise.

# Integrating an Amazon Lex V2 bot with a contact center
Integrating with contact centers

You can integrate Amazon Lex V2 bots with your contact centers to enable self-service use-cases using the Amazon Lex V2 streaming API. Use these bots as interactive voice response (IVR) agents on telephony or as a text-based chatbot integrated into your contact center. For more information about the streaming APIs, see [Streaming conversations to an Amazon Lex V2 bot](streaming.md).

With streaming APIs, you can enable the following features:
+ **Interruptions** ("barge-in") – Callers can interrupt the bot and answer a question before the prompt is complete. For more information, see [Enabling your Amazon Lex V2 bot to be interrupted by the user](interrupt-bot.md).
+ **Wait and continue** – Callers can instruct the bot to wait if they need time for retrieving additional information during a call, such as a credit card number or a booking ID. For more information, see [Enabling the Amazon Lex V2 bot to wait for the user to provide more information during a pause](wait-and-continue.md).
+ **DTMF support** – Callers can provide information via speech or DTMF interchangeably.
+ **SSML support** – You can configure Amazon Lex V2 bot prompts using SSML tags for greater control over speech generation from text. For more information, see [ Generating speech from SSML documents ](https://docs.aws.amazon.com/polly/latest/dg/ssml.html) in the *Amazon Polly developer guide*.
+ **Configurable timeouts** – You can configure how long to wait for customers to finish speaking before Amazon Lex V2 collects their speech input, such as answering a yes or no question, or providing a date or credit card number. For more information, see [Configuring timeouts for capturing user input with a Lex V2 bot](session-attribs-speech.md).
+ **Fulfillment progress updates** – You can configure the bot to respond with multiple messages based on the fulfillment status during the business logic execution for intent fulfillment. You can set the bot to respond with messages when the fulfillment begins and completes, and provides periodic updates for long running Lambda functions. For more information, see [Configuring fulfillment progress updates for your Lex V2 bot](streaming-progress.md).

# Amazon Chime SDK
Amazon Chime SDK

Use the Amazon Chime SDK to add real-time audio, video, screen sharing, and messaging capabilities to your web or mobile applications. The Amazon Chime SDK provides public switched telephone network (PSTN) audio service so that you can build custom telephony applications with an AWS Lambda function.

Amazon Chime PSTN audio is integrated with Amazon Lex V2. You can use this integration to access Amazon Lex V2 bots as interactive voice response (IVR) systems in contact centers for audio interactions. Use this to integrate Amazon Lex V2 using PSTN audio services in the following scenarios.

**Contact center integrations**—You can use the Amazon Chime Voice Connector and Amazon Chime SDK PSTN audio service to access Amazon Lex V2 bots. Use them in any contact center application that uses the session initiation protocol (SIP) for voice communications. This integration adds natural language voice conversation experiences to your existing on-premises or cloud-based contact center with SIP support. For a list of supported contact center platforms, see [Amazon Chime voice connector resources](https://aws.amazon.com/chime/voice-connector/resources/).

The following diagram shows the integration between a contact center using SIP and Amazon Lex V2.

![\[The information flow between a contact center and Amazon Lex V2 using the Amazon Chime SDK.\]](http://docs.aws.amazon.com/lexv2/latest/dg/images/chime-sip.flow.png)


**Direct telephony support**—You can build customized IVR solutions to directly access Amazon Lex V2 bots using a phone number provisioned in the Amazon Chime SDK.

 For more information, see the following topics in the *Amazon Chime SDK guide*.
+ [SIP integration using an Amazon Chime voice connector](https://docs.aws.amazon.com/chime/latest/dg/mtgs-sdk-cvc.html)
+ [Using the Amazon Chime SDK PSTN audio service](https://docs.aws.amazon.com/chime/latest/dg/build-lambdas-for-sip-sdk.html)
+ [Integrating Amazon Chime PSTN audio with Amazon Lex V2](https://docs.aws.amazon.com/chime/latest/dg/start-bot-conversation.html)

When the Amazon Chime SDK sends a request to Amazon Lex V2, it includes platform-specific information to your Lambda function and conversation logs. Use this information to determine the contact center application that is sending traffic to your bot.


| Common request attribute | Value | 
| --- | --- | 
| x-amz-lex:channels:platform | Amazon Chime SDK PSTN Audio | 

# Amazon Connect


Amazon Connect is an omnichannel cloud contact center. You can set up a contact center in a few steps, add agents located anywhere, and start engaging with your customers. For more information, see [ Get started with Amazon Connect ](https://docs.aws.amazon.com/connect/latest/adminguide/amazon-connect-get-started.html) in the *Amazon Connect administrator guide*.

You can create personalized experiences for your customers using omnichannel communications. For example, you can offer chat and voice contact based on customer preference and estimated wait times. Meanwhile agents can handle all customers from just one interface. For example, they can chat with customers, and create or respond to tasks as they are routed to them.

You can use Amazon Connect for audio interactions with your customers, or Amazon Connect Chat for text-only interactions.

For more information, see the following topics in the *Amazon Connect administrator guide*.
+ [What is Amazon Connect ](https://docs.aws.amazon.com/connect/latest/adminguide/what-is-amazon-connect.html)
+ [Add an Amazon Lex V2 bot ](https://docs.aws.amazon.com/connect/latest/adminguide/amazon-lex.html)
+ [Amazon Connect get customer input contact block](https://docs.aws.amazon.com/connect/latest/adminguide/get-customer-input.html)

When a contact center sends a request to Amazon Lex V2, it includes platform-specific information as a request attribute to your Lambda function and conversation logs. Use this information to determine which contact center application is sending traffic to your bot.


**Common request attributes for Amazon Connect**  

| Attribute | Value | 
| --- | --- | 
| x-amz-lex:channels:platform | One of the following values: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/lexv2/latest/dg/contact-center-connect.html) | 

# Genesys Cloud


Genesys Cloud is a suite of cloud services for enterprise communication, collaboration, and contact center management. Genesys Cloud is built on top of AWS and uses a distributed cloud environment that provides secure access to organizations around the work.

For more information, see the following pages on the Genesys Cloud website.
+ [ About Genesys Cloud contact center ](https://help.mypurecloud.com/articles/about-genesys-cloud-contact-center/)
+ [ About the Amazon Lex V2 integration ](https://help.mypurecloud.com/articles/about-the-amazon-lex-v2-integration/)

When a contact center sends a request to Amazon Lex V2 it includes platform-specific information as a request attribute to your Lambda function and conversation logs. Use this information to determine which contact center application is sending traffic to your bot.


**Common request attributes for Genesys Cloud**  

| Attribute | Value | 
| --- | --- | 
| x-amz-lex:channels:platform |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/lexv2/latest/dg/contact-center-genesys.html) | 

*Learn more*
+ [Power your contact center with Amazon Lex and Genesys Cloud](https://aws.amazon.com/blogs/machine-learning/enhancing-customer-service-experiences-using-conversational-ai-power-your-contact-center-with-amazon-lex-and-genesys-cloud/)