Skip to content
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

app.action listener should accept block_id-only constraints for bolt-js feature parity #988

Closed
darkfoxprime opened this issue Nov 20, 2023 · 5 comments · Fixed by #990
Closed
Labels
bug Something isn't working
Milestone

Comments

@darkfoxprime
Copy link

(Filling out the following details about bugs will help us solve your issue sooner.)

Reproducible in:

pip freeze | grep slack
python --version
sw_vers && uname -v # or `ver`

The slack_bolt version

$ .venv/bin/pip freeze | grep slack
slack-bolt==1.18.0
slack-sdk==3.24.0

Python runtime version

$ .venv/bin/python --version
Python 3.9.16

OS info

(sw_vers is not valid in RHEL-related OSes)

$ cat /etc/redhat-release && uname -v
AlmaLinux release 9.2 (Turquoise Kodkod)
#1 SMP PREEMPT_DYNAMIC Tue Sep 12 09:28:32 EDT 2023

Steps to reproduce:

@app.action( { 'type': 'block_action', 'block_id': 'response' } )
def handle_response_action(ack, client, body):
    pass

Expected result:

Per the documentation...

You can use a constraints object to listen to block_ids and action_ids (or any combination of them).

Therefore, I expected to have an action handler that responded to any action from a block with id response.

Actual result:

Failed to run a middleware (error: 'action_id')
Traceback (most recent call last):
  File "/home/darkfox/git/codeberg/darkfoxprime/FreeportTrawler/.venv/lib64/python3.9/site-packages/slack_bolt/app/app.py", line 534, in dispatch
    if listener.matches(req=req, resp=resp):
  File "/home/darkfox/git/codeberg/darkfoxprime/FreeportTrawler/.venv/lib64/python3.9/site-packages/slack_bolt/listener/listener.py", line 25, in matches
    is_matched = matcher.matches(req, resp)
  File "/home/darkfox/git/codeberg/darkfoxprime/FreeportTrawler/.venv/lib64/python3.9/site-packages/slack_bolt/listener_matcher/builtins.py", line 54, in matches
    return self.func(
  File "/home/darkfox/git/codeberg/darkfoxprime/FreeportTrawler/.venv/lib64/python3.9/site-packages/slack_bolt/listener_matcher/builtins.py", line 327, in func
    return _block_action(constraints, body)
  File "/home/darkfox/git/codeberg/darkfoxprime/FreeportTrawler/.venv/lib64/python3.9/site-packages/slack_bolt/listener_matcher/builtins.py", line 317, in _block_action
    action_id_matched = _matches(constraints["action_id"], action["action_id"])
KeyError: 'action_id'

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

@seratch seratch added the docs Improvements or additions to documentation label Nov 20, 2023
@seratch seratch added this to the 1.x milestone Nov 20, 2023
@seratch
Copy link
Member

seratch commented Nov 20, 2023

Hi @darkfoxprime, thanks for taking the time to share this feedback! Indeed, the document should clearly mention this. We will improve it later on.

Since a block_actions event can occur per a block element w/ action_id, thie is by design. Thus, please set a unique action_id for each interactive block element in your blocks.

@darkfoxprime
Copy link
Author

Hi @darkfoxprime, thanks for taking the time to share this feedback! Indeed, the document should clearly mention this. We will improve it later on.

Since a block_actions event can occur per a block element w/ action_id, thie is by design. Thus, please set a unique action_id for each interactive block element in your blocks.

The requirement for a "unique" action_id is exactly why I want to be able to add an action handler on the block_id instead. My app uses dynamically-generated sets of actions, so it's impossible for me to be able to specify action ids for responding to them. However, they all are contained within blocks with known block ids, so being able to use @app.action( { 'block_id': '...' } ) with no action_id would greatly simplify this work.

@seratch
Copy link
Member

seratch commented Nov 20, 2023

For this particular scenario, we currently recommend appending a prefix to the auto-generated action_id string values. Then pass a regexp that matches the prefix to an app.action listener.

If we receive the same request more in the future (actually this is the first time to learn this need for us), we may consider enhancing the dictionary constraint to support only having block_id. However, I have to say that it's not our team's primary focus for us at this moment. It'd appreciated if you could understand this.

@darkfoxprime
Copy link
Author

In that case, please fix the documentation so that it clearly states that the action_id is required in the constraints.

@seratch
Copy link
Member

seratch commented Nov 20, 2023

Hi @darkfoxprime, I am so sorry that I was wrong here. The document is in alignment with bolt-js, and the behavior of bolt-js is like you expect. Therefore, I must retract my above statement. We will improve bolt-python's behavior to be consistent with bolt-js. Though I'm presently occupied with a different task, I'm confident that I can make a new patch release including the fix for this issue within the next few business days.

@seratch seratch added bug Something isn't working and removed docs Improvements or additions to documentation labels Nov 20, 2023
@seratch seratch modified the milestones: 1.x, 1.18.1 Nov 20, 2023
@seratch seratch changed the title @app.action with a constraints object requires action_id even though the documentation says it's not required app.action listener should accept block_id-only constraints for bolt-js feature parity Nov 21, 2023
seratch added a commit to seratch/bolt-python that referenced this issue Nov 21, 2023
seratch added a commit that referenced this issue Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants