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.
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.
In the following sections, we walk you through the deployment for the Meeting Scheduler Slack Bot. The steps are as follows:
- Register an application within your Microsoft account. This generates the keys that are required to call the Office 365 APIs.
- Configure the Slack application. This creates the keys that the Amazon Lex bot and fulfillment Lambda function use to call Slack APIs.
- Launch the AWS CloudFormation template to generate AWS resources. You need the keys and URLs from the previous two steps.
- Connect Amazon Lex to the Slack channel.
- 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:
- For Name, enter a name for your application.
- For Redirect URL, enter
The redirect URL is required to make Microsoft Graph API calls. You also use this as the value for
RedirectURL for your CloudFormation stack.
- Choose Create.
- Choose Certificates & secrets.
- Choose New client secret.
- Enter a name for your secret.
- 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.
- Choose API permissions.
- Choose Add permission.
- Choose Microsoft Graph.
- 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).
- In addition to the application secret you captured earlier, you also need the following information from your registered app:
- Application (client) ID – For the CloudFormation stack parameter
- Directory (tenant) ID – For the CloudFormation stack parameter
- Application (client) ID – For the CloudFormation stack parameter
Configuring the Slack application
To configure your Slack application, complete the following steps:
- 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.
- Create a Slack application.
- Under OAuth and Permissions, for Bot Token Scopes, add the following:
- chat:write – Allows the bot to send messages with the given user handle
- team:read – Allows the bot to view the name, email domain, and icons for Slack workspaces the chatbot is connected to
- users:read – Allows the bot to see people in the Slack workspace
- users:read.email – Allows the bot to see the emails of people in the Slack workspace
- Choose Install App to Workspace.
- Choose Allow when prompted.
- Copy the Bot OAuth User Token, which you need when deploying the CloudFormation template in the next steps (for the parameter
- 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
HelperLambdaand generate the bot upon complete deployment of the template
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:
- On the AWS CloudFormation console, choose Create stack.
- For Upload a template file, upload the template.
- Choose Next.
- For Stack name, enter a name (for example,
- Under Parameters, provide the parameters that you recorded in the previous steps:
- ApplicationId – Client ID
- ApplicationPassword – Client secret
- AzureActiveDirectoryId – Directory ID
- CodeBucket – S3 bucket created to store the .zip files
- RedirectUri – Redirect URI; if not changed from the example (
http://localhost/myapp), leave this section as is
- SlackBotToken – Bot OAuth user token
- Choose Next.
- Choose Next
- 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.
- Choose Create stack.
- 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:
- On the Amazon Lex console, choose your newly deployed bot.
- On the Settings tab, create a dev alias and select Latest as the version.
- Click the + button to create the alias.
- On the Channels tab, choose Slack.
- For Channel Name, enter a name.
- For Alias, choose dev.
- Enter values for Client Id, Client Secret, Verification Token, and Success Page URL from the Basic Information page in your Slack app.
- Choose Activate.
- Complete your Slack integration. (You can skip step 2C, because we already completed it).
- Under Settings, choose Manage distribution.
- Choose Add to Slack.
- Authorize the bot to respond to messages.
Testing the Meeting Scheduler Slack Bot
To test your bot, complete the following steps:
- Navigate to the Slack workspace where you installed your application.
You should see the application under Apps.
- 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.
- Choose your desired date for the meeting.
If there are no times available on the day you selected, you can choose a different date.
- Enter how long you want the meeting to last.
- 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.
- Choose your desired time of day for the meeting.
- Confirm the details of your scheduled meeting.
Success! You’ve just scheduled your first meeting using your Slack bot!
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.