Setting Up a Slack App
Harness BREVIAN API tokens for Slack bot automation, enabling HTTP requests on-demand. Integrate with Zapier for a bot that interacts with BREVIAN API upon Slack mentions—streamlining team operations and boosting productivity.
Prerequisites
Slack Workspace Access
: Ability to create and manage apps.Zapier Account
: For automating workflows.BREVIAN API Token
: Securely generated from BREVIAN's API keys page.
Always keep your token safe and disable it if you suspect it has been compromised.
Step-by-Step Guide
Follow this guide to set up a Slack app and integrate it with BREVIAN API. The guide will show you how to create a simple Slack bot that responds to mentions on Slack and responds in the same channel.
1. Setup BREVIAN API Token
Make sure you have a BREVIAN API token. If you don't have one, you can generate a new one from the BREVIAN API keys page.
Get your API Token2. Create and Configure Your Slack App and Connect to Zapier
The goal of this tutorial is not to re-ierate Slack and Zapier integration. There are many resources available to help you with that. Use this offical guide to create a Slack app and connect it to Zapier.
Slack and Zapier Integration[Optional] If you want to be able to mention an user/app you need to create a custom Slack APP
- Visit the Slack Documentation page and create a new app.
- Make sure to give
app_mentions:read
,chat:write
,commands
andim:history
permissions - Install the app to your workspace
On Zapier you can create a new Zap and select Slack as the trigger app. Choose the trigger event that will initiate the workflow. For example, you can select "New Mention" as the trigger event. Use the Zapier guide above to connect your Slack app to Zapier.
3. Parse and validate the response
Add a Code by Zapier
step to run custom Python code in order to escape any messages and make sure that special characters are escaped.
import json
def escape_json_string(s):
return json.dumps(s)
escaped_string = escape_json_string(input_data['input_string'])
output = {'output': escaped_string.strip()}
3. Create a Zap
Create a new Zap in Zapier and select Slack as the trigger app. Choose the trigger event that will initiate the workflow. For example, you can select "New Mention" as the trigger event.
Based on the output of the previous input, you can now add a new action. Select "Custom Request in Webhooks by Zapier", and then set up these fields:
- Name
URL
- Description
https://chat.brevian.ai/api/v1/chat
- Name
data
- Description
{ "messages": [ { "role": "user", "content": "{output from the previous step}" } ], "agentId": "{find this is the URL of the agent you want to use e.g e1bf33db-feb6-49a3-a766-2e727ded3ee9}", }
- Name
Headers.Authorization
- Description
Add an
Authorization
header with the valueBearer {token}
- Name
Headers.Content-Type
- Description
Add a
Content-Type
header with the valueapplication/json
4. Output the response
You can now output the response from the BREVIAN API to Slack. You can use the "Send Channel Message" action in Slack to send the response to a channel or user.
The properties may look like this:
- Name
Message Text
- Description
Choose the content
Choices Message Content
from the previous step
Example configuration:
5. Test the Zap end to end
Now you're ready to test the integration end to end. You can mention the Slack bot and see the response from the BREVIAN API. Here's an example output