diff --git a/README.md b/README.md index f2a17f0..bc65930 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,52 @@ https://api.slack.com ## Installation - pip install git+git://github.com/loisaidasam/pyslack.git + pip install git+git://github.com/aneisch/pyslack.git ## Usage Post a message into your Slack integration's `#play` channel >>> from pyslack import SlackClient - >>> client = SlackClient('YOUR-TOKEN-HERE') + >>> from pyslack import SlackClient >>> client.chat_post_message('#play', "testing, testing...", username='slackbot') {u'ok': 1, u'timestamp': u'1392000237000006'} + +Post an 'attachment' message into your Slack integration's `#play` channel. (Follow guidlines at https://api.slack.com/docs/attachments) + + from pyslack import SlackClient + def post_attachment(recipient, message): + client = SlackClient('YOUR-TOKEN-HERE') + client.chat_post_attachment(recipient, message, username='BOT', icon_emoji=":cop:") + message = '''[ + { + "fallback": "Required plain-text summary of the attachment.", + + "color": "#36a64f", + + "pretext": "Optional text that appears above the attachment block", + + "author_name": "Bobby Tables", + "author_link": "http://flickr.com/bobby/", + "author_icon": "http://flickr.com/icons/bobby.jpg", + + "title": "Slack API Documentation", + "title_link": "https://api.slack.com/", + + "text": "Optional text that appears within the attachment", + + "fields": [ + { + "title": "Priority", + "value": "High", + "short": false + } + ], + + "image_url": "http://my-website.com/path/to/image.jpg" + } + ]''' + post_attachment('#play',message) Integrate a SlackHandler into your logging! diff --git a/pyslack/__init__.py b/pyslack/__init__.py index a67d32f..d1294b3 100644 --- a/pyslack/__init__.py +++ b/pyslack/__init__.py @@ -83,6 +83,20 @@ def chat_post_message(self, channel, text, **params): 'text': text, }) return self._make_request(method, params) + + def chat_post_attachment(self, channel, text, **params): + """chat.postMessage + + This method posts a message to a channel. + + https://api.slack.com/methods/chat.postMessage + """ + method = 'chat.postMessage' + params.update({ + 'channel': channel, + 'attachments': text, + }) + return self._make_request(method, params) def chat_update_message(self, channel, text, timestamp, **params): """chat.update