Nis*_*ish 5 python bots slack-api slack
我正在尝试通过他们的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)
Run Code Online (Sandbox Code Playgroud)
回应只是 {u'ok': False, u'error': u'no_text'}
Nis*_*ish 12
我想到了.
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)
Run Code Online (Sandbox Code Playgroud)
我的有效负载全部都在附件中,因为这是他们在API文档中对其进行格式化的方式.附件需要只是附件键后的数组.
归档时间: |
|
查看次数: |
5814 次 |
最近记录: |