Google Chat
Last updated Apr 21, 2026 The Google Chat Pages Plugin creates a Google Chat bot which can respond to messages. It also includes an API for interacting with Google Chat (for example, for creating messages) without the need for user input. This API is useful for situations such as alerts.
Installation
npmyarnpnpmbun
npm i @cloudflare/pages-plugin-google-chat
yarn add @cloudflare/pages-plugin-google-chat
pnpm add @cloudflare/pages-plugin-google-chat
bun add @cloudflare/pages-plugin-google-chat
Usage
import googleChatPlugin from "@cloudflare/pages-plugin-google-chat";
export const onRequest: PagesFunction = googleChatPlugin(async (message) => {
if (message.text.includes("ping")) {
return { text: "pong" };
}
return { text: "Sorry, I could not understand your message." };
});
The Plugin takes a function, which in turn takes an incoming message, and returns a Promise of a response message (or void if there should not be any response).
The Plugin only exposes a single route, which is the URL you should set in the Google Cloud Console when creating the bot.

API
The Google Chat API can be called directly using the GoogleChatAPI class:
import { GoogleChatAPI } from "@cloudflare/pages-plugin-google-chat/api";
export const onRequest: PagesFunction = () => {
// Initialize a GoogleChatAPI with your service account's credentials
const googleChat = new GoogleChatAPI({
credentials: {
client_email: "SERVICE_ACCOUNT_EMAIL_ADDRESS",
private_key: "SERVICE_ACCOUNT_PRIVATE_KEY",
},
});
// Post a message
// https://developers.google.com/chat/api/reference/rest/v1/spaces.messages/create
const message = await googleChat.createMessage(
{ parent: "spaces/AAAAAAAAAAA" },
undefined,
{
text: "I'm an alert!",
},
);
return new Response("Alert sent.");
};
We recommend storing your service account's credentials in KV rather than in plain text as above.
The following functions are available on a GoogleChatAPI instance. Each take up to three arguments: an object of path parameters, an object of query parameters, and an object of the request body; as described in the Google Chat API's documentation ↗︎.
downloadMedia↗︎getSpace↗︎listSpaces↗︎getMember↗︎listMembers↗︎createMessage↗︎deleteMessage↗︎getMessage↗︎updateMessage↗︎getAttachment↗︎
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/pages/functions/plugins/google-chat/#page","headline":"Google Chat","description":"Create a Google Chat bot with the Pages Plugin for responding to messages and sending alerts.","url":"https://developers.cloudflare.com/pages/functions/plugins/google-chat/","inLanguage":"en","image":"https://developers.cloudflare.com/pages/functions/plugins/google-chat/og.png?v=ea9fe16899d68cba","dateModified":"2026-04-21","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Set up a GraphQL server on Cloudflare Pages using the GraphQL Pages Plugin. title: GraphQL image: https://developers.cloudflare.com/pages/functions/plugins/graphql/og.png?v=5c147cfc7e65c57a
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/pages/llms.txt
Use this file to discover all available pages before exploring further.
