- Bot listens to app_mention slack event
- Then it takes the text and post it to chatgpt API
- Create a reply message on slack with chatGPT response
You can also deploy your own version of this bot using your fav cloud infra.
- Navigate to api.slack.com/apps and click on "Create New App".
- Select "From scratch" and input
Slack GPT Bot
as the name of your app. - You've just created your Slack app. Here, you'll receive 3 values that will be used for your deployment in the next step:
- Client ID: This is your App's unique public-facing ID that will be the value for the
NEXT_PUBLIC_SLACK_CLIENT_ID
env var. - Signing Secret: This is the signing secret used to validate that requests are genuinely coming from Slack. It will be the value for the
SLACK_SIGNING_SECRET
env var. - Verification Token: This is the verification token used to validate that requests are genuinely coming from Slack. It will be the value for the
SLACK_VERIFICATION_TOKEN
env var.
- Client ID: This is your App's unique public-facing ID that will be the value for the
- Navigate to platform.openai.com and signup for free.
- Now navigate to your api-keys page
- Click on
Create new secret key
(and save that key somewhere cause it won't be visible later) - Create an env var
OPENAI_API_KEY
with the value above
Well, I really wanted this project to work in Vercel or any other one-click install provider but unfourtunatly I coulnd't :( Reason is - Slack API expect the response to return within 3 seconds, if it doesn't get an answer it starts an exponential backoff requests. Vercel and other frameworks doesn't allow long timeouts for their edge functions so I had to revert to my AWS ECS which is easy enough for me.
Be sure to include all 6 of the env vars above in your deployment. (this is super important, otherwise it won't work!)
When the project finishes deploying, get your project's domain (e.g. https://slackbot.yourdomain.com
). You'll need it for the next step.
Make sure you add the url of your domain to the env file you created earlier something like SELF_URL=https://slackbot.com
For your Slack app to be able to send messages and subscribe to slack mention event in your Slack workspace, we will need to configure a few things:
-
From your Slack app home screen, select "OAuth & Permissions" from the sidebar (under "Features").
-
Scroll down to "Scopes", and add the following scopes under "Bot Token Scopes":
chat:write
chat:write.public
app_mentions:read
commands
[Slack Scopes]
-
Now, select "Event Subscriptions" from the sidebar (under "Features").
-
Toggle "Enable Events" to "ON".
-
For the "Request URL" field, input your project's domain and append
/api/event
to it. The final URL should look something likehttps:/yourdomain/api/event
. -
Scroll down to "Subscribe to bot events". Add the
app_mention
bot user event.[Slack configuration]
-
Click on "Save Changes".
- Go to "Basic Information" (under "Settings").
- Under "Install your app", click on "Install to Workspace".
- You should receive a notification that your app has been installed in your Slack workspace.
- Go back to "OAuth & Permissions". Copy the value of "Bot User OAuth Token".
- Set it as the
SLACK_OAUTH_TOKEN
env var in your project. - Redeploy your project for the changes to take effect.
- To verify that this worked, go to any channel on your Slack workspace and type something like
@aibot hello
. You should get a reply from the bot!
Kudos for getting so down the readme lol, please Star the repo and share the love!
The MIT License.
This project and it's code was inspired by vercel's slacker