This is an AIGC project by GPT-4, it writes everything including this doc, I just tweaked a little bit of the prompt by myself. If you found any issues, you can ask ChatGPT to fix it for you.
This Slack bot is designed to check and correct English grammar in Slack messages. It uses OpenAI's GPT-3.5 Turbo model for text processing.
- Visit the Slack API website and click on
Your Apps
. - Click on
Create New App
button, name your app, and select the workspace you want to install it in. - Navigate to
OAuth & Permissions
page under theFeatures
section in the sidebar. Here, add the following scopes underBot Token Scopes
:channels:history
channels:read
channels:write
chat:write
chat:write.public
users:read
- Click
Install to Workspace
button. You will be redirected to your workspace to authorize the app. Allow it. - Once installed, you will be redirected back to the
OAuth & Permissions
page. Here, you can find yourBot User OAuth Access Token
. Save this token, you'll need it later. - From your app's settings page, navigate to the
Basic Information
section. - Scroll down to find the
App Credentials
section. Here, you can find yourSigning Secret
. Save this token, you'll need it later.
Create a .env
file in your project directory with the following contents:
SLACK_BOT_TOKEN=your-bot-user-oauth-access-token
SLACK_SIGNING_SECRET=your-slack-signing-secret
OPENAI_API_KEY=your-openai-api-key
Replace your-bot-user-oauth-access-token
and your-slack-signing-secret
with the token you saved earlier and your-openai-api-key
with your OpenAI API key.
To run the bot locally, first install the dependencies using pipenv:
pipenv install
pipenv run python app.py
Now the bot is running.
After you have your public URL, go back to your app settings on Slack API website.
Navigate to 'Event Subscriptions' under the 'Features' section in the sidebar. Here, enable events.
In the Request URL
box, enter your public URL followed by /slack/events. For example, if your public URL is http://12345.ngrok.io, enter http://12345.ngrok.io:3000/slack/events as the Request URL
.
Under Subscribe to Bot Events
, click on the Add Bot User Event
button and add message.channels
event.
Finally, reinstall your app to your workspace for these changes to take effect.
Once the bot is running and installed to your workspace, it will automatically check and correct the grammar of all English messages sent in the channels it's added to.
Please note that the bot will only correct English messages and will ignore messages that contain non-English characters.