-
Notifications
You must be signed in to change notification settings - Fork 0
feat(methods): add chat.postMessage example #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f8fcdb7
524db5d
5a7ac6c
57525ee
682a665
7baceaf
b4d90a9
097dd95
9e9205f
17053e7
b3f1dc5
de7af48
802cac2
7dcf5ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| __pycache__ | ||
| .mypy_cache | ||
| .pytest_cache | ||
| .ruff_cache | ||
| .venv |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👁️🗨️ note: Hook detection might require a virtual environment here but let's follow up with these additions! |
||
| ``` | ||
|
|
||
| ## 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). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| mypy==2.3.0 | ||
| ruff==0.15.21 | ||
| slack-cli-hooks==0.3.0 | ||
| slack_sdk==3.43.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| apps.dev.json | ||
| cache/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "manifest": { | ||
| "source": "local" | ||
| }, | ||
| "project_id": "00000000-0000-0000-0000-000000000000" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "hooks": { | ||
| "get-hooks": "python3 -m slack_cli_hooks.hooks.get_hooks" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "display_information": { | ||
| "name": "Slack API Methods", | ||
| "description": "Example implementations to call \"chat\" methods" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗣️ note: We prefer method names in description to avoid character limits. |
||
| }, | ||
| "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 | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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.