This guide explains how to set up the pr-bot as a proper Slack bot using OAuth tokens instead of browser tokens.
The pr-bot uses proper OAuth bot tokens with event subscriptions for reliable Slack integration.
- Go to Slack API Apps
- Click "Create New App" → "From scratch"
- Enter app name:
pr-bot - Select your workspace
- Click "Create App"
- In your app settings, go to "OAuth & Permissions"
- Scroll down to "Scopes" → "Bot Token Scopes"
- Add the following scopes:
app_mentions:read- To respond when mentionedchannels:read- To read channel informationchat:write- To post messagesim:read- To read direct messagesim:write- To send direct messagescommands- To handle slash commands
- Scroll up to "OAuth Tokens for Your Workspace"
- Click "Install to Workspace"
- Review permissions and click "Allow"
- Copy the "Bot User OAuth Token" (starts with
xoxb-)
- Go to "Event Subscriptions" in your app settings
- Turn on "Enable Events"
- Set Request URL to:
https://your-server.com/slack/events - Under "Subscribe to bot events", add:
app_mention- When someone mentions your botmessage.im- Direct messages to your bot
- Go to "Slash Commands" in your app settings
- Create the following commands by clicking "Create New Command" for each:
- Request URL:
https://your-server.com/slack/commands - Short Description:
Show bot help and available commands - Usage Hint:
(no parameters)
- Request URL:
https://your-server.com/slack/commands - Short Description:
Analyze a PR across release branches - Usage Hint:
<PR_URL>
- Request URL:
https://your-server.com/slack/commands - Short Description:
Analyze all PRs related to a JIRA ticket - Usage Hint:
<JIRA_TICKET>
- Request URL:
https://your-server.com/slack/commands - Short Description:
Compare GitHub tag or MCE version - Usage Hint:
<COMPONENT> <VERSION> | mce <COMPONENT> <VERSION>
Add to your .env file:
# Slack Bot Configuration (recommended)
PR_BOT_SLACK_BOT_TOKEN=xoxb-your-bot-token-here# Start the pr-bot server
pr-bot -server
# Or specify a custom port
pr-bot -server -port 3000Use the individual slash commands:
/info
/pr https://github.com/openshift/assisted-service/pull/7788
/jt MGMT-20662
/version assisted-service v2.40.1
/version mce assisted-service 2.8.0
Mention the bot with commands:
@pr-bot info
@pr-bot pr https://github.com/openshift/assisted-service/pull/7788
@pr-bot jt MGMT-20662
@pr-bot version assisted-service v2.40.1
Send commands directly to the bot:
info
pr https://github.com/openshift/assisted-service/pull/7788
jt MGMT-20662
version assisted-service v2.40.1
| Command | Description | Example |
|---|---|---|
/info |
Show help and available commands | /info |
/pr <URL> |
Analyze a PR across release branches | /pr https://github.com/openshift/assisted-service/pull/7788 |
/jt <TICKET> |
Analyze all PRs related to a JIRA ticket | /jt MGMT-20662 |
/version <COMPONENT> <VERSION> |
Compare GitHub tag with previous version | /version assisted-service v2.40.1 |
/version mce <COMPONENT> <VERSION> |
Compare MCE version with previous version | /version mce assisted-service 2.8.0 |
The pr-bot server exposes these endpoints:
POST /slack/events- Slack event subscriptions (mentions, DMs)POST /slack/commands- Slack slash commandsGET /health- Health check endpoint
- Check bot token: Ensure
PR_BOT_SLACK_BOT_TOKENis set correctly - Verify scopes: Make sure all required scopes are added to your bot
- Check server logs: Look for authentication errors in server output
- Test endpoint: Verify your server is accessible at the configured URL
- URL verification: Slack will send a challenge request to verify your endpoint
- HTTPS required: Event subscriptions require HTTPS endpoints
- Response time: Your server must respond within 3 seconds
- Check logs: Look for event processing errors in server output
- Verify command setup: Ensure
/prbotcommand is configured correctly - Check request URL: Must point to
/slack/commandsendpoint - Response format: Commands must respond with plain text or JSON
- Bot tokens are more secure than browser tokens as they don't expire with user sessions
- Scopes are limited to only what the bot needs to function
- Audit trail - All bot actions are logged and attributable
- Workspace control - Admins can easily manage bot permissions
For local development with ngrok:
- Install ngrok:
npm install -g ngrok - Start your server:
pr-bot -server -port 3000 - Expose with ngrok:
ngrok http 3000 - Use the ngrok URL in your Slack app configuration
- Update Request URLs to use the ngrok domain
Example ngrok URLs:
- Events:
https://abc123.ngrok.io/slack/events - Commands:
https://abc123.ngrok.io/slack/commands