Skip to content

Commit a747f28

Browse files
authored
Add documention for injected 'args' param option (#835)
1 parent e580fda commit a747f28

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

slack_bolt/kwargs_injection/args.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ def handle_buttons(ack, respond, logger, context, body, client):
2727
view={ ... }
2828
)
2929
30+
Alternatively, you can include a parameter named `args` and it will be injected with an instance of this class.
31+
32+
@app.action("link_button")
33+
def handle_buttons(args):
34+
args.logger.info(f"request body: {args.body}")
35+
args.ack()
36+
if args.context.channel_id is not None:
37+
args.respond("Hi!")
38+
args.client.views_open(
39+
trigger_id=args.body["trigger_id"],
40+
view={ ... }
41+
)
42+
3043
"""
3144

3245
client: WebClient

slack_bolt/kwargs_injection/async_args.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ async def handle_buttons(ack, respond, logger, context, body, client):
2626
view={ ... }
2727
)
2828
29+
Alternatively, you can include a parameter named `args` and it will be injected with an instance of this class.
30+
31+
@app.action("link_button")
32+
async def handle_buttons(args):
33+
args.logger.info(f"request body: {args.body}")
34+
await args.ack()
35+
if args.context.channel_id is not None:
36+
await args.respond("Hi!")
37+
await args.client.views_open(
38+
trigger_id=args.body["trigger_id"],
39+
view={ ... }
40+
)
41+
2942
"""
3043

3144
logger: Logger

slack_bolt/kwargs_injection/async_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def build_async_required_kwargs(
8383
first_arg_name = required_arg_names[0]
8484
if first_arg_name in {"self", "cls"}:
8585
required_arg_names.pop(0)
86-
elif first_arg_name not in all_available_args.keys():
86+
elif first_arg_name not in all_available_args.keys() and first_arg_name != "args":
8787
if this_func is None:
8888
logger.warning(warning_skip_uncommon_arg_name(first_arg_name))
8989
required_arg_names.pop(0)
@@ -100,7 +100,7 @@ def build_async_required_kwargs(
100100
else:
101101
logger.warning(f"Unknown Request object type detected ({type(request)})")
102102

103-
if name not in found_arg_names:
103+
elif name not in found_arg_names:
104104
logger.warning(f"{name} is not a valid argument")
105105
kwargs[name] = None
106106
return kwargs

slack_bolt/kwargs_injection/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def build_required_kwargs(
8383
first_arg_name = required_arg_names[0]
8484
if first_arg_name in {"self", "cls"}:
8585
required_arg_names.pop(0)
86-
elif first_arg_name not in all_available_args.keys():
86+
elif first_arg_name not in all_available_args.keys() and first_arg_name != "args":
8787
if this_func is None:
8888
logger.warning(warning_skip_uncommon_arg_name(first_arg_name))
8989
required_arg_names.pop(0)
@@ -100,7 +100,7 @@ def build_required_kwargs(
100100
else:
101101
logger.warning(f"Unknown Request object type detected ({type(request)})")
102102

103-
if name not in found_arg_names:
103+
elif name not in found_arg_names:
104104
logger.warning(f"{name} is not a valid argument")
105105
kwargs[name] = None
106106
return kwargs

0 commit comments

Comments
 (0)