将附件添加到 slack 聊天消息
Adding attachements to slacker chat message
我正在尝试 post 使用 slack 消息 python api 消息
我无法按照以下代码将 link 附加到我的消息中:
attachments = [title, link_to_events, "More details"]
print type(attachments) # this is a list
slack = Slacker(slack_api_token)
# Send a message to #general channel
slack.chat.post_message(slack_channel, message, attachments=attachments)
在 slacker 代码中,看起来我们正在寻找 "list" 类型的变量:
https://github.com/os/slacker/blob/master/slacker/init.py
第 241 行:
# Ensure attachments are json encoded
if attachments:
if isinstance(attachments, list):
attachments = json.dumps(attachments)
return self.post('chat.postMessage',
data={
'channel': channel,
'text': text,
'username': username,
'as_user': as_user,
'parse': parse,
'link_names': link_names,
'attachments': attachments,
'unfurl_links': unfurl_links,
'unfurl_media': unfurl_media,
'icon_url': icon_url,
'icon_emoji': icon_emoji
})
我的代码有问题吗?
仅供参考:这是我在 slack api 文档中找到的 https://api.slack.com/custom-integrations :
{
"text": "New Help Ticket Received:",
"attachments": [
{
"title": "App hangs on reboot",
"title_link": "http://domain.com/ticket/123456",
"text": "If I restart my computer without quitting your app, it stops the reboot sequence.\nhttp://domain.com/ticket/123456",
}
]
}
好的,我找到了,
我需要 list of dicts
one_attachement = {
"title": "App hangs on reboot",
"title_link": "http://example.com/ticket/123456",
"text": "If I restart my computer without quitting your app, it stops the reboot sequence.\nhttp://example.com/ticket/123456",
}
attachements = [one_attachement]
slack.chat.post_message(slack_channel, message, attachments=attachments)
我正在尝试 post 使用 slack 消息 python api 消息 我无法按照以下代码将 link 附加到我的消息中:
attachments = [title, link_to_events, "More details"]
print type(attachments) # this is a list
slack = Slacker(slack_api_token)
# Send a message to #general channel
slack.chat.post_message(slack_channel, message, attachments=attachments)
在 slacker 代码中,看起来我们正在寻找 "list" 类型的变量:
https://github.com/os/slacker/blob/master/slacker/init.py 第 241 行:
# Ensure attachments are json encoded
if attachments:
if isinstance(attachments, list):
attachments = json.dumps(attachments)
return self.post('chat.postMessage',
data={
'channel': channel,
'text': text,
'username': username,
'as_user': as_user,
'parse': parse,
'link_names': link_names,
'attachments': attachments,
'unfurl_links': unfurl_links,
'unfurl_media': unfurl_media,
'icon_url': icon_url,
'icon_emoji': icon_emoji
})
我的代码有问题吗?
仅供参考:这是我在 slack api 文档中找到的 https://api.slack.com/custom-integrations :
{
"text": "New Help Ticket Received:",
"attachments": [
{
"title": "App hangs on reboot",
"title_link": "http://domain.com/ticket/123456",
"text": "If I restart my computer without quitting your app, it stops the reboot sequence.\nhttp://domain.com/ticket/123456",
}
]
}
好的,我找到了, 我需要 list of dicts
one_attachement = {
"title": "App hangs on reboot",
"title_link": "http://example.com/ticket/123456",
"text": "If I restart my computer without quitting your app, it stops the reboot sequence.\nhttp://example.com/ticket/123456",
}
attachements = [one_attachement]
slack.chat.post_message(slack_channel, message, attachments=attachments)