Skip to main content

Example

Google Chat Trigger Example​

What you'll build​

A minimal Google Chat app that replies to every message with the same text. Google Chat delivers interaction events over HTTP; the chat:Listener verifies the Google-signed bearer token on each request before dispatching to onMessage, which replies via the injected chat:MessageCaller.

Architecture​

Prerequisites​

  • A GCP project with the Google Chat API enabled and a Chat app configured. See the Setup Guide.
  • A public HTTPS URL for local development, for example using ngrok

Setting up the Google Chat integration​

New to WSO2 Integrator? Follow the Create a New Integration guide to set up your integration first, then return here to add the trigger.

Adding the Google Chat trigger​

Add a Google Chat event integration and implement the listener and service as described in the Google Chat event integration guide. WSO2 Integrator renders the listener and service on the design canvas, with all available handlers listed under Event Handlers.

WSO2 Integrator design canvas showing the chatListener connected to ChatService with onMessage and onAddedToSpace handlersWSO2 Integrator design canvas showing the chatListener connected to ChatService with onMessage and onAddedToSpace handlers

Select chat:ChatService in the design canvas to open the Service Designer, which lists every pre-registered event handler bound to the chatListener.

Google Chat Service Designer listing onMessage, onAddedToSpace, onRemovedFromSpace, and onCardClicked handlersGoogle Chat Service Designer listing onMessage, onAddedToSpace, onRemovedFromSpace, and onCardClicked handlers

Handling Google Chat events​

Select the onMessage row to open its flow canvas, then declare a variable for the message text and respond via the injected caller:

remote function onMessage(chat:MessageEvent event, chat:MessageCaller caller) returns error? {
string text = event.message.text ?: "";
log:printInfo("Google Chat message received", text = text);
check caller->respond({text: "Echo: " + text});
}

Running the integration​

Run the integration from WSO2 Integrator, then message your Chat app from Google Chat. Google Chat delivers the event to your listener, which invokes onMessage, logs the message, and replies with the echoed text. Verify both the log entry and the reply in the chat.

What's next​