gpt4 book ai didi

python - 添加附件到 Slackbot

转载 作者:太空狗 更新时间:2023-10-30 00:31:24 25 4
gpt4 key购买 nike

我正在尝试通过他们的 API 向 slack 消息添加附件。我正在使用他们推荐的 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 文档中就是这样格式化的。附件只需是附件键后的数组。

关于python - 添加附件到 Slackbot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40407574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com