{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-docs/functions/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["partial"]},"type":"markdown"},"seo":{"title":"Developer Documentation","siteUrl":"https://developers.sinch.com","llmstxt":{"title":"Sinch Developer Documentation","description":"LLMs.txt containing a map of all the documentation files for Sinch.","sections":[{"title":"SMS API","description":"The SMS API allows you to send and receive SMS messages with a few easy steps. You can also send bulk SMS messages to multiple customers using the Sinch SMS service.","includeFiles":["docs/sms/**/*.md","docs/sms/**/*.yaml"],"excludeFiles":["docs/sms/index.md"]},{"title":"Numbers API","description":"The Numbers API enables you to search for, view, and activate numbers. It's considered a precursor to other APIs in the Sinch product family. The numbers API can be used in tandem with any of our APIs that perform messaging or calling.","includeFiles":["docs/numbers/**/*.md","docs/numbers/**/*.yaml"],"excludeFiles":["docs/numbers/index.md"]},{"title":"Conversation API","description":"Send and receive messages globally on many popular channels with ease and confidence when using Sinch's Conversation API. Conversation API is the preferred API for sending mobile messages on SMS and other social channels with Sinch. It is a simple API with unified error messages, consistent request payloads, and common webhook payloads that are channel-agnostic.","includeFiles":["docs/conversation/**/*.md","docs/conversation/**/*.yaml"],"excludeFiles":["docs/conversation/index.md"]},{"title":"Voice API","description":"The Voice API works as a big telephony switch. The Voice API handles incoming phone calls (also known as incoming call “legs”), sets up outgoing phone calls (or outgoing call “legs”), and bridges the two. The incoming call leg may come in over a data connection (from a smartphone or web application using the Sinch SDKs) or through a local phone number (from the PSTN network). Similarly, the outgoing call leg can be over data (to another smartphone or web application using the Sinch SDKs) or the PSTN network.","includeFiles":["docs/voice/**/*.md","docs/voice/**/*.yaml"],"excludeFiles":["docs/voice/index.md"]},{"title":"Verification API","description":"The Verification API is a platform for phone number verification. It consists of the API and different software development kits (the Sinch SDKs) that you integrate with your smartphone or web application and cloud based back-end services. Together they enable SMS, Flashcall, Phone Call and Data verification in your application.","includeFiles":["docs/verification/**/*.md","docs/verification/**/*.yaml"],"excludeFiles":["docs/verification/index.md"]},{"title":"Provisioning API","description":"Provisioning API allows you to programmatically set up your senders, accounts and templates on your favorite messaging platforms on the Conversation API. For now, you can create your first WhatsApp channel through Meta's Embedded sign up, you can configure your first SMS App and configure your webhooks. As development continues, we will be adding the most commonly used channels.","includeFiles":["docs/provisioning-api/**/*.md","docs/provisioning-api/**/*.json"],"excludeFiles":["docs/provisioning-api/index.md"]},{"title":"Elastic SIP Trunking API","description":"With Elastic SIP Trunking you can create and manage your SIP trunks and phone numbers programmatically.","includeFiles":["docs/est/**/*.md","docs/est/**/*.yaml"],"excludeFiles":["docs/est/index.md"]},{"title":"Fax API","description":"Send and receive HIPAA compliant faxes on our modern fax platform using our developer-friendly API.","includeFiles":["docs/fax/**/*.md","docs/fax/**/*.yaml"],"excludeFiles":["docs/fax/index.md"]},{"title":"In-app Voice and Video SDK","description":"The In-app Voice and Video SDK enables you to add voice and video calling capabilities directly into your mobile or web application using the Sinch SDKs.","includeFiles":["docs/in-app-calling/**/*.md"],"excludeFiles":["docs/in-app-calling/index.md"]}],"hide":false,"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"your-first-function","__idx":0},"children":["Your first function"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You'll end up with: a deployed voice function that greets the caller and hangs up. No template — every line is yours."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If you want the template-based route instead, see the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"#"},"children":["quickstart"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"prerequisites","__idx":1},"children":["Prerequisites"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["CLI installed and authenticated — see ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/functions/cli/installation"},"children":["cli/installation"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["A Sinch number you own and a Voice App it's assigned to. (You can rent one with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sinch numbers available rent"]}," — see the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/functions/cli/quickstart"},"children":["CLI quickstart"]},".)"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-1--scaffold-an-empty-project","__idx":2},"children":["Step 1 — Scaffold an empty project"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"sinch functions init --name my-first-function\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Pick ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Node.js"]}," when prompted and choose the \"empty\" option (not a full template). The CLI creates a minimal project:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"my-first-function/\n├── function.ts\n├── package.json\n├── tsconfig.json\n├── sinch.json\n└── .env\n"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Change into the directory and install dependencies:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"cd my-first-function\nnpm install\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-2--write-your-handler","__idx":3},"children":["Step 2 — Write your handler"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Open ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["function.ts"]}," and replace its contents:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import type { VoiceFunction } from '@sinch/functions-runtime';\nimport { IceSvamlBuilder } from '@sinch/functions-runtime';\n\nexport default {\n  async ice(context, data) {\n    context.log?.info(`Call received from ${data.cli}`);\n\n    return new IceSvamlBuilder()\n      .say(`Hello! You dialed ${data.to?.endpoint}. Thanks for calling.`)\n      .hangup()\n      .build();\n  },\n} satisfies VoiceFunction;\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["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."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If you prefer C#, see the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"#"},"children":["C# runtime guide"]}," for the controller equivalent."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-3--run-it-locally","__idx":4},"children":["Step 3 — Run it locally"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"sinch functions dev\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The CLI starts your function on ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["http://localhost:3000"]}," with hot reload. It asks whether to open a public tunnel — say ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Yes"]},". The tunnel gives your laptop a public URL, and the CLI optionally updates your Voice App's callback URL to point at it."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Leave the terminal running. You can test without making a real call:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"# In another terminal\ncurl -X POST http://localhost:3000/ice \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"callid\": \"test-123\",\n    \"cli\": \"+15551234567\",\n    \"to\": { \"type\": \"number\", \"endpoint\": \"+15559876543\" }\n  }'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You should see a SVAML response in the curl output and a log line in the dev server."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["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."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-4--deploy","__idx":5},"children":["Step 4 — Deploy"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"sinch functions deploy\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The CLI validates, packages, uploads, and waits for the rollout. Once it reports ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Running"]},", your function is live at ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://fn-<id>.functions.sinch.com"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If your ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["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."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"step-5--watch-it-run","__idx":6},"children":["Step 5 — Watch it run"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"sinch functions logs --follow\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Opens an interactive terminal UI. Call your Sinch number and watch the ICE request come in live. Arrow keys to navigate, Enter to expand, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["q"]}," to exit."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"what-just-happened","__idx":7},"children":["What just happened"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["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."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The same pattern extends to everything else Sinch Functions can do:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Add a menu"]}," — replace ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":[".hangup()"]}," with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":[".runMenu(MenuTemplates.business('Acme'))"]}," and export a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["pie"]}," handler to route the result. See ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"#"},"children":["build an IVR"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Handle SMS"]}," — export a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["conversationWebhook"]}," and send replies with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["context.conversation"]},". See ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"#"},"children":["build an SMS responder"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Add a REST endpoint"]}," — export a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["status"]}," or ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["health"]}," function. See ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"#"},"children":["add a custom endpoint"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Call an AI voice agent"]}," — use ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":[".connectAgent(AgentProvider.ElevenLabs, ...)"]},". See ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"#"},"children":["build an AI voice agent"]},"."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"related","__idx":8},"children":["Related"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"#"},"children":["Quickstart"]}," — same flow using a pre-built template"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"#"},"children":["Handlers concept"]}," — the Express / ASP.NET MVC framing"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"#"},"children":["Voice callbacks"]}," — what ICE, ACE, PIE, DICE actually are"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"#"},"children":["Node.js runtime"]}," / ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"#"},"children":["C# runtime"]}," — deeper per-runtime guides"]}]}]},"headings":[{"value":"Your first function","id":"your-first-function","depth":1},{"value":"Prerequisites","id":"prerequisites","depth":2},{"value":"Step 1 — Scaffold an empty project","id":"step-1--scaffold-an-empty-project","depth":2},{"value":"Step 2 — Write your handler","id":"step-2--write-your-handler","depth":2},{"value":"Step 3 — Run it locally","id":"step-3--run-it-locally","depth":2},{"value":"Step 4 — Deploy","id":"step-4--deploy","depth":2},{"value":"Step 5 — Watch it run","id":"step-5--watch-it-run","depth":2},{"value":"What just happened","id":"what-just-happened","depth":2},{"value":"Related","id":"related","depth":2}],"frontmatter":{"seo":{"title":""}},"lastModified":"2026-04-15T14:23:23.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/functions/your-first-function","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}