# 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](#). ## Prerequisites - CLI installed and authenticated — see [cli/installation](/docs/functions/cli/installation). - A Sinch number you own and a Voice App it's assigned to. (You can rent one with `sinch numbers available rent` — 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 type { VoiceFunction } from '@sinch/functions-runtime'; import { IceSvamlBuilder } from '@sinch/functions-runtime'; export default { async ice(context, data) { context.log?.info(`Call received from ${data.cli}`); return new IceSvamlBuilder() .say(`Hello! You dialed ${data.to?.endpoint}. Thanks for calling.`) .hangup() .build(); }, } satisfies VoiceFunction; ``` That's the whole function. When a call comes in, Sinch posts an ICE callback to your function, you log the caller, speak a greeting, and hang up. If you prefer C#, see the [C# runtime guide](#) 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 App's callback 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/ice \ -H "Content-Type: application/json" \ -d '{ "callid": "test-123", "cli": "+15551234567", "to": { "type": "number", "endpoint": "+15559876543" } }' ``` You should see a SVAML 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://fn-.functions.sinch.com`. If your `sinch.json` is bound to a Voice App, the CLI updates the app's callback 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 ICE request come in live. Arrow keys to navigate, Enter to expand, `q` to exit. ## What just happened You wrote 12 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 `.runMenu(MenuTemplates.business('Acme'))` and export a `pie` handler to route the result. See [build an IVR](#). - **Handle SMS** — export a `conversationWebhook` and send replies with `context.conversation`. See [build an SMS responder](#). - **Add a REST endpoint** — export a `status` or `health` function. See [add a custom endpoint](#). - **Call an AI voice agent** — use `.connectAgent(AgentProvider.ElevenLabs, ...)`. See [build an AI voice agent](#). ## Related - [Quickstart](#) — same flow using a pre-built template - [Handlers concept](#) — the Express / ASP.NET MVC framing - [Voice callbacks](#) — what ICE, ACE, PIE, DICE actually are - [Node.js runtime](#) / [C# runtime](#) — deeper per-runtime guides