diff --git a/CHANGELOG.md b/CHANGELOG.md index 9db04feb..2412698f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/examples/verifyCallerId.js b/examples/verifyCallerId.js new file mode 100644 index 00000000..867af863 --- /dev/null +++ b/examples/verifyCallerId.js @@ -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) +}); diff --git a/lib/resources/verifyCallerId.js b/lib/resources/verifyCallerId.js new file mode 100644 index 00000000..eb21ece3 --- /dev/null +++ b/lib/resources/verifyCallerId.js @@ -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); + }); + }) + } + +} diff --git a/lib/rest/client-test.js b/lib/rest/client-test.js index 64f83b22..2db57f3b 100644 --- a/lib/rest/client-test.js +++ b/lib/rest/client-test.js @@ -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) { @@ -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); } } diff --git a/lib/rest/client.js b/lib/rest/client.js index c1bce649..807ea7aa 100644 --- a/lib/rest/client.js +++ b/lib/rest/client.js @@ -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() { @@ -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() { diff --git a/lib/rest/request-test.js b/lib/rest/request-test.js index e9b26bcd..6b8bad7a 100644 --- a/lib/rest/request-test.js +++ b/lib/rest/request-test.js @@ -422,6 +422,123 @@ export function Request(config) { } }); } + else if (method === 'POST' && action === 'VerifiedCallerId/') { + resolve({ + response: {}, + body: { + "api_id": "2a5e81d7-deb3-46cd-ac34-c05ca9139b6f", + "message": "Verification code is sent to number +919768368717 which is valid for 15 minutes", + "verification_uuid": "407796a6-1f3e-4607-a9d9-5a5376b59a7b" + } + }); + } + else if (method === 'POST' && action === 'VerifiedCallerId/Verification/2e68eb73-4d54-4391-bc98-71cd380911a4/') { + resolve({ + response: {}, + body: { + "alias": "abhishek", + "api_id": "584a97aa-ca1d-44f2-9dd3-e58fbacd6649", + "channel": "call", + "country": "IN", + "created_at": "2023-09-25T13:10:39.968133341Z", + "phone_number": "+919768368717", + "verification_uuid": "2e68eb73-4d54-4391-bc98-71cd380911a4" + } + }); + } + else if (method === 'POST' && action === 'VerifiedCallerId/+919768368718/') { + resolve({ + response: {}, + body: { + "alias": "testAbhishek", + "api_id": "6b143cb3-9c8a-42ad-b6b7-412ebd5c60a9", + "country": "IN", + "created_at": "2023-09-22T14:11:03.091534Z", + "modified_at": "2023-09-22T14:11:03.091534Z", + "phone_number": "+919768368718", + "subaccount": "SAMTU0Y2FKNGETYZDKNI", + "verification_uuid": "0f978b20-9e2b-4cfe-99fe-f7087c03b8e1" + } + }); + } + else if (method === 'DELETE' && action === 'VerifiedCallerId/+919768368718/') { + resolve({ + response: {}, + body: {} + }); + } + else if (method === 'GET' && action === 'VerifiedCallerId/+919768368718/') { + resolve({ + response: {}, + body: { + "alias": "test", + "api_id": "ee7c3cb1-c921-42c9-832b-950fb8344b9b", + "country": "IN", + "created_at": "2023-09-22T14:11:03.091534Z", + "modified_at": "2023-09-22T14:11:03.091534Z", + "phone_number": "+919768368718", + "subaccount": "", + "verification_uuid": "0f978b20-9e2b-4cfe-99fe-f7087c03b8e1" + } + }); + } + else if (method === 'GET' && action === 'VerifiedCallerId/') { + resolve({ + response: {}, + body: { + "api_id": "3b21c7d7-09f7-489b-b753-659814a676bf", + "meta": { + "limit": 20, + "next": null, + "offset": 0, + "previous": null, + "total_count": 4 + }, + "objects": [ + { + "alias": "abhishek", + "country": "IN", + "created_at": "2023-09-25T14:40:38.68729Z", + "modified_at": "2023-09-25T14:40:38.68729Z", + "phone_number": "+919653244280", + "resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/919653244280", + "subaccount": "", + "verification_uuid": "01be6b07-b106-46e2-8dfc-096d8e22cc0e" + }, + { + "alias": "abhishek", + "country": "IN", + "created_at": "2023-09-25T13:10:39.968133Z", + "modified_at": "2023-09-25T13:10:39.968133Z", + "phone_number": "+919768368717", + "resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/919768368717", + "subaccount": "", + "verification_uuid": "2e68eb73-4d54-4391-bc98-71cd380911a4" + }, + { + "alias": "test", + "country": "IN", + "created_at": "2023-09-22T14:11:03.091534Z", + "modified_at": "2023-09-22T14:11:03.091534Z", + "phone_number": "+919768368718", + "resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/919768368718", + "subaccount": "", + "verification_uuid": "0f978b20-9e2b-4cfe-99fe-f7087c03b8e1" + }, + { + "alias": "Test2", + "country": "", + "created_at": "2023-08-30T07:47:43.87171Z", + "modified_at": "2023-08-30T07:47:43.87171Z", + "phone_number": "+917691021365", + "resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/917691021365", + "subaccount": "SAMTU0Y2FKNGETYZDKNI", + "verification_uuid": "20265c57-2d8e-46fe-8fa8-e8ab4ee58a8c" + } + ] + } + }); + } else if (action == 'Call/aaa-deeiei3-dfddd/Record/' && method == 'DELETE') { resolve({ response: {}, diff --git a/package.json b/package.json index e1f4f771..b5059a58 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plivo", - "version": "4.58.0", + "version": "4.59.0", "description": "A Node.js SDK to make voice calls and send SMS using Plivo and to generate Plivo XML", "homepage": "https://github.com/plivo/plivo-node", "files": [ diff --git a/test/verifyCallerId.js b/test/verifyCallerId.js new file mode 100644 index 00000000..45abb328 --- /dev/null +++ b/test/verifyCallerId.js @@ -0,0 +1,51 @@ +import assert from 'assert'; +import {Client} from '../lib/rest/client-test'; + +let client = new Client('sampleid', 'sammpletoken', 'sampleproxy'); + +describe('client', function () { + let authId, authToken + + describe('VerifyCallerId', function () { + it('should initiate verify caller id request!', function () { + client.verify.initiate('+919768368718', + { + Alias: "test", + Channel: "call" + }, + ).then(function (response) { + assert.equal(response.message, 'Verification code is sent to number +919768368718 which is valid for 15 minutes') + }) + }); + it('should verify the caller id request!', function () { + client.verify.verify("2e68eb73-4d54-4391-bc98-71cd380911a4", "610534" + ).then(function (response) { + assert.equal(response.verification_uuid, '2e68eb73-4d54-4391-bc98-71cd380911a4') + }) + }); + it('should delete a verified caller Id!', function () { + client.verify.deleteVerifiedCallerId("919768368718") + .then(function (response) { + + }) + }); + it('should get verified caller Idd!', function () { + client.verify.getVerifiedCallerId("919768368718") + .then(function (response) { + assert.equal(response.verification_uuid, "0f978b20-9e2b-4cfe-99fe-f7087c03b8e1") + }) + }); + it('should update verified caller Id!', function () { + client.verify.updateVerifiedCallerId("919768368718") + .then(function (response) { + assert.equal(response.verification_uuid, '0f978b20-9e2b-4cfe-99fe-f7087c03b8e1') + }) + }); + it('should list verified caller Ids', function () { + client.verify.listVerifiedCallerId() + .then(function (response) { + assert.equal(response.length, 4) + }) + }); + }); +}) \ No newline at end of file diff --git a/types/resources/verifyCallerId.d.ts b/types/resources/verifyCallerId.d.ts new file mode 100644 index 00000000..4c64fb03 --- /dev/null +++ b/types/resources/verifyCallerId.d.ts @@ -0,0 +1,62 @@ +export class InitiateVerifyResponse { + constructor(params: object); + apiId: string; + message: string; + verificationUuid: string; +} +export class VerifyCallerIdResponse { + constructor(params: object); + apiId: string; + alias: string; + channel:string; + country:string; + createdAt:string; + phoneNumber:string; + subaccount:internal; + verificationUuid:string; +} + +export class GetVerifiedCallerIdResponse { + constructor(params: object); + apiId: string; + alias: string; + country:string; + createdAt:string; + modifiedAt:string; + phoneNumber:string; + subaccount:internal; + verificationUuid:string; +} + +export class ListVerifiedCallerIdResponse { + constructor(params: object); + apiId: string; + meta:string; + objects: object; +} + +export class Verify extends PlivoResource { + constructor(client: Function, data ? : {}); + id: string; + +} + +export class VerifyInterface extends PlivoResourceInterface { + constructor(client: Function, data ? : {}); + + initiate(phoneNumber: string,params ? : {}): Promise < InitiateVerifyResponse > ; + + verify(verificationUuid: string,otp:string,params ? : {}): Promise < VerifyCallerIdResponse > ; + + updateVerifiedCallerId(phoneNumber: string, params ? : {}): Promise < GetVerifiedCallerIdResponse > ; + + listVerifiedCallerId(params ? : {}): Promise < ListVerifiedCallerIdResponse > ; + + getVerifiedCallerId(phoneNumber: string): Promise < GetVerifiedCallerIdResponse > ; + + deleteVerifiedCallerId(phoneNumber: string): Promise < > ; +} +import { + PlivoResource, + PlivoResourceInterface +} from "../base"; diff --git a/types/rest/client-test.d.ts b/types/rest/client-test.d.ts index 7b5732d9..0e9c4c5c 100644 --- a/types/rest/client-test.d.ts +++ b/types/rest/client-test.d.ts @@ -17,6 +17,7 @@ export class Client { loa: LOAInterface; hostedMessagingNumber: HostedMessagingNumberInterface; maskingSession: MaskingSessionInterface; + verifyCallerId: VerifyCallerIdInterface; } /** * Plivo API client which can be used to access the Plivo APIs. @@ -45,4 +46,5 @@ import { Phlo } from "../resources/phlo.js"; import { LOAInterface } from "../resources/loa.js"; import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber.js"; import { MaskingSessionInterface } from "../resources/maskingSession.js"; +import { VerifyCallerIdInterface } from "../resources/verifyCallerId.js"; diff --git a/types/rest/client.d.ts b/types/rest/client.d.ts index d369e38c..55877f6a 100644 --- a/types/rest/client.d.ts +++ b/types/rest/client.d.ts @@ -32,6 +32,7 @@ export class Client { loa: LOAInterface; hostedMessagingNumber: HostedMessagingNumberInterface; maskingSession:MaskingSessionInterface; + verifyCallerId:VerifyCallerIdInterface; toJSON(...args: any[]): any; } /** @@ -67,4 +68,6 @@ import { ComplianceApplicationInterface } from "../resources/complianceApplicati import { LOAInterface } from "../resources/loa"; import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber"; import { MaskingSessionInterface } from "../resources/maskingSession.js"; +import { VerifyCallerIdInterface } from "../resources/verifyCallerId.js"; +