Download web/src/notify/NotificationsSettings.tsx from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 5.39 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/notify/NotificationsSettings.tsx
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/web/src/notify/NotificationsSettings.tsx
-
curl -L -o NotificationsSettings.tsx https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/web/src/notify/NotificationsSettings.tsx
5.39 kB
| 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<NotifySettings>('/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 ( | |
| <div className="pw-notify-settings" data-testid="notify-settings"> | |
| <Text size="sm" c="dimmed"> | |
| 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. | |
| </Text> | |
| {d && <TelegramCard tg={d.telegram} />} | |
| <section className="pw-card" aria-labelledby="notify-chat-h"> | |
| <h2 id="notify-chat-h">Webhook (optional, for n8n or other tools)</h2> | |
| {s.isLoading ? <LoadingState label="Loading the notification settings" rows={2} /> | |
| : s.error ? <ErrorAlert error={s.error} title="The notification settings could not be loaded" onRetry={() => void s.refetch()} /> | |
| : d && ( | |
| <dl className="pw-notify-dl"> | |
| <dt>Webhook</dt> | |
| <dd data-testid="notify-webhook">{d.webhook_configured ? <>Set up{d.webhook_host ? <>, sends to <b>{d.webhook_host}</b></> : null}</> : 'Not set up yet'}</dd> | |
| <dt>Signed messages</dt> | |
| <dd>{d.signing ? 'On: n8n can check that each message came from Astra' : 'Off: set FPT_NOTIFY_SECRET to sign them'}</dd> | |
| <dt>Waiting to send</dt> | |
| <dd>{d.pending}</dd> | |
| <dt>Last delivery</dt> | |
| <dd>{last ? <span className="pw-status" data-tone={last.ok ? 'green' : 'red'}>{last.ok ? 'Delivered' : 'Failed'}</span> : 'None yet'} | |
| {last && <> {fmtTs(last.at)}{last.status ? `, HTTP ${last.status}` : ''}{last.error ? `: ${last.error}` : ''}</>}</dd> | |
| </dl> | |
| )} | |
| <Group gap="sm" mt="md"> | |
| <Button leftSection={<IconSend size={15} aria-hidden />} onClick={() => test.mutate()} loading={test.isPending} disabled={!d?.webhook_configured} | |
| data-testid="notify-test">Send a test message</Button> | |
| {test.isSuccess && <Text size="sm" role="status">Test message queued. It should arrive within a minute.</Text>} | |
| </Group> | |
| {test.error ? <ErrorAlert error={test.error} title="The test message was not sent" /> : null} | |
| </section> | |
| <section className="pw-card" aria-labelledby="notify-browser-h"> | |
| <h2 id="notify-browser-h">This browser</h2> | |
| {browser.supported ? ( | |
| <> | |
| <Switch label="Tell me in this browser too" description="A system notification when the app is in the background. Only for this browser and this account." | |
| checked={browser.on} disabled={browser.blocked} onChange={(e) => void browser.setOn(e.currentTarget.checked)} /> | |
| {browser.blocked && <Text size="sm" c="dimmed" mt="xs">Your browser blocks notifications for this site. Allow them in the site settings to turn this on.</Text>} | |
| </> | |
| ) : <Text size="sm" c="dimmed">This browser does not support notifications.</Text>} | |
| </section> | |
| <section className="pw-card" aria-labelledby="notify-setup-h"> | |
| <h2 id="notify-setup-h">Set up the webhook with n8n</h2> | |
| <ol className="pw-notify-steps"> | |
| <li>In n8n, import the workflow <code>integrations/n8n/patchwise-telegram.json</code> and turn it on. Copy its production webhook URL.</li> | |
| <li>In n8n, add your Telegram bot token as a Telegram credential, and set the chat id (the workflow's README shows where).</li> | |
| <li>On the Astra server, set <code>FPT_NOTIFY_WEBHOOK_URL</code> to that webhook URL and <code>FPT_NOTIFY_SECRET</code> to a long random value; put the same value in the n8n workflow. Restart Astra.</li> | |
| <li>Come back here and press <b>Send a test message</b>.</li> | |
| </ol> | |
| </section> | |
| </div> | |
| ); | |
| } | |