@sinch/functions-runtime 0.2.3-beta → 0.3.0
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 +10 -17
- package/dist/bin/sinch-runtime.js +19 -15
- package/dist/bin/sinch-runtime.js.map +1 -1
- package/dist/index.js +37 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,15 +53,12 @@ const iceResponse = new IceSvamlBuilder()
|
|
|
53
53
|
.connectPstn('+15551234567', {
|
|
54
54
|
cli: '+15559999999',
|
|
55
55
|
enableAce: true,
|
|
56
|
-
enableDice: true
|
|
56
|
+
enableDice: true,
|
|
57
57
|
})
|
|
58
58
|
.build();
|
|
59
59
|
|
|
60
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();
|
|
61
|
+
const aceResponse = new AceSvamlBuilder().say('The call has been answered.').continue().build();
|
|
65
62
|
|
|
66
63
|
// PIE (Prompt Input Event) - handle user input
|
|
67
64
|
const pieResponse = new PieSvamlBuilder()
|
|
@@ -129,24 +126,20 @@ export async function ice(context, event) {
|
|
|
129
126
|
|
|
130
127
|
## Voice Callbacks
|
|
131
128
|
|
|
132
|
-
| Callback | Description
|
|
133
|
-
|
|
134
|
-
| `ice`
|
|
135
|
-
| `ace`
|
|
136
|
-
| `pie`
|
|
137
|
-
| `dice`
|
|
138
|
-
| `notify` | Notification events
|
|
129
|
+
| Callback | Description | Returns |
|
|
130
|
+
| -------- | ------------------------------------------------------- | ------- |
|
|
131
|
+
| `ice` | Incoming Call Event - first callback for incoming calls | SVAML |
|
|
132
|
+
| `ace` | Answered Call Event - when outbound call is answered | SVAML |
|
|
133
|
+
| `pie` | Prompt Input Event - user input (DTMF/voice) | SVAML |
|
|
134
|
+
| `dice` | Disconnected Call Event - call ended | None |
|
|
135
|
+
| `notify` | Notification events | None |
|
|
139
136
|
|
|
140
137
|
## TypeScript Support
|
|
141
138
|
|
|
142
139
|
Full TypeScript support with comprehensive types:
|
|
143
140
|
|
|
144
141
|
```typescript
|
|
145
|
-
import type {
|
|
146
|
-
FunctionContext,
|
|
147
|
-
IceCallbackData,
|
|
148
|
-
SvamletResponse
|
|
149
|
-
} from '@sinch/functions-runtime';
|
|
142
|
+
import type { FunctionContext, IceCallbackData, SvamletResponse } from '@sinch/functions-runtime';
|
|
150
143
|
|
|
151
144
|
export async function ice(
|
|
152
145
|
context: FunctionContext,
|
|
@@ -699,11 +699,11 @@ async function configureConversationWebhooks(tunnelUrl, config) {
|
|
|
699
699
|
keyId,
|
|
700
700
|
keySecret
|
|
701
701
|
});
|
|
702
|
-
const webhooksResult = await sinchClient.conversation.webhooks.list({
|
|
702
|
+
const webhooksResult = await sinchClient.conversation.webhooks.list({
|
|
703
|
+
app_id: conversationAppId
|
|
704
|
+
});
|
|
703
705
|
const existingWebhooks = webhooksResult.webhooks || [];
|
|
704
|
-
const tunnelWebhooks = existingWebhooks.filter(
|
|
705
|
-
(w) => w.target?.includes("/api/ingress/")
|
|
706
|
-
);
|
|
706
|
+
const tunnelWebhooks = existingWebhooks.filter((w) => w.target?.includes("/api/ingress/"));
|
|
707
707
|
for (const staleWebhook of tunnelWebhooks) {
|
|
708
708
|
try {
|
|
709
709
|
await sinchClient.conversation.webhooks.delete({ webhook_id: staleWebhook.id });
|
|
@@ -983,17 +983,21 @@ var TunnelClient = class {
|
|
|
983
983
|
try {
|
|
984
984
|
const updateUrl = `https://callingapi.sinch.com/v1/configuration/callbacks/applications/${appKey}/`;
|
|
985
985
|
const auth = Buffer.from(`${appKey}:${appSecret}`).toString("base64");
|
|
986
|
-
await axios.post(
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
986
|
+
await axios.post(
|
|
987
|
+
updateUrl,
|
|
988
|
+
{
|
|
989
|
+
url: {
|
|
990
|
+
primary: this.tunnelUrl,
|
|
991
|
+
fallback: null
|
|
992
|
+
}
|
|
993
|
+
},
|
|
994
|
+
{
|
|
995
|
+
headers: {
|
|
996
|
+
Authorization: `Basic ${auth}`,
|
|
997
|
+
"Content-Type": "application/json"
|
|
998
|
+
}
|
|
995
999
|
}
|
|
996
|
-
|
|
1000
|
+
);
|
|
997
1001
|
console.log("\u2705 Updated voice webhook URL");
|
|
998
1002
|
} catch (error) {
|
|
999
1003
|
console.log("\u26A0\uFE0F Could not update webhook URL:", error.message);
|
|
@@ -1003,7 +1007,7 @@ var TunnelClient = class {
|
|
|
1003
1007
|
const auth = Buffer.from(`${appKey}:${appSecret}`).toString("base64");
|
|
1004
1008
|
const response = await axios.get(listUrl, {
|
|
1005
1009
|
headers: {
|
|
1006
|
-
|
|
1010
|
+
Authorization: `Basic ${auth}`
|
|
1007
1011
|
}
|
|
1008
1012
|
});
|
|
1009
1013
|
const numbers = response.data?.numbers || [];
|