# Your first function

You'll end up with: a deployed voice function that greets the caller and hangs up. No template — every line is yours.

If you want the template-based route instead, see the [quickstart](/docs/functions/functions/quickstart).

## Prerequisites

- CLI installed and authenticated — see [cli/installation](/docs/functions/cli/installation).
- A Sinch number you own and a Voice API v2 service it's assigned to. (You can rent a number with `sinch numbers available rent` and create a service with `sinch voice services create` — see the [CLI quickstart](/docs/functions/cli/quickstart).)


## Step 1 — Scaffold an empty project

```bash
sinch functions init --name my-first-function
```

Pick **Node.js** when prompted and choose the "empty" option (not a full template). The CLI creates a minimal project:

```
my-first-function/
├── function.ts
├── package.json
├── tsconfig.json
├── sinch.json
└── .env
```

Change into the directory and install dependencies:

```bash
cd my-first-function
npm install
```

## Step 2 — Write your handler

Open `function.ts` and replace its contents:

```typescript
import { onCall } from '@sinch/functions-runtime/voice';

export const voiceWebhook = onCall({
  incoming: (call, builder) => {
    console.log(`Call received from ${call.from}`);

    return builder.answer().say('Hello! Thanks for calling.').hangup();
  },
});
```

That's the whole function. When a call comes in, Sinch delivers a `call.incoming` event to your function, you log the call, speak a greeting, and hang up.

If you prefer C#, see the [C# runtime guide](/docs/functions/functions/runtimes/csharp) for the controller equivalent.

## Step 3 — Run it locally

```bash
sinch functions dev
```

The CLI starts your function on `http://localhost:3000` with hot reload. It asks whether to open a public tunnel — say **Yes**. The tunnel gives your laptop a public URL, and the CLI optionally updates your Voice service's webhook URL to point at it.

Leave the terminal running. You can test without making a real call:

```bash
# In another terminal
curl -X POST http://localhost:3000/ \
  -H "Content-Type: application/json" \
  -d '{
    "event": "call.incoming",
    "call": {
      "callId": "01LOCALTEST0000000000000001",
      "from": { "type": "PHONE", "phone": { "number": "+15551234567" } },
      "to": { "type": "PHONE", "phone": { "number": "+15559876543" } }
    }
  }'
```

You should see a commands response in the curl output and a log line in the dev server.

Or call your Sinch number from a phone. If the tunnel is active, the call hits your laptop directly and you'll see the request live.

## Step 4 — Deploy

```bash
sinch functions deploy
```

The CLI validates, packages, uploads, and waits for the rollout. Once it reports `Running`, your function is live at `https://<name>.fn.sinch.com`.

If your `sinch.json` is bound to a Voice service, the CLI updates the service's webhook URL to the new function URL automatically. Calls to your Sinch number now hit production.

## Step 5 — Watch it run

```bash
sinch functions logs --follow
```

Opens an interactive terminal UI. Call your Sinch number and watch the `call.incoming` request come in live. Arrow keys to navigate, Enter to expand, `q` to exit.

## What just happened

You wrote a handful of lines of code. They handle every call to your Sinch number — billing, routing, authentication, TLS, logging, and scaling all happen on the platform. The only thing you had to care about was what the caller hears.

The same pattern extends to everything else Sinch Functions can do:

- **Add a menu** — replace `.hangup()` with `.menu('main', (menu) => menu.prompt(...).match(...))` and add a `manage` handler for anything the menu doesn't resolve itself. See [build an IVR](/docs/functions/functions/guides/build-an-ivr).
- **Handle SMS** — export a `conversationWebhook` and send replies with `context.conversation`. See [build an SMS responder](/docs/functions/functions/guides/build-an-sms-responder).
- **Add a REST endpoint** — export a `status` or `health` function. See [add a custom endpoint](/docs/functions/functions/guides/add-a-custom-endpoint).
- **Call an AI voice agent** — see [build an AI voice agent](/docs/functions/functions/guides/build-an-ai-voice-agent).


## Related

- [Quickstart](/docs/functions/functions/quickstart) — same flow using a pre-built template
- [Handlers concept](/docs/functions/functions/concepts/handlers) — the Express / ASP.NET MVC framing
- [Voice callbacks](/docs/functions/functions/concepts/voice-callbacks) — the call.* event lifecycle, v2 and legacy v1
- [Node.js runtime](/docs/functions/functions/runtimes/nodejs) / [C# runtime](/docs/functions/functions/runtimes/csharp) — deeper per-runtime guides