logo
Menu
Introducing Slackrock: Conversing with AI in Slack Made Easy

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

šŸ‘‹ Say Hey to Slackrock

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! šŸ“ā€ā˜ ļø

āœØ The Goal: Customization, Cost-Efficiency & Simplicity

When I set out to create Slackrock, I had three main objectives in mind:
  1. 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.
  2. 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.
  3. 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.

šŸ›ļø The Architecture: Simple Yet Powerful

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:
Slackrock AWS Cloud Architecture
Slackrock AWS Cloud Architecture

šŸ’ø Cost Breakdown

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.

šŸš€ Getting Started: A Step-by-Step Guide

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!

Prerequisites

Before we begin, make sure you have the following:
  • AWS account
  • Slack workspace where you can create and install apps
  • Python 3.12

Step 1: Request Access to Bedrock Models

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.

Step 2: Create a Slack App

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.
Slack App Installation

Step 3: Gather Slack Secrets

To ensure secure communication between Slackrock and your Slack workspace, you'll need to gather two important secrets:
  1. Navigate to 'Basic Information' in your Slack app settings and note the Signing Secret.
  2. Go to 'OAuth & Permissions' and copy the Bot User OAuth Token.

Step 4: Store Secrets in AWS Secrets Manager

Using the aws CLI, store the Slack secrets in AWS Secrets Manager:

Step 5: Build and Deploy Slackrock

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.
  1. Download the code from Github: coreylane/slackrock
  2. Run sam build to build the application.
  3. 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.

Step 6: Configure Slack App

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:
SAM Outputs
  1. Navigate to 'Event Subscriptions' and enable events.
  2. Enter the SlackrockUrl in the Request URL field and confirm that the endpoint is verified.
    Enable Slack App Event Endpoint
  3. Subscribe to bot events: app_home_opened, message.channels, message.groups, message.im.
    Slack App Event Subscriptions
  4. Save the changes.

šŸŽ‰ Time to Say Hey!

Congratulations! You've successfully set up Slackrock in your Slack workspace. Now it's time to put it to the test:
  1. Invite the Slackrock app to a channel.
  2. Mention @Slackrock in a message and ask about anything you'd like to know.
  3. You can also direct message the app itself to keep conversations private.
  4. 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.

Extra Credit: Customize the personality or tone of the responses

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:

ā” Frequently Asked Questions

How do I interact with different Bedrock models?

Users can select their preferred model directly from the Slack app's home tab.
Slackrock model switcher UI
Slackrock model switcher UI

How do I find the Model IDs?

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.

How do I deploy code changes in real-time?

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

Can I use Anthropic Claude 3 Opus?

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!

Why is there no authentication on the Lambda Function URL?

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.

šŸ™Œ Acknowledgements

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! šŸš€šŸŽø
Ā 

Comments