Merge branch 'master' into Fix_MessageResource

This commit is contained in:
Mohammed Huzaif 2021-08-25 12:15:17 +05:30 committed by GitHub
commit 053ad01214
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 80 additions and 47 deletions

View file

@ -1,7 +1,17 @@
# Change Log
## [v4.21.0](https://github.com/plivo/plivo-node/tree/v4.21.0) (2021-07-20)
- This version includes advancements to the Messaging Interface that deals with the [Send SMS/MMS](https://www.plivo.com/docs/sms/api/message#send-a-message) interface, Creating a standard structure for `request/input` arguments to make implementation easier and incorporating support for the older interface.
## [v4.22.0](https://github.com/plivo/plivo-node/tree/v4.22.0) (2021-08-17)
- Fix [add numbers to a powerpack](https://www.plivo.com/docs/sms/api/numberpool/#add-a-number) API by reverting retrievable object responses support for [Retrieve a Power pack API](https://www.plivo.com/docs/sms/api/powerpack#retrieve-a-powerpack).
## [v4.21.0](https://github.com/plivo/plivo-node/tree/v4.21.0) (2021-08-05)
- Fixed a Typescript warning about base interpretation.
- Add retrievable object responses support for [Retrieve a Power pack API](https://www.plivo.com/docs/sms/api/powerpack#retrieve-a-powerpack).
## [v4.20.1](https://github.com/plivo/plivo-node/tree/v4.20.1) (2021-07-27)
- Updates to [add a member a multi-party call API](https://www.plivo.com/docs/voice/api/multiparty-call/participants#add-a-participant).
- Remove validation range for `delay` and `ringtimeout` parameters.
- Add appropriate error message for multiple `ringtimeout` and `delaydial` values.
- Updated default HTTP client request timeout to 5 seconds.
## [v4.20.0](https://github.com/plivo/plivo-node/tree/v4.20.0) (2021-07-13)
- Power pack ID has been included to the response for the [list all messages API](https://www.plivo.com/docs/sms/api/message/list-all-messages/) and the [get message details API](https://www.plivo.com/docs/sms/api/message#retrieve-a-message).

View file

@ -106,24 +106,24 @@ export class MultiPartyCall extends PlivoResource{
if(params.ringTimeout || params.ringTimeout === 0){
validParam('ringTimeout', params.ringTimeout, [String, Number], false)
if(Number.isInteger(params.ringTimeout)){
validRange('RingTimeout', params.ringTimeout, false, 15, 120)
}
else{
if(typeof(params.ringTimeout) === 'string'){
validMultipleDestinationIntegers('ringTimeout', params.ringTimeout)
}
else if (!Number.isInteger(params.ringTimeout) && typeof(params.ringTimeout) !== 'string'){
throw new InvalidRequestError("RingTimeout must be of type int or string")
}
}
else {
params.ringTimeout = 45
}
if(params.delayDial){
validParam('delayDial', params.delayDial, [String, Number], false)
if(Number.isInteger(params.delayDial)){
validRange('DelayDial', params.delayDial, false, 1, 120)
}
else{
if(typeof(params.delayDial) === 'string'){
validMultipleDestinationIntegers('delayDial', params.delayDial)
}
else if(!Number.isInteger(params.delayDial) && typeof(params.delayDial) !== 'string'){
throw new InvalidRequestError("Dealydial must be of type int or string")
}
}
else {
params.delayDial = 0
@ -306,6 +306,12 @@ export class MultiPartyCall extends PlivoResource{
else {
params.exitSoundMethod = 'GET'
}
if(params.to && (String(params.ringTimeout).split('<').length > params.to.split('<').length)){
throw new MPCError("RingTimeout:number of ring_timeout(s) should be same as number of destination(s)")
}
if(params.to && (String(params.delayDial).split('<').length > params.to.split('<').length)){
throw new MPCError("DelayDial:number of delay_dial(s) should be same as number of destination(s)")
}
params.isVoiceRequest = 'true';
params.callerName = params.callerName || params.from;
return super.executeAction(this.id + '/Participant/', 'POST', params)

View file

@ -1,4 +1,5 @@
import {
PlivoGenericResponse,
PlivoResource,
PlivoResourceInterface
} from '../base';
@ -271,7 +272,15 @@ export class NumberInterface extends PlivoResourceInterface {
params.carrier = carrier;
params.region = region;
return super.create(params);
return new Promise((resolve, reject) => {
client('POST', action, params)
.then(response => {
resolve(new PlivoGenericResponse(response.body, idField));
})
.catch(error => {
reject(error);
});
})
}
/**

View file

@ -457,7 +457,6 @@ export class Powerpack extends PlivoResource {
* @param {string} [params.sticky_sender]
* @param {string} [params.local_connect]
* @param {object} [params.number_priority]
* @promise {object} return {@link Powerpack} object
* @fail {Error} return Error
*/
@ -696,7 +695,7 @@ export class PowerpackInterface extends PlivoResourceInterface {
* @promise {object} return {@link Powerpack} object
* @fail {Error} return Error
*/
get(uuid) {
get(uuid) {
return super.get(uuid);
}
/**
@ -777,4 +776,4 @@ export class PowerpackInterface extends PlivoResourceInterface {
list(params) {
return super.list(params);
}
}
}

View file

@ -175,6 +175,9 @@ export function Axios(config) {
if (typeof config.timeout !== 'undefined') {
options.timeout = config.timeout;
}
else if(typeof config.timeout === 'undefined'){
options.timeout = 5000;
}
return new Promise((resolve, reject) => {
if (isVoiceReq) {

View file

@ -1,5 +1,5 @@
import request from 'request';
import queryString from 'querystring';
import request from 'request';
export function Request(config) {
let auth = 'Basic ' + new Buffer(config.authId + ':' + config.authToken)
@ -1465,4 +1465,4 @@ export function Request(config) {
}
});
};
}
}

View file

@ -1,8 +1,9 @@
import request from 'request';
import queryString from 'querystring';
import * as Exceptions from '../utils/exceptions';
import * as _ from "lodash";
import queryString from 'querystring';
import request from 'request';
export function Request(config) {
let auth = 'Basic ' + new Buffer(config.authId + ':' + config.authToken)
.toString('base64');
@ -219,4 +220,4 @@ export function Request(config) {
});
});
};
}
}

View file

@ -115,17 +115,7 @@ export function validMultipleDestinationNos(paramName, paramValue, options = {})
export function validMultipleDestinationIntegers(paramName, paramValue){
let val = paramValue.split("<");
for (let i=0; i<val.length; i++){
if (!isNaN(val[i]) && Number.isInteger(parseFloat(val[i]))){
if(paramName=="delayDial"){
if(val[i]!='0'){
validRange('DelayDial Destination Value', parseInt(val[i]), false, 1, 120);
}
}
else if (paramName=="ringTimeout"){
validRange('RingTimeout Destination Value', parseInt(val[i]), false, 15, 120);
}
}
else{
if (!(/^-?\d+$/.test(val[i]))){
throw new InvalidRequestError( paramName + " Destination value must be integer");
}
}

2
package-lock.json generated
View file

@ -5591,4 +5591,4 @@
"dev": true
}
}
}
}

View file

@ -1,6 +1,6 @@
{
"name": "plivo",
"version": "4.21.0",
"version": "4.22.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": [

12
types/base.d.ts vendored
View file

@ -4,8 +4,8 @@ export class PlivoGenericResponse {
}
export class PlivoResource {
constructor(action: string, Klass: Symbol, idField: string, request: any);
update(params: object, id: string): Promise<any>;
delete(params: object): Promise<any>;
// update(params: any, id: any): Promise<any>;
delete(params: any): Promise<any>;
executeAction(task: string, method: string, params: {}, action: string): Promise<any>;
customexecuteAction(url: string, method?: string, params?: {}): Promise<any>;
customexecuteGetNumberAction(url: string, method?: string, params?: {}): any;
@ -13,7 +13,7 @@ export class PlivoResource {
}
export class PlivoResourceInterface {
constructor(action: string, Klass: Symbol, idField: string, request: any);
get(id: string, params?: {}): Promise<any>;
list(params: object): Promise<any>;
create(params: object): Promise<any>;
}
// get(id: any, params?: {}): Promise<any>;
// create(params: any): Promise<any>;
list(params: any): Promise<any>;
}

View file

@ -29,7 +29,7 @@ export class ListEndUsersResponse {
constructor(params: object);
apiId: string;
meta: Object;
objects: Array;
objects: Array<string>;
}
/**

View file

@ -42,7 +42,7 @@ export class MediaInterface extends PlivoResourceInterface {
* @method
* @fail {Error} return Error
*/
upload(files: Array): Promise<UploadMediaResponse>;
upload(files: Array<string>): Promise<UploadMediaResponse>;
/**
* Get Media by given id
* @method

View file

@ -23,7 +23,7 @@ export class MessageGetResponse {
}
export class MessageListResponse {
constructor(params: object);
errorCode: string;
errorCode: string;
fromNumber: string;
messageDirection: string;
messageState: string;
@ -34,7 +34,7 @@ export class MessageListResponse {
toNumber: string;
totalAmount: string;
totalRate: string;
units: string;
units: string;
powerpackId: string;
}
export class MMSMediaResponse {
@ -90,7 +90,7 @@ export class MessageInterface extends PlivoResourceInterface {
type: string;
url: string;
method: string;
media_urls: Array;
media_urls: Array<string>;
log: boolean;
}): Promise < MessageResponse > ;
/**

View file

@ -17,6 +17,21 @@ export class CreatePowerpackResponse {
stickySender: string;
uuid: string;
}
export class RetrievePowerpack {
constructor(params: object);
apiId: string;
applicationId: string;
applicationType: string;
createdOn: string;
localConnect: string;
name: string;
numberPool: string;
numberPriority: object;
stickySender: string;
uuid: string;
}
export class UpdatePowerpackResponse {
constructor(params: object);
apiId: string;
@ -179,7 +194,7 @@ export class PowerpackInterface extends PlivoResourceInterface {
* @promise {object} return {@link Powerpack} object
* @fail {Error} return Error
*/
get(uuid: string): any;
get(uuid: string): Promise<RetrievePowerpack>;
/**
* create Powerpack
* @method
@ -189,7 +204,7 @@ export class PowerpackInterface extends PlivoResourceInterface {
* @param {string} [params.local_connect]
* @param {string} [params.application_type]
* @param {string} [params.application_id]
* @promise {object} return {@link PlivoGenericResponse} object
* @promise {object} return {@link RetrievePowerpack} object
* @fail {Error} return Error
*/
create(name: string, params?: {}): Promise<CreatePowerpackResponse>;

View file

@ -1 +1 @@
export function Request(config: any): (method: string, action: string, params: object) => Promise<any>;
export function Request(config: any): (method: string, action: string, params: object) => Promise<any>;

View file

@ -1 +1 @@
export function Request(config: any): (method: string, action: string, params: object) => Promise<any>;
export function Request(config: any): (method: string, action: string, params: object) => Promise<any>;