我正在使用Python 2.7和python-slackclient.我有一个像这样的附件结构:
self.msg = { "attachments": [ { "fallback": "%s, %s" % (self.jiraIssueObj.fields.summary, self.link), "pretext": "Detail summary for %s" % self.jiraIssueObj, "title": self.jiraIssueObj.fields.summary, "title_link": self.link, "text": self.jiraIssueObj.fields.description[0:self.maxSummary], "color": "#7CD197", "mrkdwn_in": ["text", "pretext", "fields"] } ] }
然后,
def Send(self): if (self.msg): slack_client.api_call("chat.postMessage", channel=self.channel, text=self.msg, as_user=True) self.msg = None
但是,当这个发布时,它只是发布明文,没有格式:
{"附件":[{"title":"将Grafana升级到3.0","颜色":"#7CD197","text":"嘿伙计们,我们已经添加了JIRA maillist所以这封电子邮件会创建一张票我们如果您不想回复此电子邮件并提供其他信息,请立即排队.\n \n\u\u00a \n \n \n\u \n \n \n \n \n \n:nSent:2016年8月25日星期四11 :41 AM \n","title_link":" https://jira.jr.com/browse/ops-164 ","mrkdwn_in":["text","pretext","fields"],"pretext" :"ops-164的详细摘要","后备":"将Grafana升级到3.0,https://jira.jr.com/browse/ops-164 "}}}
我究竟做错了什么?我试着这样做也是attachments=self.msg
在Send()
打电话,但我在所有我的松弛渠道得不到任何输出这样做的时候.
事实证明,呼吁
slack_client.api_call("chat.postMessage", channel=self.channel, attachments=self.msg, as_user=True)
apears { "attachments": ... }
为您添加顶层.所以通过改变我self.msg
只需:
self.format = [{ "fallback": "%s, %s" % (self.jiraIssueObj.fields.summary, self.link), "pretext": "Detail summary for %s" % self.jiraIssueObj, "title": self.jiraIssueObj.fields.summary, "title_link": self.link, "text": self.jiraIssueObj.fields.description[0:self.maxSummary], #"color": "#7CD197", "mrkdwn_in": ["text", "pretext", "fields"] }]
没有这个外包装{ "attachments": ... }
,api能够按预期发布消息附件.