slack.mdx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ---
  2. title: '🤖 Slack'
  3. ---
  4. ## Pre-requisite
  5. - Download required packages by running `pip install --upgrade "embedchain[slack]"`.
  6. - Configure your slack bot token as environment variable `SLACK_USER_TOKEN`.
  7. - Find your user token on your [Slack Account](https://api.slack.com/authentication/token-types)
  8. - Make sure your slack user token includes [search](https://api.slack.com/scopes/search:read) scope.
  9. ## Example
  10. ### Get Started
  11. This will automatically retrieve data from the workspace associated with the user's token.
  12. ```python
  13. import os
  14. from embedchain import App
  15. os.environ["SLACK_USER_TOKEN"] = "xoxp-xxx"
  16. app = App()
  17. app.add("in:general", data_type="slack")
  18. result = app.query("what are the messages in general channel?")
  19. print(result)
  20. ```
  21. ### Customize your SlackLoader
  22. 1. Setup the Slack loader by configuring the Slack Webclient.
  23. ```Python
  24. from embedchain.loaders.slack import SlackLoader
  25. os.environ["SLACK_USER_TOKEN"] = "xoxp-*"
  26. config = {
  27. 'base_url': slack_app_url,
  28. 'headers': web_headers,
  29. 'team_id': slack_team_id,
  30. }
  31. loader = SlackLoader(config)
  32. ```
  33. NOTE: you can also pass the `config` with `base_url`, `headers`, `team_id` to setup your SlackLoader.
  34. 2. Once you setup the loader, you can create an app and load data using the above slack loader
  35. ```Python
  36. import os
  37. from embedchain.pipeline import Pipeline as App
  38. app = App()
  39. app.add("in:random", data_type="slack", loader=loader)
  40. question = "Which bots are available in the slack workspace's random channel?"
  41. # Answer: The available bot in the slack workspace's random channel is the Embedchain bot.
  42. ```
  43. 3. We automatically create a chunker to chunk your slack data, however if you wish to provide your own chunker class. Here is how you can do that:
  44. ```Python
  45. from embedchain.chunkers.slack import SlackChunker
  46. from embedchain.config.add_config import ChunkerConfig
  47. slack_chunker_config = ChunkerConfig(chunk_size=1000, chunk_overlap=0, length_function=len)
  48. slack_chunker = SlackChunker(config=slack_chunker_config)
  49. app.add(slack_chunker, data_type="slack", loader=loader, chunker=slack_chunker)
  50. ```