@sinch/functions-runtime
v0.5.12
Published
Development runtime for Sinch Functions - serverless voice applications
Downloads
3,494
Readme
@sinch/functions-runtime
Development runtime for Sinch Functions - build serverless communication workflows with ease.
Getting Started
The easiest way to get started is using the Sinch CLI:
# Install the CLI
npm install -g @sinch/cli
# Create a new function (interactive)
sinch functions initThe interactive prompt will guide you through:
- Selecting a runtime (Node.js, C#, etc.)
- Choosing a template (simple-voice-ivr recommended for first project)
- Setting up your project
Then start the local development server:
sinch functions devYour function is now running locally with hot reload!
Deploy to Production
When you're ready to deploy:
sinch functions deployYour function will be built and deployed to the Sinch Functions platform.
Features
SVAML Builders
Build voice responses with a fluent API:
import { IceSvamlBuilder, AceSvamlBuilder, PieSvamlBuilder } from '@sinch/functions-runtime';
// ICE (Incoming Call Event) - handle incoming calls
const iceResponse = new IceSvamlBuilder()
.say('Hello, welcome!')
.connectPstn('+15551234567', {
cli: '+15559999999',
enableAce: true,
enableDice: true,
})
.build();
// ACE (Answered Call Event) - handle answered outbound calls
const aceResponse = new AceSvamlBuilder().say('The call has been answered.').continue().build();
// PIE (Prompt Input Event) - handle user input
const pieResponse = new PieSvamlBuilder()
.say('You pressed ' + selection)
.hangup()
.build();Menu Builder
Create IVR menus with validation:
import { MenuBuilder, MenuTemplates } from '@sinch/functions-runtime';
// Use pre-built templates
const businessMenu = MenuTemplates.business('Acme Corp');
const yesNoMenu = MenuTemplates.yesNo('Do you want to continue?');
// Or build custom menus
const customMenu = new MenuBuilder()
.prompt('Press 1 for English, 2 for Spanish')
.option('1', 'menu(english)')
.option('2', 'menu(spanish)')
.addSubmenu('english')
.prompt('Press 1 for sales, 2 for support')
.option('1', 'return(en-sales)')
.option('2', 'return(en-support)')
.build();Cache
Store and retrieve data across function invocations:
export async function ice(context, event) {
const cache = context.cache;
// Store data
await cache.set('call-count', 1, 3600); // TTL in seconds
// Retrieve data
const count = await cache.get('call-count');
}Configuration
Access environment variables and secrets:
import { createConfig } from '@sinch/functions-runtime';
export async function ice(context, event) {
const config = createConfig(context);
// Get variables
const companyName = config.getVariable('COMPANY_NAME', 'Default');
// Get secrets (encrypted at rest)
const apiKey = config.getSecret('API_KEY');
}Voice Callbacks
| Callback | Description | Returns |
| -------- | ------------------------------------------------------- | ------- |
| ice | Incoming Call Event - first callback for incoming calls | SVAML |
| ace | Answered Call Event - when outbound call is answered | SVAML |
| pie | Prompt Input Event - user input (DTMF/voice) | SVAML |
| dice | Disconnected Call Event - call ended | None |
| notify | Notification events | None |
ace, pie, dice, and notify are optional — the platform may call them even if your function doesn't implement a handler, and the runtime returns 200 for those unimplemented callbacks (only ice is required).
Type callback data with IceCallback / AceCallback / PieCallback / DiceCallback / NotifyCallback — these match what your handler receives (the runtime delivers callId, not the raw API's callid).
TypeScript Support
Full TypeScript support with comprehensive types:
import type { FunctionContext, IceCallback, SvamletResponse } from '@sinch/functions-runtime';
export async function ice(
context: FunctionContext,
event: IceCallback
): Promise<SvamletResponse> {
// Full type safety and IntelliSense!
}Request Limits
| Limit | Value | | -------------------------------------- | ---------------------- | | Request body | 10 MB (10485760 bytes) | | Request/response body retained in logs | First 64 KB |
A body larger than the limit is rejected with 413 and a JSON response naming it:
{
"error": "Payload too large",
"message": "Request body exceeds the 10mb limit",
"limit": "10mb"
}A deployed function sits behind the platform router, which enforces the same 10 MB cap, so a body
that is accepted locally is accepted once deployed. If you receive a 413 without the JSON
body above, the router rejected the request before it reached your function.
Logs retain the first 64 KB of a request or response body, appending
…[truncated — N bytes total] when the body was longer. Only text formats are retained — JSON,
XML, plain text and form data. Anything else, including uploads, images, audio, video, PDFs and
archives, is not logged at all. Your function still receives every body in full.
Documentation
License
MIT
