mirror of
https://github.com/hwchase17/langchain.git
synced 2025-05-08 16:48:49 +00:00
Co-authored-by: Bagatur <baskaryan@gmail.com> Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
from typing import Optional, Type
|
|
|
|
from langchain_core.callbacks import CallbackManagerForToolRun
|
|
from pydantic import BaseModel, Field
|
|
|
|
from langchain_community.tools.slack.base import SlackBaseTool
|
|
|
|
|
|
class SendMessageSchema(BaseModel):
|
|
"""Input for SendMessageTool."""
|
|
|
|
message: str = Field(
|
|
...,
|
|
description="The message to be sent.",
|
|
)
|
|
channel: str = Field(
|
|
...,
|
|
description="The channel, private group, or IM channel to send message to.",
|
|
)
|
|
|
|
|
|
class SlackSendMessage(SlackBaseTool): # type: ignore[override, override]
|
|
"""Tool for sending a message in Slack."""
|
|
|
|
name: str = "send_message"
|
|
description: str = (
|
|
"Use this tool to send a message with the provided message fields."
|
|
)
|
|
args_schema: Type[SendMessageSchema] = SendMessageSchema
|
|
|
|
def _run(
|
|
self,
|
|
message: str,
|
|
channel: str,
|
|
run_manager: Optional[CallbackManagerForToolRun] = None,
|
|
) -> str:
|
|
try:
|
|
result = self.client.chat_postMessage(channel=channel, text=message)
|
|
output = "Message sent: " + str(result)
|
|
return output
|
|
except Exception as e:
|
|
return "Error creating conversation: {}".format(e)
|