如何在 Slack-bolt 中添加正确的回复功能?

问题描述

我正在尝试为 Slack 制作一个简单的教程机器人。我使用 slack_bolt 包。我只是想让机器人在用户之后重复这句话。我设法根据文档做到了。但前提是所有处理都在一个函数内进行(我注释掉了这一部分)。

我只想在函数获取输入的文本。然后处理它,然后才运行“响应”功能。但我不知道如何正确地写出这个部门。我的选择是“不工作”

from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler

import re

class AD_BOTS (App):
    "" "
        ADbot bot class,inherited from external module slack_bolt
    "" "
    pass

app_token = "..."
bot_token = "..."
signing_secret = "..."

app = AD_BOTS (token = bot_token,signing_secret = signing_secret)

# Repeat entered text
# Works if I do everything inside one function
# @ app.message (re.compile ("(.)"))
# def say_hello (message,say):
# mytext = message ['text']
# say (mytext)


# But I want:
# 1. Get entered text.
# 2. Then I'll process it
# 3.And then run the reply function
# But here I can't figure out how to do it right
@ app.message (re.compile ("(.)"))
def say_hello (message):
    mytext = message ['text']
    return mytext

def say_hello2 (say):
    say (say)

if mytext == '1':
    say_hello2 (mytext)
 
if __name__ == "__main__":
    # Run the socket mode handler by specifying an instance of the app class and the app token of the application
    SocketModeHandler (app,app_token) .start ()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)