diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 69f397f..a789e14 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,6 +16,7 @@ jobs: - "ai/slackbot-mcp-client/rich-responses/mcp-apps" - "ai/slackbot-mcp-client/slack-identity" - "block-kit" + - "methods" steps: - name: Checkout code uses: actions/checkout@v7 @@ -29,5 +30,5 @@ jobs: pip install -r requirements.txt ruff check ruff format --diff --check - mypy . - pytest -v + mypy ./**/*.py + if [ -d tests ]; then pytest -v; fi diff --git a/README.md b/README.md index 5a58c76..01c9a84 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,4 @@ This collections of examples highlights features of a Slack app in the language - **[AI in Slack](./ai)**: Agent experiences and MCP features in an interactive conversation interface. - **[Block Kit](./block-kit)**: The framework of visual components arranged to create app layouts. +- **[Methods](./methods)**: An interface for querying information from and enacting change in a Slack workspace. diff --git a/methods/.gitignore b/methods/.gitignore new file mode 100644 index 0000000..4a797c4 --- /dev/null +++ b/methods/.gitignore @@ -0,0 +1,5 @@ +__pycache__ +.mypy_cache +.pytest_cache +.ruff_cache +.venv diff --git a/methods/README.md b/methods/README.md new file mode 100644 index 0000000..5d6b815 --- /dev/null +++ b/methods/README.md @@ -0,0 +1,21 @@ +# Methods + +An interface for querying information from and enacting change in a Slack workspace. + +Read the [docs](https://docs.slack.dev/apis/web-api/) for explanations of concepts, or explore [reference](https://docs.slack.dev/reference/methods) pages for specific functionalities. + +## Making a request + +```sh +$ cd src/chat # Navigate to a method family +$ slack install --environment local # Create an app +$ vim chat_post_message.py # Edit arguments +$ export SLACK_TOKEN=xoxb-example # Set if unchanged +$ slack run chat_post_message # Make the request +``` + +## What's on call + +### chat + +- **[chat.postMessage](https://docs.slack.dev/reference/methods/chat.postmessage)**: Sends a message to a channel. [Implementation](./src/chat/chat_post_message.py). diff --git a/methods/requirements.txt b/methods/requirements.txt new file mode 100644 index 0000000..eb4a1ef --- /dev/null +++ b/methods/requirements.txt @@ -0,0 +1,4 @@ +mypy==2.3.0 +ruff==0.15.21 +slack-cli-hooks==0.3.0 +slack_sdk==3.43.0 diff --git a/methods/src/__init__.py b/methods/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/methods/src/chat/.slack/.gitignore b/methods/src/chat/.slack/.gitignore new file mode 100644 index 0000000..973ba60 --- /dev/null +++ b/methods/src/chat/.slack/.gitignore @@ -0,0 +1,2 @@ +apps.dev.json +cache/ diff --git a/methods/src/chat/.slack/config.json b/methods/src/chat/.slack/config.json new file mode 100644 index 0000000..909afbe --- /dev/null +++ b/methods/src/chat/.slack/config.json @@ -0,0 +1,6 @@ +{ + "manifest": { + "source": "local" + }, + "project_id": "00000000-0000-0000-0000-000000000000" +} diff --git a/methods/src/chat/.slack/hooks.json b/methods/src/chat/.slack/hooks.json new file mode 100644 index 0000000..ce474c9 --- /dev/null +++ b/methods/src/chat/.slack/hooks.json @@ -0,0 +1,5 @@ +{ + "hooks": { + "get-hooks": "python3 -m slack_cli_hooks.hooks.get_hooks" + } +} diff --git a/methods/src/chat/__init__.py b/methods/src/chat/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/methods/src/chat/chat_post_message.py b/methods/src/chat/chat_post_message.py new file mode 100644 index 0000000..5f862cc --- /dev/null +++ b/methods/src/chat/chat_post_message.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 chat.postMessage method +response = client.chat_postMessage( + channel="C123ABC456", + text="Here's a message for you", +) + +# Inspect the response +print(response) diff --git a/methods/src/chat/manifest.json b/methods/src/chat/manifest.json new file mode 100644 index 0000000..ad13ee2 --- /dev/null +++ b/methods/src/chat/manifest.json @@ -0,0 +1,22 @@ +{ + "display_information": { + "name": "Slack API Methods", + "description": "Example implementations to call \"chat\" methods" + }, + "features": { + "bot_user": { + "display_name": "Slack API Methods", + "always_online": true + } + }, + "oauth_config": { + "scopes": { + "bot": ["chat:write"] + } + }, + "settings": { + "org_deploy_enabled": true, + "socket_mode_enabled": false, + "token_rotation_enabled": false + } +}