slackapi / slackapi/bolt-python

Conditional Lazy Listener?

Open
#482 2 comments 1 reaction 1 assignee View on GitHub

@seratch is already working on this.

Since Oct 4, 2021.

area:async area:sync discussion enhancement
Dominant language
Python
Stars
1.3k
Forks
288
Avg merge
1d 8h
Merged PRs (30d)
10

Description

Is there a way to make it so that the lazy function triggers conditionally based on the ack response?

For example, I want my ack to do parameter validation and potentially reject the request. Right now, my solution is to have the lazy function run the same parameter validation as the ack function, but it seems a bit wasteful. I'd much rather the lazy function not get triggered at all in the scenario where the ack function returns errors to the user.

Reproducible in:
The slack_bolt version

slack-bolt==1.9.1

Python runtime version

Python 3.8.12

OS info
ProductName:    macOS
ProductVersion: 11.5.2
BuildVersion:   20G95
Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64
Steps to reproduce:

Run something like this:

def validate_the_stuff(ack, view):
    #errors = validate_inputs(view)
    errors = { "environment-select-block": "Nope" }
    if len(errors) > 0:
        ack(response_action="errors", errors=errors)
        return False
    else:
        ack(response_action="clear")

def do_the_thing(view):
    logging.error("You should not get this far")

app.view_submission('environment_select_submit')(
    ack=validate_the_stuff,
    lazy=[do_the_thing]
)
Expected result:

Don't do the thing if validation fails.

Actual result:

Does the thing even if validation fails.

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.