slack_bot.mdx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ---
  2. title: '💼 Slack Bot'
  3. ---
  4. ### 🖼️ Setup
  5. 1. Create a workspace on Slack if you don't have one already by clicking [here](https://slack.com/intl/en-in/).
  6. 2. Create a new App on your Slack account by going [here](https://api.slack.com/apps).
  7. 3. Select `From Scratch`, then enter the Bot Name and select your workspace.
  8. 4. On the left Sidebar, go to `OAuth and Permissions` and add the following scopes under `Bot Token Scopes`:
  9. ```text
  10. app_mentions:read
  11. channels:history
  12. channels:read
  13. chat:write
  14. ```
  15. 5. Now select the option `Install to Workspace` and after it's done, copy the `Bot User OAuth Token` and set it in your secrets as `SLACK_BOT_TOKEN`.
  16. 6. Run your bot now,
  17. <Tabs>
  18. <Tab title="docker">
  19. ```bash
  20. docker run --name slack-bot -e OPENAI_API_KEY=sk-xxx -e SLACK_BOT_TOKEN=xxx -p 8000:8000 embedchain/slack-bot
  21. ```
  22. </Tab>
  23. <Tab title="python">
  24. ```bash
  25. pip install --upgrade "embedchain[slack]"
  26. python3 -m embedchain.bots.slack --port 8000
  27. ```
  28. </Tab>
  29. </Tabs>
  30. 7. Expose your bot to the internet. You can use your machine's public IP or DNS. Otherwise, employ a proxy server like [ngrok](https://ngrok.com/) to make your local bot accessible.
  31. 8. On the Slack API website go to `Event Subscriptions` on the left Sidebar and turn on `Enable Events`.
  32. 9. In `Request URL`, enter your server or ngrok address.
  33. 10. After it gets verified, click on `Subscribe to bot events`, add `message.channels` Bot User Event and click on `Save Changes`.
  34. 11. Now go to your workspace, right click on the bot name in the sidebar, click `view app details`, then `add this app to a channel`.
  35. ### 🚀 Usage Instructions
  36. - Go to the channel where you have added your bot.
  37. - To add data sources to the bot, use the command:
  38. ```text
  39. add <data_type> <url_or_text>
  40. ```
  41. - To ask queries from the bot, use the command:
  42. ```text
  43. query <question>
  44. ```
  45. 🎉 Happy Chatting! 🎉