Code Monkey home page Code Monkey logo

franzdiebold / where-is-rudi Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 2.87 MB

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

License: MIT License

Python 43.93% HCL 43.37% Shell 11.69% Makefile 1.00%
google-cloud-platform google-cloud-function slack slack-api python3 google-cloud-scheduler slack-slash-command slack-app terraform google-cloud-datastore

where-is-rudi's Introduction

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.

where-is-rudi's People

Contributors

franzdiebold avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.