Skip to content

Commit

Permalink
SPARK-568641: Parse SIP name for guest calling (#3904)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhabalan authored Oct 25, 2024
1 parent ad56a4d commit a807933
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ describe('CallerId tests', () => {
const dummyCallerId = {
'x-broadworks-remote-party-info':
'userId="[email protected]";userDn="tel:+12142865888;ext=5888;country-code=1";externalId=69fde5ad-fb8b-4a1b-9998-b0999e95719b',
'p-asserted-identity': '"Bob Marley" <sip:[email protected];user=phone>',
'p-asserted-identity': '"John O\'Connor - ( Guest )" <sip:[email protected];user=phone>',
from: '"Alice" <sip:[email protected]>;tag=1932136170-1654008881246',
};

const output = callerId.fetchCallerDetails(dummyCallerId);

/* PAI should be preferred */
expect(output.name).toStrictEqual('Bob Marley');
expect(output.name).toStrictEqual("John O'Connor - ( Guest )");
expect(output.num).toStrictEqual('5888');
await waitForMsecs(50);

Expand All @@ -132,12 +132,11 @@ describe('CallerId tests', () => {
expect(callerId['callerInfo'].num).toStrictEqual('5008');
});

it(' When PA-ID ,From header is present along with x-broad-works , but name in PAI is of wrong format', async () => {
it(' When PA-ID ,From header is present along with x-broad-works , but name in PAI is missing', async () => {
const dummyCallerId = {
'x-broadworks-remote-party-info':
'userId="[email protected]";userDn="tel:+12142865888;ext=5888;country-code=1";externalId=69fde5ad-fb8b-4a1b-9998-b0999e95719b',
'p-asserted-identity':
'"69fde5ad-fb8b-4a1b-9998-b0999e95719b" <sip:[email protected];user=phone>',
'p-asserted-identity': '<sip:[email protected];user=phone>',
from: '"Alice" <sip:[email protected]>;tag=1932136170-1654008881246',
};

Expand All @@ -156,12 +155,11 @@ describe('CallerId tests', () => {
expect(callerId['callerInfo'].num).toStrictEqual('5008');
});

it(' When PA-ID ,From header is present along with x-broad-works , but name in PAI is of wrong format', async () => {
it(' When PA-ID ,From header is present along with x-broad-works , but name, number in PAI is missing', async () => {
const dummyCallerId = {
'x-broadworks-remote-party-info':
'userId="[email protected]";userDn="tel:+12142865888;ext=5888;country-code=1";externalId=69fde5ad-fb8b-4a1b-9998-b0999e95719b',
'p-asserted-identity':
'"69fde5ad-fb8b-4a1b-9998-b0999e95719b" <sip:[email protected];user=phone>',
'p-asserted-identity': '<sip:[email protected];user=phone>',
from: '"Alice" <sip:[email protected]>;tag=1932136170-1654008881246',
};

Expand Down
24 changes: 14 additions & 10 deletions packages/calling/src/CallingClient/calling/CallerId/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {CallerIdInfo} from '../../../Events/types';
import {ISDKConnector, WebexSDK} from '../../../SDKConnector/types';
import {DisplayInformation} from '../../../common/types';
import log from '../../../Logger/index';
import {CALLER_ID_FILE, FETCH_NAME, VALID_PHONE} from '../../constants';
import {CALLER_ID_FILE, VALID_PHONE_REGEX} from '../../constants';

import SDKConnector from '../../../SDKConnector';
import {ICallerId} from './types';
Expand Down Expand Up @@ -126,26 +126,30 @@ export class CallerId implements ICallerId {
*
* @param paid - Entire sip uri. Can be PA-Id or From header.
* @returns - a collection of name and number.
* @example
* const paid1 = '"John O' Connor - (Guest)" <sip:1234567890@domain>';
* const result1 = parseSipUri(paid1);
* result1.name = "John O' Connor - (Guest)"
* result1.num = "1234567890"
*/
private parseSipUri(paid: string) {
private parseSipUri(paid: string): DisplayInformation {
const result = {} as DisplayInformation;

const data = paid.split('@')[0].replace(/"/g, '');

const nameMatch = FETCH_NAME.exec(data);

const num = data.substring(data.indexOf(':') + 1, data.length);

// Extract name
const nameMatch = paid.split('<')[0].replace(/"/g, '');
if (nameMatch) {
result.name = nameMatch[0].trimEnd();
result.name = nameMatch.trim();
} else {
log.warn(`Name field not found!`, {
file: CALLER_ID_FILE,
method: 'parseSipUri',
});
}

const phoneMatch = num.match(VALID_PHONE);
// Extract number
const data = paid.split('@')[0].replace(/"/g, '');
const num = data.substring(data.indexOf(':') + 1, data.length);
const phoneMatch = num.match(VALID_PHONE_REGEX);

if (phoneMatch && phoneMatch[0].length === num.length) {
result.num = num;
Expand Down
3 changes: 1 addition & 2 deletions packages/calling/src/CallingClient/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const DUMMY_METRICS = {
},
};
export const DUMMY_MOBIUS_URL = 'https://mobius.aintgen-a-1.int.infra.webex.com/api/v1';
export const FETCH_NAME = /^[a-zA-Z ]+/;
export const IP_ENDPOINT = 'myip';
export const INITIAL_SEQ_NUMBER = 1;
export const MEDIA_ENDPOINT_RESOURCE = 'media';
Expand All @@ -57,7 +56,7 @@ export const REGISTER_RETRY_TIMEOUT = 10000;
export const SUPPLEMENTARY_SERVICES_TIMEOUT = 10000;
export const API_V1 = '/api/v1';
export const URL_ENDPOINT = '/calling/web/';
export const VALID_PHONE = /[\d\s()*#+.-]+/;
export const VALID_PHONE_REGEX = /[\d\s()*#+.-]+/;
export const WEB_AGENT = '(web)';
export const WEBEX = 'webex';
export const WEBEX_WEB_CLIENT = 'webex-web-client';
Expand Down
4 changes: 2 additions & 2 deletions packages/calling/src/CallingClient/line/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ServiceIndicator,
} from '../../common/types';
import {ILine, LINE_EVENTS} from './types';
import {LINE_FILE, VALID_PHONE} from '../constants';
import {LINE_FILE, VALID_PHONE_REGEX} from '../constants';
import log from '../../Logger';
import {IRegistration} from '../registration/types';
import {createRegistration} from '../registration';
Expand Down Expand Up @@ -234,7 +234,7 @@ export default class Line extends Eventing<LineEventTypes> implements ILine {
let call;

if (dest) {
const match = dest.address.match(VALID_PHONE);
const match = dest.address.match(VALID_PHONE_REGEX);

if (match && match[0].length === dest.address.length) {
const sanitizedNumber = dest.address
Expand Down

0 comments on commit a807933

Please sign in to comment.