Skip to content

Commit 30a42c7

Browse files
committed
Add step arg and fix bugs
1 parent a816027 commit 30a42c7

File tree

15 files changed

+870
-29
lines changed

15 files changed

+870
-29
lines changed

samples/async_steps_from_apps.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# https://api.slack.com/tutorials/workflow-builder-steps
2222

2323

24-
async def edit(ack: AsyncAck, configure: AsyncConfigure):
24+
async def edit(ack: AsyncAck, step: dict, configure: AsyncConfigure):
2525
await ack()
2626
await configure(
2727
blocks=[
@@ -76,8 +76,8 @@ async def edit(ack: AsyncAck, configure: AsyncConfigure):
7676
)
7777

7878

79-
async def save(ack: AsyncAck, body: dict, update: AsyncUpdate):
80-
state_values = body["view"]["state"]["values"]
79+
async def save(ack: AsyncAck, view: dict, update: AsyncUpdate):
80+
state_values = view["state"]["values"]
8181
await update(
8282
inputs={
8383
"taskName": {
@@ -112,9 +112,8 @@ async def save(ack: AsyncAck, body: dict, update: AsyncUpdate):
112112
pseudo_database = {}
113113

114114

115-
async def execute(body: dict, client: AsyncWebClient, complete: AsyncComplete, fail: AsyncFail):
115+
async def execute(step: dict, client: AsyncWebClient, complete: AsyncComplete, fail: AsyncFail):
116116
try:
117-
step = body["event"]["workflow_step"]
118117
await complete(
119118
outputs={
120119
"taskName": step["inputs"]["taskName"]["value"],

samples/steps_from_apps.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# instead of slack_bolt in requirements.txt
33
import sys
44

5-
65
sys.path.insert(1, "..")
76
# ------------------------------------------------
87

@@ -30,7 +29,7 @@ def log_request(logger, body, next):
3029
# https://api.slack.com/tutorials/workflow-builder-steps
3130

3231

33-
def edit(ack: Ack, configure: Configure):
32+
def edit(ack: Ack, step, configure: Configure):
3433
ack()
3534
configure(
3635
blocks=[
@@ -85,8 +84,8 @@ def edit(ack: Ack, configure: Configure):
8584
)
8685

8786

88-
def save(ack: Ack, body: dict, update: Update):
89-
state_values = body["view"]["state"]["values"]
87+
def save(ack: Ack, view: dict, update: Update):
88+
state_values = view["state"]["values"]
9089
update(
9190
inputs={
9291
"taskName": {
@@ -121,15 +120,14 @@ def save(ack: Ack, body: dict, update: Update):
121120
pseudo_database = {}
122121

123122

124-
def execute(body: dict, client: WebClient, complete: Complete, fail: Fail):
125-
step = body["event"]["workflow_step"]
123+
def execute(step: dict, client: WebClient, complete: Complete, fail: Fail):
126124
try:
127125
complete(
128126
outputs={
129-
"taskName": step["inputs"]["taskName"]["value"],
130-
"taskDescription": step["inputs"]["taskDescription"]["value"],
131-
"taskAuthorEmail": step["inputs"]["taskAuthorEmail"]["value"],
132-
}
127+
"taskName": step["inputs"]["taskName"]["value"],
128+
"taskDescription": step["inputs"]["taskDescription"]["value"],
129+
"taskAuthorEmail": step["inputs"]["taskAuthorEmail"]["value"],
130+
}
133131
)
134132

135133
user: SlackResponse = client.users_lookupByEmail(
@@ -167,6 +165,7 @@ def execute(body: dict, client: WebClient, complete: Complete, fail: Fail):
167165
"message": "Something wrong!"
168166
})
169167

168+
170169
app.step(
171170
callback_id="copy_review",
172171
edit=edit,

slack_bolt/app/app.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,7 @@ def step(
362362
step = callback_id
363363
if isinstance(callback_id, (str, Pattern)):
364364
step = WorkflowStep(
365-
callback_id=callback_id,
366-
edit=edit,
367-
save=save,
368-
execute=execute,
365+
callback_id=callback_id, edit=edit, save=save, execute=execute,
369366
)
370367
elif not isinstance(step, WorkflowStep):
371368
raise BoltError("Invalid step object")

slack_bolt/app/async_app.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,7 @@ def step(
378378
step = callback_id
379379
if isinstance(callback_id, (str, Pattern)):
380380
step = AsyncWorkflowStep(
381-
callback_id=callback_id,
382-
edit=edit,
383-
save=save,
384-
execute=execute,
381+
callback_id=callback_id, edit=edit, save=save, execute=execute,
385382
)
386383
elif not isinstance(step, AsyncWorkflowStep):
387384
raise BoltError("Invalid step object")

slack_bolt/kwargs_injection/async_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
to_command,
1414
to_event,
1515
to_message,
16+
to_step,
1617
)
1718

1819

@@ -41,6 +42,7 @@ def build_async_required_kwargs(
4142
"command": to_command(request.body),
4243
"event": to_event(request.body),
4344
"message": to_message(request.body),
45+
"step": to_step(request.body),
4446
# utilities
4547
"ack": request.context.ack,
4648
"say": request.context.say,
@@ -56,6 +58,7 @@ def build_async_required_kwargs(
5658
or all_available_args["command"]
5759
or all_available_args["event"]
5860
or all_available_args["message"]
61+
or all_available_args["step"]
5962
or request.body
6063
)
6164
for k, v in request.context.items():

slack_bolt/kwargs_injection/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
to_command,
1414
to_event,
1515
to_message,
16+
to_step,
1617
)
1718

1819

@@ -41,6 +42,7 @@ def build_required_kwargs(
4142
"command": to_command(request.body),
4243
"event": to_event(request.body),
4344
"message": to_message(request.body),
45+
"step": to_step(request.body),
4446
# utilities
4547
"ack": request.context.ack,
4648
"say": request.context.say,
@@ -56,6 +58,7 @@ def build_required_kwargs(
5658
or all_available_args["command"]
5759
or all_available_args["event"]
5860
or all_available_args["message"]
61+
or all_available_args["step"]
5962
or request.body
6063
)
6164
for k, v in request.context.items():

slack_bolt/listener/async_listener_error_handler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
to_command,
1515
to_event,
1616
to_message,
17+
to_step,
1718
)
1819

1920

@@ -66,6 +67,7 @@ async def handle(
6667
"command": to_command(request.body),
6768
"event": to_event(request.body),
6869
"message": to_message(request.body),
70+
"step": to_step(request.body),
6971
# utilities
7072
"say": request.context.say,
7173
"respond": request.context.respond,
@@ -78,6 +80,7 @@ async def handle(
7880
or all_available_args["command"]
7981
or all_available_args["event"]
8082
or all_available_args["message"]
83+
or all_available_args["step"]
8184
or request.body
8285
)
8386

slack_bolt/listener/listener_error_handler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
to_command,
1515
to_event,
1616
to_message,
17+
to_step,
1718
)
1819

1920

@@ -60,6 +61,7 @@ def handle(
6061
"command": to_command(request.body),
6162
"event": to_event(request.body),
6263
"message": to_message(request.body),
64+
"step": to_step(request.body),
6365
# utilities
6466
"say": request.context.say,
6567
"respond": request.context.respond,
@@ -72,6 +74,7 @@ def handle(
7274
or all_available_args["command"]
7375
or all_available_args["event"]
7476
or all_available_args["message"]
77+
or all_available_args["step"]
7578
or request.body
7679
)
7780

slack_bolt/listener_matcher/builtins.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ def func(body: Dict[str, Any]) -> bool:
110110

111111

112112
def workflow_step_execute(
113-
asyncio: bool = False,
113+
callback_id: Union[str, Pattern], asyncio: bool = False,
114114
) -> Union[ListenerMatcher, "AsyncListenerMatcher"]:
115115
def func(body: Dict[str, Any]) -> bool:
116116
return (
117117
is_event(body)
118118
and _matches("workflow_step_execute", body["event"]["type"])
119119
and "workflow_step" in body["event"]
120+
and _matches(callback_id, body["event"]["callback_id"])
120121
)
121122

122123
return build_listener_matcher(func, asyncio)

slack_bolt/util/payload_utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ def is_event(body: Dict[str, Any]) -> bool:
2929
)
3030

3131

32+
def is_workflow_step_execute(body: Dict[str, Any]) -> bool:
33+
return (
34+
is_event(body)
35+
and body["event"]["type"] == "workflow_step_edit"
36+
and "workflow_step" in body["event"]
37+
)
38+
39+
3240
# -------------------
3341
# Slash Commands
3442
# -------------------
@@ -205,6 +213,21 @@ def is_workflow_step_save(body: Dict[str, Any]) -> bool:
205213
return is_view_submission(body) and body["view"]["type"] == "workflow_step"
206214

207215

216+
# -------------------
217+
# Workflow Steps
218+
# -------------------
219+
220+
221+
def to_step(body: Dict[str, Any]) -> Optional[Dict[str, Any]]:
222+
# edit
223+
if is_workflow_step_edit(body):
224+
return body["workflow_step"]
225+
# execute
226+
if is_workflow_step_execute(body):
227+
return body["event"]["workflow_step"]
228+
return None
229+
230+
208231
# ------------------------------------------
209232
# Internal Utilities
210233
# ------------------------------------------

0 commit comments

Comments
 (0)