Slack auth provider
The Slack auth provider enables tools and agents to call Slack APIs (opens in a new tab) on behalf of a user. Behind the scenes, the Arcade Engine and the Slack auth provider seamlessly manage Slack OAuth 2.0 authorization for your users.
Want to quickly get started with Slack in your agent or AI app? The pre-built Arcade Slack toolkit is what you want!
What's documented here
This page describes how to use and configure Slack auth with Arcade AI.
This auth provider is used by:
- The Arcade Slack toolkit, which provides pre-built tools for interacting with Slack
- Your app code that needs to call the Slack API
- Or, your custom tools that need to call the Slack API
Configuring Slack auth
How you configure the Slack auth provider depends on whether you use the Arcade Cloud Engine or a self-hosted Engine.
With the Arcade Cloud Engine, you can start building and testing Slack auth without any configuration. Your users will see Arcade AI (demo)
as the name of the application that's requesting permission.
When you are ready to go to production, you'll want to configure the Slack auth provider with your own Slack app credentials, so users see your app name when they authorize access.
Create a Slack app
- Follow Slack's guide to registering a Slack app (opens in a new tab)
- Choose the scopes (permissions) you need for your app
- Set the redirect URL to:
https://cloud.arcade-ai.com/api/v1/oauth/callback
- Copy the client ID and client secret
Configuring Slack auth with the Arcade Cloud Engine
Coming soon! In 0.1.0-preview, the Arcade Cloud Engine does not yet support configuring auth providers.
Configuring Slack auth with a self-hosted Arcade Engine
Set environment variables
Set the following environment variables:
export SLACK_CLIENT_ID="<your client ID>"
export SLACK_CLIENT_SECRET="<your client secret>"
Or, you can set these values in a .env
file:
SLACK_CLIENT_ID="<your client ID>"
SLACK_CLIENT_SECRET="<your client secret>"
See Engine configuration for more information on how to set environment variables and configure the Arcade Engine.
Edit the Engine configuration
Edit the engine.yaml
file and add a slack
item to the auth.providers
section:
auth:
providers:
- id: slack
client_id: ${env:SLACK_CLIENT_ID}
client_secret: ${env:SLACK_CLIENT_SECRET}
Using Slack auth in app code
Use the Slack auth provider in your own agents and AI apps to get a user token for the Slack API. See authorizing agents with Arcade to understand how this works.
Use client.auth.start()
to get a user token for the Slack API:
from arcadepy import Arcade
client = Arcade() # Automatically finds the `ARCADE_API_KEY` env variable
user_id = "[email protected]"
# Start the authorization process
auth_response = client.auth.start(
user_id=user_id,
provider="slack",
scopes=[
"chat:write",
"im:write",
"users.profile:read",
"users:read",
],
)
if auth_response.status != "completed":
print("Please complete the authorization challenge in your browser:")
print(auth_response.authorization_url)
# Wait for the authorization to complete
auth_response = client.auth.wait_for_completion(auth_response)
token = auth_response.context.token
# Do something interesting with the token...
Using Slack auth in custom tools
The Arcade LLM API is a convenient way to call LLMs and automatically invoke tools. You can use the pre-built Arcade Slack toolkit to quickly build agents and AI apps that interact with Slack.
If the pre-built tools in the Slack toolkit don't meet your needs, you can author your own custom tools that interact with the Slack API.
Use the Slack()
auth class to specify that a tool requires authorization with Slack. The context.authorization.token
field will be automatically populated with the user's Slack token:
from typing import Annotated
from slack_sdk import WebClient
from arcade.sdk import ToolContext, tool
from arcade.sdk.auth import Slack
from arcade.sdk.errors import RetryableToolError
@tool(
requires_auth=Slack(
scopes=[
"chat:write",
"im:write",
"users.profile:read",
"users:read",
],
)
)
def send_dm_to_user(
context: ToolContext,
user_name: Annotated[
str,
"The Slack username of the person you want to message. Slack usernames are ALWAYS lowercase.",
],
message: Annotated[str, "The message you want to send"],
):
"""Send a direct message to a user in Slack."""
slackClient = WebClient(token=context.authorization.token)
# Retrieve the user's Slack ID based on their username
userListResponse = slackClient.users_list()
user_id = None
for user in userListResponse["members"]:
if user["name"].lower() == user_name.lower():
user_id = user["id"]
break
if not user_id:
raise RetryableToolError(
"User not found",
developer_message=f"User with username '{user_name}' not found.",
)
# Step 2: Retrieve the DM channel ID with the user
im_response = slackClient.conversations_open(users=[user_id])
dm_channel_id = im_response["channel"]["id"]
# Step 3: Send the message as if it's from you (because we're using a user token)
slackClient.chat_postMessage(channel=dm_channel_id, text=message)