Skip to content

Commit

Permalink
Merge pull request #320 from plivo/VT-6712
Browse files Browse the repository at this point in the history
verify caller id feature apis added
  • Loading branch information
abhishekGupta-Plivo authored Oct 31, 2023
2 parents 8e3d9c4 + 3558c21 commit 1092dd4
Show file tree
Hide file tree
Showing 11 changed files with 517 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [v4.59.0](https://github.com/plivo/plivo-node/tree/v4.59.0) (2023-10-19)
**Feature - Verify Caller ID**
- API support for verifying, updating, getting and deleting caller IDs.

## [v4.58.0](https://github.com/plivo/plivo-node/tree/v4.58.0) (2023-10-16)
**Introducing camapign_source field**
- campaign_source field added for LIST / GET
Expand Down
27 changes: 27 additions & 0 deletions examples/verifyCallerId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
let plivo = require('plivo')

let client = new plivo.Client(process.env.PLIVO_AUTH_ID, process.env.PLIVO_AUTH_TOKEN);

client.verify.initiate('+919999999999').then(function(response) {
console.log(response)
});

client.verify.verify("14b13c24-5262-448e-93e2-ad2419a3849e","999999").then(function(response) {
console.log(response)
});

client.verify.updateVerifiedCallerId('+919999999999',{alias : "test"}).then(function(response) {
console.log(response)
});

client.verify.getVerifiedCallerId('+919999999999').then(function(response) {
console.log(response)
});

client.verify.listVerifiedCallerId().then(function(response) {
console.log(response)
});

client.verify.deleteVerifiedCallerId('+919999999999').then(function(response) {
console.log(response)
});
246 changes: 246 additions & 0 deletions lib/resources/verifyCallerId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
import * as _ from "lodash";

import {
PlivoResource,
PlivoResourceInterface
} from '../base';
import {
extend,
validate
} from '../utils/common.js';

const clientKey = Symbol();
const action = 'VerifiedCallerId/';
const idField = 'verificationUuid';


export class InitiateVerifyResponse {
constructor(params) {
params = params || {};
this.apiId = params.apiId;
this.message = params.message;
this.verificationUuid = params.verificationUuid;
}
}

export class VerifyCallerIdResponse {
constructor(params) {
params = params || {};
this.apiId = params.apiId;
this.alias = params.alias;
this.channel = params.channel;
this.country = params.country;
this.createdAt = params.createdAt;
this.phoneNumber = params.phoneNumber;
this.subaccount = params.subaccount;
this.verificationUuid = params.verificationUuid;
}
}

export class GetVerifiedCallerIdResponse {
constructor(params) {
params = params || {};
this.apiId = params.apiId;
this.alias = params.alias;
this.country = params.country;
this.createdAt = params.createdAt;
this.modifiedAt = params.modifiedAt;
this.phoneNumber = params.phoneNumber;
this.subaccount = params.subaccount;
this.verificationUuid = params.verificationUuid;
}
}

export class ListVerifiedCallerIdResponse {
constructor(params) {
params = params || {};
this.apiId = params.apiId;
this.meta = params.meta;
this.objects = params.objects;
}
}

/**
* Represents a Verify
* @constructor
* @param {function} client - make verify api call
* @param {object} [data] - data of verify
*/

export class Verify extends PlivoResource {
constructor(client, data = {}) {
super(action, Verify, idField, client);
this[clientKey] = client;
if (idField in data) {
this.id = data[idField];
}
extend(this, data);
}

}

export class VerifyInterface extends PlivoResourceInterface {

constructor(client, data = {}) {
super(action, Verify, client);
this[clientKey] = client;
if (idField in data) {
this.id = data[idField];
}
extend(this, data);
}

initiate(phoneNumber, optionalParams = {}) {
let errors = validate([{
field: 'phoneNumber',
value: phoneNumber,
validators: ['isRequired']
}
]);

if (errors) {
return errors;
}

optionalParams.phoneNumber = phoneNumber

let client = this[clientKey];

return new Promise((resolve, reject) => {
client('POST', action, optionalParams)
.then(response => {
resolve(new InitiateVerifyResponse(response.body));
})
.catch(error => {
reject(error);
});
})
}

verify(verificationUuid, otp) {

let errors = validate([{
field: 'verificationUuid',
value: verificationUuid,
validators: ['isRequired']
},
{
field: 'otp',
value: otp,
validators: ['isRequired']
}

]);
let params = {}
params.otp = otp

if (errors) {
return errors;
}

let client = this[clientKey];

return new Promise((resolve, reject) => {
client('POST', action + 'Verification/' + verificationUuid, params)
.then(response => {
resolve(new VerifyCallerIdResponse(response.body));
})
.catch(error => {
reject(error);
});
})
}

updateVerifiedCallerId(phoneNumber, optionalParams = {}) {

let errors = validate([{
field: 'phoneNumber',
value: phoneNumber,
validators: ['isRequired']
},
]);

if (errors) {
return errors;
}

let client = this[clientKey];

return new Promise((resolve, reject) => {
client('POST', action + phoneNumber + '/', optionalParams)
.then(response => {
resolve(new GetVerifiedCallerIdResponse(response.body));
})
.catch(error => {
reject(error);
});
})
}

getVerifiedCallerId(phoneNumber) {

let errors = validate([{
field: 'phoneNumber',
value: phoneNumber,
validators: ['isRequired']
},
]);

if (errors) {
return errors;
}

let client = this[clientKey];

return new Promise((resolve, reject) => {
client('GET', action + phoneNumber + '/')
.then(response => {
resolve(new GetVerifiedCallerIdResponse(response.body));
})
.catch(error => {
reject(error);
});
})
}

listVerifiedCallerId(params = {}) {
let client = this[clientKey];

return new Promise((resolve, reject) => {
client('GET', action, params)
.then(response => {
resolve(new ListVerifiedCallerIdResponse(response.body));
})
.catch(error => {
reject(error);
});
})
}

deleteVerifiedCallerId(phoneNumber) {

let errors = validate([{
field: 'phoneNumber',
value: phoneNumber,
validators: ['isRequired']
},
]);

if (errors) {
return errors;
}

let client = this[clientKey];

return new Promise((resolve, reject) => {
client('DELETE', action + phoneNumber + '/')
.then(() => {
resolve(true);
})
.catch(error => {
reject(error);
});
})
}

}
2 changes: 2 additions & 0 deletions lib/rest/client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { LOAInterface } from "../resources/loa";
import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber";
import {SessionInterface} from "../resources/verify";
import { MaskingSessionInterface } from '../resources/maskingSession.js';
import {VerifyInterface} from "../resources/verifyCallerId";

export class Client {
constructor(authId, authToken, proxy) {
Expand Down Expand Up @@ -127,6 +128,7 @@ export class Client {
this.hostedMessagingNumber = new HostedMessagingNumberInterface(client);
this.verify_session = new SessionInterface(client);
this.maskingSession = new MaskingSessionInterface(client);
this.verify = new VerifyInterface(client);
}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/rest/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { LOAInterface } from "../resources/loa";
import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber";
import { SessionInterface } from "../resources/verify";
import { MaskingSessionInterface } from "../resources/maskingSession.js";
import {VerifyInterface} from "../resources/verifyCallerId";


exports.Response = function() {
Expand Down Expand Up @@ -115,6 +116,7 @@ export class Client {
this.hostedMessagingNumber = new HostedMessagingNumberInterface(client);
this.verify_session = new SessionInterface(client);
this.maskingSession = new MaskingSessionInterface(client)
this.verify = new VerifyInterface(client)
}

toJSON() {
Expand Down
Loading

0 comments on commit 1092dd4

Please sign in to comment.