import { Button, Group, Switch, Text } from '@mantine/core'; import { IconSend } from '@/components/icons'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { getJson, sendJson } from '../api/client'; import { ErrorAlert, fmtTs } from '../components/common'; import { LoadingState } from '../components/states'; import { TelegramCard, type TelegramState } from './TelegramCard'; import { useBrowserPref } from './useNotifications'; import './notify.css'; /** GET /api/notifications/settings (admin). */ export interface NotifySettings { webhook_configured: boolean; webhook_host: string | null; signing: boolean; pending: number; last_delivery: { at: string; ok: boolean; status: number | null; error: string | null } | null; telegram?: TelegramState; } /** Settings > Notifications: where the coworkers' messages go (Telegram, or a webhook for n8n and other tools), and this browser. */ export function NotificationsSettings() { const qc = useQueryClient(); const s = useQuery({ queryKey: ['notify-settings'], queryFn: () => getJson('/api/notifications/settings'), refetchInterval: 15_000, retry: false }); const test = useMutation({ mutationFn: () => sendJson<{ queued: boolean; id: number }>('POST', '/api/notifications/test'), onSuccess: () => { void qc.invalidateQueries({ queryKey: ['notify-settings'] }); void qc.invalidateQueries({ queryKey: ['notifications'] }); }, }); const browser = useBrowserPref(); const d = s.data; const last = d?.last_delivery; return (
When a coworker needs you (scenarios to approve, a failure to decide, a finished run, a new defect), Astra sends a message. Each message opens the right screen; nothing is approved or changed until you confirm it there. {d && }

Webhook (optional, for n8n or other tools)

{s.isLoading ? : s.error ? void s.refetch()} /> : d && (
Webhook
{d.webhook_configured ? <>Set up{d.webhook_host ? <>, sends to {d.webhook_host} : null} : 'Not set up yet'}
Signed messages
{d.signing ? 'On: n8n can check that each message came from Astra' : 'Off: set FPT_NOTIFY_SECRET to sign them'}
Waiting to send
{d.pending}
Last delivery
{last ? {last.ok ? 'Delivered' : 'Failed'} : 'None yet'} {last && <> {fmtTs(last.at)}{last.status ? `, HTTP ${last.status}` : ''}{last.error ? `: ${last.error}` : ''}}
)} {test.isSuccess && Test message queued. It should arrive within a minute.} {test.error ? : null}

This browser

{browser.supported ? ( <> void browser.setOn(e.currentTarget.checked)} /> {browser.blocked && Your browser blocks notifications for this site. Allow them in the site settings to turn this on.} ) : This browser does not support notifications.}

Set up the webhook with n8n

  1. In n8n, import the workflow integrations/n8n/patchwise-telegram.json and turn it on. Copy its production webhook URL.
  2. In n8n, add your Telegram bot token as a Telegram credential, and set the chat id (the workflow's README shows where).
  3. On the Astra server, set FPT_NOTIFY_WEBHOOK_URL to that webhook URL and FPT_NOTIFY_SECRET to a long random value; put the same value in the n8n workflow. Restart Astra.
  4. Come back here and press Send a test message.
); }