@sinch/functions-runtime 0.1.0-beta.28 → 0.2.1-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,207 +1,166 @@
1
- # @sinch/functions-runtime
2
-
3
- Development runtime for Sinch Functions - build serverless voice applications with ease.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @sinch/functions-runtime
9
- ```
10
-
11
- ## Quick Start
12
-
13
- Create a `function.js` file:
14
-
15
- ```javascript
16
- import { IceSvamlBuilder, MenuBuilder, MenuTemplates } from '@sinch/functions-runtime';
17
-
18
- // Handle incoming calls
19
- export async function ice(context, event) {
20
- return new IceSvamlBuilder()
21
- .say('Welcome to our service! Press 1 for sales, 2 for support.')
22
- .runMenu(MenuTemplates.business('Acme Corp').menus)
23
- .build();
24
- }
25
-
26
- // Handle menu selections
27
- export async function pie(context, event) {
28
- const selection = event.menuResult?.value;
29
-
30
- if (selection === 'sales') {
31
- return new IceSvamlBuilder()
32
- .say('Connecting you to sales.')
33
- .connectPstn('+15551234567')
34
- .build();
35
- }
36
-
37
- return new IceSvamlBuilder()
38
- .say('Goodbye!')
39
- .hangup()
40
- .build();
41
- }
42
- ```
43
-
44
- Run locally:
45
-
46
- ```bash
47
- npx sinch-runtime
48
- ```
49
-
50
- ## Features
51
-
52
- ### SVAML Builders
53
-
54
- Build voice responses with a fluent API:
55
-
56
- ```typescript
57
- import { IceSvamlBuilder, AceSvamlBuilder, PieSvamlBuilder } from '@sinch/functions-runtime';
58
-
59
- // ICE (Incoming Call Event) - handle incoming calls
60
- const iceResponse = new IceSvamlBuilder()
61
- .say('Hello, welcome!')
62
- .connectPstn('+15551234567', {
63
- cli: '+15559999999',
64
- enableAce: true,
65
- enableDice: true
66
- })
67
- .build();
68
-
69
- // ACE (Answered Call Event) - handle answered outbound calls
70
- const aceResponse = new AceSvamlBuilder()
71
- .say('The call has been answered.')
72
- .continue()
73
- .build();
74
-
75
- // PIE (Prompt Input Event) - handle user input
76
- const pieResponse = new PieSvamlBuilder()
77
- .say('You pressed ' + selection)
78
- .hangup()
79
- .build();
80
- ```
81
-
82
- ### Menu Builder
83
-
84
- Create IVR menus with validation:
85
-
86
- ```typescript
87
- import { MenuBuilder, MenuTemplates, createMenu } from '@sinch/functions-runtime';
88
-
89
- // Use pre-built templates
90
- const businessMenu = MenuTemplates.business('Acme Corp');
91
- const yesNoMenu = MenuTemplates.yesNo('Do you want to continue?');
92
-
93
- // Or build custom menus
94
- const customMenu = new MenuBuilder()
95
- .prompt('Press 1 for English, 2 for Spanish')
96
- .option('1', 'menu(english)')
97
- .option('2', 'menu(spanish)')
98
- .addSubmenu('english')
99
- .prompt('Press 1 for sales, 2 for support')
100
- .option('1', 'return(en-sales)')
101
- .option('2', 'return(en-support)')
102
- .build();
103
- ```
104
-
105
- ### Cache
106
-
107
- Store and retrieve data across function invocations:
108
-
109
- ```typescript
110
- import { LocalCache } from '@sinch/functions-runtime';
111
-
112
- // In your function
113
- export async function ice(context, event) {
114
- const cache = context.cache;
115
-
116
- // Store data
117
- await cache.set('call-count', 1, 3600); // TTL in seconds
118
-
119
- // Retrieve data
120
- const count = await cache.get('call-count');
121
-
122
- // Check existence
123
- if (await cache.has('call-count')) {
124
- // ...
125
- }
126
- }
127
- ```
128
-
129
- ### Configuration
130
-
131
- Access environment variables and secrets:
132
-
133
- ```typescript
134
- import { createConfig } from '@sinch/functions-runtime';
135
-
136
- export async function ice(context, event) {
137
- const config = createConfig(context);
138
-
139
- // Get variables
140
- const companyName = config.getVariable('COMPANY_NAME', 'Default');
141
-
142
- // Get secrets
143
- const apiKey = config.getSecret('API_KEY');
144
-
145
- // Require variables (throws if missing)
146
- const required = config.requireVariable('IMPORTANT_VAR');
147
- }
148
- ```
149
-
150
- ## Voice Callbacks
151
-
152
- | Callback | Description | Returns |
153
- |----------|-------------|---------|
154
- | `ice` | Incoming Call Event - first callback for incoming calls | SVAML |
155
- | `ace` | Answered Call Event - when outbound call is answered | SVAML |
156
- | `pie` | Prompt Input Event - user input (DTMF/voice) | SVAML |
157
- | `dice` | Disconnected Call Event - call ended | None |
158
- | `notify` | Notification events | None |
159
-
160
- ## TypeScript Support
161
-
162
- Full TypeScript support with comprehensive types:
163
-
164
- ```typescript
165
- import type {
166
- FunctionContext,
167
- IceCallbackData,
168
- AceCallbackData,
169
- PieCallbackData,
170
- SvamletResponse
171
- } from '@sinch/functions-runtime';
172
-
173
- export async function ice(
174
- context: FunctionContext,
175
- event: IceCallbackData
176
- ): Promise<SvamletResponse> {
177
- // Full type safety and IntelliSense!
178
- }
179
- ```
180
-
181
- ## API Reference
182
-
183
- ### Builders
184
-
185
- - `IceSvamlBuilder` - Build ICE responses
186
- - `AceSvamlBuilder` - Build ACE responses
187
- - `PieSvamlBuilder` - Build PIE responses
188
- - `MenuBuilder` - Build IVR menus
189
- - `MenuTemplates` - Pre-built menu templates
190
-
191
- ### Cache
192
-
193
- - `IFunctionCache` - Cache interface
194
- - `LocalCache` - In-memory cache (development)
195
-
196
- ### Configuration
197
-
198
- - `UniversalConfig` - Configuration utility
199
- - `createConfig()` - Create config instance
200
-
201
- ### Types
202
-
203
- All callback data types, SVAML types, and handler types are exported for TypeScript users.
204
-
205
- ## License
206
-
207
- MIT
1
+ # @sinch/functions-runtime
2
+
3
+ Development runtime for Sinch Functions - build serverless communication workflows with ease.
4
+
5
+ ## Getting Started
6
+
7
+ The easiest way to get started is using the Sinch CLI:
8
+
9
+ ```bash
10
+ # Install the CLI
11
+ npm install -g @sinch/cli
12
+
13
+ # Create a new function (interactive)
14
+ sinch functions init
15
+ ```
16
+
17
+ The interactive prompt will guide you through:
18
+ 1. Selecting a runtime (Node.js, C#, etc.)
19
+ 2. Choosing a template (simple-voice-ivr recommended for first project)
20
+ 3. Setting up your project
21
+
22
+ Then start the local development server:
23
+
24
+ ```bash
25
+ sinch functions dev
26
+ ```
27
+
28
+ Your function is now running locally with hot reload!
29
+
30
+ ## Deploy to Production
31
+
32
+ When you're ready to deploy:
33
+
34
+ ```bash
35
+ sinch functions deploy
36
+ ```
37
+
38
+ Your function will be built and deployed to the Sinch Functions platform.
39
+
40
+ ## Features
41
+
42
+ ### SVAML Builders
43
+
44
+ Build voice responses with a fluent API:
45
+
46
+ ```typescript
47
+ import { IceSvamlBuilder, AceSvamlBuilder, PieSvamlBuilder } from '@sinch/functions-runtime';
48
+
49
+ // ICE (Incoming Call Event) - handle incoming calls
50
+ const iceResponse = new IceSvamlBuilder()
51
+ .say('Hello, welcome!')
52
+ .connectPstn('+15551234567', {
53
+ cli: '+15559999999',
54
+ enableAce: true,
55
+ enableDice: true
56
+ })
57
+ .build();
58
+
59
+ // ACE (Answered Call Event) - handle answered outbound calls
60
+ const aceResponse = new AceSvamlBuilder()
61
+ .say('The call has been answered.')
62
+ .continue()
63
+ .build();
64
+
65
+ // PIE (Prompt Input Event) - handle user input
66
+ const pieResponse = new PieSvamlBuilder()
67
+ .say('You pressed ' + selection)
68
+ .hangup()
69
+ .build();
70
+ ```
71
+
72
+ ### Menu Builder
73
+
74
+ Create IVR menus with validation:
75
+
76
+ ```typescript
77
+ import { MenuBuilder, MenuTemplates } from '@sinch/functions-runtime';
78
+
79
+ // Use pre-built templates
80
+ const businessMenu = MenuTemplates.business('Acme Corp');
81
+ const yesNoMenu = MenuTemplates.yesNo('Do you want to continue?');
82
+
83
+ // Or build custom menus
84
+ const customMenu = new MenuBuilder()
85
+ .prompt('Press 1 for English, 2 for Spanish')
86
+ .option('1', 'menu(english)')
87
+ .option('2', 'menu(spanish)')
88
+ .addSubmenu('english')
89
+ .prompt('Press 1 for sales, 2 for support')
90
+ .option('1', 'return(en-sales)')
91
+ .option('2', 'return(en-support)')
92
+ .build();
93
+ ```
94
+
95
+ ### Cache
96
+
97
+ Store and retrieve data across function invocations:
98
+
99
+ ```typescript
100
+ export async function ice(context, event) {
101
+ const cache = context.cache;
102
+
103
+ // Store data
104
+ await cache.set('call-count', 1, 3600); // TTL in seconds
105
+
106
+ // Retrieve data
107
+ const count = await cache.get('call-count');
108
+ }
109
+ ```
110
+
111
+ ### Configuration
112
+
113
+ Access environment variables and secrets:
114
+
115
+ ```typescript
116
+ import { createConfig } from '@sinch/functions-runtime';
117
+
118
+ export async function ice(context, event) {
119
+ const config = createConfig(context);
120
+
121
+ // Get variables
122
+ const companyName = config.getVariable('COMPANY_NAME', 'Default');
123
+
124
+ // Get secrets (encrypted at rest)
125
+ const apiKey = config.getSecret('API_KEY');
126
+ }
127
+ ```
128
+
129
+ ## Voice Callbacks
130
+
131
+ | Callback | Description | Returns |
132
+ |----------|-------------|---------|
133
+ | `ice` | Incoming Call Event - first callback for incoming calls | SVAML |
134
+ | `ace` | Answered Call Event - when outbound call is answered | SVAML |
135
+ | `pie` | Prompt Input Event - user input (DTMF/voice) | SVAML |
136
+ | `dice` | Disconnected Call Event - call ended | None |
137
+ | `notify` | Notification events | None |
138
+
139
+ ## TypeScript Support
140
+
141
+ Full TypeScript support with comprehensive types:
142
+
143
+ ```typescript
144
+ import type {
145
+ FunctionContext,
146
+ IceCallbackData,
147
+ SvamletResponse
148
+ } from '@sinch/functions-runtime';
149
+
150
+ export async function ice(
151
+ context: FunctionContext,
152
+ event: IceCallbackData
153
+ ): Promise<SvamletResponse> {
154
+ // Full type safety and IntelliSense!
155
+ }
156
+ ```
157
+
158
+ ## Documentation
159
+
160
+ - [Sinch Functions Documentation](https://developers.sinch.com/docs/functions)
161
+ - [Sinch Voice API](https://developers.sinch.com/docs/voice)
162
+ - [SVAML Reference](https://developers.sinch.com/docs/voice/api-reference/svaml)
163
+
164
+ ## License
165
+
166
+ MIT