Skip to content

Commit babac6c

Browse files
committed
update
1 parent eb010b9 commit babac6c

File tree

7 files changed

+45
-40
lines changed

7 files changed

+45
-40
lines changed

messaging/work-objects/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ __pycache__
33
.pytest_cache
44
.ruff_cache
55
.venv
6-
.slack
6+
.slack

messaging/work-objects/README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,35 @@ You can also [post](https://docs.slack.dev/messaging/work-objects/#implementatio
66

77
Read the [docs](https://docs.slack.dev/messaging/work-objects/) to learn more!
88

9-
## Running locally
9+
## Setup
1010

11-
### 0. Create an app
11+
### Option 1: Create a new app with the Slack CLI
1212

13-
Create an app and add `myappdomain.com`as an [app unfurl domain](https://docs.slack.dev/messaging/unfurling-links-in-messages/#configuring_domains) (or update the unfurl URLs in `metadata.py` with your domain). Also enable [Work Object Previews](https://docs.slack.dev/messaging/work-objects/#implementation) for your app.
13+
```bash
14+
slack init && slack run
15+
```
16+
17+
### Option 2: Create a Slack App in the UI and copy over your tokens
1418

15-
### 1. Setup environment variables
19+
Create an app on [https://api.slack.com/apps](https://api.slack.com/apps) from the app manifest in this repo (`manifest.json`).
1620

17-
```zsh
18-
# Replace with your tokens
21+
Configure environment variables:
22+
```bash
23+
# OAuth & Permissions → Bot User OAuth Token
1924
export SLACK_BOT_TOKEN=<your-bot-token>
20-
export SLACK_APP_TOKEN=<your-app-level-token>
25+
# Basic Information → App-Level Tokens (create one with the `connections:write` scope)
26+
export SLACK_APP_TOKEN=<your-app-token>
2127
```
2228

23-
### 2. Setup your local project
24-
25-
```zsh
29+
Install dependencies and run the app:
30+
```bash
2631
# Setup virtual environment
2732
python3 -m venv .venv
2833
source .venv/bin/activate
2934

3035
# Install the dependencies
3136
pip install -r requirements.txt
32-
```
3337

34-
### 3. Start the server
35-
```zsh
36-
python3 src/app.py
38+
# Start the server
39+
python3 app.py
3740
```
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import os
2+
import sys
23
import logging
34
from slack_bolt import App
45
from slack_bolt.adapter.socket_mode import SocketModeHandler
56
from slack_sdk import WebClient
67
from slack_sdk.models.metadata import EventAndEntityMetadata
7-
from metadata import sample_entities
8+
from metadata import sample_entities, sample_task_unfurl_url, sample_file_unfurl_url
89

910

1011
# Initializes your app with your bot token
@@ -64,11 +65,13 @@ def work_object_edit_callback(view: dict, body: dict, client: WebClient, logger:
6465
entity_url = view["entity_url"]
6566
entity = sample_entities[entity_url]
6667

67-
attributes = entity.entity_payload.entity_attributes
68-
attributes.title.text = view["state"]["values"]["title"]["title.input"]["value"]
69-
entity.entity_payload.entity_attributes = attributes
70-
71-
entity.entity_payload.fields.description.value = view["state"]["values"]["description"]["description.input"]["value"]
68+
if "title" in view["state"]["values"]:
69+
attributes = entity.entity_payload.entity_attributes
70+
attributes.title.text = view["state"]["values"]["title"]["title.input"]["value"]
71+
entity.entity_payload.entity_attributes = attributes
72+
73+
if "description" in view["state"]["values"]:
74+
entity.entity_payload.fields.description.value = view["state"]["values"]["description"]["description.input"]["value"]
7275

7376
if entity is not None:
7477
client.entity_presentDetails(
@@ -85,4 +88,10 @@ def work_object_edit_callback(view: dict, body: dict, client: WebClient, logger:
8588

8689
# Start your app
8790
if __name__ == "__main__":
88-
SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()
91+
try:
92+
print("Try sharing this link: ", sample_task_unfurl_url)
93+
print("Or this link: ", sample_file_unfurl_url)
94+
SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()
95+
except Exception as error:
96+
print(f"Failed to start app: {error}", file=sys.stderr)
97+
sys.exit(1)
Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
{
22
"display_information": {
3-
"name": "Work Objects for Bolt Python App"
3+
"name": "work_objects_python",
4+
"description": "A sample app demonstrating Slack Work Objects functionality"
45
},
56
"features": {
67
"rich_previews": {
78
"is_active": true,
8-
"entity_types": [
9-
"slack#/entities/task"
10-
]
11-
},
12-
"unfurl_domains": [
13-
"tmpdomain.com"
14-
],
15-
"app_home": {
16-
"home_tab_enabled": false,
17-
"messages_tab_enabled": true,
18-
"messages_tab_read_only_enabled": false
9+
"entity_types": ["slack#/entities/task", "slack#/entities/file"]
1910
},
11+
"unfurl_domains": ["work-objects-python.com"],
2012
"bot_user": {
21-
"display_name": "WorkObjectsApp",
13+
"display_name": "work_objects_python_bot",
2214
"always_online": true
2315
}
2416
},
2517
"oauth_config": {
2618
"scopes": {
27-
"bot": ["channels:history", "chat:write", "im:history", "links:read", "links:write"]
19+
"bot": ["chat:write", "links:read", "links:write"]
2820
}
2921
},
3022
"settings": {
@@ -38,4 +30,4 @@
3830
"socket_mode_enabled": true,
3931
"token_rotation_enabled": false
4032
}
41-
}
33+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
)
1919

2020
# Update the URL here to match your app's domain
21-
sample_task_unfurl_url = "https://myappdomain.com/task"
22-
sample_file_unfurl_url = "https://myappdomain.com/file"
21+
sample_task_unfurl_url = "https://work-objects-python.com/task"
22+
sample_file_unfurl_url = "https://work-objects-python.com/file"
2323

2424
sample_entities = {
2525
sample_task_unfurl_url: EntityMetadata(
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mypy==1.18.2
22
pytest==9.0.1
33
ruff==0.14.5
4-
#slack_sdk==3.39.0
4+
slack_sdk>=3.39.0
5+
slack-bolt
56
slack-cli-hooks<1.0.0

messaging/work-objects/src/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)