ZaxR / busy-beaver

The Chicago Python Community Engagement Slack bot

Home Page:https://www.chipy.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Busy Beaver

Busy Beaver Logo

Build Status License: MIT

Chicago Python's Community Engagement Slack bot.

Introduction

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.

Features

GitHub Activity

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 DMing the bot with the phrase: connect. The bot requires users to sign into GitHub to ensure only authorized activity is posted in the channel.

Retweeter

Busy-Beaver retweets posts made to the @ChicagoPython Twitter account in the #at-chicagopython channel on the ChiPy Slack.

Roadmap

We are currently working on additional features to improve ChiPy community engagement. Please join the conversation in #busy-beaver-meta on the ChiPy Slack.

Development Notes

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.

Web Application Stack

Tests

vcr.py records cassettes of requests and responses for new tests, and replays them for previously written tests. Make sure to filter credentials

DevOps

Services

We are grateful to the following organizations for providing free services to open source projects:

Installation Notes

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.

API Docs

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.

GitHub Summary Endpoint

  • Start the process to run a summary by making a POST request to /poll-twitter with Authentication header set to token {token} and JSON body:
{
  "channel": "busy-beaver"
}

Retweeter Endpoint

  • Check Twitter feed for new posts to share on Slack by making a POST request to /github-summary with Authentication header set to token {token} and JSON body:
{
  "channel": "at-chicagopython"
}

Creating API Account and Token

admin = ApiUser(username="admin", token="abc123!")
db.session.add(admin)
db.session.commit()

Development Environment

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

Slack Permission Scopes

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

Todo

GitHub Events

About

The Chicago Python Community Engagement Slack bot

https://www.chipy.org

License:MIT License


Languages

Language:Python 88.6%Language:Makefile 7.2%Language:Dockerfile 2.3%Language:Mako 0.9%Language:Shell 0.9%