Introducing Slackrock: Conversing with AI in Slack Made Easy
Slackrock is a conversational AI assistant powered by Amazon Bedrock that brings the power of cutting-edge language models directly to your Slack workspace.
Published Jun 21, 2024
Last Modified Jun 22, 2024
Hey Slackers! I'm thrilled to introduce the AWS builder community to Slackrock (https://github.com/coreylane/slackrock), a conversational AI Slack App that you can easily deploy into your own environment.
As someone fascinated by the potential of recent developments in AI, I've been tinkering with various tools and platforms to explore how we can harness its capabilities in our everyday tasks. New tools are great, but keeping track of yet another app or browser tab is just one more context-switch that slows us down and takes us out of our flow state. Like many of you, I use Slack frequently, and I couldn't find an existing solution that met my needs, so Slackrock was born ā a solution that combines the capabilities of Amazon Bedrock with the familiarity of Slack.
Slackrock running in pirate mode! š“āā ļø
When I set out to create Slackrock, I had three main objectives in mind:
- Customization: One of the coolest features of Slackrock is the ability for users to easily switch which model they are using directly from the app's home tab. This makes it easy to experiment with various models, each with its own strengths and quirks. Whether you're a fan of Amazon Titan, Anthropic Claude, Mistral AI, Cohere Command, or Meta Llama, Slackrock has a variety of models to tackle any use case. And with the flexibility of Slack Bolt for Python, extending the functionality to meet your specific needs is a breeze.
- Cost Efficiency: I'm not a big fan of static monthly subscription fees that only seem to increase over time. I wanted to ensure that users only pay for what they use, leveraging Amazon Bedrock's pay-as-you-go pricing model meets this requirement. By utilizing serverless compute and efficient Graviton2 processors, Slackrock minimizes operational overhead and delivers the best price performance ratio available.
- Simplicity: Getting started with Slackrock is a breeze! With just a few
sam
commands, you can deploy a serverless application template and have your own Slack bot up and running in no time. Plus, it works seamlessly with free Slack workspace, so you don't need any fancy pro or enterprise plans to use it.
At its core, Slackrock leverages the Amazon Bedrock Converse API to enable multi-turn conversations across a variety of models. This means the app can retain context over a long period, allowing you to pick up conversations right where you left off.
The architecture is designed to be straightforward and efficient. Check out the diagram below to see how it all comes together:
At this point, you may be thinking, 'Wow, this looks cool, but it seems expensive.' You might wonder about the cost of running your own AWS compute and data infrastructure, plus the expense of using all the models, and that's fair. But fear not, I've run the numbers and think you may be surprised at how how much bang for your buck Slackrock provides.
- AWS Lambda: Provides the heavy lifting for this solution, which includes 1,000,000 free requests per month and up to 400,000 GB-seconds or 3.2 million seconds of compute time per month.
- Amazon DynamoDB: The serverless, NoSQL database we use to keep track of user preferences in the app, comes with 25 GB of storage and enough read & write capacity to handle up to 200M requests per month.
- Amazon Bedrock: The gateway to our AI models, and the only service that will incur costs for personal deployments. The cost varies depending which model is invoked. The default model, Claude 3.5 Sonnet, currently costs $3 per million input tokens and $15 per million output tokens. Slackrock logs exactly how many tokens are used per inference request, which will help you calculate costs.
Alright, let's dive deep into the nitty-gritty of setting up Slackrock in your own environment. Don't worry; it doesn't take very long and it's easier than you might think!
Before we begin, make sure you have the following:
- AWS account
- Slack workspace where you can create and install apps
- Python 3.12
To get started, request access to the desired Amazon Bedrock models. The default model used in Slackrock is Anthropic Claude 3.5 Sonnet, but feel free to explore others that pique your interest.
Next, create a new Slack app (https://api.slack.com/apps) using the provided
slack-app-manifest.yaml
file. Once the app is created, install it in your Slack workspace.To ensure secure communication between Slackrock and your Slack workspace, you'll need to gather two important secrets:
- Navigate to 'Basic Information' in your Slack app settings and note the
Signing Secret
. - Go to 'OAuth & Permissions' and copy the
Bot User OAuth Token
.
Using the
aws
CLI, store the Slack secrets in AWS Secrets Manager:With the secrets securely stored, it's time to build and deploy Slackrock to your AWS account. Make sure your AWS access credentials are properly loaded in your environment.
- Download the code from Github: coreylane/slackrock
- Run
sam build
to build the application. - Run
sam deploy --guided
to deploy Slackrock.
ā When prompted, answer `y` to the question "Slackrock Function URL has no authentication. Is this okay? [y/N]". I'll explain the reasoning behind this later in the FAQ section.
After the deployment is complete, take note of the
SlackrockUrl
output from the CloudFormation stack. Head back to your Slack app developer page and follow these steps:- Navigate to 'Event Subscriptions' and enable events.
- Enter the
SlackrockUrl
in the Request URL field and confirm that the endpoint is verified. - Subscribe to bot events: app_home_opened, message.channels, message.groups, message.im.
- Save the changes.
Congratulations! You've successfully set up Slackrock in your Slack workspace. Now it's time to put it to the test:
- Invite the Slackrock app to a channel.
- Mention
@Slackrock
in a message and ask about anything you'd like to know. - You can also direct message the app itself to keep conversations private.
- Navigate to the app's home tab and try out different models.
If you encounter any issues or the bot seems unresponsive, check the CloudWatch Logs for any error messages.
Modifying the system prompt in the Converse API call allows you greater influence and control over how Bedrock models respond. You can fine-tune the system prompt to give your bot a unique personality, adhere to specific constraints, meet business requirements, or add additional context for specific use cases.
For example, if you want your bot to respond in character as a pirate š“āā ļø, you can set a system prompt like this:
Check out the example response:
Users can select their preferred model directly from the Slack app's home tab.
The complete list of currently available Bedrock model IDs can be found here. However, keep in mind that not all available Bedrock models are supported by the Converse API.
To iterate on the code locally and test changes live in your AWS account, use the
sam sync
command. It starts a process that watches your local application for changes and automatically syncs them to the AWS Cloud.sam sync --watch --stack-name Slackrock
Currently, the Anthropic Claude 3 Opus model is only available in the US West (Oregon, us-west-2) region. To use it, change the
region
parameter in samconfig.toml
and give it a try!You might be wondering why we're allowing public access to the Lambda function URL without authentication. While it may seem concerning, rest assured that the slack_bolt Python library used in Slackrock securely verifies the authenticity and integrity of incoming requests from Slack using the `signing_secret` and `token`.
When Slack sends a request to your Lambda function URL, it includes a special
X-Slack-Signature
header containing a hash signature computed using your app's SLACK_SIGNING_SECRET
and the request payload. The slack_bolt library automatically verifies this signature, ensuring that the request is genuinely coming from Slack and hasn't been tampered with.Additionally, the
SLACK_BOT_TOKEN
is used to authenticate your app when making API calls to Slack, ensuring that your app has the necessary permissions to perform actions and retrieve information.So, while the Lambda function URL is publicly accessible, the combination of the
signing_secret
and token
provides a secure mechanism for authenticating and authorizing requests between Slack and Slackrock.Slackrock wouldn't be possible without the incredible work done by the teams at AWS, Slack, and the open-source community. A big shout-out to the teams behind Slack Bolt for Python and the Amazon Bedrock platform.
I'm excited to see how Slackrock evolves and the amazing conversations it enables. If you have any questions, feedback, or just want to geek out about Bedrock and Slack, feel free to reach out! š
I hope you find Slackrock useful as an everyday tool and a fascinating playground to experiment with Bedrock's features. If you have the time and interest to help, please take a look at the issues on GitHub and feel free to jump in!
Happy Slackrocking! ššø
Ā
Ā