Skip to content

feat(methods): add chat.postMessage example - #132

Open
zimeg wants to merge 13 commits into
mainfrom
methods-typecheck-only
Open

feat(methods): add chat.postMessage example#132
zimeg wants to merge 13 commits into
mainfrom
methods-typecheck-only

Conversation

@zimeg

@zimeg zimeg commented Jul 14, 2026

Copy link
Copy Markdown
Member

Summary

Adds a methods/ chat.postMessage example to the Bolt for Python examples — the first entry in a new methods/ showcase of individual Slack Web API method calls with the slack_sdk WebClient.

  • src/chat/chat_post_message.py reads a token from the environment, initializes a WebClient, and calls chat_postMessage.
  • The example is a flat, top-to-bottom script with a manifest.json requesting only chat:write.
  • methods/README.md documents the family and links the implementation; the top-level README lists the new showcase.

The example is validated in CI by ruff (lint/format) and mypyslack_sdk's typed keyword arguments catch wrong types, missing required args, and misspelled arguments at check time.

Testing

From methods/:

export SLACK_TOKEN="xoxb-..."
slack install --environment local
python -m src.chat.chat_post_message

Confirm the message posts to the configured channel.


Supersedes the runtime-test / mock-server exploration in #131 (closed).

🤖 Generated with Claude Code

zimeg and others added 3 commits July 14, 2026 16:47
Add a methods/ chat.postMessage example verified by ruff + mypy, with no
runtime test. slack_sdk's chat_postMessage has typed keyword arguments, so
mypy catches wrong types, missing required args, and misspelled arguments
(e.g. chnnel -> "Missing named argument channel") without a mock server.

This is an alternative to the mock-server runtime-test approach for
side-by-side comparison.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Add methods to the CI matrix and treat pytest exit code 5 ("no tests
collected") as success, so the type-check-only methods example (which has
no tests) passes CI while still running ruff and mypy. Real test failures
(exit 1) still fail the build.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Match the runtime branch: add a chat manifest.json requesting only
chat:write, move the scope out of the README into the manifest, and use the
method's exact docs description.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Comment thread .github/workflows/test.yml Outdated
Comment on lines +34 to +35
# Exit code 5 = "no tests collected" (e.g. type-check-only showcases); treat as success.
pytest -v || [ $? -eq 5 ]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zimeg added 3 commits August 11, 2026 20:33
Mirror the bolt-js-examples methods README: tighten the intro, add a
'Making a request' walkthrough, and rename 'What's on display' to
'What's on call'. Adapt the run flow to Python — the walkthrough runs
from the package root (cd methods) so 'python -m src.chat.chat_post_message'
resolves.
Flatten the example into a top-level script matching the bolt-js
counterpart: read the token, initialize the client, call the method.
Drops the example01() wrapper, __main__ block, and the now-unused
SlackResponse import.
@zimeg zimeg changed the title feat(methods): add chat.postMessage example (typecheck-only) feat(methods): add chat.postMessage example Aug 12, 2026
zimeg added 3 commits August 11, 2026 22:16
The CI 'Run tests' step invokes pytest, but methods only pinned mypy,
ruff, and slack_sdk — so pytest failed with 'command not found' (exit
127), which the '|| [ $? -eq 5 ]' no-tests guard doesn't catch.
Install pytest (matching block-kit's pin) so it runs, collects no tests,
and exits 5 — which the guard treats as success.
Revert adding pytest to methods requirements; instead gate the pytest
invocation on a tests/ directory. methods is type-check-only and ships
no tests, so pytest was failing with 'command not found'. Guarding on
[ -d tests ] skips it cleanly for methods while still running tests
(and surfacing real failures) for showcases that have them.
Match the methods entry to its README: 'An interface for querying
information from and enacting change in a Slack workspace' rather than
the outdated 'Individual Slack Web API method calls' phrasing.
@zimeg zimeg added new PR only - a new app is being introduced python Pull requests that update python code labels Aug 12, 2026
@zimeg zimeg self-assigned this Aug 12, 2026
@zimeg zimeg added the documentation Improvements or additions to documentation label Aug 12, 2026
zimeg added 2 commits August 11, 2026 22:27
The example reads one variable (SLACK_TOKEN), so 'an environment
variable' is more accurate than the plural.

@zimeg zimeg left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👁️‍🗨️ A neartime is arrived!

Comment thread .github/workflows/test.yml Outdated
{
"display_information": {
"name": "Slack API Methods",
"description": "Example implementations to call \"chat\" methods"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗣️ note: We prefer method names in description to avoid character limits.

Comment thread methods/README.md
@@ -0,0 +1,21 @@
# Methods

An interface for querying information from and enacting change in a Slack workspace.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤓 note: Most wording is gathered from docs upstream if found.

Co-authored-by: Eden Zimbelman <zim@o526.net>
@zimeg
zimeg marked this pull request as ready for review August 12, 2026 05:35
@zimeg
zimeg requested a review from a team as a code owner August 12, 2026 05:35

@srtaalej srtaalej left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⭐ working great thank you for this change 💟
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation new PR only - a new app is being introduced python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants