Slack Integration Guide - PinionAI Agent Runner
This guide covers Slack app setup, local development, and production deployment of the Slack bot implemented in chat_slack.py.
Table of Contents
- Slack App Configuration
- Environment Setup
- Local Deployment
- Production Deployment on a VM
- Usage Guide
- Troubleshooting
1. Slack App Configuration
To use the Slack integration, create and configure a Slack App in the Slack API Dashboard.
A. Create the App
- Click Create New App > From scratch.
- Name your app (for example, "PinionAI Bot") and select your workspace.
B. Enable Socket Mode
- In the left sidebar, go to Settings > Socket Mode.
- Toggle Enable Socket Mode to On.
- Generate an App-level token with the
connections:writescope. - Copy this token as
SLACK_APP_TOKEN. - Enable Interactivity & Shortcuts, Slash Commands, and Events.
C. Configure Bot Scopes
- Go to Features > OAuth & Permissions.
- Add these bot scopes:
chat:writefiles:readim:historychannels:historygroups:history- Install the app to your workspace.
- Copy the Bot User OAuth Token as
SLACK_BOT_TOKEN.
D. Enable Events
- Go to Features > Event Subscriptions.
- Enable events.
- Subscribe to:
message.channelsmessage.groupsmessage.im
E. Enable the Messages Tab
- Go to Features > App Home.
- Ensure Messages Tab is enabled.
- Allow users to send slash commands and messages from the Messages tab.
F. Add Slash Commands
- Go to Features > Slash Commands.
- Create
/endwith a short description such as "Ends the PinionAI chat session".
2. Environment Setup
Use a local .env file for development and a server-side env file or Docker env file for production.
Example local environment:
client_id=<YOUR_CLIENT_ID>
client_secret=<YOUR_CLIENT_SECRET>
agent_id=<YOUR_AGENT_ID>
host_url=https://api.pinionai.com
SLACK_BOT_TOKEN=xoxb-...
SLACK_APP_TOKEN=xapp-...
For production, the same values can be placed in deploy/prod-slack/env.yaml for Cloud Run-style deployments, or converted into a .env file for a VM deployment.
3. Local Deployment
- Activate your environment:
- Install dependencies:
- Run the bot:
4. Production Deployment on a VM
A VM is the recommended production hosting option for this Slack bot because it keeps a long-running Socket Mode connection alive.
4.1 Build the Slack-specific container image
Use the Slack-specific Dockerfile:
4.2 Prepare the environment file
On the VM, create a .env file with the same values you would normally put in deploy/prod-slack/env.yaml.
Example:
host_url=https://api.pinionai.com
client_id=<YOUR_CLIENT_ID>
client_secret=<YOUR_CLIENT_SECRET>
agent_id=<YOUR_AGENT_ID>
SLACK_BOT_TOKEN=xoxb-...
SLACK_APP_TOKEN=xapp-...
4.3 Run the container on the VM
docker run -d \
--name pinionai-slack \
--restart unless-stopped \
--env-file /path/to/.env \
pinionai-slack:latest
Check logs with:
4.4 Google Compute Engine VM
- Create a Debian 12 or Ubuntu 22.04 VM in GCP.
- Allow SSH and optionally HTTP/HTTPS traffic.
- Install Docker on the VM.
- Copy the repository to the server.
- Build the image using
Dockerfile.slack. - Start the container as shown above.
Example install steps on Debian/Ubuntu:
sudo apt update
sudo apt install -y docker.io
sudo systemctl enable docker
sudo systemctl start docker
sudo usermod -aG docker "$USER"
4.5 DigitalOcean Droplet
- Create a Debian 12 or Ubuntu 22.04 droplet.
- SSH into the droplet.
- Install Docker.
- Clone the repository and build the Slack image.
- Run the container with your
.envfile.
Example:
sudo apt update
sudo apt install -y docker.io
sudo systemctl enable docker
sudo systemctl start docker
4.6 Optional systemd service
If you prefer process management over Docker, run the bot directly from a Python virtual environment with a systemd unit. This is a good fit for long-running production use.
5. Usage Guide
Chatting
- Direct Message: Send a message to the bot in its Messages tab.
- Channels: Invite the bot to a channel and type a message.
Dynamic Agent Loading
You can change the active agent for a channel by uploading a .aia file.
- Upload the
.aiafile to the chat. - The bot will switch to that agent for subsequent messages in that channel.
- If the file is private, the bot will ask for the
key_secret.
Cleaning Slack Formatting
The bot removes Slack formatting wrappers such as <mailto:...> before sending text to the AI.
Ending a Session
To clear the active session:
- Use
/end, or - Send
!endas a message.
6. Troubleshooting
- "Sending messages to this app has been turned off": Enable the Messages tab and user messaging in App Home.
- Bot does not reply in channels: Ensure the bot is invited to the channel and that
message.channelsis subscribed. - Bot does not see messages: Check event subscriptions and app scopes.
- Module import errors: Make sure the virtual environment is activated and that dependencies are installed.