slackchannelreader

simple slack client which polls messages and images from a given channel.


Keywords
Slack, client, channel, chat, download
License
MIT
Install
pip install slackchannelreader==0.1.2

Documentation

SlackChannelReader

This is a very simple Slack client (using legacy auth) which is able to poll

  • messages
  • images from a given Slack channel.

It is intended as data source for info displays.

This version requires Python 3 or later.

Build info

Build Status

https://travis-ci.org/irgangla/slackchannelreader

codecov

https://codecov.io/gh/irgangla/slackchannelreader

Usage

see main.py

    # environment variable SLACK_TOKEN contains Slack legacy token
    # environment variable SLACK_CHANNEL contains the Slack channel ID
    # or config file with format:
    # token = <your token>
    # channel = <channel ID>
    # using the config file:
    client = SlackInfoClient(config_file='slack.txt')
    # Update every 30 seconds, triggers a request
    client.auto_update(seconds=30)
    # timestamp of latest message
    latest = None
    for i in range(0, 5):
        if not client.message_stamp:
            if client.update_stamp:
                print("No messages in channel.")
            else:
                print("No messages received at the moment")
        elif not latest or latest != client.message_stamp:
            latest = client.message_stamp
            print("Latest 3 Messages:")
            for m in client.messages(limit=3):
                print(m)
            image = client.images(limit=1)
            if image:
                print("Latest image: %s" % image[0])
        else:
            print("No new messages available.")

        sleep(30)