如何从 slack api 的附件中获取操作结果
how to get actions result from slack api's attachment
如何使用 python SlackClient 接收附件操作。如何获得用户的回复?
代码:
intro_msg = json.dumps([{"text": "Choose an action", "fallback": "You are unable to choose an option",
"callback_id": "lunch_intro", "color": "#3AA3E3", "attachment_type": "default",
"actions": [
{"name": "enroll", "text": "Enroll", "type": "button", "value": "enroll"},
{"name": "leave", "text": "Leave", "type": "button", "value": "leave"}]}])
result = self.sc.api_call("chat.postMessage", channel=channel, text="What would you like to do?",attachments=intro_msg,as_user=True)
- 定义一个 Slack 应用程序
- 您的应用(Python 脚本)需要 运行 在 Slack 可以访问的 public 网络服务器上(如果您使用 ngrok 等工具,也可以通过本地机器访问)
- 在 "Interactive messages"
下的 Slack 应用配置中将您的应用的 URL 作为 "request URL"
- 一旦用户点击其中一个按钮,Slack 将通过 POST 请求调用您的应用,该请求将包含用户选择的操作
查看您链接的 documentation 以了解详细信息,例如 Slack 请求的数据结构。
如何使用 python SlackClient 接收附件操作。如何获得用户的回复?
代码:
intro_msg = json.dumps([{"text": "Choose an action", "fallback": "You are unable to choose an option",
"callback_id": "lunch_intro", "color": "#3AA3E3", "attachment_type": "default",
"actions": [
{"name": "enroll", "text": "Enroll", "type": "button", "value": "enroll"},
{"name": "leave", "text": "Leave", "type": "button", "value": "leave"}]}])
result = self.sc.api_call("chat.postMessage", channel=channel, text="What would you like to do?",attachments=intro_msg,as_user=True)
- 定义一个 Slack 应用程序
- 您的应用(Python 脚本)需要 运行 在 Slack 可以访问的 public 网络服务器上(如果您使用 ngrok 等工具,也可以通过本地机器访问)
- 在 "Interactive messages" 下的 Slack 应用配置中将您的应用的 URL 作为 "request URL"
- 一旦用户点击其中一个按钮,Slack 将通过 POST 请求调用您的应用,该请求将包含用户选择的操作
查看您链接的 documentation 以了解详细信息,例如 Slack 请求的数据结构。