From 1c241276e418730f5bddffc679499a9c20b7b403 Mon Sep 17 00:00:00 2001 From: ashutoshkumar-plivo Date: Fri, 21 Jul 2023 14:26:56 +0530 Subject: [PATCH 01/11] SMS:6065- Node SDK for Verify --- lib/resources/verify.js | 194 ++++++++++++++++++++++++++++++++++++++++ lib/rest/axios.js | 2 +- lib/rest/client.js | 5 +- lib/rest/request.js | 2 +- 4 files changed, 200 insertions(+), 3 deletions(-) create mode 100644 lib/resources/verify.js diff --git a/lib/resources/verify.js b/lib/resources/verify.js new file mode 100644 index 00000000..15fbe406 --- /dev/null +++ b/lib/resources/verify.js @@ -0,0 +1,194 @@ +import * as _ from "lodash"; + +import { + PlivoResource, + PlivoResourceInterface +} from '../base'; +import { + extend, + validate +} from '../utils/common.js'; + +const action = 'Verify/Session/'; +const idField = 'session_uuid'; +let actionKey = Symbol('api action'); +let klassKey = Symbol('constructor'); +let idKey = Symbol('id filed'); +let clientKey = Symbol('make api call'); + + +export class SessionResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.message = params.message; + this.sessionUuid = params.sessionUuid; + if (params.invalidNumber != undefined ){ + this.invalid_number = params.invalidNumber; + } + } +} + +export class SessionGetResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.sessionUuid = params.sessionUuid; + this.appUuid = params.appUuid; + this.recipient = params.recipient; + this.channel = params.channel; + this.status = params.status; + this.count = params.count; + this.attemptDetails = params.attemptDetails; + this.createdAt = params.createdAt; + this.updatedAt = params.updatedAt; + + this.charges = Object.assign({}, params.charges); + + this.charges.totalCharge = params.charges.totalCharge; + this.charges.validationCharge = params.charges.validationCharge; + this.charges.attemptCharges = params.charges.attemptCharges + } +} + +/** + * Represents a Session + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class Session extends PlivoResource { + constructor(client, data = {}) { + super(action, Session, idField, client); + this[actionKey] = action; + this[clientKey] = client; + if (idField in data) { + this.id = data[idField]; + }; + + extend(this, data); + } + +} + + +/** + * Represents a Session Interface + * @constructor + * @param {function} client - make api call + * @param {object} [data] - data of call + */ +export class SessionInterface extends PlivoResourceInterface { + constructor(client, data = {}) { + super(action, Session, idField, client); + extend(this, data); + this[clientKey] = client; + this[actionKey] = action; + this[klassKey] = Session; + this[idKey] = idField; + } + + /** + * Send Session + * @method + * @param {Object} sessionReq- request body fields + * @promise {object} return {@link PlivoGenericMessage} object if success + * @fail {Error} return Error + */ + create(sessionReq){ + + var isObject = arguments.length; + var app_uuid, recipient, url, method, channel + + if (isObject === 1) { + app_uuid = sessionReq.app_uuid + recipient = sessionReq.recipient + url = sessionReq.url + method = sessionReq.method + channel = sessionReq.channel + } + + let errors = validate([{ + field: 'recipient', + value: recipient, + validators: ['isRequired'] + }, + ]); + + if (errors) { + return errors + } + + let params = {} + if (isObject === 1) { + if(app_uuid) { + params.app_uuid = app_uuid + } + if(recipient) { + params.recipient = recipient + } + if(channel) { + params.channel = channel + } + if(url) { + params.url = url + } + if(method) { + params.method = method + } + } + + let client = this[clientKey]; + let idField = this[idKey]; + let action = this[actionKey] + (this.id ? this.id + '/' : ''); + + return new Promise((resolve, reject) => { + client('POST', action, params) + .then(response => { + resolve(new SessionResponse(response.body, idField)); + }) + .catch(error => { + reject(error); + }); + }) + + } + + + /** + * Get Session by given id + * @method + * @param {string} id - id of session + * @promise {object} return {@link Session} object if success + * @fail {Error} return Error + */ + get(id) { + let errors = validate([{ + field: 'id', + value: id, + validators: ['isRequired'] + }]); + + if (errors) { + return errors; + } + + let client = this[clientKey]; + let action = this[actionKey]; + + return new Promise((resolve, reject) => { + if (action !== '' && !id) { + reject(new Error(this[idKey] + ' must be set')); + } + client('GET', action + (id ? id + '/' : '')) + .then(response => { + resolve(new SessionGetResponse(response.body, client)); + }) + .catch(error => { + reject(error); + }); + }); + } + + +} diff --git a/lib/rest/axios.js b/lib/rest/axios.js index 04b0eea5..42c34faf 100644 --- a/lib/rest/axios.js +++ b/lib/rest/axios.js @@ -142,7 +142,7 @@ export function Axios(config) { headers: headers, json: true }; - let apiVoiceUris = ['https://api.plivo.com/v1/Account/','https://api.plivo.com/v1/Account/','https://api.plivo.com/v1/Account/']; + let apiVoiceUris = ['https://api-messaging.sms.plivodev.com/v1/Account/','https://api-messaging.sms.plivodev.com/v1/Account/','https://api-messaging.sms.plivodev.com/v1/Account/']; let isVoiceReq = false; if (params) { if (params.hasOwnProperty('is_call_insights_request')) { diff --git a/lib/rest/client.js b/lib/rest/client.js index 5e8c6ca3..1e49deb4 100644 --- a/lib/rest/client.js +++ b/lib/rest/client.js @@ -32,6 +32,7 @@ import { ComplianceApplicationInterface } from "../resources/complianceApplicati import { MultiPartyCallInterface } from "../resources/multiPartyCall"; import { LOAInterface } from "../resources/loa"; import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber"; +import { SessionInterface } from "../resources/verify"; exports.Response = function() { @@ -76,7 +77,7 @@ export class Client { authId: authId, authToken: authToken, version: "v1", - url: "https://api.plivo.com/v1/Account/" + authId, + url: "https://api-messaging.sms.plivodev.com/v1/Account/" + authId, userAgent: `${"plivo-node"}/${version || "Unknown Version"} (Node: ${ process.version })` @@ -111,6 +112,8 @@ export class Client { this.multiPartyCalls = new MultiPartyCallInterface(client); this.loa = new LOAInterface(client); this.hostedMessagingNumber = new HostedMessagingNumberInterface(client); + this.verify_session = new SessionInterface(client); + } toJSON() { diff --git a/lib/rest/request.js b/lib/rest/request.js index 4a908190..89c94d38 100644 --- a/lib/rest/request.js +++ b/lib/rest/request.js @@ -33,7 +33,7 @@ export function Request(config) { headers: headers, json: true }; - let apiVoiceUris = ['https://api.plivo.com/v1/Account/','https://api.plivo.com/v1/Account/','https://api.plivo.com/v1/Account/']; + let apiVoiceUris = ['https://api-messaging.sms.plivodev.com/v1/Account/','https://api-messaging.sms.plivodev.com/v1/Account/','https://api-messaging.sms.plivodev.com/v1/Account/']; let isVoiceReq = false; if (params) { if (params.hasOwnProperty('is_call_insights_request')) { From ac637ece39b57809144ef64c2d152fd023353369 Mon Sep 17 00:00:00 2001 From: ashutoshkumar-plivo Date: Tue, 25 Jul 2023 12:15:11 +0530 Subject: [PATCH 02/11] added api's --- lib/resources/verify.js | 92 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/lib/resources/verify.js b/lib/resources/verify.js index 15fbe406..4fe54a8c 100644 --- a/lib/resources/verify.js +++ b/lib/resources/verify.js @@ -8,6 +8,7 @@ import { extend, validate } from '../utils/common.js'; +import {MessageListResponse} from "./messages"; const action = 'Verify/Session/'; const idField = 'session_uuid'; @@ -51,6 +52,27 @@ export class SessionGetResponse { } } +export class SessionListResponse { + constructor(params) { + params = params || {}; + this.sessionUuid = params.sessionUuid; + this.appUuid = params.appUuid; + this.recipient = params.recipient; + this.channel = params.channel; + this.status = params.status; + this.count = params.count; + this.attemptDetails = params.attemptDetails; + this.createdAt = params.createdAt; + this.updatedAt = params.updatedAt; + + this.charges = Object.assign({}, params.charges); + + this.charges.totalCharge = params.charges.totalCharge; + this.charges.validationCharge = params.charges.validationCharge; + this.charges.attemptCharges = params.charges.attemptCharges + } +} + /** * Represents a Session * @constructor @@ -190,5 +212,75 @@ export class SessionInterface extends PlivoResourceInterface { }); } + list(params) { + let client = this[clientKey]; + let action = this[actionKey]; + return new Promise((resolve, reject) => { + client('GET', action, params) + .then(response => { + let objects = []; + Object.defineProperty(objects, 'meta', { + value: response.body.meta, + enumerable: true + }); + Object.defineProperty(objects, 'apiId', { + value: response.body.apiId, + enumerable: true + }) + response.body.sessions.forEach(item => { + objects.push(new SessionListResponse(item, client)); + }); + resolve(objects); + }) + .catch(error => { + reject(error); + }); + }); + } + + validate(req) { + var id, otp + var isObject = arguments.length; + if (isObject === 1) { + id = req.id + otp = req.otp + } + let errors = validate([{ + field: 'id', + value: id, + validators: ['isRequired'] + }]); + + if (errors) { + return errors; + } + + errors = validate([{ + field: 'otp', + value: otp, + validators: ['isRequired'] + }]); + + if (errors) { + return errors; + } + let params = {} + params.otp = otp + + let client = this[clientKey]; + let idField = this[idKey]; + let action = this[actionKey]; + + return new Promise((resolve, reject) => { + client('POST', action + (id ? id + '/' : ''), params) + .then(response => { + resolve(new SessionResponse(response.body, idField)); + }) + .catch(error => { + reject(error); + }); + }) + + } } From 923f3bf18bcd015402e87121fccf8bb05051dbc1 Mon Sep 17 00:00:00 2001 From: ashutoshkumar-plivo Date: Mon, 31 Jul 2023 09:54:30 +0530 Subject: [PATCH 03/11] added utc's and changelog --- CHANGELOG.md | 8 +++ lib/resources/verify.js | 9 ++- lib/rest/axios.js | 2 +- lib/rest/client-test.js | 2 + lib/rest/client.js | 2 +- lib/rest/request-test.js | 116 +++++++++++++++++++++++++++++++++++++-- lib/rest/request.js | 2 +- package.json | 2 +- test/verify.js | 47 ++++++++++++++++ 9 files changed, 181 insertions(+), 9 deletions(-) create mode 100644 test/verify.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 693fa9a5..81aa1e08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ # Change Log + +## [v4.52.0] +**Verify Service API's** +- Create Session API +- Get Session API +- List Session API +- Validate Session API + ## [v4.51.0](https://github.com/plivo/plivo-go/tree/v4.51.0) (2023-07-07) **Fix Intermediate GET request failure** - GET API request body removed diff --git a/lib/resources/verify.js b/lib/resources/verify.js index 4fe54a8c..ffef686a 100644 --- a/lib/resources/verify.js +++ b/lib/resources/verify.js @@ -8,7 +8,6 @@ import { extend, validate } from '../utils/common.js'; -import {MessageListResponse} from "./messages"; const action = 'Verify/Session/'; const idField = 'session_uuid'; @@ -36,10 +35,14 @@ export class SessionGetResponse { this.apiId = params.apiId; this.sessionUuid = params.sessionUuid; this.appUuid = params.appUuid; + this.alias = params.alias; this.recipient = params.recipient; this.channel = params.channel; this.status = params.status; this.count = params.count; + this.requestor_ip = params.requestor_ip; + this.destination_country_iso2 = params.destination_country_iso2; + this.destination_network = params.destination_network; this.attemptDetails = params.attemptDetails; this.createdAt = params.createdAt; this.updatedAt = params.updatedAt; @@ -58,9 +61,13 @@ export class SessionListResponse { this.sessionUuid = params.sessionUuid; this.appUuid = params.appUuid; this.recipient = params.recipient; + this.alias = params.alias; this.channel = params.channel; this.status = params.status; this.count = params.count; + this.requestor_ip = params.requestor_ip; + this.destination_country_iso2 = params.destination_country_iso2; + this.destination_network = params.destination_network; this.attemptDetails = params.attemptDetails; this.createdAt = params.createdAt; this.updatedAt = params.updatedAt; diff --git a/lib/rest/axios.js b/lib/rest/axios.js index 42c34faf..04b0eea5 100644 --- a/lib/rest/axios.js +++ b/lib/rest/axios.js @@ -142,7 +142,7 @@ export function Axios(config) { headers: headers, json: true }; - let apiVoiceUris = ['https://api-messaging.sms.plivodev.com/v1/Account/','https://api-messaging.sms.plivodev.com/v1/Account/','https://api-messaging.sms.plivodev.com/v1/Account/']; + let apiVoiceUris = ['https://api.plivo.com/v1/Account/','https://api.plivo.com/v1/Account/','https://api.plivo.com/v1/Account/']; let isVoiceReq = false; if (params) { if (params.hasOwnProperty('is_call_insights_request')) { diff --git a/lib/rest/client-test.js b/lib/rest/client-test.js index dcf282c4..a4318370 100644 --- a/lib/rest/client-test.js +++ b/lib/rest/client-test.js @@ -69,6 +69,7 @@ import { ComplianceRequirementInterface } from "../resources/complianceRequireme import { ComplianceApplicationInterface } from "../resources/complianceApplications"; import { LOAInterface } from "../resources/loa"; import { HostedMessagingNumberInterface } from "../resources/hostedMessagingNumber"; +import {SessionInterface} from "../resources/verify"; export class Client { constructor(authId, authToken, proxy) { @@ -123,6 +124,7 @@ export class Client { this.multiPartyCalls = new MultiPartyCallInterface(client); this.loa = new LOAInterface(client); this.hostedMessagingNumber = new HostedMessagingNumberInterface(client); + this.verify_session = new SessionInterface(client); } } diff --git a/lib/rest/client.js b/lib/rest/client.js index 1e49deb4..658c6c43 100644 --- a/lib/rest/client.js +++ b/lib/rest/client.js @@ -77,7 +77,7 @@ export class Client { authId: authId, authToken: authToken, version: "v1", - url: "https://api-messaging.sms.plivodev.com/v1/Account/" + authId, + url: "https://api.plivo.com/v1/Account/" + authId, userAgent: `${"plivo-node"}/${version || "Unknown Version"} (Node: ${ process.version })` diff --git a/lib/rest/request-test.js b/lib/rest/request-test.js index eec1f959..072add4e 100644 --- a/lib/rest/request-test.js +++ b/lib/rest/request-test.js @@ -1709,7 +1709,7 @@ export function Request(config) { total_amount: '0.00000', total_rate: '0.00350', units: 1, - requester_ip: "192.168.1.1", + requester_ip: "192.168.1.1", is_domestic: false } }); @@ -1952,7 +1952,7 @@ export function Request(config) { total_amount: '0.00000', total_rate: '0.00350', units: 1, - requester_ip: '192.168.1.2', + requester_ip: '192.168.1.2', is_domestic: false } }); @@ -1982,7 +1982,7 @@ export function Request(config) { total_amount: '0.00000', total_rate: '0.00350', units: 1, - requester_ip: "192.168.1.1", + requester_ip: "192.168.1.1", is_domestic: false }, { @@ -1998,7 +1998,7 @@ export function Request(config) { total_amount: '0.00000', total_rate: '0.00350', units: 1, - requester_ip: "192.168.1.2", + requester_ip: "192.168.1.2", is_domestic: false } ] @@ -2276,6 +2276,114 @@ export function Request(config) { }); } + else if (method == 'POST' && action == 'Verify/Session/') { + resolve({ + response: {}, + body: { + message: 'Session initiated', + session_uuid: 'db3ce55a-7f1d-11e1-8ea7-1231380bc196', + api_id: 'db342550-7f1d-11e1-8ea7-1231380bc196' + } + }); + } + + else if (method == 'GET' && action == 'Verify/Session/1/') { + resolve({ + response: {}, + body: { + api_id: 'c3f2f101-ff46-44dd-808a-00408deba5d1', + session_uuid: 'd8f1b187-ddcb-438a-a298-eb17fb2b31f5', + app_uuid: '3cdec449-a367-435e-b4f9-40d777a7cfcc', + alias: 'new_voice45', + recipient: '918707046406', + channel: 'sms', + status: 'verified', + count: 1, + requestor_ip: '', + destination_country_iso2: 'IN', + destination_network: 'Jio', + attempt_details: [ + { + channel: 'sms', + attempt_uuid: 'e2f66aeb-6b98-42a9-ba81-0aba74a7eb7c', + status: 'delivered', + time: '2023-07-24T22:47:21.279363+05:30' + } + ], + charges: { + total_charge: '0.07100', + validation_charge: '0.05', + attempt_charges: [ + { + attempt_uuid: 'e2f66aeb-6b98-42a9-ba81-0aba74a7eb7c', + channel: 'sms', + charge: '0.02100' + } + ] + }, + created_at: '2023-07-24T22:47:19.243437+05:30', + updated_at: '2023-07-24T22:47:21.279363+05:30' + } + }) + } + + else if (method == 'GET' && action == 'Verify/Session/') { + resolve({ + response: {}, + body: { + api_id: 'c3f2f101-ff46-44dd-808a-00408deba5d1', + meta: { + limit: 20, + offset: 0, + next: null, + previous: null + }, + sessions:[{session_uuid: 'd8f1b187-ddcb-438a-a298-eb17fb2b31f5', + app_uuid: '3cdec449-a367-435e-b4f9-40d777a7cfcc', + alias: 'new_voice45', + recipient: '918707046406', + channel: 'sms', + status: 'verified', + count: 1, + requestor_ip: '', + destination_country_iso2: 'IN', + destination_network: 'Jio', + attempt_details: [ + { + channel: 'sms', + attempt_uuid: 'e2f66aeb-6b98-42a9-ba81-0aba74a7eb7c', + status: 'delivered', + time: '2023-07-24T22:47:21.279363+05:30' + } + ], + charges: { + total_charge: '0.07100', + validation_charge: '0.05', + attempt_charges: [ + { + attempt_uuid: 'e2f66aeb-6b98-42a9-ba81-0aba74a7eb7c', + channel: 'sms', + charge: '0.02100' + } + ] + }, + created_at: '2023-07-24T22:47:19.243437+05:30', + updated_at: '2023-07-24T22:47:21.279363+05:30'}] + } + }) + } + + else if (method == 'POST' && action == 'Verify/Session/1/') { + resolve({ + response: {}, + body: { + message: 'session validated successfully.', + session_uuid: 'db3ce55a-7f1d-11e1-8ea7-1231380bc196', + api_id: 'db342550-7f1d-11e1-8ea7-1231380bc196' + } + }); + } + // =========== If no combination found, raise issue ============================ else { console.log('===>--->', method, action, '=>', params); diff --git a/lib/rest/request.js b/lib/rest/request.js index 89c94d38..4a908190 100644 --- a/lib/rest/request.js +++ b/lib/rest/request.js @@ -33,7 +33,7 @@ export function Request(config) { headers: headers, json: true }; - let apiVoiceUris = ['https://api-messaging.sms.plivodev.com/v1/Account/','https://api-messaging.sms.plivodev.com/v1/Account/','https://api-messaging.sms.plivodev.com/v1/Account/']; + let apiVoiceUris = ['https://api.plivo.com/v1/Account/','https://api.plivo.com/v1/Account/','https://api.plivo.com/v1/Account/']; let isVoiceReq = false; if (params) { if (params.hasOwnProperty('is_call_insights_request')) { diff --git a/package.json b/package.json index d316b602..f2e5a8d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plivo", - "version": "4.51.0", + "version": "4.52.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/verify.js b/test/verify.js new file mode 100644 index 00000000..0319e381 --- /dev/null +++ b/test/verify.js @@ -0,0 +1,47 @@ +import { + Client +} from '../lib/rest/client-test'; +import { + PlivoGenericResponse +} from '../lib/base.js'; +import assert from 'assert'; +import sinon from 'sinon'; + +let client = new Client('sampleid', 'sammpletoken', 'sampleproxy'); + +describe('session', function () { + + it('should create session via interface', function () { + return client.verify_session.create({ + recipient: '+14156667778', + }) + .then(function (session) { + assert.equal(session.message, 'Session initiated') + }) + }); + + it('should get session', function () { + return client.verify_session.get(1) + .then(function (session) { + assert.equal(session.alias, 'new_voice45') + }) + }); + + it('list sessions', function () { + return client.verify_session.list() + .then(function (session) { + assert.equal(session[0].count, 1) + }) + }); + + it('should validate session via interface', function () { + return client.verify_session.validate({ + id: 1, + otp: 123456 + }) + .then(function (session) { + assert.equal(session.message, 'session validated successfully.') + }) + }); + +}); From ab79a477940f2a2380c6aabb2a722d839562f77a Mon Sep 17 00:00:00 2001 From: ashutoshkumar-plivo Date: Mon, 7 Aug 2023 10:04:56 +0530 Subject: [PATCH 04/11] added the link --- CHANGELOG.md | 2 +- examples/verify.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 examples/verify.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 81aa1e08..4480feb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [v4.52.0] +## [v4.52.0](https://github.com/plivo/plivo-go/tree/v4.52.0) **Verify Service API's** - Create Session API - Get Session API diff --git a/examples/verify.js b/examples/verify.js new file mode 100644 index 00000000..ec0719ce --- /dev/null +++ b/examples/verify.js @@ -0,0 +1,23 @@ +let plivo = require('plivo') + +let client = new plivo.Client(process.env.PLIVO_AUTH_ID, process.env.PLIVO_AUTH_TOKEN); + +client.verify_session.create({ + recipient: '+14156667778', +}).then(function(response) { + console.log(response) +}); + +client.verify_session.get('5c533d15-1975-4f20-80be-40174142ea37').then(function(response) { + console.log(response) +}); + +client.verify_session.list().then(function(response) { + console.log(response) +}); + +client.verify_session.validate({id:'c549be00-0e74-4ccb-ac04-8a778312b861',otp:'123456'}).then(function(response) { + console.log(response) +}).catch(function (error) { + console.log(error) +}); From 2a91bf6b2d8e8540f40c673d16481274792ced56 Mon Sep 17 00:00:00 2001 From: ashutoshkumar-plivo Date: Mon, 7 Aug 2023 16:50:50 +0530 Subject: [PATCH 05/11] fix the param --- lib/resources/verify.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/resources/verify.js b/lib/resources/verify.js index ffef686a..71bdcb50 100644 --- a/lib/resources/verify.js +++ b/lib/resources/verify.js @@ -40,9 +40,9 @@ export class SessionGetResponse { this.channel = params.channel; this.status = params.status; this.count = params.count; - this.requestor_ip = params.requestor_ip; - this.destination_country_iso2 = params.destination_country_iso2; - this.destination_network = params.destination_network; + this.requestor_ip = params.requestorIp; + this.destination_country_iso2 = params.destinationCountryIso2; + this.destination_network = params.destinationNetwork; this.attemptDetails = params.attemptDetails; this.createdAt = params.createdAt; this.updatedAt = params.updatedAt; @@ -65,9 +65,9 @@ export class SessionListResponse { this.channel = params.channel; this.status = params.status; this.count = params.count; - this.requestor_ip = params.requestor_ip; - this.destination_country_iso2 = params.destination_country_iso2; - this.destination_network = params.destination_network; + this.requestor_ip = params.requestorIp; + this.destination_country_iso2 = params.destinationCountryIso2; + this.destination_network = params.destinationNetwork; this.attemptDetails = params.attemptDetails; this.createdAt = params.createdAt; this.updatedAt = params.updatedAt; From d19b604d10fdd9ded54f523030870f153d2d05cf Mon Sep 17 00:00:00 2001 From: ashutoshkumar-plivo Date: Mon, 7 Aug 2023 17:09:16 +0530 Subject: [PATCH 06/11] fix the validation message --- lib/resources/verify.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/resources/verify.js b/lib/resources/verify.js index 71bdcb50..de89fbb5 100644 --- a/lib/resources/verify.js +++ b/lib/resources/verify.js @@ -29,6 +29,17 @@ export class SessionResponse { } } +export class ValidateSessionResponse { + constructor(params) { + params = params || {}; + this.apiId = params.apiId; + this.message = params.message; + if (params.invalidNumber != undefined ){ + this.invalid_number = params.invalidNumber; + } + } +} + export class SessionGetResponse { constructor(params) { params = params || {}; @@ -282,7 +293,7 @@ export class SessionInterface extends PlivoResourceInterface { return new Promise((resolve, reject) => { client('POST', action + (id ? id + '/' : ''), params) .then(response => { - resolve(new SessionResponse(response.body, idField)); + resolve(new ValidateSessionResponse(response.body, idField)); }) .catch(error => { reject(error); From cefed9c50b7f965ea9b5266360b3599510df2f86 Mon Sep 17 00:00:00 2001 From: ashutoshkumar-plivo Date: Wed, 9 Aug 2023 20:49:19 +0530 Subject: [PATCH 07/11] added meta in response --- lib/resources/verify.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/resources/verify.js b/lib/resources/verify.js index de89fbb5..9035b2c2 100644 --- a/lib/resources/verify.js +++ b/lib/resources/verify.js @@ -236,6 +236,10 @@ export class SessionInterface extends PlivoResourceInterface { return new Promise((resolve, reject) => { client('GET', action, params) .then(response => { + let sessions = { + api_id: response.body.apiId, + meta: response.body.meta + } let objects = []; Object.defineProperty(objects, 'meta', { value: response.body.meta, @@ -248,7 +252,8 @@ export class SessionInterface extends PlivoResourceInterface { response.body.sessions.forEach(item => { objects.push(new SessionListResponse(item, client)); }); - resolve(objects); + sessions.sessions = objects + resolve(sessions); }) .catch(error => { reject(error); From 93e6621f5b8367ddfba0d78a7a7d6217d6709d41 Mon Sep 17 00:00:00 2001 From: ashutoshkumar-plivo Date: Wed, 9 Aug 2023 20:59:10 +0530 Subject: [PATCH 08/11] fixed the utcs --- test/verify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/verify.js b/test/verify.js index 0319e381..2055451f 100644 --- a/test/verify.js +++ b/test/verify.js @@ -30,7 +30,7 @@ describe('session', function () { it('list sessions', function () { return client.verify_session.list() .then(function (session) { - assert.equal(session[0].count, 1) + assert.equal(session.sessions[0].count, 1) }) }); From 2c74c71e21d3b4364ecc4c3ae9dad8834dfbefc8 Mon Sep 17 00:00:00 2001 From: ashutoshkumar-plivo Date: Thu, 10 Aug 2023 11:31:38 +0530 Subject: [PATCH 09/11] handle cases for null scenario --- lib/resources/verify.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/resources/verify.js b/lib/resources/verify.js index 9035b2c2..de04d586 100644 --- a/lib/resources/verify.js +++ b/lib/resources/verify.js @@ -249,10 +249,14 @@ export class SessionInterface extends PlivoResourceInterface { value: response.body.apiId, enumerable: true }) - response.body.sessions.forEach(item => { - objects.push(new SessionListResponse(item, client)); - }); - sessions.sessions = objects + if (response.body.sessions !== null) { + response.body.sessions.forEach(item => { + objects.push(new SessionListResponse(item, client)); + }); + sessions.sessions = objects + } else { + sessions.sessions = null + } resolve(sessions); }) .catch(error => { From 24ba4489a8eac887af3800e14134e488503503fd Mon Sep 17 00:00:00 2001 From: ashutoshkumar-plivo Date: Thu, 10 Aug 2023 12:24:25 +0530 Subject: [PATCH 10/11] update the version --- CHANGELOG.md | 14 ++++++++------ package.json | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25f9254c..c5bd8871 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,17 @@ # Change Log + +## [v4.55.0](https://github.com/plivo/plivo-node/tree/v4.55.0) +**Verify Service API's** +- Create Session API - To initiate a session +- Get Session API - Get session detail +- List Session API - List Session details +- Validate Session API + ## [v4.54.0](https://github.com/plivo/plivo-node/tree/v4.54.0) (2023-08-07) **Feature - WhatsApp message support** - Added new param `template` and new message_type `whatsapp` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message) - Added new `message_states` (`read`) `message_type`(`whatsapp`),`conversation_id`, `conversation_origin`, `conversation_expiry_timestamp` in [list all messages API](https://www.plivo.com/docs/sms/api/message#list-all-messages) and [get message details API](https://www.plivo.com/docs/sms/api/message#retrieve-a-message) response -## [v4.54.0](https://github.com/plivo/plivo-go/tree/v4.54.0) -**Verify Service API's** -- Create Session API -- Get Session API -- List Session API -- Validate Session API ## [4.53.0](https://github.com/plivo/plivo-node/tree/v4.53.0) (2023-08-03) **Feature - DLT parameters** diff --git a/package.json b/package.json index ca3ed89c..9e4a1008 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plivo", - "version": "4.54.0", + "version": "4.55.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": [ From fc5f72083cd7cce43033012a7a62190599d1d82f Mon Sep 17 00:00:00 2001 From: ashutoshkumar-plivo Date: Thu, 10 Aug 2023 12:25:15 +0530 Subject: [PATCH 11/11] update the version --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5bd8871..70822654 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [v4.55.0](https://github.com/plivo/plivo-node/tree/v4.55.0) +## [v4.55.0](https://github.com/plivo/plivo-node/tree/v4.55.0) (2023-08-10) **Verify Service API's** - Create Session API - To initiate a session - Get Session API - Get session detail