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.
-
Get the desired GChat webhook URL. You can register a webhook by following the Google Chat webhooks documentation.
-
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
-
You may run the application in dev mode,
make dev
Or in a container using
make container-run
-
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 -
To clean up, stop and remove the container and the image.
make container-destroy
-
Build the application. This will create a deployable JAR file in the
target/deploymentdirectory.make build
-
Create up a Pub/Sub topic.
gcloud pubsub topics create topic-inspirational-morning
-
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"
-
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"
-
[OPTIONAL] Trigger the job manually
gcloud scheduler jobs run schedule-job-inspirational-morning --location="us-central1"
-
Delete the function
gcloud functions delete inspirational-morning --region=us-central1
-
Delete the job schedule
gcloud scheduler jobs delete schedule-job-inspirational-morning --location=us-central1 -
Delete the topic
gcloud pubsub topics delete topic-inspirational-morning