This will help you get started with the Slack toolkit. For detailed documentation of all SlackToolkit features and configurations head to the API reference.
To use this toolkit, you will need to get a token as explained in the Slack API docs. Once you’ve received a SLACK_USER_TOKEN, you can input it as an environment variable below.
Copy
Ask AI
import getpassimport osif not os.getenv("SLACK_USER_TOKEN"): os.environ["SLACK_USER_TOKEN"] = getpass.getpass("Enter your Slack user token: ")
To enable automated tracing of individual tools, set your LangSmith API key:
Copy
Ask AI
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")# os.environ["LANGSMITH_TRACING"] = "true"
[SlackGetChannel(client=<slack_sdk.web.client.WebClient object at 0x113caa8c0>), SlackGetMessage(client=<slack_sdk.web.client.WebClient object at 0x113caa4d0>), SlackScheduleMessage(client=<slack_sdk.web.client.WebClient object at 0x113caa440>), SlackSendMessage(client=<slack_sdk.web.client.WebClient object at 0x113caa410>)]
example_query = "When was the #general channel created?"events = agent_executor.stream( {"messages": [("user", example_query)]}, stream_mode="values",)for event in events: message = event["messages"][-1] if message.type != "tool": # mask sensitive information event["messages"][-1].pretty_print()
Copy
Ask AI
================================ Human Message =================================When was the #general channel created?================================== Ai Message ==================================Tool Calls: get_channelid_name_dict (call_NXDkALjoOx97uF1v0CoZTqtJ) Call ID: call_NXDkALjoOx97uF1v0CoZTqtJ Args:================================== Ai Message ==================================The #general channel was created on timestamp 1671043305.
Copy
Ask AI
example_query = "Send a friendly greeting to channel C072Q1LP4QM."events = agent_executor.stream( {"messages": [("user", example_query)]}, stream_mode="values",)for event in events: message = event["messages"][-1] if message.type != "tool": # mask sensitive information event["messages"][-1].pretty_print()
Copy
Ask AI
================================ Human Message =================================Send a friendly greeting to channel C072Q1LP4QM.================================== Ai Message ==================================Tool Calls: send_message (call_xQxpv4wFeAZNZgSBJRIuaizi) Call ID: call_xQxpv4wFeAZNZgSBJRIuaizi Args: message: Hello! Have a great day! channel: C072Q1LP4QM================================== Ai Message ==================================I have sent a friendly greeting to the channel C072Q1LP4QM.