Skip to main content

Yet Another Slack bot

Project description

YAS

Yet Another Slack bot

The operations team at Refinery29 was replacing a old system for launching development systems which utilized an older version of Hubot. At the time our team was more comfortable with python than the Node/Coffeescript which Hubot is built on, and we were already familiar with python modules with which we could interface with the systems we wanted our new bot to interact with. Thus YAS was born.

YAS is framework which tests Slack messages which are available to it against handlers which will operate on a message if they are the first handler to produce a truthy result upon running a test against the message. A simple practical example is the built in id handler. This handler has a test which looks for a message starting with id. If it does, the handler is invoked, replying with some information about the server yas is running on.

Slack has a number of message types of which only a few are initiated by a user and in most cases only a subset of user initiated messages will be meant to be handled by your bot. To handle these cases a number of handlers are included with yas, but are not automatically added, and must be included in the list of handlers when that is configured.

Setup

Yas may be run directly, but it won't do much, so setup including one or more additional handlers will be included here.

The easiest method (as of version 2.0) is to construct a Docker image based on the yas image and install the additional handlers and configure them. Alternatively, if any of the handlers has a Dockerfile available, that could be used as a base on which to add any others, but since Docker files need to be manually combined it is likely easier to simply construct a new image based directly on yas'. For instance, the yas-jenkins handler can be built with a Dockerfile such as:

FROM schlueter/yas:latest

ENV YAS_JENKINS_JOBS '{}'
ENV YAS_JENKINS_URL ''
ENV YAS_JENKINS_USERNAME ''
ENV YAS_JENKINS_PASSWORD ''

COPY . .
RUN python -m pip install yas-jenkins

To add an additional handler, its configuration need only be added and it installed as well.

Once built, the resulting image may be run with the appropriate configuration provided in environment variables with:

docker run --rm --tty \
 --env YAS_SLACK_TOKEN=xoxb-XXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXX \
 --env YAS_BOT_NAME=yas \
 --env YAS_JENKINS_URL=https://jenkins.example.com \
 --env YAS_JENKINS_USERNAME=yas \
 --env YAS_JENKINS_PASSWORD=supersecret \
 --env YAS_JENKINS_JOBS='{"MyJob": "build (?P<branch>\\w+)"}' \
 --env YAS_HANDLER_LIST=yas.handlers.ignored_types_handler.,yas.handlers.not_talking_to_bot_handler.,yas.handlers.help_handler.,yas.handlers.identify_handler.,YasJenkinsHandler.,yas.handlers.rules_handler.,yas.handlers.default_handler. \
 my-yas-image:my-tag

For yas to function, the YAS_SLACK_TOKEN, YAS_BOT_NAME, and YAS_HANDLER_LIST variables must be provided. The token and name must be obtained/configured from a new or existing bot in your Slack organization. A new bot may be created at https://my.slack.com/services/new/bot.

The handler list should include most of the default handlers, potentially discluding those not being generally necessary to yas' normal functioning being the identify_handler, rules_handler, and the default_handler. The help_handler is also not necessary to yas operating in a reasonable manner, but it may be utilized by other plugins to make help functionality available.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yas-2.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

yas-2.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file yas-2.0.tar.gz.

File metadata

  • Download URL: yas-2.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for yas-2.0.tar.gz
Algorithm Hash digest
SHA256 64a8b90b0b7525ec0b5231c166f57bd86d5a2350683b5f6e302b45de73ba26e9
MD5 34676731b83c0a7913acf330ae6b1c4c
BLAKE2b-256 1247aa8ac2195d5f24de972ec6002e833097fbb08e73f339e64113e2cb9b212e

See more details on using hashes here.

File details

Details for the file yas-2.0-py3-none-any.whl.

File metadata

  • Download URL: yas-2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for yas-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92b05aa9110446e2eb1a735d8aef75513a9b9a59fc445a96a2318a196da9f76d
MD5 10b923fb5845e19d6588498e1a86ac75
BLAKE2b-256 1a3b593cf692b571dd6cfa0781da17160ca83824b6bdfa90d74d0f1a7d491961

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page