Python 如何从用户那里获取关于slack的输入以进一步进行?

Python 如何从用户那里获取关于slack的输入以进一步进行?,python,slack,slack-api,Python,Slack,Slack Api,我在聊天机器人上工作,机器人询问用户名,然后机器人回复问候语+姓名。当我在带有input()的终端上使用这个函数,但无法理解如何从slack接受输入并使用该输入时,这个函数就起作用了 def start(request, channel): response = ('\n\nHello!') send_response(response, channel) name = ('Please tell me your name.\n') send_response(n

我在聊天机器人上工作,机器人询问用户名,然后机器人回复问候语+姓名。当我在带有input()的终端上使用这个函数,但无法理解如何从slack接受输入并使用该输入时,这个函数就起作用了

def start(request, channel):
    response = ('\n\nHello!')
    send_response(response, channel)
    name = ('Please tell me your name.\n')
    send_response(name, channel)    
    name = request
    greet = "Hello" + name
    send_response(greet, channel)

def send_response(response,channel):
    slack_client.api_call("chat.postMessage", channel=channel, text=response, as_user=True)

def parse_slack_output(slack_rtm_output):
    output_list = slack_rtm_output
    if output_list and len(output_list) > 0:
        for output in output_list:
            if output and 'text' in output and AT_BOT in output['text']:
                # return text after the @ mention, whitespace removed
                return output['text'].split(AT_BOT)[1].strip(), \
                    output['channel']
    return None, None

if __name__ == "__main__":

    READ_WEBSOCKET_DELAY = 1 # 1 second delay between reading from firehose
    if slack_client.rtm_connect():
        print ("connected and running!")
        while True:
            request, channel = parse_slack_output(slack_client.rtm_read())
            if request and channel:
                start(request, channel)
            time.sleep(READ_WEBSOCKET_DELAY)
    else:
        print("Connection failed. Invalid Slack token or bot ID?")

根据slack doc,dialog.open()方法是实现您的需求的方法。

编辑: RASA NLU-CORE为基于会话的聊天机器人提供了更多选择


插槽填充是存储名称或任何其他值并在对话中进一步使用它所需的内容。

这在技术上是可行的,但在我看来,基于聊天的对话对于用例来说更为用户友好。@ErikKalkoken,我已根据您的评论更新了答案:)