Package: community_mailbot
Thecommunity_mailbotis a friendly bot that tells subscribers to LSST DM’s legacy Mailman email lists about things happening oncommunity.lsst.org.The bot likes to be awakened regularly bycron; each time it will ask the Discourse server about latest messages in different categories that the bot tracks (you can set this with a simpleconfig.jsonfile).
If there is are new topics,community_mailbotwill 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.InstallationCreate a virtual environment running Python 3.5, then:pipinstallcommunity_mailbotRunning the community mailbotKeys to the KingdomYou’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 thecommunity_mailbotsubaccount)$DISCOURSE_KEY(the Discourse key should correspond to a user with sufficient permissions)$DISCOURSE_USEROptionally set$COMMUNITY_MAILBOT_CACHEto the location where you want the Mailbot to keep track of its topics it has forwarded.Setup Topic → Email MappingTo 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_categoriesIf you set the aforementioned environment variables, you won’t need to provide any arguments to the script.Next, create aconfig.jsonfile.
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 thedictin the value matches theMandrill 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 alist, you can have multiple recipients.Pre-cache old topicsBefore having the bot send emails, you’ll want it to know about and ignore older messages.
To warm up the cache, we’ll run theforward_discoursescript with the--cache-onlyoption.forward_discourseconfig.json--cache-onlyNote thatforward_discoursecan configure itself with the environment variables you’ve already setup.
Runforward_discourse--helpfor the full set of options.Set up a cron scheduleThe bot works best when it regularly monitors a Discourse site for new topics.cronis 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 calledrun_mailbot.sh:#!/bin/bashsource/home/ec2-user/.bash_profilesourceactivatecommunity_mailbotforward_discourse/home/ec2-user/config.jsonecho"$(date)Ran forward_discourse"This script sets up up the shell environment, loads a Python environment, and then runs the mailbot.Then instructcronto run this script every 10 minutesFirst, open thecrontabin your terminalcrontab-eAnd add a line for the bot*/10****/home/ec2-user/run_mailbot.shThen sit back and watch the email flow.DevelopmentTo develop on thecommunity_mailbot, you’ll need to clone the repository and install a development copy (preferably in avirtualenv):gitclonehttps://github.com/lsst-sqre/community_mailbot.gitcdcommunity_mailbotpythonsetup.pydevelopTo run the test suite:python-munittestdiscover-scommunity_mailbot/testsRough SpotsThecommunity_mailbotis 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.LicenseCopyright 2015 AURA/LSST.MIT licensed; seeLICENSEfile.