Send a Google Chat Notification from a GitHub Action

Anuradha Karunarathna
4 min readSep 18, 2021

--

Send your notification as you wish

When you are finding this blog, you might be searching for “how to send a google chat notification from a GitHub action”. You may have already tried out several marketplace actions available for google chat notifications; such as,

but you are not satisfied with them because they don't provide much flexibility to alter your notification as you wish. If that is the case, you have come to the right place.

I’ll solve your problem without any third-party actions but only with curl and JSON.

No one needs notifications without a reason. So I’ll also pick a use case for this blog.

Use Case: An open-source GitHub repository owner needs to receive notifications when issues are created in his repo. He expects to see the issue title, issue link, issue creator, applied labels in that notification.

Let’s do it.

1. Configure WebHook in a Google Chat Room to receive notifications[1]:

Create a Chat Room in your Google account -> Navigate to the chat space menu -> Select “Manage Webhooks”. Give a name to your webhook. Provide an avatar URL if needed(optional) ->Click on Save. Then copy the webhook link.

2. Select the GitHub Repository: https://github.com/AnuradhaSK/greeting-card-manager

3. Configure secrets need for the GitHub action. We maintain the webhook URL (created in step 1)as a repository secret.

i. Navigate to Settings -> Secrets and click on New repository secret .

Add a new repository secret

ii. Add a name to the secret (I have used it as WEBHOOK) and paste the webhook URL in that value section. NOTE: If you need to receive notifications into the same thread of the chat add the query param threadKey=<some-value> at the end of the URL.

Add a repository secret

4. Configure the GitHub Action.

i. Create issue-creation.yml file in <repository>/.github/workflows path. NOTE : .yml extension is mandatory

ii. Add the file content as follows and save.

First, we have defined a name for the action. Then the event trigger has been mentioned as on issue opening [2]. Next, we define the job. This action will be run on ubuntu-latest it has 2 steps.

  • The first step Git Issue Detailsis an optional one for this task. I have added it to print all the required values of the issue. You can find the issue’s properties from [3]
  • Next step Google Chat Notification , is the important one here. It sends a POST request to the configured webhook. The payload is the message content. ${{ secrets.WEBHOOK }} picks the repository secret named as WEBHOOK .
  • The message content can be changed as you wish. Refer simple messages or card formatting messages.

iii. Once the .yml file is saved navigate to the actions section of the repo. You will see the action was created.

Created workflow

5. Create a Git issue in the repo and see the notification.

Submit your issue and check the actions section. You will find a running workflow.

create a git issue
running workflow

Once the workflow is completed successfully you will receive the notification on google chat.

Google chat notification

Try it out 🤗👊

Reference:

[1] https://developers.google.com/chat/how-tos/webhooks

[2] https://docs.github.com/en/actions/reference/events-that-trigger-workflows#issues

[3]https://docs.github.com/en/rest/reference/issues#get-an-issue

--

--

Anuradha Karunarathna

Technical Lead @ WSO2 | Computer Science and Engineering graduate@ University of Moratuwa, SriLanka