# Quickstart (/docs)

From a new workspace to a call handled by your program, on your machine.

You will run a small program on your laptop, bring your workspace's calls to it through the tunnel, and call it from your computer. You need Node 22.18 or later.

## 1. Create a workspace [#1-create-a-workspace]

Sign up at herald cloud. The workspace comes with a **test line**: digits that ring your workspace from any SIP phone, before you add a number of your own. Lines → Test line shows it.

## 2. Write the program [#2-write-the-program]

```bash
mkdir hello && cd hello
npm init -y && npm pkg set type=module
npm install @herald-voice/sdk ws
```

```ts title="server.ts"
import { herald, tone } from "@herald-voice/sdk";

const app = herald({
  secret: process.env.HERALD_SECRET,
  onCall: async (call) => {
    console.log(`call from ${call.from} to ${call.number}`);
    await call.play(tone(660, 300));
    const { digits } = await call.digits({ max: 1, timeout: "6s", prompt: tone(880, 200) });
    console.log(`the caller pressed ${digits || "nothing"}`);
    await call.play(tone(440, 300));
    await call.hangup();
  },
  onEnded: (ev) => console.log(`ended: ${ev.end_reason}`),
});

await app.listen(4000, { path: "/herald" });
```

`onCall` runs once for each call. Each `await` waits for the caller: `play` plays audio, `digits` waits for keys, `hangup` ends the call. `secret` makes the app refuse requests herald did not sign.

## 3. Sign in the CLI [#3-sign-in-the-cli]

```bash
npx @herald-voice/cli login --app <herald cloud URL>
```

It opens the browser: sign in and approve the code the terminal shows. Then write the workspace's signing secret to `.env`:

```bash
npx @herald-voice/cli env > .env
```

## 4. Start the program and the tunnel [#4-start-the-program-and-the-tunnel]

```bash
node --env-file=.env server.ts
```

In another terminal:

```bash
npx @herald-voice/cli tunnel 4000 --path /herald
```

```text
calls reach http://127.0.0.1:4000/herald
call your test line: sip:712345678901@<herald SIP address>
leave this running; Ctrl-C stops it
```

The tunnel switches the workspace to it: herald now sends the workspace's calls to `http://127.0.0.1:4000/herald` on your machine.

## 5. Call it [#5-call-it]

On macOS, call the test line with the computer's microphone and speaker:

```bash
npx @herald-voice/cli phone
```

You hear a tone, then a higher one: press a key. The program prints it, plays a last tone and hangs up. From another computer, call `sip:<test line>@<herald SIP address>` from a SIP softphone.

To try the program without calling, send it a signed test request and see what it answered:

```bash
npx @herald-voice/cli test
```

## 6. See the call [#6-see-the-call]

```bash
npx @herald-voice/cli calls
```

The dashboard shows it too, under Calls, with how it ended.

## Next [#next]

- Add your number and the SIP account (trunk) that brings its calls: Lines in the dashboard, or [`herald-cloud numbers` and `trunks`](/docs/cli#numbers). See [Concepts](/docs/concepts).
- Talk to the caller with a voice model: [`connectRealtime`](/docs/sdk#connectrealtime).
- Deploy the program and give herald its public URL: [`herald-cloud backend --url`](/docs/cli#backend), or Lines → Test line → A public URL.
- Place calls out: [`HeraldClient`](/docs/sdk#heraldclient).