@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 +167 -166
- package/dist/bin/sinch-runtime.js +0 -0
- package/dist/bin/sinch-runtime.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
.
|
|
63
|
-
.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.
|
|
69
|
-
.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
.
|
|
87
|
-
.option('
|
|
88
|
-
.
|
|
89
|
-
.
|
|
90
|
-
.
|
|
91
|
-
.option('
|
|
92
|
-
.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
| `
|
|
135
|
-
| `
|
|
136
|
-
| `
|
|
137
|
-
| `
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
- [Sinch
|
|
162
|
-
- [
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|