Skip to content

WhereIsRudi 🐢 is an interactive Slack app to inform your colleagues whether your dog@work is in the office today! πŸŽ‰

License

Notifications You must be signed in to change notification settings

FranzDiebold/where-is-rudi

Repository files navigation

WhereIsRudi 🐢

app:slack technology: Google Cloud Platform IaC: Terraform Lint Status license: MIT

WhereIsRudi is an interactive Slack app to inform your colleagues whether your dog@work is in the office today! πŸŽ‰

Usage

Colleagues

Slack Example Colleagues

Use the Slash Command \whereisrudi in any channel, direct message or any other slack conversation. That's it!

Dog Owner

Slack Example Dog Owner

You will get a message every (working day) morning to ask you whether you bring your dog to the office today. Just answer with one tap or click via the actions in the message. It's that easy!

Architecture & Sequence

WhereIsRudi architecture

Linting

Local linting may be done using the Makefile:

make install
make lint

Deployment

For easier deployment, the infrastructure as code (IaC) software tool Terraform is used.

Preparations

  1. Install Terraform: https://learn.hashicorp.com/terraform/getting-started/install.html
  2. Define a Google Cloud Platform (GCP) project id, i.e. whereisrudi-<random_number> and enter it in:
  3. Run preparation script:
    1. Run prepare_gcp.sh: bash prepare_gcp.sh. You may run this in the Google Cloud Shell editor. This will:
      • Create a Google Cloud Platform project.
      • Create Service Account and bind the roles roles/owner, roles/iam.serviceAccountUser, roles/storage.admin, roles/appengine.appAdmin, roles/cloudscheduler.admin, roles/pubsub.editor and roles/cloudfunctions.developer.
      • Create new private key for the Service Account and save in the file account.json.
      • Enable the Google Cloud Platform APIs appengine, cloudfunctions, cloudscheduler and datastore.
      • You will be asked to enable billing for the created project when running the script.
    2. Copy the file account.json into the deployment folder.

Deployment

  1. Commands need to be run in deployment folder: cd /deployment
  2. Initialize the Terraform working directory: terraform init
  3. Generate and show the Terraform execution plan: terraform plan
  4. Build the infrastructure: terraform apply and confirm with yes. This step will output the endpoint URLs slack_actions_function_url and slack_slash_commands_function_url that you need to enter in the Slack API console.

To destroy/delete the infrastructure: terraform destroy and confirm with yes

Google Cloud Platform Resources

The following Google Cloud Platform resources are created via Terraform:

Google Cloud Function

Google Cloud Functions

Three cloud functions with environment variables:

  • gather-information (triggered by Google Pub/Sub topic gather-information-schedule)
    • SLACK_API_TOKEN: Slack App OAuth Access Token (starting with xoxp-)
    • USER_ID: Slack user id of dog owner.
  • slack-actions (triggered by HTTP)
    • SLACK_API_VERIFICATION_TOKEN: Slack App Verification Token
  • slack-slash-commands (triggered by HTTP)
    • SLACK_API_VERIFICATION_TOKEN: Slack App Verification Token

Google Cloud Scheduler

Google Cloud Scheduler

Google Pub/Sub topic gather-information-schedule should be triggered every working day (monday - friday) at 7:30 AM.

Therefore the frequency is set to 30 7 * * 1-5.

Google Cloud Datastore / Google Cloud Firestore Datastore Mode

Google Cloud Datastore

The cloud functions create a entities of kind days. The entity id is the day string (i.e. 2019-09-14). The entities only have one boolean field in_office, which is not indexed.

Slack API/App

Slack App

Create a new Slack app in the Slack API console: https://api.slack.com/apps.

Bot User

Slack API Bot User

Create a Bot User, i.e. WhereIsRudi.

OAuth & Permissions

Slack API Permissions

In OAuth & Permissions in Scopes, add permission scope chat:write:bot and incoming-webhook to Conversations and bot and commands to Interactivity.

Interactive Components

Slack API Actions

Add Interactivity request URL pointing to your Google Cloud Function slack-actions. You got this URL as output from the terraform apply step before, named slack_actions_function_url.

Slash Commands

Slack API Slash Commands 1

Slack API Slash Commands 2

Create new Slash command /whereisrudi with request URL pointing to your Google Cloud Function slack-slash-commands. You got this URL as output from the terraform apply step before, named slack_slash_commands_function_url.

Design

See /design.