向Slackbot添加附件

尼什

我正在尝试通过其API将附件添加到备用消息中。我正在使用他们推荐的python包装器。我可以发送和接收基本消息,但是当我尝试以2个按钮的形式添加附件时,它会失败。我制作了一个松弛的应用程序,并按照机器人在其API中的说明链接了该机器人。我已经仔细检查了API,无法弄清楚到底发生了什么。

def process_message(message, channel):
    intro_msg = json.loads('{
                      "text": "What would you like to do?",
                      "attachments": [
                        {
                          "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"
                            }
                          ]
                        }
                      ]
                    }')
    r = sc.api_call("chat.postMessage", channel=channel, attachments=intro_msg)

回应只是 {u'ok': False, u'error': u'no_text'}

尼什

我想到了。

python包装器将有效负载分离出来。

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"}]}])

sc.api_call("chat.postMessage", channel=channel, text="What would you like to do?", attachments=intro_msg, as_user=True)

我的有效负载全部包含在附件中,因为这是它们在API文档中对其进行格式化的方式。附件只需是附件键之后的数组。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章