Skip to content

Commit

Permalink
consolidated commit from personal email
Browse files Browse the repository at this point in the history
  • Loading branch information
YSaxon committed Feb 23, 2023
1 parent e580fda commit 0e16c59
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
13 changes: 13 additions & 0 deletions slack_bolt/kwargs_injection/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ def handle_buttons(ack, respond, logger, context, body, client):
view={ ... }
)
Alternatively, you can include a parameter named `args` and it will be injected with an instance of this class.
@app.action("link_button")
def handle_buttons(args):
args.logger.info(f"request body: {args.body}")
args.ack()
if args.context.channel_id is not None:
args.respond("Hi!")
args.client.views_open(
trigger_id=args.body["trigger_id"],
view={ ... }
)
"""

client: WebClient
Expand Down
13 changes: 13 additions & 0 deletions slack_bolt/kwargs_injection/async_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ async def handle_buttons(ack, respond, logger, context, body, client):
view={ ... }
)
Alternatively, you can include a parameter named `args` and it will be injected with an instance of this class.
@app.action("link_button")
async def handle_buttons(args):
args.logger.info(f"request body: {args.body}")
await args.ack()
if args.context.channel_id is not None:
await args.respond("Hi!")
await args.client.views_open(
trigger_id=args.body["trigger_id"],
view={ ... }
)
"""

logger: Logger
Expand Down
4 changes: 2 additions & 2 deletions slack_bolt/kwargs_injection/async_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def build_async_required_kwargs(
first_arg_name = required_arg_names[0]
if first_arg_name in {"self", "cls"}:
required_arg_names.pop(0)
elif first_arg_name not in all_available_args.keys():
elif first_arg_name not in all_available_args.keys() and first_arg_name != "args":
if this_func is None:
logger.warning(warning_skip_uncommon_arg_name(first_arg_name))
required_arg_names.pop(0)
Expand All @@ -100,7 +100,7 @@ def build_async_required_kwargs(
else:
logger.warning(f"Unknown Request object type detected ({type(request)})")

if name not in found_arg_names:
elif name not in found_arg_names:
logger.warning(f"{name} is not a valid argument")
kwargs[name] = None
return kwargs
4 changes: 2 additions & 2 deletions slack_bolt/kwargs_injection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def build_required_kwargs(
first_arg_name = required_arg_names[0]
if first_arg_name in {"self", "cls"}:
required_arg_names.pop(0)
elif first_arg_name not in all_available_args.keys():
elif first_arg_name not in all_available_args.keys() and first_arg_name != "args":
if this_func is None:
logger.warning(warning_skip_uncommon_arg_name(first_arg_name))
required_arg_names.pop(0)
Expand All @@ -100,7 +100,7 @@ def build_required_kwargs(
else:
logger.warning(f"Unknown Request object type detected ({type(request)})")

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

0 comments on commit 0e16c59

Please sign in to comment.