You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
langchain/libs/community/langchain_community/tools/slack/get_channel.py

35 lines
1.0 KiB
Python

import json
import logging
from typing import Optional
from langchain_core.callbacks import CallbackManagerForToolRun
from langchain_community.tools.slack.base import SlackBaseTool
class SlackGetChannel(SlackBaseTool):
name: str = "get_channelid_name_dict"
description: str = "Use this tool to get channelid-name dict."
def _run(
self,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
try:
logging.getLogger(__name__)
result = self.client.conversations_list()
channels = result["channels"]
filtered_result = [
{key: channel[key] for key in ("id", "name", "created", "num_members")}
for channel in channels
if "id" in channel
and "name" in channel
and "created" in channel
and "num_members" in channel
]
return json.dumps(filtered_result)
except Exception as e:
return "Error creating conversation: {}".format(e)