messages into Slack with customization and rich formatting. • Outgoing Webhooks • Send messages from Slack to your service in real-time. • Bot Users • Connect to Slack to read and write as a real-time bot.
slackclient import SlackClient # Token found at https://api.slack.com/web#authentication token = "xoxb-52095439187-CYPqixxxxxzwR9MoriR" sc = SlackClient(token) if sc.rtm_connect(): while True: results = sc.rtm_read() for result in results: if 'type' in result: if result['type'] == u'message' and not('subtype' in result): channel = result['channel'] text = result['text'] user = result['user'] if channel != u'C02HKPG5U' and user != u'U1J2TCX5H': # Filter out: # C02HKPG5U ==> General channel # U07SJTAMC ==> Bot it's self try: sc.rtm_send_message(channel, text) except Exception, e: print e print result time.sleep(5) else: print "Connection Failed, invalid token?" Python