slackapi / slackapi/bolt-python

Conditional Lazy Listener?

未关闭
#482 2 条评论 1 个 reaction 已指派 1 人 在 GitHub 查看

@seratch 已经在做这个了。

开始于 2021年10月4日。

area:async area:sync discussion enhancement
主要语言
Python
星标
1.3k
派生
288
平均合并
1 天 8 小时
30 天内合并 PR
10

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。