This is really just a super quick 'n dirty fork of the existing ChatGPT Slack Bot running on Cloudflare Workers, but using the Workers AI LLama 2 Model.
Follow the steps below to get started.
- clone this repo
- install everything:
npm run i
- deploy the Worker quickly so you can add the secrets:
npm run deploy
- take note of the URL you get from the deploy script, you need it for the Slack config
- create your Slack App, get the secrets and add them to your Worker
Your Cloudflare worker will need to know the Slack bot's token.
Then add your bot's token running the following command. Paste the token when prompted to enter it.
npx wrangler secret put SLACK_TOKEN
Finally add the Slack signing secret. Paste the secret when prompted to enter it.
npx wrangler secret put SLACK_SIGNING_SECRET
The Slack app will be used to listen for request in Slack and post messages back into Slack. In order to support all of slack-chatgpt's features, there are a couple of steps needed. However, you can also choose to setup just the features you need.
Start by creating a Slack app on api.slack.com/apps. You are free to choose any name for the app that fits your needs.
Make sure to add the Bots feature to the Slack app and add the following scopes:
chat:write.public
app_mentions:read
channels:history
chat:write
chat:write.public
commands
groups:history
im:history
Take note of your bot's OAuth token and your app's signing secret as you will need add both to your Cloudflare worker later.
In order for the bot to respond to mentions and direct messages, you must enable Event Subscriptions in your Slack app and pass the URL to your Cloudflare Worker followed by the path /events
, e.g. https://slack-chatgpt.shapehq.workers.dev/events
.
Make sure to subscribe to the following events:
app_mention
message.im
Add a slash command to your Slack app. You are free to choose the command, description, and usage hint that fits your needs but make sure to set the URL to your Cloudflare Worker followed by the path /commands
, e.g. https://slack-chatgpt.shapehq.workers.dev/commands
.
In order to respond to a message using ChatGPT, you must enable interactivity on your Slack app. Make sure to set the URL to your Cloudflare Worker followed by the path /interactivity
, e.g. https://slack-chatgpt.shapehq.workers.dev/interactivity
.
Then create a new shortcut and select "On messages" when asked about where the shortcut should appear. You are free to choose the name and description that fit your needs but make sure to set the callback ID to ask_chatgpt_on_message
.
To add the global shortcut to your workspace, you must enable interactivity on your Slack app. You may have already done this when adding the shortcut to messages. When enabling interactivity, you should make sure to set the URL to your Cloudflare Worker followed by the path /interactivity
, e.g. https://slack-chatgpt.shapehq.workers.dev/interactivity
.
Then create a new shortcut and select "Global" when asked about where the shortcut should appear. You are free to choose the name and description that fit your needs but make sure to set the callback ID to ask_chatgpt_global
.
slack-chatgpt can be used to interact with ChatGPT in several ways on Slack.
When mentioning the bot, it will post a reply in a thread so it does not clutter the conversation.
People in the workspace can write messages messages to the bot in which case it replies directly within the conversation.
Use the slash command to ask ChatGPT a question and have it reply within the conversation.
The shortcut on messages can be used to answer a message using ChatGPT.
The global shortcut can be used to have ChatGPT help you write a message and then send that message to a channel or you can copy the message and send it yourself.