@sinch/functions-runtime 0.2.3-beta → 0.3.1

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
@@ -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 | 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 |
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,
@@ -686,8 +686,8 @@ async function configureConversationWebhooks(tunnelUrl, config) {
686
686
  try {
687
687
  const conversationAppId = process.env.CONVERSATION_APP_ID;
688
688
  const projectId = process.env.PROJECT_ID;
689
- const keyId = process.env.KEY_ID;
690
- const keySecret = process.env.KEY_SECRET;
689
+ const keyId = process.env.PROJECT_ID_API_KEY;
690
+ const keySecret = process.env.PROJECT_ID_API_SECRET;
691
691
  if (!conversationAppId || !projectId || !keyId || !keySecret) {
692
692
  console.log("\u{1F4A1} Conversation API not fully configured - skipping webhook setup");
693
693
  return;
@@ -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({ app_id: conversationAppId });
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 });
@@ -731,8 +731,8 @@ async function cleanupConversationWebhook(config) {
731
731
  try {
732
732
  const conversationAppId = process.env.CONVERSATION_APP_ID;
733
733
  const projectId = process.env.PROJECT_ID;
734
- const keyId = process.env.KEY_ID;
735
- const keySecret = process.env.KEY_SECRET;
734
+ const keyId = process.env.PROJECT_ID_API_KEY;
735
+ const keySecret = process.env.PROJECT_ID_API_SECRET;
736
736
  if (!conversationAppId || !projectId || !keyId || !keySecret) return;
737
737
  const sinchClient = new SinchClient2({
738
738
  projectId,
@@ -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(updateUrl, {
987
- url: {
988
- primary: this.tunnelUrl,
989
- fallback: null
990
- }
991
- }, {
992
- headers: {
993
- "Authorization": `Basic ${auth}`,
994
- "Content-Type": "application/json"
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
- "Authorization": `Basic ${auth}`
1010
+ Authorization: `Basic ${auth}`
1007
1011
  }
1008
1012
  });
1009
1013
  const numbers = response.data?.numbers || [];