Make sure to enter your env variables in .env
pnpm i
cp .env.example .env
# development
pnpm dev
# production
pnpm start
Format: q? <question>
Format: i? <image prompt>
Format: @your-bot tldr
To create a Slack bot on the Slack website, follow these steps:
- Go to the Slack API website: https://api.slack.com/
- Sign in to your Slack account or create a new one if you haven't already.
- Click on the "Your Apps" button on the top-right corner of the page, or use this direct link: https://api.slack.com/apps
- Click the "Create New App" button.
- In the "Create a Slack App" dialog, enter the following information: App Name: Choose a name for your Slack bot. Development Slack Workspace: Select a workspace where you want to develop and test your Slack bot. Click the "Create App" button.
- After creating the app, you'll be redirected to the "Basic Information" page. Here, you can find your "App ID" and manage your app settings.
- Under "Add features and functionality," click on "Bots" and then click the "Add a bot" button to add a bot user to your app.
- Set a display name and default username for your bot and click "Add Bot" to save.
- From the left sidebar, click on "OAuth & Permissions" under "Features."
- Scroll down to the "Scopes" section and add the necessary bot token scopes. For the example provided in the previous answer, you'll need the following scopes:
- app_mentions:read
- channels:history
- chat:write
- groups:history
- groups:read
- users:write
- users:read
- Scroll up to the "OAuth Tokens for Your Workspace" section and click the "Install App to Workspace" button. Grant the requested permissions.
- After installing the app, you'll see the "Bot User OAuth Token" under "OAuth Tokens for Your Workspace." Copy this token and use it as your SLACK_BOT_TOKEN.
To enable Socket Mode, follow these additional steps:
- From the left sidebar, click on "Socket Mode" under "Settings."
- Enable Socket Mode by toggling the switch.
- Click the "Generate Token" button to generate an App-Level token with the connections:write scope. Copy this token and use it as your SLACK_APP_TOKEN.
Now you have created a Slack bot and have the necessary tokens to use with the example code provided earlier. Make sure to invite the bot to the channels where you want it to be active by typing /invite @your-bot-username
in those channels.
Make sure you have set whitelisted channels in your .env
file.
You can get Channel IDs by right-clicking on a channel in the side bar and click Copy link here:
For example the link for mine is:
https://zolplay.slack.com/archives/C04F7ML901G
Which means the Channel ID is C04F7ML901G
SLACK_WHITELISTED_CHANNELS="C04F7ML901G"
If you want the bot to listen for multiple channels, you can separate the channel IDs by commas like this:
SLACK_WHITELISTED_CHANNELS="C04F7ML901G,C04F7ML901Z,C04F7ML901D"