Skip to content

Commit

Permalink
Merge pull request #158 from plivo/New_Voice_API_and_MPC
Browse files Browse the repository at this point in the history
Voice requests retry logic
  • Loading branch information
nixonsam authored Aug 5, 2020
2 parents 1a3a14d + 450aa57 commit 58c9f23
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 56 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## [4.8.0](https://github.com/plivo/plivo-node/releases/tag/v4.8.0)(2020-07-23)
- Add retries to multiple regions for voice requests.

## [4.7.0](https://github.com/plivo/plivo-node/releases/tag/v4.7.0)(2020-05-28)
- Add JWT helper functions.

Expand Down
3 changes: 3 additions & 0 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export class PlivoResource {
client('POST', action + id + '/', params)
.then(response => {
extend(that, response.body);
if (params.hasOwnProperty('isVoiceRequest')){
delete params.isVoiceRequest;
}
extend(that, params);
resolve(that);
})
Expand Down
21 changes: 19 additions & 2 deletions lib/resources/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class Application extends PlivoResource {
* @fail {Error} return Error
*/
update(params) {
params.isVoiceRequest = 'true';
return super.update(params);
}

Expand All @@ -59,6 +60,7 @@ export class Application extends PlivoResource {
if (typeof params.cascade === 'boolean') {
params.cascade = params.cascade.toString();
}
params.isVoiceRequest = 'true';
return super.delete(params);
}

Expand Down Expand Up @@ -86,7 +88,22 @@ export class ApplicationInterface extends PlivoResourceInterface {
* @fail {Error} return Error
*/
get(id) {
return super.get(id);
let params = {}
params.isVoiceRequest = 'true'
return super.get(id, params);
}

/**
* list applications
* @method
* @param {object} params - params to list applications
* @param {string} [params.subaccount] - ID of the subaccount if present
* @param {integer} [params.limit] - To display no of results per page
* @param {integer} [params.offset] - No of value items by which results should be offset
*/
list(params= {}) {
params.isVoiceRequest = 'true';
return super.list(params);
}

/**
Expand Down Expand Up @@ -122,7 +139,7 @@ export class ApplicationInterface extends PlivoResourceInterface {
}

params.app_name = appName;

params.isVoiceRequest = 'true';
return super.create(params);
}

Expand Down
35 changes: 27 additions & 8 deletions lib/resources/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export class Call extends PlivoResource {
* @fail {Error} return Error
*/
hangup() {
return super.delete();
let params = {}
params.isVoiceRequest = 'true';
return super.delete(params);
}

/**
Expand All @@ -48,6 +50,7 @@ export class Call extends PlivoResource {
* @fail {Error} return Error
*/
transfer(params) {
params.isVoiceRequest = 'true';
return super.update(params);
}
/**
Expand All @@ -69,6 +72,7 @@ export class Call extends PlivoResource {
* @fail {Error} return Error
*/
startRecording(params) {
params.isVoiceRequest = 'true';
return super.executeAction(this.id + '/Record/', 'POST', params);
}
/**
Expand All @@ -79,6 +83,7 @@ export class Call extends PlivoResource {
* @fail {Error} return Error
*/
stopRecording(params) {
params.isVoiceRequest = 'true';
return super.executeAction(this.id + '/Record/', 'DELETE', params);
}

Expand All @@ -104,6 +109,7 @@ export class Call extends PlivoResource {
startPlayingMusic(urls, optionalParams) {
let params = optionalParams || {};
params.urls = urls;
params.isVoiceRequest = 'true';

let errors = validate([
{field: 'urls', value: urls, validators: ['isRequired', 'isString']}
Expand All @@ -122,7 +128,9 @@ export class Call extends PlivoResource {
* @fail {Error} returns Error
*/
stopPlayingMusic() {
return super.executeAction(this.id + '/Play/', 'DELETE');
let params = {}
params.isVoiceRequest = 'true'
return super.executeAction(this.id + '/Play/', 'DELETE', params);
}

/**
Expand Down Expand Up @@ -154,6 +162,7 @@ export class Call extends PlivoResource {

let params = optionalParams || {};
params.text = text;
params.isVoiceRequest = 'true';

return super.executeAction(this.id + '/Speak/', 'POST', params);
}
Expand All @@ -165,7 +174,9 @@ export class Call extends PlivoResource {
* @fail {Error} returns Error
*/
stopSpeakingText() {
return super.executeAction(this.id + '/Speak/', 'DELETE');
let params = {}
params.isVoiceRequest = 'true';
return super.executeAction(this.id + '/Speak/', 'DELETE', params);
}

/**
Expand All @@ -185,7 +196,7 @@ export class Call extends PlivoResource {

let params = optionalParams || {};
params.digits = digits;

params.isVoiceRequest = 'true';
return super.executeAction(this.id + '/DTMF/', 'POST', params);
}

Expand All @@ -196,7 +207,9 @@ export class Call extends PlivoResource {
* @fail {Error} returns Error
*/
cancel() {
return super.executeAction('Request/' + this.id + '/', 'DELETE', {}, '');
let params = {};
params.isVoiceRequest = 'true';
return super.executeAction('Request/' + this.id + '/', 'DELETE', params, '');
}
}

Expand Down Expand Up @@ -233,7 +246,9 @@ export class CallInterface extends PlivoResourceInterface {
if (errors) {
return errors;
}
return super.get(id);
let params = {}
params.isVoiceRequest = 'true';
return super.get(id, params);
}

/**
Expand All @@ -244,6 +259,7 @@ export class CallInterface extends PlivoResourceInterface {
* @fail {Error} returns Error
*/
list(params) {
params.isVoiceRequest = 'true';
return super.list(params);
}

Expand Down Expand Up @@ -289,6 +305,7 @@ export class CallInterface extends PlivoResourceInterface {
params.from = from;
params.to = _.isArray(to) ? _.join(to, '<') : to;
params.answer_url = answerUrl;
params.isVoiceRequest = 'true';

return super.create(params);
}
Expand Down Expand Up @@ -582,6 +599,7 @@ class LiveCallInterface extends PlivoResourceInterface {
}
return super.get(id, {
status: 'live',
isVoiceRequest: 'true'
});
}

Expand All @@ -591,7 +609,7 @@ class LiveCallInterface extends PlivoResourceInterface {
params = {}
}
params.status = 'live'

params.isVoiceRequest = 'true'
return new Promise((resolve, reject) => {
client('GET', action, params)
.then(response => {
Expand Down Expand Up @@ -640,14 +658,15 @@ class QueuedCallInterface extends PlivoResourceInterface {
}
return super.get(id, {
status: 'queued',
isVoiceRequest: 'true'
});
}

list() {
let client = this[clientKey];

return new Promise((resolve, reject) => {
client('GET', action, {status: 'queued'})
client('GET', action, {status: 'queued', isVoiceRequest: 'true'})
.then(response => {
let calls = [];
response.body.calls.forEach(callUuid => {
Expand Down
Loading

0 comments on commit 58c9f23

Please sign in to comment.