# Example app

Canonical page: https://docs.ovok.com/signals/tutorial/example-app

<Effort complexity={2} clients="Node.js 22 or later" time="15 minutes" />

This app ties the tutorial together in one file. It verifies each delivery, creates a patient, posts a heart rate above the band, and acknowledges the alert when `alert.triggered` arrives.

It expects the band from [Create a patient](/signals/tutorial/create-patient) and a subscriber for your tunnel URL from [Register a webhook](/signals/tutorial/register-webhook).

## Set up [Terminal] [#set-up-terminal]

```bash
npm init -y && npm install express standardwebhooks
```

```bash title=".env"
OVOK_MANAGER_ID=…
OVOK_MANAGER_SECRET=…
OVOK_SUBMITTER_ID=…
OVOK_SUBMITTER_SECRET=…
SIGNALS_SIGNING_SECRET=whsec_…
```

## Write the app [Server-side] [#write-the-app-server-side]

```js title="app.mjs"
import express from 'express';
import { Webhook } from 'standardwebhooks';

const API = 'https://api.sandbox.ovok.com/v1/signals/api';
const env = process.env;
const basic = (id, secret) => `Basic ${Buffer.from(`${id}:${secret}`).toString('base64')}`;
const manager = basic(env.OVOK_MANAGER_ID, env.OVOK_MANAGER_SECRET);
const submitter = basic(env.OVOK_SUBMITTER_ID, env.OVOK_SUBMITTER_SECRET);

async function call(authorization, path, body) {
  const response = await fetch(`${API}${path}`, {
    method: 'POST',
    headers: { authorization, 'content-type': 'application/json' },
    body: JSON.stringify(body),
  });
  if (!response.ok) throw new Error(`${path} answered ${response.status}`);
}

const webhook = new Webhook(env.SIGNALS_SIGNING_SECRET);
const app = express();

app.post('/signals/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
  let event;
  try {
    event = webhook.verify(req.body, req.headers);
  } catch {
    return res.sendStatus(400);
  }
  res.sendStatus(204);
  console.log(event.type, event.data.patientRefId);

  if (event.type === 'alert.triggered') {
    await call(manager, `/alert/${event.data.id}/ack`, {
      actor: { reference: 'Practitioner/123', display: 'Dr. Max Mustermann' },
    });
  }
});

app.listen(3000, async () => {
  await call(manager, '/patient', { patients: [{ refId: 'resident-001', name: 'Resident 001' }] });
  await call(submitter, '/observation', {
    patientRefId: 'resident-001',
    identifier: [{ system: 'urn:example:readings', value: `reading-${Date.now()}` }],
    code: { coding: [{ system: 'http://loinc.org', code: '8867-4' }] },
    valueQuantity: { value: 132, unit: '/min' },
    effectiveDateTime: new Date().toISOString(),
  });
});
```

- Each run posts a new `identifier`, so a rerun is not refused as a duplicate.
- The receiver answers `204` before it acknowledges, so a slow call never delays the delivery.

## Run it [Terminal] [#run-it-terminal]

```bash
node --env-file=.env app.mjs
```

## Verify your integration [#verify-your-integration]

The log shows these lines, the first two in either order:

```text
alert.triggered resident-001
episode.opened resident-001
alert.acknowledged resident-001
```

If a line is missing, see [Debugging](/signals/tutorial/debugging).

## See also [#see-also]

- [Signals webhooks](/signals/standalone/webhooks): every event and its payload
- [Verify webhooks](/signals/standalone/verify-webhooks): signatures in more languages
- [Mutual TLS](/signals/standalone/mtls): require client certificates
