Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to send 'attachment' #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
14 changes: 14 additions & 0 deletions pyslack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down