@sinch/functions-runtime 0.2.1-beta → 0.2.2-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,166 +1,167 @@
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
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
+
19
+ 1. Selecting a runtime (Node.js, C#, etc.)
20
+ 2. Choosing a template (simple-voice-ivr recommended for first project)
21
+ 3. Setting up your project
22
+
23
+ Then start the local development server:
24
+
25
+ ```bash
26
+ sinch functions dev
27
+ ```
28
+
29
+ Your function is now running locally with hot reload!
30
+
31
+ ## Deploy to Production
32
+
33
+ When you're ready to deploy:
34
+
35
+ ```bash
36
+ sinch functions deploy
37
+ ```
38
+
39
+ Your function will be built and deployed to the Sinch Functions platform.
40
+
41
+ ## Features
42
+
43
+ ### SVAML Builders
44
+
45
+ Build voice responses with a fluent API:
46
+
47
+ ```typescript
48
+ import { IceSvamlBuilder, AceSvamlBuilder, PieSvamlBuilder } from '@sinch/functions-runtime';
49
+
50
+ // ICE (Incoming Call Event) - handle incoming calls
51
+ const iceResponse = new IceSvamlBuilder()
52
+ .say('Hello, welcome!')
53
+ .connectPstn('+15551234567', {
54
+ cli: '+15559999999',
55
+ enableAce: true,
56
+ enableDice: true
57
+ })
58
+ .build();
59
+
60
+ // ACE (Answered Call Event) - handle answered outbound calls
61
+ const aceResponse = new AceSvamlBuilder()
62
+ .say('The call has been answered.')
63
+ .continue()
64
+ .build();
65
+
66
+ // PIE (Prompt Input Event) - handle user input
67
+ const pieResponse = new PieSvamlBuilder()
68
+ .say('You pressed ' + selection)
69
+ .hangup()
70
+ .build();
71
+ ```
72
+
73
+ ### Menu Builder
74
+
75
+ Create IVR menus with validation:
76
+
77
+ ```typescript
78
+ import { MenuBuilder, MenuTemplates } from '@sinch/functions-runtime';
79
+
80
+ // Use pre-built templates
81
+ const businessMenu = MenuTemplates.business('Acme Corp');
82
+ const yesNoMenu = MenuTemplates.yesNo('Do you want to continue?');
83
+
84
+ // Or build custom menus
85
+ const customMenu = new MenuBuilder()
86
+ .prompt('Press 1 for English, 2 for Spanish')
87
+ .option('1', 'menu(english)')
88
+ .option('2', 'menu(spanish)')
89
+ .addSubmenu('english')
90
+ .prompt('Press 1 for sales, 2 for support')
91
+ .option('1', 'return(en-sales)')
92
+ .option('2', 'return(en-support)')
93
+ .build();
94
+ ```
95
+
96
+ ### Cache
97
+
98
+ Store and retrieve data across function invocations:
99
+
100
+ ```typescript
101
+ export async function ice(context, event) {
102
+ const cache = context.cache;
103
+
104
+ // Store data
105
+ await cache.set('call-count', 1, 3600); // TTL in seconds
106
+
107
+ // Retrieve data
108
+ const count = await cache.get('call-count');
109
+ }
110
+ ```
111
+
112
+ ### Configuration
113
+
114
+ Access environment variables and secrets:
115
+
116
+ ```typescript
117
+ import { createConfig } from '@sinch/functions-runtime';
118
+
119
+ export async function ice(context, event) {
120
+ const config = createConfig(context);
121
+
122
+ // Get variables
123
+ const companyName = config.getVariable('COMPANY_NAME', 'Default');
124
+
125
+ // Get secrets (encrypted at rest)
126
+ const apiKey = config.getSecret('API_KEY');
127
+ }
128
+ ```
129
+
130
+ ## Voice Callbacks
131
+
132
+ | Callback | Description | Returns |
133
+ |----------|-------------|---------|
134
+ | `ice` | Incoming Call Event - first callback for incoming calls | SVAML |
135
+ | `ace` | Answered Call Event - when outbound call is answered | SVAML |
136
+ | `pie` | Prompt Input Event - user input (DTMF/voice) | SVAML |
137
+ | `dice` | Disconnected Call Event - call ended | None |
138
+ | `notify` | Notification events | None |
139
+
140
+ ## TypeScript Support
141
+
142
+ Full TypeScript support with comprehensive types:
143
+
144
+ ```typescript
145
+ import type {
146
+ FunctionContext,
147
+ IceCallbackData,
148
+ SvamletResponse
149
+ } from '@sinch/functions-runtime';
150
+
151
+ export async function ice(
152
+ context: FunctionContext,
153
+ event: IceCallbackData
154
+ ): Promise<SvamletResponse> {
155
+ // Full type safety and IntelliSense!
156
+ }
157
+ ```
158
+
159
+ ## Documentation
160
+
161
+ - [Sinch Functions Documentation](https://developers.sinch.com/docs/functions)
162
+ - [Sinch Voice API](https://developers.sinch.com/docs/voice)
163
+ - [SVAML Reference](https://developers.sinch.com/docs/voice/api-reference/svaml)
164
+
165
+ ## License
166
+
167
+ MIT
File without changes