

# 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.