python - Adding attachements to slacker chat message -
i'm trying post message using slacker python api slack messages i'm not able attach link messages code below :
attachments = [title, link_to_events, "more details"] print type(attachments) # list slack = slacker(slack_api_token) # send message #general channel slack.chat.post_message(slack_channel, message, attachments=attachments)
in slacker code, looks looking "list" type of variable:
https://github.com/os/slacker/blob/master/slacker/init.py line 241:
# ensure attachments 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 })
is there problem code ?
fyi : i've found in slack api documentation https://api.slack.com/custom-integrations :
{ "text": "new ticket received:", "attachments": [ { "title": "app hangs on reboot", "title_link": "http://domain.com/ticket/123456", "text": "if restart computer without quitting app, stops reboot sequence.\nhttp://domain.com/ticket/123456", } ] }
all right i've found it, need list of dicts
one_attachement = { "title": "app hangs on reboot", "title_link": "http://example.com/ticket/123456", "text": "if restart computer without quitting app, stops reboot sequence.\nhttp://example.com/ticket/123456", } attachements = [one_attachement] slack.chat.post_message(slack_channel, message, attachments=attachments)
Comments
Post a Comment