telnyx 7.18.0 → 7.20.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/CHANGELOG.md +22 -0
- package/README.md +90 -0
- package/client.d.mts +3 -6
- package/client.d.mts.map +1 -1
- package/client.d.ts +3 -6
- package/client.d.ts.map +1 -1
- package/client.js +3 -6
- package/client.js.map +1 -1
- package/client.mjs +3 -6
- package/client.mjs.map +1 -1
- package/lib/webhooks.d.mts +1 -1
- package/lib/webhooks.d.mts.map +1 -1
- package/lib/webhooks.d.ts +1 -1
- package/lib/webhooks.d.ts.map +1 -1
- package/lib/webhooks.js +74 -39
- package/lib/webhooks.js.map +1 -1
- package/lib/webhooks.mjs +52 -17
- package/lib/webhooks.mjs.map +1 -1
- package/package.json +3 -5
- package/resources/ai/assistants/assistants.d.mts +49 -20
- package/resources/ai/assistants/assistants.d.mts.map +1 -1
- package/resources/ai/assistants/assistants.d.ts +49 -20
- package/resources/ai/assistants/assistants.d.ts.map +1 -1
- package/resources/ai/assistants/assistants.js.map +1 -1
- package/resources/ai/assistants/assistants.mjs.map +1 -1
- package/resources/calls/actions.d.mts +8 -0
- package/resources/calls/actions.d.mts.map +1 -1
- package/resources/calls/actions.d.ts +8 -0
- package/resources/calls/actions.d.ts.map +1 -1
- package/resources/calls/calls.d.mts +8 -0
- package/resources/calls/calls.d.mts.map +1 -1
- package/resources/calls/calls.d.ts +8 -0
- package/resources/calls/calls.d.ts.map +1 -1
- package/resources/calls/calls.js.map +1 -1
- package/resources/calls/calls.mjs.map +1 -1
- package/resources/credential-connections/actions.d.mts +9 -9
- package/resources/credential-connections/actions.d.mts.map +1 -1
- package/resources/credential-connections/actions.d.ts +9 -9
- package/resources/credential-connections/actions.d.ts.map +1 -1
- package/resources/credential-connections/actions.js +3 -3
- package/resources/credential-connections/actions.mjs +3 -3
- package/resources/credential-connections/credential-connections.d.mts +2 -2
- package/resources/credential-connections/credential-connections.d.ts +2 -2
- package/resources/external-requirements/external-requirements.d.mts +10 -0
- package/resources/external-requirements/external-requirements.d.mts.map +1 -0
- package/resources/external-requirements/external-requirements.d.ts +10 -0
- package/resources/external-requirements/external-requirements.d.ts.map +1 -0
- package/resources/external-requirements/external-requirements.js +17 -0
- package/resources/external-requirements/external-requirements.js.map +1 -0
- package/resources/external-requirements/external-requirements.mjs +12 -0
- package/resources/external-requirements/external-requirements.mjs.map +1 -0
- package/resources/external-requirements/index.d.mts +3 -0
- package/resources/external-requirements/index.d.mts.map +1 -0
- package/resources/external-requirements/index.d.ts +3 -0
- package/resources/external-requirements/index.d.ts.map +1 -0
- package/resources/external-requirements/index.js +9 -0
- package/resources/external-requirements/index.js.map +1 -0
- package/resources/external-requirements/index.mjs +4 -0
- package/resources/external-requirements/index.mjs.map +1 -0
- package/resources/external-requirements/sub-number-orders.d.mts +151 -0
- package/resources/external-requirements/sub-number-orders.d.mts.map +1 -0
- package/resources/external-requirements/sub-number-orders.d.ts +151 -0
- package/resources/external-requirements/sub-number-orders.d.ts.map +1 -0
- package/resources/external-requirements/sub-number-orders.js +61 -0
- package/resources/external-requirements/sub-number-orders.js.map +1 -0
- package/resources/external-requirements/sub-number-orders.mjs +57 -0
- package/resources/external-requirements/sub-number-orders.mjs.map +1 -0
- package/resources/external-requirements.d.mts +2 -0
- package/resources/external-requirements.d.mts.map +1 -0
- package/resources/external-requirements.d.ts +2 -0
- package/resources/external-requirements.d.ts.map +1 -0
- package/resources/external-requirements.js +6 -0
- package/resources/external-requirements.js.map +1 -0
- package/resources/external-requirements.mjs +3 -0
- package/resources/external-requirements.mjs.map +1 -0
- package/resources/index.d.mts +1 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +5 -5
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/outbound-voice-profiles.d.mts +30 -30
- package/resources/outbound-voice-profiles.d.ts +30 -30
- package/resources/uac-connections/actions.d.mts +9 -9
- package/resources/uac-connections/actions.d.mts.map +1 -1
- package/resources/uac-connections/actions.d.ts +9 -9
- package/resources/uac-connections/actions.d.ts.map +1 -1
- package/resources/uac-connections/actions.js +3 -3
- package/resources/uac-connections/actions.mjs +3 -3
- package/resources/webhooks.d.mts +1 -1
- package/resources/webhooks.d.mts.map +1 -1
- package/resources/webhooks.d.ts +1 -1
- package/resources/webhooks.d.ts.map +1 -1
- package/resources/webhooks.js +4 -11
- package/resources/webhooks.js.map +1 -1
- package/resources/webhooks.mjs +4 -11
- package/resources/webhooks.mjs.map +1 -1
- package/src/client.ts +5 -16
- package/src/lib/webhooks.ts +59 -18
- package/src/resources/ai/assistants/assistants.ts +52 -19
- package/src/resources/calls/actions.ts +9 -0
- package/src/resources/calls/calls.ts +9 -0
- package/src/resources/credential-connections/actions.ts +9 -9
- package/src/resources/credential-connections/credential-connections.ts +2 -2
- package/src/resources/external-requirements/external-requirements.ts +27 -0
- package/src/resources/external-requirements/index.ts +10 -0
- package/src/resources/external-requirements/sub-number-orders.ts +202 -0
- package/src/resources/external-requirements.ts +3 -0
- package/src/resources/index.ts +1 -5
- package/src/resources/outbound-voice-profiles.ts +30 -30
- package/src/resources/uac-connections/actions.ts +9 -9
- package/src/resources/webhooks.ts +5 -11
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/resources/sip-registration-status.d.mts +0 -142
- package/resources/sip-registration-status.d.mts.map +0 -1
- package/resources/sip-registration-status.d.ts +0 -142
- package/resources/sip-registration-status.d.ts.map +0 -1
- package/resources/sip-registration-status.js +0 -32
- package/resources/sip-registration-status.js.map +0 -1
- package/resources/sip-registration-status.mjs +0 -28
- package/resources/sip-registration-status.mjs.map +0 -1
- package/src/resources/sip-registration-status.ts +0 -181
package/lib/webhooks.js
CHANGED
|
@@ -1,26 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
* Telnyx webhook verification using native Ed25519.
|
|
4
|
-
*
|
|
5
|
-
* This class provides Ed25519 signature verification for Telnyx webhooks
|
|
6
|
-
* using Node's built-in crypto module (no external dependencies).
|
|
7
|
-
*
|
|
8
|
-
* @example Using base64 public key from Mission Control
|
|
9
|
-
* const webhook = new TelnyxWebhook('eu2zvPjhY6odxV34Z/EsRiERvTodkev4Fq0SlK90Izg=');
|
|
10
|
-
* await webhook.verify(payload, headers);
|
|
11
|
-
*
|
|
12
|
-
* @example Using with Telnyx client
|
|
13
|
-
* const client = new Telnyx({
|
|
14
|
-
* apiKey: process.env.TELNYX_API_KEY,
|
|
15
|
-
* publicKey: process.env.TELNYX_PUBLIC_KEY, // Base64 string from Mission Control
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
18
|
-
* // Express example
|
|
19
|
-
* app.post('/webhooks', express.raw({ type: 'application/json' }), async (req, res) => {
|
|
20
|
-
* const event = await client.webhooks.unwrap(req.body.toString(), { headers: req.headers });
|
|
21
|
-
* // Signature automatically verified
|
|
22
|
-
* });
|
|
23
|
-
*/
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
24
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
25
4
|
if (k2 === undefined) k2 = k;
|
|
26
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -58,6 +37,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
58
37
|
exports.TelnyxWebhook = exports.TelnyxWebhookVerificationError = void 0;
|
|
59
38
|
exports.unsafeUnwrapWebhook = unsafeUnwrapWebhook;
|
|
60
39
|
exports.unwrapWebhook = unwrapWebhook;
|
|
40
|
+
/**
|
|
41
|
+
* Telnyx webhook verification using native Ed25519.
|
|
42
|
+
*
|
|
43
|
+
* This class provides Ed25519 signature verification for Telnyx webhooks
|
|
44
|
+
* using Node's built-in crypto module (no external dependencies).
|
|
45
|
+
*
|
|
46
|
+
* @example Using base64 public key from Mission Control
|
|
47
|
+
* const webhook = new TelnyxWebhook('eu2zvPjhY6odxV34Z/EsRiERvTodkev4Fq0SlK90Izg=');
|
|
48
|
+
* await webhook.verify(payload, headers);
|
|
49
|
+
*
|
|
50
|
+
* @example Using with Telnyx client
|
|
51
|
+
* const client = new Telnyx({
|
|
52
|
+
* apiKey: process.env.TELNYX_API_KEY,
|
|
53
|
+
* publicKey: process.env.TELNYX_PUBLIC_KEY, // Base64 string from Mission Control
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* // Express example
|
|
57
|
+
* app.post('/webhooks', express.raw({ type: 'application/json' }), async (req, res) => {
|
|
58
|
+
* const event = await client.webhooks.unwrap(req.body.toString(), { headers: req.headers });
|
|
59
|
+
* // Signature automatically verified
|
|
60
|
+
* });
|
|
61
|
+
*/
|
|
61
62
|
const error_1 = require("../core/error.js");
|
|
62
63
|
class TelnyxWebhookVerificationError extends error_1.TelnyxError {
|
|
63
64
|
constructor(message) {
|
|
@@ -70,16 +71,45 @@ function unsafeUnwrapWebhook(body) {
|
|
|
70
71
|
return JSON.parse(body);
|
|
71
72
|
}
|
|
72
73
|
async function unwrapWebhook(body, options, clientPublicKey) {
|
|
73
|
-
if (options?.headers) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
await webhook.verify(body, options.headers);
|
|
74
|
+
if (!options?.headers) {
|
|
75
|
+
throw new TelnyxWebhookVerificationError('Webhook headers are required for verification');
|
|
76
|
+
}
|
|
77
|
+
const key = options.key || clientPublicKey;
|
|
78
|
+
if (!key) {
|
|
79
|
+
throw new TelnyxWebhookVerificationError('No public key provided for webhook verification');
|
|
80
80
|
}
|
|
81
|
+
const webhook = new TelnyxWebhook(key);
|
|
82
|
+
await webhook.verify(body, options.headers);
|
|
81
83
|
return unsafeUnwrapWebhook(body);
|
|
82
84
|
}
|
|
85
|
+
const BASE64_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
86
|
+
/** Decode strict, padded base64 without relying on Node's Buffer global. */
|
|
87
|
+
function decodeBase64(value) {
|
|
88
|
+
if (value.length === 0 || value.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(value)) {
|
|
89
|
+
throw new Error('Invalid base64');
|
|
90
|
+
}
|
|
91
|
+
const padding = value.endsWith('==') ? 2
|
|
92
|
+
: value.endsWith('=') ? 1
|
|
93
|
+
: 0;
|
|
94
|
+
const output = new Uint8Array((value.length / 4) * 3 - padding);
|
|
95
|
+
let outputIndex = 0;
|
|
96
|
+
for (let index = 0; index < value.length; index += 4) {
|
|
97
|
+
const a = BASE64_ALPHABET.indexOf(value[index]);
|
|
98
|
+
const b = BASE64_ALPHABET.indexOf(value[index + 1]);
|
|
99
|
+
const c = value[index + 2] === '=' ? 0 : BASE64_ALPHABET.indexOf(value[index + 2]);
|
|
100
|
+
const d = value[index + 3] === '=' ? 0 : BASE64_ALPHABET.indexOf(value[index + 3]);
|
|
101
|
+
if (a < 0 || b < 0 || c < 0 || d < 0)
|
|
102
|
+
throw new Error('Invalid base64');
|
|
103
|
+
const chunk = (a << 18) | (b << 12) | (c << 6) | d;
|
|
104
|
+
if (outputIndex < output.length)
|
|
105
|
+
output[outputIndex++] = (chunk >> 16) & 0xff;
|
|
106
|
+
if (outputIndex < output.length)
|
|
107
|
+
output[outputIndex++] = (chunk >> 8) & 0xff;
|
|
108
|
+
if (outputIndex < output.length)
|
|
109
|
+
output[outputIndex++] = chunk & 0xff;
|
|
110
|
+
}
|
|
111
|
+
return output;
|
|
112
|
+
}
|
|
83
113
|
// Get crypto implementation (works in Node.js and browsers)
|
|
84
114
|
async function getCrypto() {
|
|
85
115
|
if (typeof globalThis.crypto !== 'undefined' && globalThis.crypto.subtle) {
|
|
@@ -100,11 +130,11 @@ class TelnyxWebhook {
|
|
|
100
130
|
if (typeof key === 'string') {
|
|
101
131
|
try {
|
|
102
132
|
// Telnyx provides keys in base64 format
|
|
103
|
-
const keyBytes =
|
|
133
|
+
const keyBytes = decodeBase64(key);
|
|
104
134
|
if (keyBytes.length !== 32) {
|
|
105
135
|
throw new TelnyxWebhookVerificationError(`Invalid public key: expected 32 bytes, got ${keyBytes.length} bytes`);
|
|
106
136
|
}
|
|
107
|
-
this.verifyKey =
|
|
137
|
+
this.verifyKey = keyBytes;
|
|
108
138
|
}
|
|
109
139
|
catch (exc) {
|
|
110
140
|
if (exc instanceof TelnyxWebhookVerificationError) {
|
|
@@ -114,6 +144,9 @@ class TelnyxWebhook {
|
|
|
114
144
|
}
|
|
115
145
|
}
|
|
116
146
|
else {
|
|
147
|
+
if (key.length !== 32) {
|
|
148
|
+
throw new TelnyxWebhookVerificationError(`Invalid public key: expected 32 bytes, got ${key.length} bytes`);
|
|
149
|
+
}
|
|
117
150
|
this.verifyKey = key;
|
|
118
151
|
}
|
|
119
152
|
}
|
|
@@ -137,7 +170,13 @@ class TelnyxWebhook {
|
|
|
137
170
|
}
|
|
138
171
|
// Validate timestamp format and prevent replay attacks
|
|
139
172
|
try {
|
|
140
|
-
|
|
173
|
+
if (!/^\d+$/.test(timestampHeader)) {
|
|
174
|
+
throw new TelnyxWebhookVerificationError(`Invalid timestamp format: ${timestampHeader}`);
|
|
175
|
+
}
|
|
176
|
+
const webhookTime = Number(timestampHeader);
|
|
177
|
+
if (!Number.isSafeInteger(webhookTime)) {
|
|
178
|
+
throw new TelnyxWebhookVerificationError(`Invalid timestamp format: ${timestampHeader}`);
|
|
179
|
+
}
|
|
141
180
|
const currentTime = Math.floor(Date.now() / 1000);
|
|
142
181
|
// Allow 5 minutes tolerance
|
|
143
182
|
if (Math.abs(currentTime - webhookTime) > 300) {
|
|
@@ -153,7 +192,7 @@ class TelnyxWebhook {
|
|
|
153
192
|
// Decode the signature from base64
|
|
154
193
|
let signature;
|
|
155
194
|
try {
|
|
156
|
-
const signatureBuffer =
|
|
195
|
+
const signatureBuffer = decodeBase64(signatureHeader);
|
|
157
196
|
if (signatureBuffer.length !== 64) {
|
|
158
197
|
throw new Error(`Invalid signature length: expected 64 bytes, got ${signatureBuffer.length} bytes`);
|
|
159
198
|
}
|
|
@@ -162,13 +201,9 @@ class TelnyxWebhook {
|
|
|
162
201
|
catch (exc) {
|
|
163
202
|
throw new TelnyxWebhookVerificationError(`Invalid signature format: ${signatureHeader}`);
|
|
164
203
|
}
|
|
165
|
-
// Create the signed payload: timestamp|payload
|
|
204
|
+
// Create the exact signed payload: timestamp|unmodified payload
|
|
166
205
|
const encoder = new TextEncoder();
|
|
167
|
-
const signedPayload =
|
|
168
|
-
...encoder.encode(timestampHeader),
|
|
169
|
-
...encoder.encode('|'),
|
|
170
|
-
...encoder.encode(payload),
|
|
171
|
-
]);
|
|
206
|
+
const signedPayload = encoder.encode(`${timestampHeader}|${payload}`);
|
|
172
207
|
// Verify the signature using native crypto
|
|
173
208
|
let isValid;
|
|
174
209
|
try {
|
package/lib/webhooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/lib/webhooks.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/lib/webhooks.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCtF,kDAEC;AAED,sCAiBC;AA1DD;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,4CAA4C;AAE5C,MAAa,8BAA+B,SAAQ,mBAAW;IAC7D,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC/C,CAAC;CACF;AALD,wEAKC;AAOD,SAAgB,mBAAmB,CAAI,IAAY;IACjD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAC;AAC/B,CAAC;AAEM,KAAK,UAAU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ClE,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACK,SAAS,CAAC,OAA+B,EAAE,IAAY;QAC7D,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACrC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACnD,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,SAAS,EAAE,CAAC;gBACpC,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAlID,sCAkIC"}
|
package/lib/webhooks.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
1
2
|
/**
|
|
2
3
|
* Telnyx webhook verification using native Ed25519.
|
|
3
4
|
*
|
|
@@ -31,16 +32,45 @@ export function unsafeUnwrapWebhook(body) {
|
|
|
31
32
|
return JSON.parse(body);
|
|
32
33
|
}
|
|
33
34
|
export async function unwrapWebhook(body, options, clientPublicKey) {
|
|
34
|
-
if (options?.headers) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
await webhook.verify(body, options.headers);
|
|
35
|
+
if (!options?.headers) {
|
|
36
|
+
throw new TelnyxWebhookVerificationError('Webhook headers are required for verification');
|
|
37
|
+
}
|
|
38
|
+
const key = options.key || clientPublicKey;
|
|
39
|
+
if (!key) {
|
|
40
|
+
throw new TelnyxWebhookVerificationError('No public key provided for webhook verification');
|
|
41
41
|
}
|
|
42
|
+
const webhook = new TelnyxWebhook(key);
|
|
43
|
+
await webhook.verify(body, options.headers);
|
|
42
44
|
return unsafeUnwrapWebhook(body);
|
|
43
45
|
}
|
|
46
|
+
const BASE64_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
47
|
+
/** Decode strict, padded base64 without relying on Node's Buffer global. */
|
|
48
|
+
function decodeBase64(value) {
|
|
49
|
+
if (value.length === 0 || value.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(value)) {
|
|
50
|
+
throw new Error('Invalid base64');
|
|
51
|
+
}
|
|
52
|
+
const padding = value.endsWith('==') ? 2
|
|
53
|
+
: value.endsWith('=') ? 1
|
|
54
|
+
: 0;
|
|
55
|
+
const output = new Uint8Array((value.length / 4) * 3 - padding);
|
|
56
|
+
let outputIndex = 0;
|
|
57
|
+
for (let index = 0; index < value.length; index += 4) {
|
|
58
|
+
const a = BASE64_ALPHABET.indexOf(value[index]);
|
|
59
|
+
const b = BASE64_ALPHABET.indexOf(value[index + 1]);
|
|
60
|
+
const c = value[index + 2] === '=' ? 0 : BASE64_ALPHABET.indexOf(value[index + 2]);
|
|
61
|
+
const d = value[index + 3] === '=' ? 0 : BASE64_ALPHABET.indexOf(value[index + 3]);
|
|
62
|
+
if (a < 0 || b < 0 || c < 0 || d < 0)
|
|
63
|
+
throw new Error('Invalid base64');
|
|
64
|
+
const chunk = (a << 18) | (b << 12) | (c << 6) | d;
|
|
65
|
+
if (outputIndex < output.length)
|
|
66
|
+
output[outputIndex++] = (chunk >> 16) & 0xff;
|
|
67
|
+
if (outputIndex < output.length)
|
|
68
|
+
output[outputIndex++] = (chunk >> 8) & 0xff;
|
|
69
|
+
if (outputIndex < output.length)
|
|
70
|
+
output[outputIndex++] = chunk & 0xff;
|
|
71
|
+
}
|
|
72
|
+
return output;
|
|
73
|
+
}
|
|
44
74
|
// Get crypto implementation (works in Node.js and browsers)
|
|
45
75
|
async function getCrypto() {
|
|
46
76
|
if (typeof globalThis.crypto !== 'undefined' && globalThis.crypto.subtle) {
|
|
@@ -61,11 +91,11 @@ export class TelnyxWebhook {
|
|
|
61
91
|
if (typeof key === 'string') {
|
|
62
92
|
try {
|
|
63
93
|
// Telnyx provides keys in base64 format
|
|
64
|
-
const keyBytes =
|
|
94
|
+
const keyBytes = decodeBase64(key);
|
|
65
95
|
if (keyBytes.length !== 32) {
|
|
66
96
|
throw new TelnyxWebhookVerificationError(`Invalid public key: expected 32 bytes, got ${keyBytes.length} bytes`);
|
|
67
97
|
}
|
|
68
|
-
this.verifyKey =
|
|
98
|
+
this.verifyKey = keyBytes;
|
|
69
99
|
}
|
|
70
100
|
catch (exc) {
|
|
71
101
|
if (exc instanceof TelnyxWebhookVerificationError) {
|
|
@@ -75,6 +105,9 @@ export class TelnyxWebhook {
|
|
|
75
105
|
}
|
|
76
106
|
}
|
|
77
107
|
else {
|
|
108
|
+
if (key.length !== 32) {
|
|
109
|
+
throw new TelnyxWebhookVerificationError(`Invalid public key: expected 32 bytes, got ${key.length} bytes`);
|
|
110
|
+
}
|
|
78
111
|
this.verifyKey = key;
|
|
79
112
|
}
|
|
80
113
|
}
|
|
@@ -98,7 +131,13 @@ export class TelnyxWebhook {
|
|
|
98
131
|
}
|
|
99
132
|
// Validate timestamp format and prevent replay attacks
|
|
100
133
|
try {
|
|
101
|
-
|
|
134
|
+
if (!/^\d+$/.test(timestampHeader)) {
|
|
135
|
+
throw new TelnyxWebhookVerificationError(`Invalid timestamp format: ${timestampHeader}`);
|
|
136
|
+
}
|
|
137
|
+
const webhookTime = Number(timestampHeader);
|
|
138
|
+
if (!Number.isSafeInteger(webhookTime)) {
|
|
139
|
+
throw new TelnyxWebhookVerificationError(`Invalid timestamp format: ${timestampHeader}`);
|
|
140
|
+
}
|
|
102
141
|
const currentTime = Math.floor(Date.now() / 1000);
|
|
103
142
|
// Allow 5 minutes tolerance
|
|
104
143
|
if (Math.abs(currentTime - webhookTime) > 300) {
|
|
@@ -114,7 +153,7 @@ export class TelnyxWebhook {
|
|
|
114
153
|
// Decode the signature from base64
|
|
115
154
|
let signature;
|
|
116
155
|
try {
|
|
117
|
-
const signatureBuffer =
|
|
156
|
+
const signatureBuffer = decodeBase64(signatureHeader);
|
|
118
157
|
if (signatureBuffer.length !== 64) {
|
|
119
158
|
throw new Error(`Invalid signature length: expected 64 bytes, got ${signatureBuffer.length} bytes`);
|
|
120
159
|
}
|
|
@@ -123,13 +162,9 @@ export class TelnyxWebhook {
|
|
|
123
162
|
catch (exc) {
|
|
124
163
|
throw new TelnyxWebhookVerificationError(`Invalid signature format: ${signatureHeader}`);
|
|
125
164
|
}
|
|
126
|
-
// Create the signed payload: timestamp|payload
|
|
165
|
+
// Create the exact signed payload: timestamp|unmodified payload
|
|
127
166
|
const encoder = new TextEncoder();
|
|
128
|
-
const signedPayload =
|
|
129
|
-
...encoder.encode(timestampHeader),
|
|
130
|
-
...encoder.encode('|'),
|
|
131
|
-
...encoder.encode(payload),
|
|
132
|
-
]);
|
|
167
|
+
const signedPayload = encoder.encode(`${timestampHeader}|${payload}`);
|
|
133
168
|
// Verify the signature using native crypto
|
|
134
169
|
let isValid;
|
|
135
170
|
try {
|
package/lib/webhooks.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.mjs","sourceRoot":"","sources":["../src/lib/webhooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,WAAW,EAAE,0BAAsB;AAE5C,MAAM,OAAO,8BAA+B,SAAQ,WAAW;IAC7D,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC/C,CAAC;CACF;AAOD,MAAM,UAAU,mBAAmB,CAAI,IAAY;IACjD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAC;AAC/B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAY,EACZ,OAAyC,EACzC,eAA8B;IAE9B,IAAI,OAAO,EAAE,OAAO,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"webhooks.mjs","sourceRoot":"","sources":["../src/lib/webhooks.ts"],"names":[],"mappings":"AAAA,s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AC,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE;gBACjG,QAAQ;aACT,CAAC,CAAC;YAEH,OAAO,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;QACvF,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,8BAA8B,CAAC,0DAA0D,CAAC,CAAC;QACvG,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,8BAA8B,CACtC,iEAAiE,CAClE,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACK,SAAS,CAAC,OAA+B,EAAE,IAAY;QAC7D,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACrC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACnD,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,SAAS,EAAE,CAAC;gBACpC,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "telnyx",
|
|
3
|
-
"version": "7.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "7.20.0",
|
|
4
|
+
"description": "The official TypeScript library for the Telnyx API",
|
|
5
5
|
"author": "Telnyx <support@telnyx.com>",
|
|
6
6
|
"types": "./index.d.ts",
|
|
7
7
|
"main": "./index.js",
|
|
@@ -15,9 +15,7 @@
|
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"standardwebhooks": "^1.0.0"
|
|
20
|
-
},
|
|
18
|
+
"dependencies": {},
|
|
21
19
|
"peerDependencies": {
|
|
22
20
|
"ws": "^8.18.0"
|
|
23
21
|
},
|
|
@@ -373,6 +373,15 @@ export declare namespace AssistantTool {
|
|
|
373
373
|
* Telnyx manage it.
|
|
374
374
|
*/
|
|
375
375
|
description?: string;
|
|
376
|
+
/**
|
|
377
|
+
* The number the inbound call was received on, forwarded so an unverified
|
|
378
|
+
* non-Telnyx `from` can be used as the caller id -- typically to transfer out as
|
|
379
|
+
* the original caller by pairing `from: "{{telnyx_end_user_target}}"` with
|
|
380
|
+
* `diversion: "{{telnyx_agent_target}}"`. The caller id is only accepted while
|
|
381
|
+
* that number is still on an active inbound call to this `diversion` number, and
|
|
382
|
+
* the `diversion` number must be one you own or have verified.
|
|
383
|
+
*/
|
|
384
|
+
diversion?: string;
|
|
376
385
|
/**
|
|
377
386
|
* Configuration for voicemail detection (AMD - Answering Machine Detection) on the
|
|
378
387
|
* transferred call. Allows the assistant to detect when a voicemail system answers
|
|
@@ -2206,17 +2215,19 @@ export interface TranscriptionSettings {
|
|
|
2206
2215
|
* supported models will automatically detect the language. For `deepgram/flux`,
|
|
2207
2216
|
* supported values are: `auto` (Telnyx language detection controls the language
|
|
2208
2217
|
* hint), `multi` (no language hint), and language-specific hints `en`, `es`, `fr`,
|
|
2209
|
-
* `de`, `hi`, `ru`, `pt`, `ja`, `it`, and `nl`. For `soniox/stt-rt-v4
|
|
2210
|
-
* omits the language hint and lets Soniox auto-detect;
|
|
2211
|
-
* `es`) bias detection toward that language
|
|
2212
|
-
*
|
|
2213
|
-
*
|
|
2214
|
-
*
|
|
2215
|
-
* `
|
|
2216
|
-
*
|
|
2217
|
-
*
|
|
2218
|
-
* `
|
|
2219
|
-
*
|
|
2218
|
+
* `de`, `hi`, `ru`, `pt`, `ja`, `it`, and `nl`. For `soniox/stt-rt-v4` and
|
|
2219
|
+
* `soniox/stt-rt-v5`, `auto` omits the language hint and lets Soniox auto-detect;
|
|
2220
|
+
* ISO 639-1 codes (e.g. `en`, `es`) bias detection toward that language;
|
|
2221
|
+
* `settings.language_hints` can pin multiple languages at once instead. For
|
|
2222
|
+
* `humain/realtime`, supported values are `ar`, `en`, `codeswitch` (Arabic/English
|
|
2223
|
+
* code-switching), and `auto` (resolves server-side to code-switching). Unlike
|
|
2224
|
+
* other models, `humain/realtime` does not fall back to `auto` when `language` is
|
|
2225
|
+
* omitted — omitting it applies `en` instead. For `reson8/turns`, supported values
|
|
2226
|
+
* are `auto` (or unset) for automatic language detection, and the language codes
|
|
2227
|
+
* `nl`, `en`, `fr`, `fy`, `de`, `it`, `pl`, `pt`, `es`, and `sv` to fix the
|
|
2228
|
+
* transcription language. For `cohere/ar-stt`, supported values are `ar` and `en`;
|
|
2229
|
+
* unlike other models, this model does not auto-detect and defaults to `ar` when
|
|
2230
|
+
* `language` is omitted.
|
|
2220
2231
|
*/
|
|
2221
2232
|
language?: string;
|
|
2222
2233
|
/**
|
|
@@ -2230,8 +2241,9 @@ export interface TranscriptionSettings {
|
|
|
2230
2241
|
* - `assemblyai/universal-streaming` is a multilingual streaming model with
|
|
2231
2242
|
* configurable turn detection.
|
|
2232
2243
|
* - `xai/grok-stt` is a multilingual Grok STT model.
|
|
2233
|
-
* - `soniox/stt-rt-v4`
|
|
2234
|
-
* detection
|
|
2244
|
+
* - `soniox/stt-rt-v4` and `soniox/stt-rt-v5` are multilingual streaming models
|
|
2245
|
+
* with automatic language detection, configurable endpointing, term biasing
|
|
2246
|
+
* (`context`), and `language_hints`.
|
|
2235
2247
|
* - `nvidia/parakeet-v3` is a multilingual transcription model with automatic
|
|
2236
2248
|
* language detection.
|
|
2237
2249
|
* - `humain/realtime` is a streaming model with native Arabic and Arabic/English
|
|
@@ -2240,7 +2252,7 @@ export interface TranscriptionSettings {
|
|
|
2240
2252
|
* with automatic language detection.
|
|
2241
2253
|
* - `cohere/ar-stt` is a non-streaming Arabic and English transcription model.
|
|
2242
2254
|
*/
|
|
2243
|
-
model?: 'deepgram/flux' | 'deepgram/nova-3' | 'deepgram/nova-2' | 'azure/fast' | 'assemblyai/universal-streaming' | 'xai/grok-stt' | 'soniox/stt-rt-v4' | 'nvidia/parakeet-v3' | 'humain/realtime' | 'reson8/turns' | 'cohere/ar-stt' | 'distil-whisper/distil-large-v2' | 'openai/whisper-large-v3-turbo';
|
|
2255
|
+
model?: 'deepgram/flux' | 'deepgram/nova-3' | 'deepgram/nova-2' | 'azure/fast' | 'assemblyai/universal-streaming' | 'xai/grok-stt' | 'soniox/stt-rt-v4' | 'soniox/stt-rt-v5' | 'nvidia/parakeet-v3' | 'humain/realtime' | 'reson8/turns' | 'cohere/ar-stt' | 'distil-whisper/distil-large-v2' | 'openai/whisper-large-v3-turbo';
|
|
2244
2256
|
/**
|
|
2245
2257
|
* Region on third party cloud providers (currently Azure) if using one of their
|
|
2246
2258
|
* models. Some regions require `api_key_ref`.
|
|
@@ -2249,6 +2261,16 @@ export interface TranscriptionSettings {
|
|
|
2249
2261
|
settings?: TranscriptionSettingsConfig;
|
|
2250
2262
|
}
|
|
2251
2263
|
export interface TranscriptionSettingsConfig {
|
|
2264
|
+
/**
|
|
2265
|
+
* Available only for soniox/stt-rt-v4 and soniox/stt-rt-v5. A comma-separated list
|
|
2266
|
+
* of terms to boost for recognition during transcription, for staff names,
|
|
2267
|
+
* building names, or other domain-specific vocabulary. This field may be templated
|
|
2268
|
+
* with
|
|
2269
|
+
* [dynamic variables](https://developers.telnyx.com/docs/inference/ai-assistants/dynamic-variables)
|
|
2270
|
+
* using mustache syntax (e.g. `Telnyx,{{customer_name}},VoIP`). Variables are
|
|
2271
|
+
* resolved at call time before the value is sent to Soniox.
|
|
2272
|
+
*/
|
|
2273
|
+
context?: string;
|
|
2252
2274
|
/**
|
|
2253
2275
|
* Available only for deepgram/flux. Confidence threshold for eager end of turn
|
|
2254
2276
|
* detection. Must be lower than or equal to eot_threshold. Setting this equal to
|
|
@@ -2256,8 +2278,9 @@ export interface TranscriptionSettingsConfig {
|
|
|
2256
2278
|
*/
|
|
2257
2279
|
eager_eot_threshold?: number;
|
|
2258
2280
|
/**
|
|
2259
|
-
* Available only for soniox/stt-rt-v4. When true, Soniox
|
|
2260
|
-
* events at the cadence configured by
|
|
2281
|
+
* Available only for soniox/stt-rt-v4 and soniox/stt-rt-v5. When true, Soniox
|
|
2282
|
+
* emits end-of-utterance events at the cadence configured by
|
|
2283
|
+
* `max_endpoint_delay_ms`.
|
|
2261
2284
|
*/
|
|
2262
2285
|
enable_endpoint_detection?: boolean;
|
|
2263
2286
|
/**
|
|
@@ -2277,8 +2300,8 @@ export interface TranscriptionSettingsConfig {
|
|
|
2277
2300
|
*/
|
|
2278
2301
|
eot_timeout_ms?: number;
|
|
2279
2302
|
/**
|
|
2280
|
-
* Available only for soniox/stt-rt-v4. When true, Soniox
|
|
2281
|
-
* (non-final) results in addition to finalized transcripts.
|
|
2303
|
+
* Available only for soniox/stt-rt-v4 and soniox/stt-rt-v5. When true, Soniox
|
|
2304
|
+
* streams interim (non-final) results in addition to finalized transcripts.
|
|
2282
2305
|
*/
|
|
2283
2306
|
interim_results?: boolean;
|
|
2284
2307
|
/**
|
|
@@ -2292,8 +2315,14 @@ export interface TranscriptionSettingsConfig {
|
|
|
2292
2315
|
*/
|
|
2293
2316
|
keyterm?: string;
|
|
2294
2317
|
/**
|
|
2295
|
-
* Available only for soniox/stt-rt-v4.
|
|
2296
|
-
*
|
|
2318
|
+
* Available only for soniox/stt-rt-v4 and soniox/stt-rt-v5. A list of ISO 639-1
|
|
2319
|
+
* language codes (e.g. `["nl", "fr"]`) to pin recognition to multiple languages at
|
|
2320
|
+
* once, overriding the single hint derived from `language`.
|
|
2321
|
+
*/
|
|
2322
|
+
language_hints?: Array<string>;
|
|
2323
|
+
/**
|
|
2324
|
+
* Available only for soniox/stt-rt-v4 and soniox/stt-rt-v5. Maximum silence (in
|
|
2325
|
+
* milliseconds) before Soniox emits an end-of-utterance event. Only honored when
|
|
2297
2326
|
* `enable_endpoint_detection` is true.
|
|
2298
2327
|
*/
|
|
2299
2328
|
max_endpoint_delay_ms?: number;
|