如何从slackapi的附件中获取操作结果

2024-03-28 10:42:24 发布

您现在位置:Python中文网/ 问答频道 /正文

如何使用python SlackClient接收附件操作。如何获得用户回复?你知道吗

enter image description here

代码:

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)

https://api.slack.com/interactive-messages


Tags: totextnameanapi附件valuetype
1条回答
网友
1楼 · 发布于 2024-03-28 10:42:24
  1. 定义松弛应用程序
  2. 你的应用程序(Python脚本)需要在Slack可以访问的公共web服务器上运行(如果你使用ngrok之类的工具,也可以在本地机器上运行)
  3. 将应用程序的URL作为“请求URL”放在Slack应用程序配置的“交互式消息”下
  4. 一旦用户单击其中一个按钮,Slack将使用POST请求调用您的应用程序,该请求将包含用户选择的操作

查看您链接的documentation,了解Slack请求的数据结构的详细信息。你知道吗

相关问题 更多 >