Skip to content

Repository files navigation

Inspirational Morning

Send a good morning message to your Google Chat webhook. The message would include the day of the week, a quote, and the author of the quote. Quote and its author is fetched using ZenQuotes API.

Note

Google Chat webhook only supports Google Workspace accounts.

Local dev

  1. Get the desired GChat webhook URL. You can register a webhook by following the Google Chat webhooks documentation.

  2. Save the webhook URL, and optionally a time zone, in the .env file in the root of the project. For example:

    GSPACE_WEBHOOK=https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY&token=TOKEN
    TIMEZONE=Pacific/Midway
  3. You may run the application in dev mode,

    make dev

    Or in a container using

    make container-run
  4. Once the container is running, hit the exposed REST endpoint to send the greeting.

    curl --silent --request POST --location http://localhost:3005/api/greet | jq
  5. To clean up, stop and remove the container and the image.

    make container-destroy

Deploy to Google Cloud Functions

  1. Build the application. This will create a deployable JAR file in the target/deployment directory.

    make build
  2. Create up a Pub/Sub topic.

    gcloud pubsub topics create topic-inspirational-morning
  3. Create a cron job schedule for every weekday at 08:00.

    gcloud scheduler jobs create pubsub schedule-job-inspirational-morning \
       --schedule="0 8 * * 1-5" \
       --topic=topic-inspirational-morning \
       --message-body="job is triggered" \
       --time-zone="Pacific/Auckland" \
       --location="us-central1"
  4. Deploy the application as a Cloud Function

    gcloud functions deploy inspirational-morning \
       --gen2 \
       --allow-unauthenticated \
       --trigger-topic=topic-inspirational-morning \
       --region=us-central1 \
       --timeout=540s \
       --entry-point=io.quarkus.gcp.functions.QuarkusCloudEventsFunction \
       --runtime=java17 \
       --memory=256MiB \
       --cpu=0.167 \
       --source=target/deployment \
       --set-env-vars=TIMEZONE="Pacific/Auckland",GSPACE_WEBHOOK="https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY&token=TOKEN"
  5. [OPTIONAL] Trigger the job manually

    gcloud scheduler jobs run schedule-job-inspirational-morning --location="us-central1"

Google Cloud Clean up

  1. Delete the function

    gcloud functions delete inspirational-morning --region=us-central1
  2. Delete the job schedule

    gcloud scheduler jobs delete schedule-job-inspirational-morning --location=us-central1
  3. Delete the topic

    gcloud pubsub topics delete topic-inspirational-morning

Reference guides

About

A serverless function to send a good morning greeting along with an inspirational quote to a Google Chat webhook, every weekday.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages