Skip to main content

community_mailbot

https://img.shields.io/pypi/v/community_mailbot.svg

The community_mailbot is a friendly bot that tells subscribers to LSST DM’s legacy Mailman email lists about things happening on community.lsst.org.

The bot likes to be awakened regularly by cron; each time it will ask the Discourse server about latest messages in different categories that the bot tracks (you can set this with a simple config.json file). If there is are new topics, community_mailbot will send an email to the appropriate email lists using its buddy, Mandrill. Before the bot goes back to sleep, it keeps note of all the topics it’s emailed already in a simple JSON cache file.

Installation

Create a virtual environment running Python 3.5, then:

pip install community_mailbot

Running the community mailbot

Keys to the Kingdom

You’ll need to get API keys from community.lsst.org and Mandrill. Set them to the following environment variables:

  • $MANDRILL_KEY (note, use the API key for the community_mailbot subaccount)

  • $DISCOURSE_KEY (the Discourse key should correspond to a user with sufficient permissions)

  • $DISCOURSE_USER

Optionally set $COMMUNITY_MAILBOT_CACHE to the location where you want the Mailbot to keep track of its topics it has forwarded.

Setup Topic → Email Mapping

To setup how Discourse categories are mapped to recipient email addresses, you need to know the integer IDs for each relevant category. To get these, run the included script:

discourse_categories

If you set the aforementioned environment variables, you won’t need to provide any arguments to the script.

Next, create a config.json file. It’s a simple hash structure; each key-value pair is the Discourse category ID and a list of email recipients for that category. The general format is:

{
    "<id>": [{"email": "<email address>",
              "name": "<recipient name>",
              "type": "to"}],
}

The structure of the dict in the value matches the Mandrill send-template API. The "type" field should typically be "to", but could also be "cc" or "bcc".

Note that since the recipient information for each category is a list, you can have multiple recipients.

Pre-cache old topics

Before having the bot send emails, you’ll want it to know about and ignore older messages. To warm up the cache, we’ll run the forward_discourse script with the --cache-only option.

forward_discourse config.json --cache-only

Note that forward_discourse can configure itself with the environment variables you’ve already setup. Run forward_discourse --help for the full set of options.

Set up a cron schedule

The bot works best when it regularly monitors a Discourse site for new topics. cron is a great way to set this up.

It’s useful to create a shell script to contain all of the script arguments. For example, create a script called run_mailbot.sh:

#!/bin/bash
source /home/ec2-user/.bash_profile
source activate community_mailbot
forward_discourse /home/ec2-user/config.json

echo "$(date) Ran forward_discourse"

This script sets up up the shell environment, loads a Python environment, and then runs the mailbot.

Then instruct cron to run this script every 10 minutes

First, open the crontab in your terminal

crontab -e

And add a line for the bot

*/10 * * * * /home/ec2-user/run_mailbot.sh

Then sit back and watch the email flow.

Development

To develop on the community_mailbot, you’ll need to clone the repository and install a development copy (preferably in a virtualenv):

git clone https://github.com/lsst-sqre/community_mailbot.git
cd community_mailbot
python setup.py develop

To run the test suite:

python -m unittest discover -s community_mailbot/tests

Rough Spots

The community_mailbot is meant to be fairly general and usable for any Discourse installation.

However, beware that the Mandrill email template information is current hard-coded. Ideally this would be user-configurable.

License

Copyright 2015 AURA/LSST.

MIT licensed; see LICENSE file.

Metadata

Release files for community_mailbot 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for community_mailbot 0.1.1
File Size Uploaded
community_mailbot-0.1.1.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for community_mailbot 0.1.1
File Interpreter ABI Platform
community_mailbot-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 22.4 kB

Release files / community_mailbot-0.1.1.tar.gz

Download URL community_mailbot-0.1.1.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
394e70e6dd876c665387e8ccde4327083b50bdb7c6a53543b6e2acdf2321c532
BLAKE2b-256 checksum
How to use checksums
e8441021d410043fa77f735b5d74eafaac6661d05356909b5c286e41cfd4dd7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / community_mailbot-0.1.1-py3-none-any.whl

Download URL community_mailbot-0.1.1-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4de99bbc997752c28c0893bbbf86ab6c771d7eebb3af08ff872760eba535984
BLAKE2b-256 checksum
How to use checksums
555d6eaba3c58160ef35b367922e4ac48002d18f52951f9356b3bfd4c7de5e7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page