Merge branch 'main' into feat/feat/inband_dtmf_command

This commit is contained in:
Hoan Luu Huu
2023-12-01 13:40:43 +07:00
committed by GitHub
7 changed files with 95 additions and 12 deletions
+40
View File
@@ -155,6 +155,9 @@ router.get('/:sid/RegisteredSipUsers', async(req, res) => {
if (!result || result.length === 0) {
throw new DbErrorBadRequest(`account not found for sid ${account_sid}`);
}
if (!result[0].sip_realm) {
throw new DbErrorBadRequest('account does not have sip_realm configuration');
}
const users = await registrar.getRegisteredUsersForRealm(result[0].sip_realm);
res.status(200).json(users.map((u) => `${u}@${result[0].sip_realm}`));
} catch (err) {
@@ -162,6 +165,43 @@ router.get('/:sid/RegisteredSipUsers', async(req, res) => {
}
});
router.post('/:sid/RegisteredSipUsers', async(req, res) => {
const {logger, registrar} = req.app.locals;
const users = req.body;
try {
const account_sid = parseAccountSid(req);
await validateRequest(req, account_sid);
const result = await Account.retrieve(account_sid);
if (!result || result.length === 0) {
throw new DbErrorBadRequest(`account not found for sid ${account_sid}`);
}
if (!result[0].sip_realm) {
throw new DbErrorBadRequest('account does not have sip_realm configuration');
}
if (!users || !Array.isArray(users) || users.length === 0) {
return res.status(200).json(await registrar.getRegisteredUsersDetailsForRealm(result[0].sip_realm));
}
const ret = [];
for (const u of users) {
const user = await registrar.query(`${u}@${result[0].sip_realm}`) || {
name: u,
contact: null,
expiryTime: 0,
protocol: null,
registered_status: 'inactive'
};
delete user.sbcAddress;
ret.push({
name: u,
...user
});
}
res.status(200).json(ret);
} catch (err) {
sysError(logger, res, err);
}
});
router.get('/:sid/RegisteredSipUsers/:client', async(req, res) => {
const {logger, registrar, lookupClientByAccountAndUsername} = req.app.locals;
const client = req.params.client;
+7 -4
View File
@@ -132,7 +132,8 @@ const encryptCredential = (obj) => {
custom_tts_url,
auth_token = '',
cobalt_server_uri,
model_id
model_id,
options
} = obj;
switch (vendor) {
@@ -210,7 +211,7 @@ const encryptCredential = (obj) => {
case 'elevenlabs':
assert(api_key, 'invalid elevenLabs speech credential: api_key is required');
assert(model_id, 'invalid elevenLabs speech credential: model_id is required');
const elevenlabsData = JSON.stringify({api_key, model_id});
const elevenlabsData = JSON.stringify({api_key, model_id, options});
return encrypt(elevenlabsData);
case 'assemblyai':
@@ -411,7 +412,8 @@ router.put('/:sid', async(req, res) => {
custom_stt_url,
custom_tts_url,
cobalt_server_uri,
model_id
model_id,
options
} = req.body;
const newCred = {
@@ -433,7 +435,8 @@ router.put('/:sid', async(req, res) => {
custom_stt_url,
custom_tts_url,
cobalt_server_uri,
model_id
model_id,
options
};
logger.info({o, newCred}, 'updating speech credential with this new credential');
obj.credential = encryptCredential(newCred);
+21
View File
@@ -4192,6 +4192,27 @@ paths:
type: array
items:
type: string
post:
tags:
- Accounts
summary: retrieve online sip users for an account by list of sip username
operationId: listRegisteredSipUsers
requestBody:
content:
application/json:
schema:
type: array
items:
type: string
responses:
200:
description: retrieve online sip users for an account
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/RegisteredClient'
/Accounts/{AccountSid}/RegisteredSipUsers/{Client}:
parameters:
- name: Client
+1
View File
@@ -395,6 +395,7 @@ function decryptCredential(obj, credential, logger, isObscureKey = true) {
const o = JSON.parse(decrypt(credential));
obj.api_key = isObscureKey ? obscureKey(o.api_key) : o.api_key;
obj.model_id = o.model_id;
obj.options = o.options;
} else if (obj.vendor.startsWith('custom:')) {
const o = JSON.parse(decrypt(credential));
obj.auth_token = isObscureKey ? obscureKey(o.auth_token) : o.auth_token;
+7 -7
View File
@@ -17,7 +17,7 @@
"@google-cloud/storage": "^6.12.0",
"@jambonz/db-helpers": "^0.9.1",
"@jambonz/lamejs": "^1.2.2",
"@jambonz/mw-registrar": "^0.2.5",
"@jambonz/mw-registrar": "^0.2.7",
"@jambonz/realtimedb-helpers": "^0.8.7",
"@jambonz/speech-utils": "^0.0.26",
"@jambonz/time-series": "^0.2.8",
@@ -1951,9 +1951,9 @@
}
},
"node_modules/@jambonz/mw-registrar": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/@jambonz/mw-registrar/-/mw-registrar-0.2.5.tgz",
"integrity": "sha512-+aBI2xpR6Ir140Hi7/ED+z5Hl7NgCalyVzTLNlgUVzTvsMLtyZZh6n9IQipKnuKvhh4nPM4aJ+JuFhi1UH9zEA==",
"version": "0.2.7",
"resolved": "https://registry.npmjs.org/@jambonz/mw-registrar/-/mw-registrar-0.2.7.tgz",
"integrity": "sha512-ckvIimjR2NpTcX1L5ryyXH1ynHhHl4wkGkt4wiip6Ngc+gb5Nf9eQF+zHShvahHi863gOdxtV7K7sAWQQHELGQ==",
"dependencies": {
"debug": "^4.3.4"
}
@@ -11413,9 +11413,9 @@
}
},
"@jambonz/mw-registrar": {
"version": "0.2.5",
"resolved": "https://registry.npmjs.org/@jambonz/mw-registrar/-/mw-registrar-0.2.5.tgz",
"integrity": "sha512-+aBI2xpR6Ir140Hi7/ED+z5Hl7NgCalyVzTLNlgUVzTvsMLtyZZh6n9IQipKnuKvhh4nPM4aJ+JuFhi1UH9zEA==",
"version": "0.2.7",
"resolved": "https://registry.npmjs.org/@jambonz/mw-registrar/-/mw-registrar-0.2.7.tgz",
"integrity": "sha512-ckvIimjR2NpTcX1L5ryyXH1ynHhHl4wkGkt4wiip6Ngc+gb5Nf9eQF+zHShvahHi863gOdxtV7K7sAWQQHELGQ==",
"requires": {
"debug": "^4.3.4"
}
+1 -1
View File
@@ -27,7 +27,7 @@
"@google-cloud/storage": "^6.12.0",
"@jambonz/db-helpers": "^0.9.1",
"@jambonz/lamejs": "^1.2.2",
"@jambonz/mw-registrar": "^0.2.5",
"@jambonz/mw-registrar": "^0.2.7",
"@jambonz/realtimedb-helpers": "^0.8.7",
"@jambonz/speech-utils": "^0.0.26",
"@jambonz/time-series": "^0.2.8",
+18
View File
@@ -85,6 +85,24 @@ test('client test', async(t) => {
t.ok(result.length === 1 && result[0] === 'dhorton@drachtio.org',
'successfully queried all registered clients');
result = await request.post(`/Accounts/${account_sid}/RegisteredSipUsers`, {
resolveWithFullResponse: true,
auth: authAdmin,
json: true,
body: ['dhorton']
});
t.ok(result.body.length === 1 && result.body[0].name === 'dhorton',
'successfully queried all registered clients');
result = await request.post(`/Accounts/${account_sid}/RegisteredSipUsers`, {
resolveWithFullResponse: true,
auth: authAdmin,
json: true,
body: []
});
t.ok(result.body.length === 1 && result.body[0].name === 'dhorton',
'successfully queried all registered clients');
/* query all entity */
result = await request.get('/Clients', {
auth: authAdmin,