slack.mdx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. 1. Setup the Slack loader by configuring the Slack Webclient.
  11. ```Python
  12. from embedchain.loaders.slack import SlackLoader
  13. os.environ["SLACK_USER_TOKEN"] = "xoxp-*"
  14. loader = SlackLoader()
  15. """
  16. config = {
  17. 'base_url': slack_app_url,
  18. 'headers': web_headers,
  19. 'team_id': slack_team_id,
  20. }
  21. loader = SlackLoader(config)
  22. """
  23. ```
  24. NOTE: you can also pass the `config` with `base_url`, `headers`, `team_id` to setup your SlackLoader.
  25. 2. Once you setup the loader, you can create an app and load data using the above slack loader
  26. ```Python
  27. import os
  28. from embedchain.pipeline import Pipeline as App
  29. app = App()
  30. app.add("in:random", data_type="slack", loader=loader)
  31. question = "Which bots are available in the slack workspace's random channel?"
  32. # Answer: The available bot in the slack workspace's random channel is the Embedchain bot.
  33. ```
  34. 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:
  35. ```Python
  36. from embedchain.chunkers.slack import SlackChunker
  37. from embedchain.config.add_config import ChunkerConfig
  38. slack_chunker_config = ChunkerConfig(chunk_size=1000, chunk_overlap=0, length_function=len)
  39. slack_chunker = SlackChunker(config=slack_chunker_config)
  40. app.add(slack_chunker, data_type="slack", loader=loader, chunker=slack_chunker)
  41. ```