Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat: google chat webhook (#1661)
Thibault Le Ouay33697e8b43f5
diff --git a/apps/dashboard/next-env.d.ts b/apps/dashboard/next-env.d.tsindex 9edff1c7c..c4b7818fb 100644--- a/apps/dashboard/next-env.d.ts+++ b/apps/dashboard/next-env.d.ts@@ -1,6 +1,6 @@/// <reference types="next" />/// <reference types="next/image-types/global" />-import "./.next/types/routes.d.ts";+import "./.next/dev/types/routes.d.ts";// NOTE: This file should not be edited// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.diff --git a/apps/dashboard/package.json b/apps/dashboard/package.jsonindex f67415c15..5354ed0eb 100644--- a/apps/dashboard/package.json+++ b/apps/dashboard/package.json@@ -32,6 +32,7 @@"@openstatus/icons": "workspace:*","@openstatus/notification-discord": "workspace:*","@openstatus/notification-emails": "workspace:*",+ "@openstatus/notification-google-chat": "workspace:*","@openstatus/notification-ntfy": "workspace:*","@openstatus/notification-opsgenie": "workspace:*","@openstatus/notification-pagerduty": "workspace:*",diff --git a/apps/dashboard/src/components/forms/notifications/form-google-chat.tsx b/apps/dashboard/src/components/forms/notifications/form-google-chat.tsxnew file mode 100644index 000000000..81a6b6bf5--- /dev/null+++ b/apps/dashboard/src/components/forms/notifications/form-google-chat.tsx@@ -0,0 +1,231 @@+"use client";++import { Checkbox } from "@/components/ui/checkbox";+import {+ FormControl,+ FormDescription,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from "@/components/ui/form";++import {+ FormCardContent,+ FormCardSeparator,+} from "@/components/forms/form-card";+import { useFormSheetDirty } from "@/components/forms/form-sheet";+import { Button } from "@/components/ui/button";+import { Form } from "@/components/ui/form";+import { Input } from "@/components/ui/input";+import { Label } from "@/components/ui/label";++import { useTRPC } from "@/lib/trpc/client";+import { cn } from "@/lib/utils";+import { zodResolver } from "@hookform/resolvers/zod";+import { useMutation } from "@tanstack/react-query";+import { isTRPCClientError } from "@trpc/client";+import React, { useTransition } from "react";+import { useForm } from "react-hook-form";+import { toast } from "sonner";+import { z } from "zod";++const schema = z.object({+ name: z.string(),+ provider: z.literal("google-chat"),+ data: z.string(),+ monitors: z.array(z.number()),+});++type FormValues = z.infer<typeof schema>;++export function FormGoogleChat({+ defaultValues,+ onSubmit,+ className,+ monitors,+ ...props+}: Omit<React.ComponentProps<"form">, "onSubmit"> & {+ defaultValues?: FormValues;+ onSubmit: (values: FormValues) => Promise<void>;+ monitors: { id: number; name: string }[];+}) {+ const form = useForm<FormValues>({+ resolver: zodResolver(schema),+ defaultValues: defaultValues ?? {+ name: "",+ provider: "google-chat",+ data: "",+ monitors: [],+ },+ });+ const [isPending, startTransition] = useTransition();+ const { setIsDirty } = useFormSheetDirty();+ const trpc = useTRPC();++ const sendTestMutation = useMutation(+ trpc.notification.sendTest.mutationOptions(),+ );++ const formIsDirty = form.formState.isDirty;+ React.useEffect(() => {+ setIsDirty(formIsDirty);+ }, [formIsDirty, setIsDirty]);++ function submitAction(values: FormValues) {+ if (isPending) return;++ startTransition(async () => {+ try {+ const promise = onSubmit(values);+ toast.promise(promise, {+ loading: "Saving...",+ success: "Saved",+ error: (error) => {+ if (isTRPCClientError(error)) {+ return error.message;+ }+ return "Failed to save";+ },+ });+ await promise;+ } catch (error) {+ console.error(error);+ }+ });+ }++ function testAction() {+ if (isPending) return;++ startTransition(async () => {+ try {+ const provider = form.getValues("provider");+ const data = form.getValues("data");+ const promise = sendTestMutation.mutateAsync({+ provider,+ data: {+ "google-chat": data,+ },+ });+ toast.promise(promise, {+ loading: "Sending test...",+ success: "Test sent",+ error: (error) => {+ if (error instanceof Error) {+ return error.message;+ }+ return "Failed to send test";+ },+ });+ await promise;+ } catch (error) {+ console.error(error);+ }+ });+ }++ return (+ <Form {...form}>+ <form+ className={cn("grid gap-4", className)}+ onSubmit={form.handleSubmit(submitAction)}+ {...props}+ >+ <FormCardContent className="grid gap-4">+ <FormField+ control={form.control}+ name="name"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Name</FormLabel>+ <FormControl>+ <Input placeholder="My Notifier" {...field} />+ </FormControl>+ <FormMessage />+ <FormDescription>+ Enter a descriptive name for your notifier.+ </FormDescription>+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="data"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Google Chat Webhook</FormLabel>+ <FormControl>+ <Input placeholder="https://..." {...field} />+ </FormControl>+ <FormMessage />+ <FormDescription>+ Enter the phone number to send notifications to.+ </FormDescription>+ </FormItem>+ )}+ />+ <div>+ <Button+ variant="outline"+ size="sm"+ type="button"+ onClick={testAction}+ >+ Send Test+ </Button>+ </div>+ </FormCardContent>+ <FormCardSeparator />+ <FormCardContent>+ <FormField+ control={form.control}+ name="monitors"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Monitors</FormLabel>+ <FormDescription>+ Select the monitors you want to notify.+ </FormDescription>+ <div className="grid gap-3">+ <div className="flex items-center gap-2">+ <FormControl>+ <Checkbox+ id="all"+ checked={field.value?.length === monitors.length}+ onCheckedChange={(checked) => {+ field.onChange(+ checked ? monitors.map((m) => m.id) : [],+ );+ }}+ />+ </FormControl>+ <Label htmlFor="all">Select all</Label>+ </div>+ {monitors.map((item) => (+ <div key={item.id} className="flex items-center gap-2">+ <FormControl>+ <Checkbox+ id={String(item.id)}+ checked={field.value?.includes(item.id)}+ onCheckedChange={(checked) => {+ const newValue = checked+ ? [...(field.value || []), item.id]+ : field.value?.filter((id) => id !== item.id);+ field.onChange(newValue);+ }}+ />+ </FormControl>+ <Label htmlFor={String(item.id)}>{item.name}</Label>+ </div>+ ))}+ </div>+ <FormMessage />+ </FormItem>+ )}+ />+ </FormCardContent>+ </form>+ </Form>+ );+}diff --git a/apps/dashboard/src/components/forms/notifications/form.tsx b/apps/dashboard/src/components/forms/notifications/form.tsxindex 5a4e0b92b..094e7266a 100644--- a/apps/dashboard/src/components/forms/notifications/form.tsx+++ b/apps/dashboard/src/components/forms/notifications/form.tsx@@ -33,6 +33,7 @@ const schema = z.object({"ntfy","telegram","whatsapp",+ "google-chat",]),data: z.record(z.string(), z.string()).or(z.string()),monitors: z.array(z.number()),diff --git a/apps/dashboard/src/data/notifications.client.ts b/apps/dashboard/src/data/notifications.client.tsindex aa8d3b231..30943b9bb 100644--- a/apps/dashboard/src/data/notifications.client.ts+++ b/apps/dashboard/src/data/notifications.client.ts@@ -1,5 +1,6 @@import { FormDiscord } from "@/components/forms/notifications/form-discord";import { FormEmail } from "@/components/forms/notifications/form-email";+import { FormGoogleChat } from "@/components/forms/notifications/form-google-chat";import { FormNtfy } from "@/components/forms/notifications/form-ntfy";import { FormOpsGenie } from "@/components/forms/notifications/form-opsgenie";import { FormPagerDuty } from "@/components/forms/notifications/form-pagerduty";@@ -8,7 +9,12 @@ import { FormSms } from "@/components/forms/notifications/form-sms";import { FormTelegram } from "@/components/forms/notifications/form-telegram";import { FormWebhook } from "@/components/forms/notifications/form-webhook";import { FormWhatsApp } from "@/components/forms/notifications/form-whatsapp";-import { DiscordIcon, TelegramIcon, WhatsappIcon } from "@openstatus/icons";+import {+ DiscordIcon,+ GoogleIcon,+ TelegramIcon,+ WhatsappIcon,+} from "@openstatus/icons";import { OpsGenieIcon } from "@openstatus/icons";import { PagerDutyIcon } from "@openstatus/icons";import { SlackIcon } from "@openstatus/icons";@@ -96,6 +102,12 @@ export const config = {form: FormOpsGenie,sendTest: sendTestOpsGenie,},+ "google-chat": {+ icon: GoogleIcon,+ label: "Google Chat",+ form: FormGoogleChat,+ sendTest: sendTestWebhook,+ },pagerduty: {icon: PagerDutyIcon,label: "PagerDuty",diff --git a/apps/docs/src/content/docs/reference/notification.mdx b/apps/docs/src/content/docs/reference/notification.mdxindex 406932474..06d588c75 100644--- a/apps/docs/src/content/docs/reference/notification.mdx+++ b/apps/docs/src/content/docs/reference/notification.mdx@@ -20,6 +20,9 @@ Require an email addressRequire a [discord webhook](https://support.discord.com/hc/en-us/articles/228383668) e.g. `https://discordapp.com/api/webhooks/123456789012345678/abcdefghijklmnopqrstuvwxyz1234567890`+### Google Chat++Require a [Google Chat webhook](https://developers.google.com/workspace/chat/quickstart/webhooks)### SMSRequire a phone number (international format e.g. +14155552671)diff --git a/apps/web/public/assets/changelog/google-chat.png b/apps/web/public/assets/changelog/google-chat.pngnew file mode 100644index 000000000..235318e06Binary files /dev/null and b/apps/web/public/assets/changelog/google-chat.png differdiff --git a/apps/web/src/content/pages/changelog/google-chat-notifications.mdx b/apps/web/src/content/pages/changelog/google-chat-notifications.mdxnew file mode 100644index 000000000..6a59929df--- /dev/null+++ b/apps/web/src/content/pages/changelog/google-chat-notifications.mdx@@ -0,0 +1,10 @@+---+title: "Google Chat Notifications"+description: ""+image: "/assets/changelog/google-chat.png"+publishedAt: "2025-12-16"+author: "openstatus"+category: "notifications"+---++You can now receive your uptime notifications via Google Chat.diff --git a/apps/workflows/.dockerignore b/apps/workflows/.dockerignoreindex 5dad7bbcf..5e73b32b9 100644--- a/apps/workflows/.dockerignore+++ b/apps/workflows/.dockerignore@@ -1,4 +1,4 @@-# This file is generated by Dofigen v2.5.1+# This file is generated by Dofigen v2.6.0# See https://github.com/lenra-io/dofigennode_modulesdiff --git a/apps/workflows/Dockerfile b/apps/workflows/Dockerfileindex fdfd756a4..56c58a333 100644--- a/apps/workflows/Dockerfile+++ b/apps/workflows/Dockerfile@@ -1,11 +1,11 @@-# syntax=docker/dockerfile:1.11-# This file is generated by Dofigen v2.5.1+# syntax=docker/dockerfile:1.19.0+# This file is generated by Dofigen v2.6.0# See https://github.com/lenra-io/dofigen# ca-certs-FROM debian@sha256:530a3348fc4b5734ffe1a137ddbcee6850154285251b53c3425c386ea8fac77b AS ca-certs+FROM debian@sha256:5fc1d68d490d6e22a8b182f67d2b9ed800e6dd49e997dd595a46977fe7cece46 AS ca-certsLABEL \- org.opencontainers.image.base.digest="sha256:530a3348fc4b5734ffe1a137ddbcee6850154285251b53c3425c386ea8fac77b" \+ org.opencontainers.image.base.digest="sha256:5fc1d68d490d6e22a8b182f67d2b9ed800e6dd49e997dd595a46977fe7cece46" \org.opencontainers.image.base.name="docker.io/debian:bullseye-slim"RUN apt update && apt install -y ca-certificates && update-ca-certificates@@ -36,6 +36,7 @@ RUN \--mount=type=bind,target=packages/emails/package.json,source=packages/emails/package.json \--mount=type=bind,target=packages/notifications/discord/package.json,source=packages/notifications/discord/package.json \--mount=type=bind,target=packages/notifications/email/package.json,source=packages/notifications/email/package.json \+ --mount=type=bind,target=packages/notifications/google-chat/package.json,source=packages/notifications/google-chat/package.json \--mount=type=bind,target=packages/notifications/ntfy/package.json,source=packages/notifications/ntfy/package.json \--mount=type=bind,target=packages/notifications/opsgenie/package.json,source=packages/notifications/opsgenie/package.json \--mount=type=bind,target=packages/notifications/pagerduty/package.json,source=packages/notifications/pagerduty/package.json \@@ -83,11 +84,11 @@ COPY \RUN bun install# runtime-FROM debian@sha256:530a3348fc4b5734ffe1a137ddbcee6850154285251b53c3425c386ea8fac77b AS runtime+FROM debian@sha256:5fc1d68d490d6e22a8b182f67d2b9ed800e6dd49e997dd595a46977fe7cece46 AS runtimeLABEL \- io.dofigen.version="2.5.1" \+ io.dofigen.version="2.6.0" \org.opencontainers.image.authors="OpenStatus Team" \- org.opencontainers.image.base.digest="sha256:530a3348fc4b5734ffe1a137ddbcee6850154285251b53c3425c386ea8fac77b" \+ org.opencontainers.image.base.digest="sha256:5fc1d68d490d6e22a8b182f67d2b9ed800e6dd49e997dd595a46977fe7cece46" \org.opencontainers.image.base.name="docker.io/debian:bullseye-slim" \org.opencontainers.image.description="Background job processing and probe scheduling for OpenStatus" \org.opencontainers.image.source="https://github.com/openstatusHQ/openstatus" \diff --git a/apps/workflows/dofigen.lock b/apps/workflows/dofigen.lockindex 2d31e6f61..c82ca5221 100644--- a/apps/workflows/dofigen.lock+++ b/apps/workflows/dofigen.lock@@ -12,27 +12,29 @@ effective: |- /packages/error- /packages/trackerbuilders:- build:+ docker:fromImage:path: oven/bundigest: sha256:fbf8e67e9d3b806c86be7a2f2e9bae801f2d9212a21db4dcf8cc9889f5a3c9c4label:org.opencontainers.image.base.name: docker.io/oven/bun:1.3.3org.opencontainers.image.base.digest: sha256:fbf8e67e9d3b806c86be7a2f2e9bae801f2d9212a21db4dcf8cc9889f5a3c9c4- org.opencontainers.image.stage: buildworkdir: /app/apps/workflows- env:- NODE_ENV: productioncopy:- paths:- .target: /app/- - fromBuilder: install- paths:- - /app/node_modules- target: /app/node_modulesrun:- - bun build --compile --target bun --sourcemap --format=cjs src/index.ts --outfile=app --external '@libsql/*' --external libsql+ - bun run src/build-docker.ts+ ca-certs:+ fromImage:+ path: debian+ digest: sha256:5fc1d68d490d6e22a8b182f67d2b9ed800e6dd49e997dd595a46977fe7cece46+ label:+ org.opencontainers.image.base.name: docker.io/debian:bullseye-slim+ org.opencontainers.image.base.digest: sha256:5fc1d68d490d6e22a8b182f67d2b9ed800e6dd49e997dd595a46977fe7cece46+ run:+ - apt update && apt install -y ca-certificates && update-ca-certificateslibsql:fromImage:path: oven/bun@@ -48,14 +50,35 @@ effective: |target: /app/package.jsonrun:- bun install+ build:+ fromImage:+ path: oven/bun+ digest: sha256:fbf8e67e9d3b806c86be7a2f2e9bae801f2d9212a21db4dcf8cc9889f5a3c9c4+ label:+ org.opencontainers.image.base.name: docker.io/oven/bun:1.3.3+ org.opencontainers.image.base.digest: sha256:fbf8e67e9d3b806c86be7a2f2e9bae801f2d9212a21db4dcf8cc9889f5a3c9c4+ org.opencontainers.image.stage: build+ workdir: /app/apps/workflows+ env:+ NODE_ENV: production+ copy:+ - paths:+ - .+ target: /app/+ - fromBuilder: install+ paths:+ - /app/node_modules+ target: /app/node_modules+ run:+ - bun build --compile --target bun --sourcemap --format=cjs src/index.ts --outfile=app --external '@libsql/*' --external libsqlinstall:fromImage:path: oven/bundigest: sha256:fbf8e67e9d3b806c86be7a2f2e9bae801f2d9212a21db4dcf8cc9889f5a3c9c4label:+ org.opencontainers.image.base.name: docker.io/oven/bun:1.3.3org.opencontainers.image.base.digest: sha256:fbf8e67e9d3b806c86be7a2f2e9bae801f2d9212a21db4dcf8cc9889f5a3c9c4org.opencontainers.image.stage: install- org.opencontainers.image.base.name: docker.io/oven/bun:1.3.3workdir: /app/run:- bun install --production --frozen-lockfile --verbose@@ -78,6 +101,8 @@ effective: |source: packages/notifications/discord/package.json- target: packages/notifications/email/package.jsonsource: packages/notifications/email/package.json+ - target: packages/notifications/google-chat/package.json+ source: packages/notifications/google-chat/package.json- target: packages/notifications/ntfy/package.jsonsource: packages/notifications/ntfy/package.json- target: packages/notifications/opsgenie/package.json@@ -106,41 +131,18 @@ effective: |source: packages/upstash/package.json- target: packages/theme-store/package.jsonsource: packages/theme-store/package.json- ca-certs:- fromImage:- path: debian- digest: sha256:530a3348fc4b5734ffe1a137ddbcee6850154285251b53c3425c386ea8fac77b- label:- org.opencontainers.image.base.name: docker.io/debian:bullseye-slim- org.opencontainers.image.base.digest: sha256:530a3348fc4b5734ffe1a137ddbcee6850154285251b53c3425c386ea8fac77b- run:- - apt update && apt install -y ca-certificates && update-ca-certificates- docker:- fromImage:- path: oven/bun- digest: sha256:fbf8e67e9d3b806c86be7a2f2e9bae801f2d9212a21db4dcf8cc9889f5a3c9c4- label:- org.opencontainers.image.base.digest: sha256:fbf8e67e9d3b806c86be7a2f2e9bae801f2d9212a21db4dcf8cc9889f5a3c9c4- org.opencontainers.image.base.name: docker.io/oven/bun:1.3.3- workdir: /app/apps/workflows- copy:- - paths:- - .- target: /app/- run:- - bun run src/build-docker.tsfromImage:path: debian- digest: sha256:530a3348fc4b5734ffe1a137ddbcee6850154285251b53c3425c386ea8fac77b+ digest: sha256:5fc1d68d490d6e22a8b182f67d2b9ed800e6dd49e997dd595a46977fe7cece46label:org.opencontainers.image.authors: OpenStatus Team- org.opencontainers.image.source: https://github.com/openstatusHQ/openstatusorg.opencontainers.image.base.name: docker.io/debian:bullseye-slim- org.opencontainers.image.base.digest: sha256:530a3348fc4b5734ffe1a137ddbcee6850154285251b53c3425c386ea8fac77b- org.opencontainers.image.description: Background job processing and probe scheduling for OpenStatusorg.opencontainers.image.vendor: OpenStatus+ io.dofigen.version: 2.6.0+ org.opencontainers.image.description: Background job processing and probe scheduling for OpenStatus+ org.opencontainers.image.base.digest: sha256:5fc1d68d490d6e22a8b182f67d2b9ed800e6dd49e997dd595a46977fe7cece46+ org.opencontainers.image.source: https://github.com/openstatusHQ/openstatusorg.opencontainers.image.title: OpenStatus Workflows- io.dofigen.version: 2.5.1workdir: /app/copy:- fromBuilder: build@@ -166,17 +168,17 @@ effective: |- port: 3000images:docker.io:+ library:+ debian:+ bullseye-slim:+ digest: sha256:5fc1d68d490d6e22a8b182f67d2b9ed800e6dd49e997dd595a46977fe7cece46oven:bun:1.3.3:digest: sha256:fbf8e67e9d3b806c86be7a2f2e9bae801f2d9212a21db4dcf8cc9889f5a3c9c4- library:- debian:- bullseye-slim:- digest: sha256:530a3348fc4b5734ffe1a137ddbcee6850154285251b53c3425c386ea8fac77bresources:dofigen.yml:- hash: 7e59e1efd94f649c01720f89c8966945798a8a0c4572e2fb783d6e406e5384c4+ hash: a1eb7b5ea5ae9202fedceba5f4e792dac4955311d07045e2338d3bec811c7cdfcontent: |ignore:- node_modules@@ -205,6 +207,7 @@ resources:- packages/emails/package.json- packages/notifications/discord/package.json- packages/notifications/email/package.json+ - packages/notifications/google-chat/package.json- packages/notifications/ntfy/package.json- packages/notifications/opsgenie/package.json- packages/notifications/pagerduty/package.jsondiff --git a/apps/workflows/dofigen.yml b/apps/workflows/dofigen.ymlindex 625c24a7e..b1f194db5 100644--- a/apps/workflows/dofigen.yml+++ b/apps/workflows/dofigen.yml@@ -25,6 +25,7 @@ builders:- packages/emails/package.json- packages/notifications/discord/package.json- packages/notifications/email/package.json+ - packages/notifications/google-chat/package.json- packages/notifications/ntfy/package.json- packages/notifications/opsgenie/package.json- packages/notifications/pagerduty/package.jsondiff --git a/apps/workflows/package.json b/apps/workflows/package.jsonindex 25cbc8b8a..53f5e4d7d 100644--- a/apps/workflows/package.json+++ b/apps/workflows/package.json@@ -15,6 +15,7 @@"@openstatus/emails": "workspace:*","@openstatus/notification-discord": "workspace:*","@openstatus/notification-emails": "workspace:*",+ "@openstatus/notification-google-chat": "workspace:*","@openstatus/notification-ntfy": "workspace:*","@openstatus/notification-opsgenie": "workspace:*","@openstatus/notification-pagerduty": "workspace:*",diff --git a/apps/workflows/src/checker/utils.ts b/apps/workflows/src/checker/utils.tsindex d905920bd..a1245d180 100644--- a/apps/workflows/src/checker/utils.ts+++ b/apps/workflows/src/checker/utils.ts@@ -14,6 +14,11 @@ import {sendDegraded as sendEmailDegraded,sendRecovery as sendEmailRecovery,} from "@openstatus/notification-emails";+import {+ sendAlert as sendGoogleChatAlert,+ sendDegraded as sendGoogleChatDegraded,+ sendRecovery as sendGoogleChatRecovery,+} from "@openstatus/notification-google-chat";import {sendAlert as sendNtfyAlert,sendDegraded as sendNtfyDegraded,@@ -92,6 +97,11 @@ export const providerToFunction = {sendRecovery: sendEmailRecovery,sendDegraded: sendEmailDegraded,},+ "google-chat": {+ sendAlert: sendGoogleChatAlert,+ sendRecovery: sendGoogleChatRecovery,+ sendDegraded: sendGoogleChatDegraded,+ },ntfy: {sendAlert: sendNtfyAlert,sendRecovery: sendNtfyRecovery,diff --git a/packages/api/package.json b/packages/api/package.jsonindex 0aebea5e3..00428f369 100644--- a/packages/api/package.json+++ b/packages/api/package.json@@ -13,6 +13,7 @@"@openstatus/db": "workspace:*","@openstatus/emails": "workspace:*","@openstatus/error": "workspace:*",+ "@openstatus/notification-google-chat": "workspace:*","@openstatus/notification-telegram": "workspace:*","@openstatus/notification-twillio-whatsapp": "workspace:*","@openstatus/regions": "workspace:*",diff --git a/packages/api/src/router/notification.ts b/packages/api/src/router/notification.tsindex 198a4a4ff..010ed1f8f 100644--- a/packages/api/src/router/notification.ts+++ b/packages/api/src/router/notification.ts@@ -4,6 +4,7 @@ import { z } from "zod";import { type SQL, and, count, db, eq, inArray } from "@openstatus/db";import {NotificationDataSchema,+ googleChatDataSchema,insertNotificationSchema,monitor,notification,@@ -17,8 +18,10 @@ import {import { Events } from "@openstatus/analytics";import { SchemaError } from "@openstatus/error";+import { sendTest as sendGoogleChatTest } from "@openstatus/notification-google-chat";import { sendTest as sendTelegramTest } from "@openstatus/notification-telegram";import { sendTest as sendWhatsAppTest } from "@openstatus/notification-twillio-whatsapp";+import { createTRPCRouter, protectedProcedure } from "../trpc";export const notificationRouter = createTRPCRouter({@@ -490,6 +493,19 @@ export const notificationRouter = createTRPCRouter({return;}+ if (opts.input.provider === "google-chat") {+ const _data = googleChatDataSchema.safeParse(opts.input.data);+ console.log(opts.input.data);+ console.log(_data);+ if (!_data.success) {+ throw new TRPCError({+ code: "BAD_REQUEST",+ message: SchemaError.fromZod(_data.error, opts.input).message,+ });+ }+ await sendGoogleChatTest(_data.data["google-chat"]);+ return;+ }throw new TRPCError({code: "BAD_REQUEST",diff --git a/packages/db/src/schema/notifications/constants.ts b/packages/db/src/schema/notifications/constants.tsindex fbc194e1d..cab6a568f 100644--- a/packages/db/src/schema/notifications/constants.ts+++ b/packages/db/src/schema/notifications/constants.ts@@ -1,6 +1,7 @@export const notificationProvider = ["discord","email",+ "google-chat","ntfy","pagerduty","opsgenie",diff --git a/packages/db/src/schema/notifications/validation.ts b/packages/db/src/schema/notifications/validation.tsindex 861cd95cf..773c38a61 100644--- a/packages/db/src/schema/notifications/validation.ts+++ b/packages/db/src/schema/notifications/validation.ts@@ -55,6 +55,7 @@ export const emailDataSchema = z.object({ email: emailSchema });export const phoneDataSchema = z.object({ sms: phoneSchema });export const slackDataSchema = z.object({ slack: urlSchema });export const discordDataSchema = z.object({ discord: urlSchema });+export const googleChatDataSchema = z.object({ "google-chat": urlSchema });export const pagerdutyDataSchema = z.object({ pagerduty: z.string() });export const opsgenieDataSchema = z.object({opsgenie: z.object({@@ -98,6 +99,12 @@ export const InsertNotificationWithDataSchema = z.discriminatedUnion(data: emailDataSchema,}),),+ insertNotificationSchema.merge(+ z.object({+ provider: z.literal("google-chat"),+ data: googleChatDataSchema,+ }),+ ),insertNotificationSchema.merge(z.object({provider: z.literal("ntfy"),diff --git a/packages/notifications/google-chat/.gitignore b/packages/notifications/google-chat/.gitignorenew file mode 100644index 000000000..f81d56eaa--- /dev/null+++ b/packages/notifications/google-chat/.gitignore@@ -0,0 +1,169 @@+# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore++# Logs++logs+_.log+npm-debug.log_+yarn-debug.log*+yarn-error.log*+lerna-debug.log*+.pnpm-debug.log*++# Diagnostic reports (https://nodejs.org/api/report.html)++report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json++# Runtime data++pids+_.pid+_.seed+\*.pid.lock++# Directory for instrumented libs generated by jscoverage/JSCover++lib-cov++# Coverage directory used by tools like istanbul++coverage+\*.lcov++# nyc test coverage++.nyc_output++# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)++.grunt++# Bower dependency directory (https://bower.io/)++bower_components++# node-waf configuration++.lock-wscript++# Compiled binary addons (https://nodejs.org/api/addons.html)++build/Release++# Dependency directories++node_modules/+jspm_packages/++# Snowpack dependency directory (https://snowpack.dev/)++web_modules/++# TypeScript cache++\*.tsbuildinfo++# Optional npm cache directory++.npm++# Optional eslint cache++.eslintcache++# Optional stylelint cache++.stylelintcache++# Microbundle cache++.rpt2_cache/+.rts2_cache_cjs/+.rts2_cache_es/+.rts2_cache_umd/++# Optional REPL history++.node_repl_history++# Output of 'npm pack'++\*.tgz++# Yarn Integrity file++.yarn-integrity++# dotenv environment variable files++.env+.env.development.local+.env.test.local+.env.production.local+.env.local++# parcel-bundler cache (https://parceljs.org/)++.cache+.parcel-cache++# Next.js build output++.next+out++# Nuxt.js build / generate output++.nuxt+dist++# Gatsby files++.cache/++# Comment in the public line in if your project uses Gatsby and not Next.js++# https://nextjs.org/blog/next-9-1#public-directory-support++# public++# vuepress build output++.vuepress/dist++# vuepress v2.x temp and cache directory++.temp+.cache++# Docusaurus cache and generated files++.docusaurus++# Serverless directories++.serverless/++# FuseBox cache++.fusebox/++# DynamoDB Local files++.dynamodb/++# TernJS port file++.tern-port++# Stores VSCode versions used for testing VSCode extensions++.vscode-test++# yarn v2++.yarn/cache+.yarn/unplugged+.yarn/build-state.yml+.yarn/install-state.gz+.pnp.\*diff --git a/packages/notifications/google-chat/README.md b/packages/notifications/google-chat/README.mdnew file mode 100644index 000000000..2df8a1d56--- /dev/null+++ b/packages/notifications/google-chat/README.md@@ -0,0 +1,16 @@+# @openstatus/notifications-discord++To install dependencies:++```bash+bun install+```++To run:++```bash+bun run src/index.ts+```++This project was created using `bun init` in bun v1.0.0. [Bun](https://bun.sh)+is a fast all-in-one JavaScript runtime.diff --git a/packages/notifications/google-chat/package.json b/packages/notifications/google-chat/package.jsonnew file mode 100644index 000000000..97f4edcce--- /dev/null+++ b/packages/notifications/google-chat/package.json@@ -0,0 +1,18 @@+{+ "name": "@openstatus/notification-google-chat",+ "version": "1.0.0",+ "main": "src/index.ts",+ "scripts": {+ "test": "bun test"+ },+ "dependencies": {+ "@openstatus/db": "workspace:*",+ "zod": "3.25.76"+ },+ "devDependencies": {+ "@openstatus/tsconfig": "workspace:*",+ "@types/node": "24.0.8",+ "bun-types": "1.3.1",+ "typescript": "5.9.3"+ }+}diff --git a/packages/notifications/google-chat/src/index.test.ts b/packages/notifications/google-chat/src/index.test.tsnew file mode 100644index 000000000..7f9b847a9--- /dev/null+++ b/packages/notifications/google-chat/src/index.test.ts@@ -0,0 +1,159 @@+import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";+import { selectNotificationSchema } from "@openstatus/db/src/schema";+import { sendAlert, sendDegraded, sendRecovery, sendTest } from "./index";++describe("Google Chat Notifications", () => {+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>+ let fetchMock: any = undefined;++ beforeEach(() => {+ // @ts-expect-error+ fetchMock = spyOn(global, "fetch").mockImplementation(() =>+ Promise.resolve(new Response(null, { status: 200 })),+ );+ });++ afterEach(() => {+ if (fetchMock) {+ fetchMock.mockRestore();+ }+ });++ const createMockMonitor = () => ({+ id: "monitor-1",+ name: "API Health Check",+ url: "https://api.example.com/health",+ jobType: "http" as const,+ periodicity: "5m" as const,+ status: "active" as const,+ createdAt: new Date(),+ updatedAt: new Date(),+ region: "iad",+ });++ const createMockNotification = () => ({+ id: 1,+ name: "Google Chat Notification",+ provider: "google-chat",+ workspaceId: 1,+ createdAt: new Date(),+ updatedAt: new Date(),+ data: '{"google-chat":"https://google.com/api/webhooks/123456789/abcdefgh"}',+ });++ test("Send Alert", async () => {+ const monitor = createMockMonitor();+ const notification = selectNotificationSchema.parse(+ createMockNotification(),+ );++ await sendAlert({+ // @ts-expect-error+ monitor,+ notification,+ statusCode: 500,+ message: "Something went wrong",+ cronTimestamp: Date.now(),+ });++ expect(fetchMock).toHaveBeenCalledTimes(1);+ const callArgs = fetchMock.mock.calls[0];+ expect(callArgs[0]).toBe(+ "https://google.com/api/webhooks/123456789/abcdefgh",+ );+ expect(callArgs[1].method).toBe("POST");+ expect(callArgs[1].headers["Content-Type"]).toBe("application/json");++ const body = JSON.parse(callArgs[1].body);+ console.log(body);+ expect(body.text).toContain("🚨 Alert");+ expect(body.text).toContain("API Health Check");+ expect(body.text).toContain("Something went wrong");+ });++ test("Send Recovery", async () => {+ const monitor = createMockMonitor();+ const notification = selectNotificationSchema.parse(+ createMockNotification(),+ );++ await sendRecovery({+ // @ts-expect-error+ monitor,+ notification,+ statusCode: 200,+ message: "Service recovered",+ cronTimestamp: Date.now(),+ });++ expect(fetchMock).toHaveBeenCalledTimes(1);+ const callArgs = fetchMock.mock.calls[0];+ const body = JSON.parse(callArgs[1].body);+ expect(body.text).toContain("✅ Recovered");+ expect(body.text).toContain("API Health Check");+ });++ test("Send Degraded", async () => {+ const monitor = createMockMonitor();+ const notification = selectNotificationSchema.parse(+ createMockNotification(),+ );++ await sendDegraded({+ // @ts-expect-error+ monitor,+ notification,+ statusCode: 503,+ message: "Service degraded",+ cronTimestamp: Date.now(),+ });++ expect(fetchMock).toHaveBeenCalledTimes(1);+ const callArgs = fetchMock.mock.calls[0];+ const body = JSON.parse(callArgs[1].body);+ expect(body.text).toContain("⚠️ Degraded");+ expect(body.text).toContain("API Health Check");+ });++ test("Send Test Google Chat Message", async () => {+ const webhookUrl = "https://google.com/api/webhooks/123456789/abcdefgh";++ const result = await sendTest(webhookUrl);++ expect(result).toBe(true);+ expect(fetchMock).toHaveBeenCalledTimes(1);+ const callArgs = fetchMock.mock.calls[0];+ expect(callArgs[0]).toBe(webhookUrl);+ const body = JSON.parse(callArgs[1].body);+ expect(body.text).toContain("🧪 Test");+ expect(body.text).toContain("OpenStatus");+ });++ test("Send Test Google Chat Message with empty webhookUrl", async () => {+ const result = await sendTest("");++ expect(result).toBe(false);+ expect(fetchMock).not.toHaveBeenCalled();+ });++ test("Handle fetch error gracefully", async () => {+ fetchMock.mockImplementation(() =>+ Promise.reject(new Error("Network error")),+ );++ const monitor = createMockMonitor();+ const notification = selectNotificationSchema.parse(+ createMockNotification(),+ );+ expect(+ sendAlert({+ // @ts-expect-error+ monitor,+ notification,+ statusCode: 500,+ message: "Error",+ cronTimestamp: Date.now(),+ }),+ ).rejects.toThrow();+ });+});diff --git a/packages/notifications/google-chat/src/index.ts b/packages/notifications/google-chat/src/index.tsnew file mode 100644index 000000000..f3acf0fed--- /dev/null+++ b/packages/notifications/google-chat/src/index.ts@@ -0,0 +1,148 @@+import type { Monitor, Notification } from "@openstatus/db/src/schema";+import { googleChatDataSchema } from "@openstatus/db/src/schema";+import type { Region } from "@openstatus/db/src/schema/constants";++const postToWebhook = async (content: string, webhookUrl: string) => {+ const res = await fetch(webhookUrl, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ text: content,+ }),+ });+ if (!res.ok) {+ throw new Error(+ `Failed to send Google Chat webhook: ${res.status} ${res.statusText}`,+ );+ }+};++export const sendAlert = async ({+ monitor,+ notification,+ statusCode,+ message,+ cronTimestamp,+}: {+ monitor: Monitor;+ notification: Notification;+ statusCode?: number;+ message?: string;+ incidentId?: string;+ cronTimestamp: number;+ latency?: number;+ region?: Region;+}) => {+ const notificationData = googleChatDataSchema.parse(+ JSON.parse(notification.data),+ );+ const { "google-chat": webhookUrl } = notificationData; // webhook url+ const { name } = monitor;++ try {+ await postToWebhook(+ `*🚨 Alert <${monitor.url}|${name}>*\nStatus Code: ${+ statusCode || "_empty_"+ }\nMessage: ${+ message || "_empty_"+ }\nCron Timestamp: ${cronTimestamp} (${new Date(+ cronTimestamp,+ ).toISOString()})\n> Check your <https://www.openstatus.dev/app/|Dashboard>.\n`,+ webhookUrl,+ );+ } catch (err) {+ console.error(err);+ throw err;+ }+};++export const sendRecovery = async ({+ monitor,+ notification,+ // biome-ignore lint/correctness/noUnusedVariables: <explanation>+ statusCode,+ // biome-ignore lint/correctness/noUnusedVariables: <explanation>+ message,+ // biome-ignore lint/correctness/noUnusedVariables: <explanation>+ incidentId,+}: {+ monitor: Monitor;+ notification: Notification;+ statusCode?: number;+ message?: string;+ incidentId?: string;+ cronTimestamp: number;+ latency?: number;+ region?: Region;+}) => {+ const notificationData = googleChatDataSchema.parse(+ JSON.parse(notification.data),+ );+ const { "google-chat": webhookUrl } = notificationData; // webhook url+ const { name } = monitor;++ try {+ await postToWebhook(+ `*✅ Recovered <${monitor.url}|${name}>**\n> Check your <https://www.openstatus.dev/app/|Dashboard>.\n`,+ webhookUrl,+ );+ } catch (err) {+ console.error(err);+ throw err;+ }+};++export const sendDegraded = async ({+ monitor,+ notification,+ // biome-ignore lint/correctness/noUnusedVariables: <explanation>+ statusCode,+ // biome-ignore lint/correctness/noUnusedVariables: <explanation>+ message,+ // biome-ignore lint/correctness/noUnusedVariables: <explanation>+ incidentId,+}: {+ monitor: Monitor;+ notification: Notification;+ statusCode?: number;+ message?: string;+ incidentId?: string;+ cronTimestamp: number;+ latency?: number;+ region?: Region;+}) => {+ const notificationData = googleChatDataSchema.parse(+ JSON.parse(notification.data),+ );+ const { "google-chat": webhookUrl } = notificationData; // webhook url+ const { name } = monitor;++ try {+ await postToWebhook(+ `*⚠️ Degraded <${monitor.url}|${name}>*\n> Check your <https://www.openstatus.dev/app/|Dashboard>.\n`,+ webhookUrl,+ );+ } catch (err) {+ console.error(err);+ throw err;+ }+};++export const sendTest = async (webhookUrl: string) => {+ if (!webhookUrl) {+ return false;+ }+ console.log(webhookUrl);+ try {+ await postToWebhook(+ "*🧪 Test <https://www.openstatus.dev/|OpenStatus>*\nIf you can read this, your Google Chat webhook is functioning correctly!\n> Check your <https://www.openstatus.dev/app/|Dashboard>.\n",+ webhookUrl,+ );+ return true;+ } catch (_err) {+ console.log(_err);+ return false;+ }+};diff --git a/packages/notifications/google-chat/src/mock.ts b/packages/notifications/google-chat/src/mock.tsnew file mode 100644index 000000000..1134b2449--- /dev/null+++ b/packages/notifications/google-chat/src/mock.ts@@ -0,0 +1,64 @@+import type { Monitor, Notification } from "@openstatus/db/src/schema";+import { sendAlert, sendDegraded, sendRecovery, sendTest } from "./index";++const monitor: Monitor = {+ id: 1,+ name: "OpenStatus Docs",+ url: "https://docs.openstatus.dev",+ periodicity: "10m",+ jobType: "http",+ active: true,+ public: true,+ createdAt: null,+ updatedAt: null,+ regions: ["ams", "fra"],+ description: "Monitor Description",+ headers: [],+ body: "",+ workspaceId: 1,+ timeout: 45000,+ degradedAfter: null,+ assertions: null,+ status: "active",+ method: "GET",+ deletedAt: null,+ otelEndpoint: null,+ otelHeaders: [],+ followRedirects: true,+ retry: 3,+};++const notification: Notification = {+ id: 1,+ name: "Discord",+ data: `{ "discord": "${process.env.DISCORD_WEBHOOK}" }`,+ createdAt: null,+ updatedAt: null,+ workspaceId: 1,+ provider: "discord",+};++const cronTimestamp = Date.now();++if (process.env.NODE_ENV === "development") {+ await sendDegraded({+ monitor,+ notification,+ cronTimestamp,+ });++ await sendAlert({+ monitor,+ notification,+ statusCode: 500,+ cronTimestamp,+ });++ await sendRecovery({+ monitor,+ notification,+ cronTimestamp,+ });++ await sendTest("");+}diff --git a/packages/notifications/google-chat/tsconfig.json b/packages/notifications/google-chat/tsconfig.jsonnew file mode 100644index 000000000..b4382e67e--- /dev/null+++ b/packages/notifications/google-chat/tsconfig.json@@ -0,0 +1,7 @@+{+ "extends": "@openstatus/tsconfig/nextjs.json",+ "include": ["src", "*.ts"],+ "compilerOptions": {+ "types": ["bun-types"]+ }+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex bed1d3bea..1ccd36661 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -98,6 +98,9 @@ importers:'@openstatus/notification-emails':specifier: workspace:*version: link:../../packages/notifications/email+ '@openstatus/notification-google-chat':+ specifier: workspace:*+ version: link:../../packages/notifications/google-chat'@openstatus/notification-ntfy':specifier: workspace:*version: link:../../packages/notifications/ntfy@@ -1079,6 +1082,9 @@ importers:'@openstatus/notification-emails':specifier: workspace:*version: link:../../packages/notifications/email+ '@openstatus/notification-google-chat':+ specifier: workspace:*+ version: link:../../packages/notifications/google-chat'@openstatus/notification-ntfy':specifier: workspace:*version: link:../../packages/notifications/ntfy@@ -1183,6 +1189,9 @@ importers:'@openstatus/error':specifier: workspace:*version: link:../error+ '@openstatus/notification-google-chat':+ specifier: workspace:*+ version: link:../notifications/google-chat'@openstatus/notification-telegram':specifier: workspace:*version: link:../notifications/telegram@@ -1486,6 +1495,28 @@ importers:specifier: 5.9.3version: 5.9.3+ packages/notifications/google-chat:+ dependencies:+ '@openstatus/db':+ specifier: workspace:*+ version: link:../../db+ zod:+ specifier: 3.25.76+ version: 3.25.76+ devDependencies:+ '@openstatus/tsconfig':+ specifier: workspace:*+ version: link:../../tsconfig+ '@types/node':+ specifier: 24.0.8+ version: 24.0.8+ bun-types:+ specifier: 1.3.1+ version: 1.3.1(@types/[email protected])+ typescript:+ specifier: 5.9.3+ version: 5.9.3+packages/notifications/ntfy:dependencies:'@openstatus/db':