Skip to content

Commit

Permalink
feat get registered client status (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
xquanluu authored Nov 3, 2023
1 parent 72d2877 commit 1e9f388
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
24 changes: 24 additions & 0 deletions lib/routes/api/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ router.post('/:sid/VoipCarriers', async(req, res) => {
sysError(logger, res, err);
}
});

router.get('/:sid/RegisteredSipUsers', async(req, res) => {
const {logger, registrar} = req.app.locals;
try {
Expand All @@ -161,6 +162,29 @@ router.get('/:sid/RegisteredSipUsers', async(req, res) => {
}
});

router.get('/:sid/RegisteredSipUsers/:client', async(req, res) => {
const {logger, registrar} = req.app.locals;
const client = req.params.client;
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}`);
}
const user = await registrar.query(`${client}@${result[0].sip_realm}`);
res.status(200).json({
name: client,
contact: user ? user.contact : null,
expiryTime: user ? user.expiryTime : 0,
protocol: user ? user.protocol : null,
registered_status: user ? 'active' : 'inactive'
});
} catch (err) {
sysError(logger, res, err);
}
});

function coerceNumbers(callInfo) {
if (Array.isArray(callInfo)) {
return callInfo.map((ci) => {
Expand Down
48 changes: 47 additions & 1 deletion lib/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ tags:
description: Least Cost Routing Routes operations
- name: LcrCarrierSetEntries
description: Least Cost Routing Carrier Set Entries operation
- name: GoogleCustomVOices
- name: GoogleCustomVoices
description: Google Custom voices operation
paths:
/BetaInviteCodes:
Expand Down Expand Up @@ -4188,6 +4188,27 @@ paths:
type: array
items:
type: string
/Accounts/{AccountSid}/RegisteredSipUsers/{Client}:
parameters:
- name: Client
in: path
required: true
style: simple
explode: false
schema:
type: string
get:
tags:
- Accounts
summary: retrieve registered client registration
operationId: getRegisteredClient
responses:
200:
description: registered client found
content:
application/json:
schema:
$ref: '#/components/schemas/RegisteredClient'
/Lcrs:
post:
tags:
Expand Down Expand Up @@ -5772,6 +5793,31 @@ components:
- name
- reported_usage
- model
RegisteredClient:
type: object
properties:
name:
type: string
example: xhoaluu
contact:
type: string
example: sip:[email protected];transport=ws
expiryTime:
type: number
example: 1698981449173
protocol:
type: string
example: wss
registered_status:
type: string
enum:
- active
- inactive
required:
- speech_credential_sid
- name
- reported_usage
- model

security:
- bearerAuth: []

0 comments on commit 1e9f388

Please sign in to comment.