Skip to content

Commit 549640b

Browse files
zimegClaude
andcommitted
feat(methods): add codeChannels method examples
Add a code_channels method family under methods/src/ demonstrating the typed codeChannels.* Web API methods: create (spin up a code channel for a session) and setView (publish a diff to the channel's code tab). Mirrors the existing per-family layout (manifest with code_channels:manage scope + the code_channels feature, .slack local app, one script per method) and the typecheck-only verification approach. Depends on the codeChannels.* methods being available in slack-sdk. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
1 parent d519cb3 commit 549640b

8 files changed

Lines changed: 84 additions & 0 deletions

File tree

‎methods/README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ $ slack run chat_post_message # Make the request
1919
### chat
2020

2121
- **[chat.postMessage](https://docs.slack.dev/reference/methods/chat.postmessage)**: Sends a message to a channel. [Implementation](./src/chat/chat_post_message.py).
22+
23+
### codeChannels
24+
25+
- **[codeChannels.create](https://docs.slack.dev/reference/methods/codeChannels.create)**: Creates a code channel for a session. [Implementation](./src/code_channels/code_channels_create.py).
26+
- **[codeChannels.setView](https://docs.slack.dev/reference/methods/codeChannels.setView)**: Publishes a view tab (such as a diff) to a code channel. [Implementation](./src/code_channels/code_channels_set_view.py).
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
apps.dev.json
2+
cache/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"manifest": {
3+
"source": "local"
4+
},
5+
"project_id": "00000000-0000-0000-0000-000000000000"
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"hooks": {
3+
"get-hooks": "python3 -m slack_cli_hooks.hooks.get_hooks"
4+
}
5+
}

‎methods/src/code_channels/__init__.py‎

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
3+
from slack_sdk import WebClient
4+
5+
# Read a token from an environment variable
6+
token = os.environ.get("SLACK_TOKEN")
7+
8+
# Initialize
9+
client = WebClient(token=token)
10+
11+
# Call the codeChannels.create method to spin up a code channel for a session,
12+
# rooted at the message that asked for it
13+
response = client.codeChannels_create(
14+
name="Fix flaky login test",
15+
origin_channel_id="C123ABC456",
16+
origin_message_ts="1717171717.123456",
17+
)
18+
19+
# Inspect the response
20+
print(response)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
3+
from slack_sdk import WebClient
4+
5+
# Read a token from an environment variable
6+
token = os.environ.get("SLACK_TOKEN")
7+
8+
# Initialize
9+
client = WebClient(token=token)
10+
11+
# Call the codeChannels.setView method to publish a diff to the channel's code tab
12+
response = client.codeChannels_setView(
13+
channel_id="C123ABC456",
14+
type="diff",
15+
content="diff --git a/cron.py b/cron.py\n--- a/cron.py\n+++ b/cron.py\n@@ ...",
16+
base_branch="main",
17+
head_branch="agent/migrate-cron",
18+
)
19+
20+
# Inspect the response
21+
print(response)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"display_information": {
3+
"name": "Slack API Methods",
4+
"description": "Example implementations to call \"codeChannels\" methods"
5+
},
6+
"features": {
7+
"bot_user": {
8+
"display_name": "Slack API Methods",
9+
"always_online": true
10+
},
11+
"code_channels": {
12+
"enabled": true
13+
}
14+
},
15+
"oauth_config": {
16+
"scopes": {
17+
"bot": ["app_mentions:read", "channels:history", "chat:write", "code_channels:manage"]
18+
}
19+
},
20+
"settings": {
21+
"org_deploy_enabled": true,
22+
"socket_mode_enabled": false,
23+
"token_rotation_enabled": false
24+
}
25+
}

0 commit comments

Comments
 (0)