mirror of
https://github.com/donl/plivo-node.git
synced 2026-06-30 06:12:08 -06:00
Merge branch 'master' into VT-1641-app-cascade-delete
This commit is contained in:
commit
a403eaa4de
8 changed files with 201 additions and 12 deletions
|
|
@ -1,7 +1,12 @@
|
|||
# Change Log
|
||||
|
||||
## [4.2.0](https://github.com/plivo/plivo-node/releases/tag/v4.2.0)(2020-02-25)
|
||||
## [4.4.0](https://github.com/plivo/plivo-node/releases/tag/v4.4.0)(2020-03-30)
|
||||
- Add Tollfree support for Powerpack
|
||||
|
||||
## [4.3.0](https://github.com/plivo/plivo-node/releases/tag/v4.3.0)(2020-03-27)
|
||||
- Add post call quality feedback API support.
|
||||
|
||||
## [4.2.0](https://github.com/plivo/plivo-node/releases/tag/v4.2.0)(2020-02-25)
|
||||
- Add Media support.
|
||||
|
||||
## [4.1.9](https://github.com/plivo/plivo-node/releases/tag/v4.1.9)(2020-02-12)
|
||||
|
|
|
|||
9
examples/callFeedback.js
Normal file
9
examples/callFeedback.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
var Plivo = require('../dist/rest/client.js');
|
||||
var client = new Plivo.Client();
|
||||
|
||||
client.callFeedback.create('call_uuid', 4, ["ISSUE"], "User Feedback").then(function(call_feedback) {
|
||||
console.log("\n============ send feedback ===========\n", call_feedback)
|
||||
})
|
||||
.catch(function(response) {
|
||||
console.log("\n============ Error :: ===========\n", response);
|
||||
});
|
||||
61
lib/resources/callFeedback.js
Normal file
61
lib/resources/callFeedback.js
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import {extend, validate} from '../utils/common.js';
|
||||
import {PlivoResource, PlivoResourceInterface} from '../base';
|
||||
import * as _ from "lodash";
|
||||
|
||||
const clientKey = Symbol();
|
||||
const action = 'Call/';
|
||||
const idField = 'callUuid';
|
||||
const CALLINSIGHTS_BASE_URL = 'https://stats.plivo.com/'
|
||||
|
||||
export class CallFeedback extends PlivoResource {
|
||||
constructor(client, data = {}) {
|
||||
super(action, Call, idField, client);
|
||||
|
||||
if (idField in data) {
|
||||
this.id = data[idField];
|
||||
}
|
||||
|
||||
extend(this, data);
|
||||
this[clientKey] = client;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a CallFeedback Interface
|
||||
* @constructor
|
||||
* @param {function} client - make api call
|
||||
* @param {object} [data] - data of call
|
||||
*/
|
||||
export class CallFeedbackInterface extends PlivoResourceInterface {
|
||||
constructor(client, data = {}) {
|
||||
super(action, CallFeedback, idField, client);
|
||||
extend(this, data);
|
||||
|
||||
this[clientKey] = client;
|
||||
}
|
||||
|
||||
create(callUUID, rating, issues=[], notes="") {
|
||||
let errors = validate([
|
||||
{field: 'callUUId', value: callUUID, validators: ['isRequired']},
|
||||
{field: 'rating', value: rating, validators: ['isRequired']}
|
||||
]);
|
||||
|
||||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
|
||||
var params = {};
|
||||
params.rating = rating;
|
||||
if (issues.length > 0) {
|
||||
params.issues = issues;
|
||||
}
|
||||
if (notes.length > 0) {
|
||||
params.notes = notes;
|
||||
}
|
||||
params.isCallInsightsRequest = "";
|
||||
params.CallInsightsBaseUrl = CALLINSIGHTS_BASE_URL;
|
||||
params.CallInsightsRequestPath = `v1/Call/${callUUID}/Feedback/`;
|
||||
return super.create(params);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -98,16 +98,28 @@ export class Powerpack extends PlivoResource {
|
|||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'POST', params);
|
||||
}
|
||||
add_tollfree(tollfree) {
|
||||
var params = {};
|
||||
params['rent'] = 'false';
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Tollfree/' + tollfree + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'POST', params);
|
||||
}
|
||||
remove_number(number, unrent = false) {
|
||||
var params = {};
|
||||
if (typeof unrent === 'boolean') {
|
||||
params['unrent'] = unrent.toString();
|
||||
} else {
|
||||
params['unrent'] = unrent;
|
||||
}
|
||||
params['unrent'] = unrent.toString();
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'DELETE', params);
|
||||
}
|
||||
remove_tollfree(tollfree, unrent = false) {
|
||||
var params = {};
|
||||
params['unrent'] = unrent.toString();
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Tollfree/' + tollfree + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'DELETE', params);
|
||||
}
|
||||
remove_shortcode(shortcode) {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Shortcode/' + shortcode + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'DELETE');
|
||||
}
|
||||
list_shortcodes(params) {
|
||||
if (params === undefined) {
|
||||
params = {};
|
||||
|
|
@ -115,10 +127,21 @@ export class Powerpack extends PlivoResource {
|
|||
let path = 'NumberPool/' + this.number_pool_id + '/Shortcode/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET', params);
|
||||
}
|
||||
list_tollfree(params) {
|
||||
if (params === undefined) {
|
||||
params = {};
|
||||
}
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Tollfree/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET', params);
|
||||
}
|
||||
find_shortcode(shortcode) {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Shortcode/' + shortcode + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET');
|
||||
}
|
||||
find_tollfree(tollfree) {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Tollfree/' + tollfree + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET');
|
||||
}
|
||||
buy_add_number(params) {
|
||||
var number = params.number;
|
||||
var rentparam = {};
|
||||
|
|
@ -184,6 +207,9 @@ export class NumberPool extends PlivoResource {
|
|||
this.shortcodes = new Shortcode(client, {
|
||||
number_pool_id: data.number_pool_id
|
||||
});
|
||||
this.tollfree = new Tollfree(client, {
|
||||
number_pool_id: data.number_pool_id
|
||||
});
|
||||
|
||||
extend(this, data);
|
||||
}
|
||||
|
|
@ -286,11 +312,7 @@ export class Numbers extends PlivoResource {
|
|||
}
|
||||
remove(number, unrent = false) {
|
||||
var params = {};
|
||||
if (typeof unrent === 'boolean') {
|
||||
params['unrent'] = unrent.toString();
|
||||
} else {
|
||||
params['unrent'] = unrent;
|
||||
}
|
||||
params['unrent'] = unrent.toString();
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Number/' + number + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'DELETE', params);
|
||||
}
|
||||
|
|
@ -312,6 +334,40 @@ export class Shortcode extends PlivoResource {
|
|||
let path = 'NumberPool/' + this.number_pool_id + '/Shortcode/' + shortcode + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET');
|
||||
}
|
||||
remove(shortcode) {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Shortcode/' + shortcode + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'DELETE');
|
||||
}
|
||||
}
|
||||
export class Tollfree extends PlivoResource {
|
||||
constructor(client, data = {}) {
|
||||
super(action, Tollfree, numberPoolField, client);
|
||||
extend(this, data);
|
||||
this.number_pool_id = data.number_pool_id;
|
||||
}
|
||||
add(tollfree) {
|
||||
var params = {};
|
||||
params['rent'] = 'false';
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Tollfree/' + tollfree + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'POST', params);
|
||||
}
|
||||
remove(tollfree, unrent = false) {
|
||||
var params = {};
|
||||
params['unrent'] = unrent.toString();
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Tollfree/' + tollfree + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'DELETE', params);
|
||||
}
|
||||
list(params) {
|
||||
if (params === undefined) {
|
||||
params = {};
|
||||
}
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Tollfree/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET', params);
|
||||
}
|
||||
find(tollfree) {
|
||||
let path = 'NumberPool/' + this.number_pool_id + '/Tollfree/' + tollfree + '/';
|
||||
return super.customexecuteAction(path.toString().trim(), 'GET');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Represents a Powerpack interface
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import { RecordingInterface } from "../resources/recordings";
|
|||
import { Response } from "../utils/plivoxml";
|
||||
import { validateSignature } from "../utils/security";
|
||||
import { stringify } from "./../utils/jsonStrinfigier";
|
||||
import { CallFeedbackInterface } from "../resources/callFeedback";
|
||||
import { MediaInterface } from "../resources/media.js";
|
||||
|
||||
exports.Response = function() {
|
||||
|
|
@ -72,6 +73,7 @@ export class Client {
|
|||
this.numbers = new NumberInterface(client);
|
||||
this.pricings = new PricingInterface(client);
|
||||
this.recordings = new RecordingInterface(client);
|
||||
this.callFeedback = new CallFeedbackInterface(client);
|
||||
this.media = new MediaInterface(client);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,15 @@ export function Request(config) {
|
|||
headers: headers,
|
||||
json: true
|
||||
};
|
||||
|
||||
if (params.hasOwnProperty('is_call_insights_request')) {
|
||||
options.url = params.call_insights_base_url + params.call_insights_request_path;
|
||||
delete params.is_call_insights_request;
|
||||
delete params.call_insights_base_url;
|
||||
delete params.call_insights_request_path;
|
||||
delete options.formData;
|
||||
options.json = params;
|
||||
}
|
||||
|
||||
if (method === 'GET' && options.formData !== '') {
|
||||
let query = '?' + queryString.stringify(params);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "plivo",
|
||||
"version": "4.2.0",
|
||||
"version": "4.4.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": [
|
||||
|
|
|
|||
|
|
@ -87,5 +87,52 @@ describe('PowerpackInterface', function () {
|
|||
assert.notEqual(result.length, 0)
|
||||
})
|
||||
});
|
||||
it('list tollfree via interface', function () {
|
||||
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
|
||||
function (powerpack) {
|
||||
return powerpack.list_tollfree()
|
||||
})
|
||||
.then(function (result) {
|
||||
assert.notEqual(result.length, 0)
|
||||
})
|
||||
});
|
||||
it('find tollfree via interface', function () {
|
||||
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
|
||||
function (powerpack) {
|
||||
return powerpack.find_tollfree('18772209942')
|
||||
})
|
||||
.then(function (result) {
|
||||
assert.Equal(result.number, "18772209942")
|
||||
})
|
||||
});
|
||||
it('add tollfree to powerpack via interface', function () {
|
||||
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
|
||||
function (powerpack) {
|
||||
return powerpack.add_tollfree('18772209942')
|
||||
})
|
||||
.then(function (result) {
|
||||
assert.Equal(result.number, "18772209942")
|
||||
})
|
||||
});
|
||||
it('remove tollfree via interface', function () {
|
||||
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
|
||||
function (powerpack) {
|
||||
return powerpack.remove_tollfree("18772209942", true)
|
||||
})
|
||||
.then(function (result) {
|
||||
assert.notEqual(result.response, "success")
|
||||
})
|
||||
});
|
||||
|
||||
it('remove shortcode via interface', function () {
|
||||
client.powerpacks.get("5ec4c8c9-cd74-42b5-9e41-0d7670d6bb46").then(
|
||||
function (powerpack) {
|
||||
return powerpack.remove_shortcode("444444")
|
||||
})
|
||||
.then(function (result) {
|
||||
assert.notEqual(result.response, "success")
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue