Coder Social home page Coder Social logo

google-chat-notification's Introduction

Google-chat-notification

This project provide tools that helps to send message to Google Chat from any pub/sub message. The tools support templating messages base on Handlebars

Create a Google chat webhook

To create a webhook, register it in the Google Chat space you want to receive messages, then write a script that sends messages.

Step 1: Register the incoming webhook

  1. Open Google Chat in a web browser.
  2. Go to the space to which you want to add a webhook.
  3. At the top, next to space title, click arrow_drop_down Down Arrow > The icon for manage webhooks Manage webhooks.
  4. If this space already has other webhooks, click Add another. Otherwise, skip this step.
  5. For Name, enter "Quickstart Webhook".
  6. For Avatar URL, enter https://developers.google.com/chat/images/chat-product-icon.png.
  7. Click SAVE.
  8. Click content_copy Copy to copy the full webhook URL.
  9. Click outside the box to close the Incoming webhooks dialog.

For more details, please refer to this documentation

Deploy a handlebar (HBS) template and upload to a GCS bucket

This function use handlebar templating. Thanks to this you can create powerfull message template depends on the pub/sub message recieved. Google chat support 2 type of message :

You can find 2 sample of Handlebars templating for message here with corresponding event and for cards here with this event.

To render the .hbs template, the library use JsonPath. You receive a JSON message from pubsub, then the function populate the template with the JSON value refered to the JsonPath syntax provided in your hbs file ( with the {{ <"jsonptath query">}} syntax).

Let say your hbs file is "mytemplate.hbs" and the bucket "mybucket-hbs" has been created. Execute :

# if my mybucket-hbs does not exist
# gsutil mb gs://mybucket-hbs/

# Copy template to the target bucket
gsutil cp mytemplate.hbs gs://mybucket-hbs/

Deploy the Cloud Function

For more details about how to deploy a Cloud Function, please refer to this documentation

Clone the github repo

  1. First of all clone the github repo
git clone https://github.com/jbleroy1/google-chat-notifier.git
  1. Create pub/sub topic
gcloud pubsub topics create chat-notification
  1. Deploy Cloud Function
gcloud functions deploy my-pubsub-function \
 --gen2 \
 --region=europe-west2 \
 --runtime=java17 \
 --source=./google-chat-notifier \
 --entry-point=com.google.cloud.PubSubListener \
 --trigger-topic=chat-notification \
 --set-env-vars CHAT_URL="< chat web hook >",TEMPLATE_FILE_BUCKET=< bucket name >,TEMPLATE_FILE_OBJECT=< HBS object name >

Service account

This documentation use the default service account provided by Cloud Function. You can specify your own SA. Be sure this SA have :

  • Read access to the HBS GCS bucket (access to the template)
  • Pub/Sub can send notification to your Cloud Function endpoint

Disclaimer

This is not an officially supported Google product. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.

google-chat-notification's People

Contributors

jbleroy1 avatar

Watchers

 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.