我为Slack构建了一个Workspace App,它现在附带了一个通道(在Apps头下),用户可以在这里向应用程序本身发送消息。这会触发 在message.app_主页事件,我的后端接收到。我想使用chat.postMessage对该消息进行响应,但响应中只显示消息文本。我发送的所有附件都没有出现在频道中。将此结构作为对斜杠命令请求的JSON响应的一部分返回可以正常工作。在
以下是我发送的附件结构:
(
{
"title": "Create a space, optionally setting its name and adding other users",
"text": "`/luffa create [space name] [teammates]`\nExample: `/luffa create Marketing Campaign 2018 @john @kate`",
"color": SLACK_COLOR,
},
{
"title": "Start a new meeting, optionally strating it in the space matching the provided name",
"text": "`/luffa start [space name]`\nExample: `/luffa start Marketing Campaign 2018`",
"color": SLACK_COLOR,
},
{
"title": "Search Luffa",
"text": "`/luffa search [query]`\nExample: `/luffa search interviews before:Yesterday `",
"color": SLACK_COLOR,
},
{
"text": "There is more help available in our Help Center: https://help.okluffa.com/",
},
)
我正在使用slackclientPython库来包装对Slack API的调用。在
没有返回错误消息,并且基于documentation的结构似乎是正确的。有什么东西不见了吗?在
一些小问题需要检查-请尝试删除
attachments
结构中每个最后一个值上的多余逗号,因为插入into the Slack message tester here时,这些逗号会导致验证错误:问题是我传递给slackclient1.2.1的数据结构是一个
tuple
的对象。该库将仅序列化为JSONlist
或dict
对象。(请参见slackrequest.py
,第94行,if isinstance(v, (list, dict)):
)。传递一个元组或任何其他iterable都将无法正确序列化,Slack API将忽略附件。对请求的JSON响应不是问题,因为Python的JSON序列化程序将所有iterable转换为JSON数组。在我通过将
list
传递给slackclient方法解决了这个问题。在相关问题 更多 >
编程相关推荐