Skip to content

Commit

Permalink
Merge pull request #141 from plivo/post-feedback
Browse files Browse the repository at this point in the history
Post feedback
  • Loading branch information
nixonsam authored Mar 27, 2020
2 parents 9417b70 + 00fc70c commit 95c1ea6
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Change Log

## [4.2.0](https://github.com/plivo/plivo-node/releases/tag/v4.2.0)(2020-02-25)
## [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)
Expand Down
9 changes: 9 additions & 0 deletions examples/callFeedback.js
Original file line number Diff line number Diff line change
@@ -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 changes: 61 additions & 0 deletions lib/resources/callFeedback.js
Original file line number Diff line number Diff line change
@@ -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);
}

}
2 changes: 2 additions & 0 deletions lib/rest/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}

Expand Down
9 changes: 9 additions & 0 deletions lib/rest/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plivo",
"version": "4.2.0",
"version": "4.3.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": [
Expand Down

0 comments on commit 95c1ea6

Please sign in to comment.