Chicago Python's Community Engagement Slack bot.
With over four thousand members, the Chicago Python Users Group (ChiPy) is one of the largest Python communities in the world. Slack has become the primary method of communication amongst our members in-between events. We developed an open-source Slack bot, codename: Busy Beaver, to increase community engagement.
Slides from Busy Beaver's release announcement. YouTube link is forthcoming.
Busy-Beaver posts daily summaries of public GitHub activity for registered users in the #busy-beaver
channel on the ChiPy Slack. The goal of this feature is to increase engagement by sparking conversations around GitHub activity.
Users sign up for an account by DM
ing the bot with the phrase: connect
. The bot requires users to sign into GitHub to ensure only authorized activity is posted in the channel.
Busy-Beaver retweets posts made to the @ChicagoPython Twitter account in the #at-chicagopython
channel on the ChiPy Slack.
We are currently working on additional features to improve ChiPy community engagement. Please join the conversation in #busy-beaver-meta
on the ChiPy Slack.
Busy-Beaver is an open source project where all artificats (code, Docker image, etc) are online. We use the Twelve-Factor Application Methodology for building services to design the CICD process and to keep information secure.
vcr.py
records cassettes of requests and responses for new tests, and replays them for previously written tests. Make sure to filter credentials
- watchtower (monitors DockerHub, downloads and deploys latest image)
- Ansible
- DigitalOcean
We are grateful to the following organizations for providing free services to open source projects:
- GitHub (code repo, issues)
- DockerHub (hosting Docker images)
- Travis CI (continuous integration platform)
Create a Slack app via the Slack API. The app will need Event Subscriptions configured to send information to a server for processing. Specifically, the Slack app is subscribed to message.im bot events, which include direct messages sent to the bot. The app will also need scopes configured in OAuth & Permissions (see here).
Configure a server with an endpoint URL to receive HTTP POST requests when message.im
events occur. A service like ngrok is useful here for local development purposes.
Create a GitHub app. The sole function of this app is to provide a means for the Slack user to validate their GitHub account.
When a Slack user chats "connect" to the bot user via direct message, the server receives the event details and generates a unique state
identifier. The server logs the Slack user and identifier to our server database. The bot user chats a GitHub URL containing our GitHub app's client_id
and the state
identifier. The URL leads the user to a validation page in which they log in to GitHub and approve access to basic public information. Upon approval, the GitHub user's details and state
identifier are sent to another server endpoint. The server updates the Slack user record with GitHub user details by using the state
identifier as a common key.
Can make requests to REST endpoints to kick off processes. Currently we are using CRON to run repetitive tasks; this is managed by Ansible to avoid manual configuration.
- Start the process to run a summary by making a
POST
request to/poll-twitter
withAuthentication
header set totoken {token}
and JSON body:
{
"channel": "busy-beaver"
}
- Check Twitter feed for new posts to share on Slack by making a
POST
request to/github-summary
withAuthentication
header set totoken {token}
and JSON body:
{
"channel": "at-chicagopython"
}
admin = ApiUser(username="admin", token="abc123!")
db.session.add(admin)
db.session.commit()
export DATABASE_URI=sqlite:///busy_beaver.db
export GITHUB_APP_CLIENT_ID=[client-id]
export GITHUB_APP_CLIENT_SECRET=[client-secret]
export GITHUB_OAUTH_TOKEN=[token-here]
export SLACK_BOTUSER_OAUTH_TOKEN=[token-here]
export TWITTER_CONSUMER_KEY=[token-here]
export TWITTER_CONSUMER_SECRET=[token-here]
export TWITTER_ACCESS_TOKEN=[token-here]
export TWITTER_ACCESS_TOKEN_SECRET=[token-here]
Leverage Docker-Compose to create a containerized local development environment. Please see the Makefile
for available commands.
pdb++ Configuration
PDB++ improves the debugging experience inside the shell.
# ./.pdbrc.py
import pdb
class Config(pdb.DefaultConfig):
sticky_by_default = True # start in sticky mode
current_line_color = 40 # black
TODO: elaborate on permissions
CONVERSATIONS
Access information about user’s public channels
channels:read
Send messages as BusyBeaverStaging
chat:write:bot
INTERACTIVITY
Add a bot user with the username @busybeaver
bot
BOT EVENTS
A message was posted in a direct message channel
message.im
- ETag, need to set up DB for this
- mark events that are new
- rate limiting
- far away concern
- GraphQL
- CreateEvent
ref_type
repository - ForkEvent
- IssuesEvent
action
opened - PublicEvent
- PullRequestEvent
action
opened - PushEvent
- ReleaseEvent
- WatchEvent
action
started