Slack
This notebook shows how to use the Slack chat loader. This class helps map exported slack conversations to LangChain chat messages.
The process has three steps:
- Export the desired conversation thread by following the instructions here.
- Create the
SlackChatLoader
with the file path pointed to the json file or directory of JSON files - Call
loader.load()
(orloader.lazy_load()
) to perform the conversion. Optionally usemerge_chat_runs
to combine message from the same sender in sequence, and/ormap_ai_messages
to convert messages from the specified sender to the "AIMessage" class.
1. Create message dump
Currently (2023/08/23) this loader best supports a zip directory of files in the format generated by exporting your a direct message conversation from Slack. Follow up-to-date instructions from slack on how to do so.
We have an example in the LangChain repo.
import requests
permalink = "https://raw.githubusercontent.com/langchain-ai/langchain/342087bdfa3ac31d622385d0f2d09cf5e06c8db3/libs/langchain/tests/integration_tests/examples/slack_export.zip"
response = requests.get(permalink)
with open("slack_dump.zip", "wb") as f:
f.write(response.content)
2. Create the Chat Loader
Provide the loader with the file path to the zip directory. You can optionally specify the user id that maps to an ai message as well an configure whether to merge message runs.
from langchain_community.chat_loaders.slack import SlackChatLoader
API Reference:SlackChatLoader
loader = SlackChatLoader(
path="slack_dump.zip",
)