https://github.com/franzdiebold/where-is-rudi
WhereIsRudi 🐶 is an interactive Slack app to inform your colleagues whether your dog@work is in the office today! 🎉
https://github.com/franzdiebold/where-is-rudi
github-actions google-cloud-datastore google-cloud-function google-cloud-platform google-cloud-scheduler python3 slack slack-api slack-app slack-slash-command terraform
Last synced: about 1 year ago
JSON representation
WhereIsRudi 🐶 is an interactive Slack app to inform your colleagues whether your dog@work is in the office today! 🎉
- Host: GitHub
- URL: https://github.com/franzdiebold/where-is-rudi
- Owner: FranzDiebold
- License: mit
- Created: 2019-09-15T15:35:43.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-24T06:41:32.000Z (over 6 years ago)
- Last Synced: 2025-04-06T01:32:17.587Z (over 1 year ago)
- Topics: github-actions, google-cloud-datastore, google-cloud-function, google-cloud-platform, google-cloud-scheduler, python3, slack, slack-api, slack-app, slack-slash-command, terraform
- Language: Python
- Homepage:
- Size: 2.8 MB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# WhereIsRudi :dog:
[](https://slack.com)
[](https://cloud.google.com)
[](./deployment/main.tf)
[](https://github.com/FranzDiebold/where-is-rudi/actions?query=workflow%3A%22Lint%22)
[](./LICENSE.md)

*WhereIsRudi* is an interactive [Slack](https://slack.com) app to inform your colleagues whether your dog@work is in the office today! :tada:
## Usage
### Colleagues

Use the [Slash Command](https://api.slack.com/slash-commands) `\whereisrudi` in any channel, direct message or any other slack conversation. That's it!
### 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

## Linting
Local linting may be done using the Makefile:
```shell
make install
make lint
```
## Deployment
For easier deployment, the *infrastructure as code* (IaC) software tool [Terraform](https://www.terraform.io/) is used.
#### Preparations
1. Install Terraform: [https://learn.hashicorp.com/terraform/getting-started/install.html](https://learn.hashicorp.com/terraform/getting-started/install.html)
2. Define a Google Cloud Platform (GCP) project id, i.e. `whereisrudi-` and enter it in:
- [`deployment/prepare_gcp.sh`](./deployment/prepare_gcp.sh)
- [`deployment/variables.tf`](./deployment/variables.tf)
3. Run preparation script:
1. Run `prepare_gcp.sh`: `bash prepare_gcp.sh`. You may run this in the [Google Cloud Shell editor](https://ssh.cloud.google.com/cloudshell/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](https://console.cloud.google.com) resources are created via Terraform:
#### Google Cloud Function

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 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

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](https://api.slack.com/apps).
#### Bot User

Create a Bot User, i.e. `WhereIsRudi`.
#### OAuth & 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

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


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](./design/).