首页 > 解决方案 > 将变量从 slack webhook 传递到 Autopilot

问题描述

我想知道是否可以将来自 Slack 的传入帖子请求中的用户名与 Autopilot 一起使用。

我已尝试检查文档,但找不到任何有关处理 Autopilot 传入请求的参考。也许它不受支持,但有人知道它是否可能吗?

标签: twilio

解决方案


我最终能够使用来自 Autopilot 的响应数据,并发现我能够从 json 响应中获取用户标识符,如下所示:

user_name = request.form['UserIdentifier']

这允许我通过传入的 webhooks 应用程序在 slack 中发送直接消息,因为使用上述用户名作为通道键的值,如下所示。

payload={'text':"Ok, I'm working on it. I'll let you know when your request is ready.", "channel":user_name}
        webhook_url= 'https://hooks.slack.com/services/<slack id>/<slack id>'

        response = requests.post(
        webhook_url, data=json.dumps(payload),
        headers={'Content-Type': 'application/json'})

        if response.status_code != 200:
            raise ValueError(
                'Request to slack returned an error %s, the response is:\n%s'
                % (response.status_code, response.text)
            )

推荐阅读