From 67d25e02716d51aac6057ee084fc6a1815062a72 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Wed, 19 Aug 2026 23:05:49 -0700 Subject: [PATCH] feat(methods): add codeChannels method examples Add examples for the codeChannels.* methods with a minimal code_channels:manage manifest and the standard .slack CLI hooks. Stacked on the agents.sessions examples. Co-Authored-By: Claude --- methods/README.md | 13 +++++++++ methods/src/code_channels/.slack/.gitignore | 2 ++ methods/src/code_channels/.slack/config.json | 6 +++++ methods/src/code_channels/.slack/hooks.json | 5 ++++ methods/src/code_channels/__init__.py | 0 .../code_channels/code_channels_archive.py | 18 +++++++++++++ .../src/code_channels/code_channels_create.py | 19 +++++++++++++ .../code_channels/code_channels_get_canvas.py | 18 +++++++++++++ .../code_channels/code_channels_list_views.py | 17 ++++++++++++ .../code_channels_remove_view.py | 18 +++++++++++++ .../src/code_channels/code_channels_rename.py | 18 +++++++++++++ .../code_channels_set_canvas_content.py | 19 +++++++++++++ .../code_channels_set_commands.py | 27 +++++++++++++++++++ .../code_channels_set_properties.py | 27 +++++++++++++++++++ .../code_channels/code_channels_set_view.py | 21 +++++++++++++++ methods/src/code_channels/manifest.json | 25 +++++++++++++++++ 16 files changed, 253 insertions(+) create mode 100644 methods/src/code_channels/.slack/.gitignore create mode 100644 methods/src/code_channels/.slack/config.json create mode 100644 methods/src/code_channels/.slack/hooks.json create mode 100644 methods/src/code_channels/__init__.py create mode 100644 methods/src/code_channels/code_channels_archive.py create mode 100644 methods/src/code_channels/code_channels_create.py create mode 100644 methods/src/code_channels/code_channels_get_canvas.py create mode 100644 methods/src/code_channels/code_channels_list_views.py create mode 100644 methods/src/code_channels/code_channels_remove_view.py create mode 100644 methods/src/code_channels/code_channels_rename.py create mode 100644 methods/src/code_channels/code_channels_set_canvas_content.py create mode 100644 methods/src/code_channels/code_channels_set_commands.py create mode 100644 methods/src/code_channels/code_channels_set_properties.py create mode 100644 methods/src/code_channels/code_channels_set_view.py create mode 100644 methods/src/code_channels/manifest.json diff --git a/methods/README.md b/methods/README.md index 7969f8d..777bcef 100644 --- a/methods/README.md +++ b/methods/README.md @@ -24,3 +24,16 @@ $ slack run chat_post_message # Make the request ### chat - **[chat.postMessage](https://docs.slack.dev/reference/methods/chat.postmessage)**: Sends a message to a channel. [Implementation](./src/chat/chat_post_message.py). + +### codeChannels + +- **[codeChannels.archive](https://docs.slack.dev/reference/methods/codeChannels.archive)**: Archives a code channel, optionally recording a summary message on the channel. [Implementation](./src/code_channels/code_channels_archive.py). +- **[codeChannels.create](https://docs.slack.dev/reference/methods/codeChannels.create)**: Creates a dedicated code channel for an agent session. [Implementation](./src/code_channels/code_channels_create.py). +- **[codeChannels.getCanvas](https://docs.slack.dev/reference/methods/codeChannels.getCanvas)**: Fetches a canvas attached to a code channel — full content plus comment threads — in a single round-trip. [Implementation](./src/code_channels/code_channels_get_canvas.py). +- **[codeChannels.listViews](https://docs.slack.dev/reference/methods/codeChannels.listViews)**: Lists the view tabs attached to a code channel. [Implementation](./src/code_channels/code_channels_list_views.py). +- **[codeChannels.removeView](https://docs.slack.dev/reference/methods/codeChannels.removeView)**: Removes a view from a code channel. [Implementation](./src/code_channels/code_channels_remove_view.py). +- **[codeChannels.rename](https://docs.slack.dev/reference/methods/codeChannels.rename)**: Renames a code channel. [Implementation](./src/code_channels/code_channels_rename.py). +- **[codeChannels.setCanvasContent](https://docs.slack.dev/reference/methods/codeChannels.setCanvasContent)**: Replaces the full markdown content of a canvas attached to a code channel, preserving the comment threads on the sections your agent didn't change. [Implementation](./src/code_channels/code_channels_set_canvas_content.py). +- **[codeChannels.setCommands](https://docs.slack.dev/reference/methods/codeChannels.setCommands)**: Registers the set of slash commands your agent offers in a code channel. [Implementation](./src/code_channels/code_channels_set_commands.py). +- **[codeChannels.setProperties](https://docs.slack.dev/reference/methods/codeChannels.setProperties)**: Sets properties on a code channel: context bar items and external resource details. [Implementation](./src/code_channels/code_channels_set_properties.py). +- **[codeChannels.setView](https://docs.slack.dev/reference/methods/codeChannels.setView)**: Creates or updates a view in a code channel. Views can render HTML, diffs, Block Kit, or canvases as tabs alongside the conversation. [Implementation](./src/code_channels/code_channels_set_view.py). diff --git a/methods/src/code_channels/.slack/.gitignore b/methods/src/code_channels/.slack/.gitignore new file mode 100644 index 0000000..973ba60 --- /dev/null +++ b/methods/src/code_channels/.slack/.gitignore @@ -0,0 +1,2 @@ +apps.dev.json +cache/ diff --git a/methods/src/code_channels/.slack/config.json b/methods/src/code_channels/.slack/config.json new file mode 100644 index 0000000..909afbe --- /dev/null +++ b/methods/src/code_channels/.slack/config.json @@ -0,0 +1,6 @@ +{ + "manifest": { + "source": "local" + }, + "project_id": "00000000-0000-0000-0000-000000000000" +} diff --git a/methods/src/code_channels/.slack/hooks.json b/methods/src/code_channels/.slack/hooks.json new file mode 100644 index 0000000..ce474c9 --- /dev/null +++ b/methods/src/code_channels/.slack/hooks.json @@ -0,0 +1,5 @@ +{ + "hooks": { + "get-hooks": "python3 -m slack_cli_hooks.hooks.get_hooks" + } +} diff --git a/methods/src/code_channels/__init__.py b/methods/src/code_channels/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/methods/src/code_channels/code_channels_archive.py b/methods/src/code_channels/code_channels_archive.py new file mode 100644 index 0000000..338ae1e --- /dev/null +++ b/methods/src/code_channels/code_channels_archive.py @@ -0,0 +1,18 @@ +import os + +from slack_sdk import WebClient + +# Read a token from an environment variable +token = os.environ.get("SLACK_TOKEN") + +# Initialize +client = WebClient(token=token) + +# Call the codeChannels.archive method +response = client.codeChannels_archive( + channel_id="C123ABC456", + summary_message_ts="1717171717.123456", +) + +# Inspect the response +print(response) diff --git a/methods/src/code_channels/code_channels_create.py b/methods/src/code_channels/code_channels_create.py new file mode 100644 index 0000000..1f5c02a --- /dev/null +++ b/methods/src/code_channels/code_channels_create.py @@ -0,0 +1,19 @@ +import os + +from slack_sdk import WebClient + +# Read a token from an environment variable +token = os.environ.get("SLACK_TOKEN") + +# Initialize +client = WebClient(token=token) + +# Call the codeChannels.create method +response = client.codeChannels_create( + name="Fix flaky login test", + origin_channel_id="C123ABC456", + origin_message_ts="1717171717.123456", +) + +# Inspect the response +print(response) diff --git a/methods/src/code_channels/code_channels_get_canvas.py b/methods/src/code_channels/code_channels_get_canvas.py new file mode 100644 index 0000000..016d0aa --- /dev/null +++ b/methods/src/code_channels/code_channels_get_canvas.py @@ -0,0 +1,18 @@ +import os + +from slack_sdk import WebClient + +# Read a token from an environment variable +token = os.environ.get("SLACK_TOKEN") + +# Initialize +client = WebClient(token=token) + +# Call the codeChannels.getCanvas method +response = client.codeChannels_getCanvas( + channel_id="C123ABC456", + canvas_id="F123ABC456", +) + +# Inspect the response +print(response) diff --git a/methods/src/code_channels/code_channels_list_views.py b/methods/src/code_channels/code_channels_list_views.py new file mode 100644 index 0000000..928d18d --- /dev/null +++ b/methods/src/code_channels/code_channels_list_views.py @@ -0,0 +1,17 @@ +import os + +from slack_sdk import WebClient + +# Read a token from an environment variable +token = os.environ.get("SLACK_TOKEN") + +# Initialize +client = WebClient(token=token) + +# Call the codeChannels.listViews method +response = client.codeChannels_listViews( + channel_id="C123ABC456", +) + +# Inspect the response +print(response) diff --git a/methods/src/code_channels/code_channels_remove_view.py b/methods/src/code_channels/code_channels_remove_view.py new file mode 100644 index 0000000..f8101a6 --- /dev/null +++ b/methods/src/code_channels/code_channels_remove_view.py @@ -0,0 +1,18 @@ +import os + +from slack_sdk import WebClient + +# Read a token from an environment variable +token = os.environ.get("SLACK_TOKEN") + +# Initialize +client = WebClient(token=token) + +# Call the codeChannels.removeView method +response = client.codeChannels_removeView( + channel_id="C123ABC456", + view_id="V123ABC456", +) + +# Inspect the response +print(response) diff --git a/methods/src/code_channels/code_channels_rename.py b/methods/src/code_channels/code_channels_rename.py new file mode 100644 index 0000000..097d446 --- /dev/null +++ b/methods/src/code_channels/code_channels_rename.py @@ -0,0 +1,18 @@ +import os + +from slack_sdk import WebClient + +# Read a token from an environment variable +token = os.environ.get("SLACK_TOKEN") + +# Initialize +client = WebClient(token=token) + +# Call the codeChannels.rename method +response = client.codeChannels_rename( + channel_id="C123ABC456", + name="Fix flaky login test v2", +) + +# Inspect the response +print(response) diff --git a/methods/src/code_channels/code_channels_set_canvas_content.py b/methods/src/code_channels/code_channels_set_canvas_content.py new file mode 100644 index 0000000..ea3e365 --- /dev/null +++ b/methods/src/code_channels/code_channels_set_canvas_content.py @@ -0,0 +1,19 @@ +import os + +from slack_sdk import WebClient + +# Read a token from an environment variable +token = os.environ.get("SLACK_TOKEN") + +# Initialize +client = WebClient(token=token) + +# Call the codeChannels.setCanvasContent method +response = client.codeChannels_setCanvasContent( + channel_id="C123ABC456", + canvas_id="F123ABC456", + content="# Plan\n\n1. Reproduce the flaky test\n2. Fix the race\n3. Verify", +) + +# Inspect the response +print(response) diff --git a/methods/src/code_channels/code_channels_set_commands.py b/methods/src/code_channels/code_channels_set_commands.py new file mode 100644 index 0000000..0abe872 --- /dev/null +++ b/methods/src/code_channels/code_channels_set_commands.py @@ -0,0 +1,27 @@ +import os + +from slack_sdk import WebClient + +# Read a token from an environment variable +token = os.environ.get("SLACK_TOKEN") + +# Initialize +client = WebClient(token=token) + +# Call the codeChannels.setCommands method +response = client.codeChannels_setCommands( + channel_id="C123ABC456", + commands=[ + { + "name": "test", + "description": "Run the test suite", + }, + { + "name": "diff", + "description": "Show the current diff", + }, + ], +) + +# Inspect the response +print(response) diff --git a/methods/src/code_channels/code_channels_set_properties.py b/methods/src/code_channels/code_channels_set_properties.py new file mode 100644 index 0000000..71219f8 --- /dev/null +++ b/methods/src/code_channels/code_channels_set_properties.py @@ -0,0 +1,27 @@ +import os + +from slack_sdk import WebClient + +# Read a token from an environment variable +token = os.environ.get("SLACK_TOKEN") + +# Initialize +client = WebClient(token=token) + +# Call the codeChannels.setProperties method +response = client.codeChannels_setProperties( + channel_id="C123ABC456", + code_channel={ + "context_bar_items": [ + { + "key": "repo", + "label": "acme/billing", + "icon": "folder", + "url": "https://github.com/acme/billing", + }, + ] + }, +) + +# Inspect the response +print(response) diff --git a/methods/src/code_channels/code_channels_set_view.py b/methods/src/code_channels/code_channels_set_view.py new file mode 100644 index 0000000..98fffa7 --- /dev/null +++ b/methods/src/code_channels/code_channels_set_view.py @@ -0,0 +1,21 @@ +import os + +from slack_sdk import WebClient + +# Read a token from an environment variable +token = os.environ.get("SLACK_TOKEN") + +# Initialize +client = WebClient(token=token) + +# Call the codeChannels.setView method +response = client.codeChannels_setView( + channel_id="C123ABC456", + type="diff", + content="diff --git a/cron.py b/cron.py\n--- a/cron.py\n+++ b/cron.py\n@@ ...", + base_branch="main", + head_branch="agent/migrate-cron", +) + +# Inspect the response +print(response) diff --git a/methods/src/code_channels/manifest.json b/methods/src/code_channels/manifest.json new file mode 100644 index 0000000..3c0f74d --- /dev/null +++ b/methods/src/code_channels/manifest.json @@ -0,0 +1,25 @@ +{ + "display_information": { + "name": "Slack API Methods", + "description": "Example implementations to call \"codeChannels\" methods" + }, + "features": { + "bot_user": { + "display_name": "Slack API Methods", + "always_online": true + }, + "code_channels": { + "enabled": true + } + }, + "oauth_config": { + "scopes": { + "bot": ["code_channels:manage"] + } + }, + "settings": { + "org_deploy_enabled": true, + "socket_mode_enabled": false, + "token_rotation_enabled": false + } +}