Git Product home page Git Product logo

layabout's Introduction

Layabout

Unix build status on Travis CI

Code coverage on Coveralls

ISC Licensed

Docs on Read the Docs

Python Version

Layabout on PyPI

โš ๏ธ Layabout is deprecated. There will be no further support. โš ๏ธ

Layabout is a small event handling library on top of the Slack RTM API.

from pprint import pprint
from layabout import Layabout

app = Layabout()


@app.handle('*')
def debug(slack, event):
    """ Pretty print every event seen by the app. """
    pprint(event)


@app.handle('message')
def echo(slack, event):
    """ Echo all messages seen by the app except our own. """
    if event.get('subtype') != 'bot_message':
        slack.rtm_send_message(event['channel'], event['text'])


def someone_leaves(events):
    """ Return False if a member leaves, otherwise True. """
    return not any(e.get('type') == 'member_left_channel'
                   for e in events)


if __name__ == '__main__':
    # Automatically load app token from $LAYABOUT_TOKEN and run!
    app.run(until=someone_leaves)
    print("Looks like someone left a channel!")

Installation

To install Layabout use pip and PyPI:

pip install layabout

What's It Good For?

You can think of Layabout as a micro framework for building Slack bots. Since it wraps Slack's RTM API it does best with tasks like interacting with users, responding to channel messages, and monitoring events. If you want more ideas on what you can do with it check out the examples.

Features

Not sold yet? Here's a list of features to sweeten the deal.

  • Automatically load Slack API tokens from environment variables, provide them directly, or even bring your own SlackClient.
  • Register multiple event handlers for one event.
  • Register a single handler for multiple events by stacking decorators.
  • Configurable application shutdown.
  • Configurable retry logic in the event of lost connections.
  • Lightweight. Depends only on the official Python slackclient library.

Code of Conduct

Everyone interacting with the Layabout project's codebase is expected to follow the Code of Conduct.

layabout's People

Contributors

mikecanoy avatar radicalzephyr avatar reillysiemens avatar sophiekan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

radicalzephyr

layabout's Issues

Create example applications

Create a few simple example applications using the framework. Some requirements:

  • Showcase early connecting and calling the Slack Web API before entering the RTM loop.
  • Showcase runtime addition of handlers by using Layabout.handle as a normal function rather than a decorator.
  • Showcase conditional exiting using the until parameter to Layabout.run.

These should all exist in a examples/ directory from the root of the project and contain their own subdirectories. They should all be pip installable and declare a relative dependency on the library via file path so they can be run against whatever the current development version is.

Create a Complex Example

The complex example should showcase dynamic modification of Layabout. One possible example would be a Layabout application that allows registration/deregistration of "administrative" users. These users could, through Slack messages, change how the Slack bot responds to certain keywords in channels.

Add Python 3.7 Support

Now that Python 3.7 has been ๐ŸŽ‰๐ŸŽˆofficially released ๐Ÿฐ๐Ÿพ it's time to look at adding support for this version. The first step would be to test manually with Python 3.7, but I don't want to add official 3.7 support until it can be part of the CI pipeline. It looks like the best option for now is to watch for progress on travis-ci #9815.

Simple example should fail gracefully and informatively when Slack API token is not present

I attempted to run the simple example without having a Slack API token. Having never used layabout or the Slack RTM API, I didn't know I needed one. This exception should be handled more gracefully and tell the user that a token is needed and possibly where/how to get it. This would be helpful for people whose first experience with Slack APIs is layabout.

(layabout) sophie@leaflet:~/layabout/examples/simple$ pipenv run example
Printing all events. Press Ctrl-C to quit.

Traceback (most recent call last):
  File "example.py", line 17, in <module>
    app.run()
  File "/home/sophie/layabout/layabout.py", line 230, in run
    backoff=backoff
  File "/home/sophie/layabout/layabout.py", line 181, in _ensure_slack
    slack: SlackClient = _create_slack(connector)
  File "/home/sophie/.virtualenvs/layabout/lib/python3.6/functools.py", line 803, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "/home/sophie/layabout/layabout.py", line 296, in _create_slack_with_env_var
    raise MissingToken(f"Could not acquire token from {env_var}")
layabout.MissingToken: Could not acquire token from LAYABOUT_TOKEN

Write a user guide

Write a user guide to complement the auto-generated API documentation. It should include:

  • An immediate note about the Python 3.6+ only support
  • Installation steps
  • Quickstart guide (Just two quick examples should do)
  • Support information (i.e. where to file bugs)
  • Changelog
  • Authors
  • Licensing information
  • Code of Conduct
  • Contributing guide
  • Rationale for why the library exists

The Requests documentation is an excellent example to use when implementing this. The Marshmallow docs are also a good resource.

Consider an alternative to setup.py

Pipfile (and its counterpart Pipfile.lock) are a new way of declaring Python project metadata. They aren't currently respected by pip proper, but they're fast-tracked to be included in the near future and they're respected by the pipenv, which looks like a great alternative to the typical dev process using virtualenvwrapper.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.