Slack bot built with Node.js and Express.js that leverages anthropic for chat completion, Slack Web API for sending messages, Slack Events API for listening to messages and Trigger.dev for background tasks.
- Chat completion using anthropic
- Send messages to Slack
- Listen to messages from Slack
- Background tasks using Trigger.dev
- Clone the repository
git clone https://github.com/Kritik-J/slack-bot
- Install dependencies
npm install
- Copy the
.env.example
file to.env
cp .env.example .env
Grab Trigger.dev credentials from the dashboard and update the .env
file
- Navigate to the Trigger.dev dashboard Trigger.dev
- Create a new project v3, If you don't have one
- Navigate to the project settings page and grab the project id and set it in the
.env
file asTRIGGER_PROJECT_ID
- Navigate to the API keys page and grab the api key and set it in the
.env
file asTRIGGER_SECRET_KEY
Note: As of now Trigger.dev v3 is still in developer preview.
Navigate to Anthropic and create an account. Grab the api key and set it in the .env
file as ANTHROPIC_API_KEY
- Start the server
npm run dev
- Start Trigger.dev
npm run dev:trigger
- Start ngrok
ngrok http your_port
- Create a Slack app
Navigate to Slack API click on Create New App
and choose From scratch
. Fill in the required details and click on Create App
.
- Install the app to your workspace
Navigate to OAuth & Permissions
, scroll down to Scopes
and add the following scopes to bot token scopes: chat:write
. Click on Install to Workspace
.
- Get the Bot User OAuth Token
Once the app is installed to your workspace, You will find the Bot User OAuth Token
under OAuth & Permissions
section. Copy the token and paste it in the .env
file as SLACK_BOT_TOKEN
- Subscribe to the events
Navigate to Event Subscriptions
, enable events and paste the ngrok URL followed by /slack/events
in the Request URL
field. Subscribe to the following bot events: app_mention
- Signing Secret
Navigate to Basic Information
and copy the Signing Secret
and paste it in the .env
file as SLACK_SIGNING_SECRET
- Deploy trigger.dev tasks
npx trigger.dev@beta deploy
Note: Make sure to set environment variables in the Trigger.dev dashboard
- Deploy your server to a cloud provider like railway, heroku, etc.
Note: Make sure to set environment variables in the cloud provider dashboard as well, Also replace the ngrok URL with the deployed server URL in the Slack app settings.