Tuesday, June 7, 2016

Python: Using the Slack API

Motivation
Slack is a great tool for team communication.  It also provides a simple way to integrate automated scripts, via incoming and outgoing web hooks.  This is useful for batch programs to post status updates automatically and/or notify team members when a program is done, has errored out, etc. 

Setup

Clone this repository:
https://github.com/os/slacker

Install the python program using
python setup.py install clean
pip install --user --upgrade slacker

Here's the python code:
from slacker import Slacker

message = """
 @johndoe: 16-476 done: 3.61%
""".strip()

slack = Slacker('private-key')
slack.chat.post_message('#channel', message, icon_emoji=":rolled_up_newspaper:", username="Pulse", link_names=1)


No comments:

Post a Comment