Scheduling work meetings in Slack with Amazon Lex

Imagine being able to schedule a meeting or get notified about updates in your code repositories without leaving your preferred messaging platform. This could save you time and increase productivity. With the advent of chatbots, these mundane tasks are now easier than ever. Amazon Lex, a service for building chatbots, offers native integration with popular messaging applications such as Slack to offer a simple, yet powerful user experience. In a previous post, we explored how to schedule an appointment in Office 365 using an Amazon Lex bot and a custom web application to book meetings with a single user via email. In this post, we take advantage of Slack APIs to schedule meetings with multiple users by referencing their information in the Slack workspace. The Meeting Scheduler Slack Bot takes care of comparing calendars, finding open timeslots, and scheduling the actual meeting all without leaving the Slack workspace.

To accomplish this integration, we use a combination of AWS services (specifically Amazon Lex and AWS Lambda), and schedule actual meetings in Outlook. We use the chatbot to get the information needed to schedule a meeting, because these users also exist in Slack workspaces.

The following diagram illustrates the architecture of our solution.


Before getting started, make sure you have the following prerequisites:

  • An Office 365 account. If you don’t have an existing account, you can use the free trial of Office 365 Business Premium.
  • Approval from your Azure Active Directory administrator for the Office 365 application registration.

Estimated cost

You incur AWS usage charges when deploying resources and interacting with the Amazon Lex bot. For more information, see Amazon Lex pricing and AWS Lambda Pricing. Depending on the configured deployments for the Office 365 account and Slack account, additional charges may be incurred depending on the selected licenses.

Deployment steps

In the following sections, we walk you through the deployment for the Meeting Scheduler Slack Bot. The steps are as follows:

  1. Register an application within your Microsoft account. This generates the keys that are required to call the Office 365 APIs.
  2. Configure the Slack application. This creates the keys that the Amazon Lex bot and fulfillment Lambda function use to call Slack APIs.
  3. Launch the AWS CloudFormation template to generate AWS resources. You need the keys and URLs from the previous two steps.
  4. Connect Amazon Lex to the Slack channel.
  5. Test your Meeting Scheduler Slack Bot by typing a message into your Slack application.

Registering an application within your Microsoft account

To register your application in your Microsoft account, complete the following steps:

  1. Log in to your Azure portal and navigate to App registrations.
  2. Choose New registration.

  1. For Name, enter a name for your application.
  2. For Redirect URL, enter http://localhost/myapp.

The redirect URL is required to make Microsoft Graph API calls. You also use this as the value for RedirectURL for your CloudFormation stack.

The redirect URL is required to make Microsoft Graph API calls.

  1. Choose Create.
  2. Choose Certificates & secrets.

  1. Choose New client secret.

  1. Enter a name for your secret.
  2. Choose Save.

Before navigating away from this page, take note of the secret value (which you use as the ApplicationPassword parameter from the CloudFormation stack). This is the only time you can view the secret.

  1. Choose API permissions.

  1. Choose Add permission.
  2. Choose Microsoft Graph.

  1. For Select permissions, under Calendars, select Calendars.ReadWrite.

You need your Active Directory administrator to grant access to these permissions in order for the bot to be successful. These permissions give the application the ability to use service credentials to run certain actions, such as reading a calendar (to find available times) and writing (to schedule the meetings).

  1. In addition to the application secret you captured earlier, you also need the following information from your registered app:
    1. Application (client) ID – For the CloudFormation stack parameter Client ID
    2. Directory (tenant) ID – For the CloudFormation stack parameter ActiveDirectoryID

Configuring the Slack application

To configure your Slack application, complete the following steps:

  1. Sign up for a Slack account and create a Slack team. For instructions, see Using Slack.

In the next step, you create a Slack application, which any Slack team can install. If you already have a Slack team set up, you may move on to the next step.

  1. Create a Slack application.
  2. Under OAuth and Permissions, for Bot Token Scopes, add the following:
    1. chat:write – Allows the bot to send messages with the given user handle
    2. team:read – Allows the bot to view the name, email domain, and icons for Slack workspaces the chatbot is connected to
    3. users:read – Allows the bot to see people in the Slack workspace
    4. – Allows the bot to see the emails of people in the Slack workspace
  3. Choose Install App to Workspace.
  4. Choose Allow when prompted.
  5. Copy the Bot OAuth User Token, which you need when deploying the CloudFormation template in the next steps (for the parameter SlackBotToken).
  6. Save the information found in the Basic Information section for a later step.

Deploying the CloudFormation template

The following CloudFormation template creates the necessary chatbot resources into your AWS account. The resources consist of the following:

  • BotFulfillmentLambdaLayer – The Lambda layer that contains the libraries necessary to run the function
  • LambdaExecutionRole – A basic Lambda execution role that allows the fulfillment function to get secrets from AWS Secrets Manager
  • HelperLambdaExecutionRole – The Lambda execution role that allows the helper function to create Amazon Lex bots
  • BotFulfillmentLambda – The Lambda function that handles fulfillment of the bot
  • HelperLambda – The Lambda function that generates the bot
  • SlackAppTokens – Secrets in Secrets Manager for using Slack APIs
  • O365Secretes – Secrets in Secrets Manager for using Office 365 APIs
  • HelperLambdaExecute – A custom CloudFormation resource to run the HelperLambda and generate the bot upon complete deployment of the template

The HelperLambda function runs automatically after the CloudFormation template has finished deploying. This function generates a bot definition, slot types, utterances, and Lambda fulfillment connections in the Amazon Lex bot. The template takes approximately 10 minutes to deploy.

To deploy your resources, complete the following steps:

  1. On the AWS CloudFormation console, choose Create stack.
  2. For Upload a template file, upload the template.
  3. Choose Next.

Choose Next.

  1. For Stack name, enter a name (for example, MeetingScheduler).

For Stack name, enter a name (for example, MeetingScheduler).

  1. Under Parameters, provide the parameters that you recorded in the previous steps:
    1. ApplicationId – Client ID
    2. ApplicationPassword – Client secret
    3. AzureActiveDirectoryId – Directory ID
    4. CodeBucket – S3 bucket created to store the .zip files
    5. RedirectUri – Redirect URI; if not changed from the example (http://localhost/myapp), leave this section as is
    6. SlackBotToken – Bot OAuth user token
  2. Choose Next.

Choose Next.

  1. Choose Next
  2. Select the I acknowledge that AWS CloudFormation might create IAM resources

This allows AWS CloudFormation to create the AWS Identity and Access Management (IAM) resources necessary to run our application. This includes the Lambda function execution roles and giving Amazon Lex the permissions to call those functions.

  1. Choose Create stack.

Choose Create stack.

  1. Wait for the stack creation to complete.

You can monitor the status on the AWS CloudFormation console. Stack creation should take approximately 5 minutes.

Connecting the Amazon Lex bot to the Slack channel

To connect your bot to Slack, complete the following steps:

  1. On the Amazon Lex console, choose your newly deployed bot.
  2. On the Settings tab, create a dev alias and select Latest as the version.
  3. Click the + button to create the alias.
  4. On the Channels tab, choose Slack.
  5. For Channel Name, enter a name.
  6. For Alias, choose dev.
  7. Enter values for Client Id, Client Secret, Verification Token, and Success Page URL from the Basic Information page in your Slack app.

Enter values for Client Id, Client Secret, Verification Token, and Success Page URL

  1. Choose Activate.
  2. Complete your Slack integration. (You can skip step 2C, because we already completed it).
  3. Under Settings, choose Manage distribution.
  4. Choose Add to Slack.
  5. Authorize the bot to respond to messages.

Testing the Meeting Scheduler Slack Bot

To test your bot, complete the following steps:

  1. Navigate to the Slack workspace where you installed your application.

You should see the application under Apps.

You should see the application under Apps.

  1. To schedule a meeting with your bot, try entering Schedule a meeting.

The following screenshot shows the bot’s response. You’re presented with the next five available work days to choose from.

The following screenshot shows the bot’s response.

  1. Choose your desired date for the meeting.

If there are no times available on the day you selected, you can choose a different date.

  1. Enter how long you want the meeting to last.
  2. When asked who to invite to the meeting, enter your team member’s Slack handle.

The user must have their Active Directory email address associated with their Slack profile.

  1. Choose your desired time of day for the meeting.

Choose your desired time of day for the meeting.

  1. Confirm the details of your scheduled meeting.

Confirm the details of your scheduled meeting.

Success! You’ve just scheduled your first meeting using your Slack bot!

Success! You’ve just scheduled your first meeting using your Slack bot!

Cleaning up

To avoid incurring future charges, delete the resources by deleting the CloudFormation stack. Upon completion, delete the files uploaded to the S3 bucket, then delete the bucket itself.


Using Amazon Lex with Slack can help improve efficiency for daily tasks. This post shows how you can combine AWS services to create a chatbot that assists in scheduling meetings. It shows how to grant permissions, interact with Amazon Lex, and use external APIs to deliver powerful functionality and further boost productivity. The contents of this post and solution can be applied to other common workloads such as querying a database, maintaining a Git repo, or even interacting with other AWS services.

By integrating AWS with APIs like Office 365 and Slack, you can achieve even more automated functionality and improve the user experience. To get more hands on with building and deploying chatbots with Amazon Lex, check out these tutorials:

About the Authors

Kevin Wang is a Solutions Architect for AWS, and passionate about building new applications on the latest AWS services. With a background in investment finance, Kevin loves to blend financial analysis with new technologies to find innovative ways to help customers. An inquisitive and pragmatic developer at heart, he loves community-driven learning and sharing of technology.



Kim Wendt is a Solutions Architect at AWS, responsible for helping global media & entertainment companies on their journey to the cloud. Prior to AWS, she was a Software Developer for the US Navy, and uses her development skills to build solutions for customers. She has a passion for continuous learning and is currently pursuing a masters in Computer Science with a focus in Machine Learning.


View Original Source ( Here.

Leave a Reply

Your email address will not be published. Required fields are marked *

Shared by: AWS Machine Learning