-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added phlo client. * Finished implementaiton of initializing phlo client. * Finished logic for v2 methods of multiparty call(not members). * Added test cases for multiparty call. * Finished logic for phlo get api. * Added member method structure. * Finished implementation of phlo.run(). * Finished api calls for multi party(except abort transfer). * Deleted old rest.js file. * Finished abortTranfer implementation with test cases. * Finished implementation of member.resumeCall(). * Finished all member functions. * Reverted debugging logic. * Removed console.log * Added samples for all apis. method structure change for abort transfer. * Resolved nsp issue. * Audit fix. * Package Lock Fix. * Added test proxy for test cases. * Resolved issue in request.js json format. * Improved comments. * Added test cases for .get() methods. * Removed async await to support older browsers. * Modified examples of phlo, removed async await. * Resolved example issues, remove auth credentials. * Removed es6 declaration syntaxes from phlo example. * Added logic to pass payload. * changed beta version 4.1-beta.1 * changed beta version 4.1-beta.1 * changed beta version 4.1-beta.1 * changes in changelog & readme- Add PHLO support
- Loading branch information
Showing
15 changed files
with
6,522 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
var plivo = require('../dist/rest/client-test.js'); | ||
var PhloClient = plivo.PhloClient; | ||
|
||
|
||
var authId = 'auth-id'; | ||
var authToken = 'auth-token'; | ||
var phloId = 'sample-phlo-id'; | ||
var mpcId = 'sample-mpc-id'; | ||
|
||
var mpcSourceNo = '919920700964'; | ||
var mpcTargetNo = '919620074923'; | ||
var role = 'agent'; | ||
var phloClient = phlo = null; | ||
|
||
//Get Phlo details by phlo id | ||
phloClient = new PhloClient(authId, authToken); | ||
phloClient.phlo.get(phloId).then(function (result) { | ||
console.log('phlo details =>', result); | ||
}).catch(function (err) { | ||
console.log('Failed to fetch phlo details', err); | ||
});; | ||
|
||
|
||
// Run phlo | ||
phloClient = new PhloClient(authId, authToken); | ||
phloClient.phlo(phloId).run().then(function (result) { | ||
console.log('Phlo run result', result); | ||
}).catch(function (err) { | ||
console.error('Phlo run failed', err); | ||
}); | ||
|
||
|
||
/**************************** Multiparty call examples **************************/ | ||
|
||
// Get multi-party call details | ||
phloClient = new PhloClient(authId, authToken); | ||
phloClient.phlo(phloId).multiPartyCall.get(mpcId).then(function (result) { | ||
console.log('multi party call details api result', result); | ||
}).catch(function (err) { | ||
console.log('multi party call details api failed', err); | ||
}) | ||
|
||
|
||
// Add member to multi party call | ||
phloClient = new PhloClient(authId, authToken); | ||
phloClient.phlo(phloId).multiPartyCall(mpcId).call(mpcSourceNo, mpcTargetNo, role).then(function (result) { | ||
console.log('Multiparty call result', result); | ||
}).catch(function (err) { | ||
console.log('Multiparty call failed', err); | ||
}); | ||
|
||
|
||
// Warm Transfer - multi party call | ||
phloClient = new PhloClient(authId, authToken); | ||
phloClient.phlo(phloId).multiPartyCall(mpcId).warmTransfer(mpcSourceNo, mpcTargetNo, role).then(function (result) { | ||
console.log('Warm transfer result', result); | ||
}).catch(function (err) { | ||
console.log('Warm transfer failed', err); | ||
}); | ||
|
||
|
||
// Cold Transfer - multi party call | ||
phloClient = new PhloClient(authId, authToken); | ||
phloClient.phlo(phloId).multiPartyCall(mpcId).coldTransfer(mpcSourceNo, mpcTargetNo, role).then(function (result) { | ||
console.log('Cold transfer result', result); | ||
}).catch(function (err) { | ||
console.log('Cold transfer failed', err); | ||
}); | ||
|
||
|
||
// Abort Transfer - multi party call | ||
phloClient = new PhloClient(authId, authToken); | ||
phloClient.phlo(phloId).multiPartyCall(mpcId).abortTransfer(mpcSourceNo).then(function (result) { | ||
console.log('abort transfer result', result); | ||
}).catch(function (err) { | ||
console.log('abort transfer failed', err); | ||
}); | ||
|
||
/**************************** Multiparty call member examples **************************/ | ||
|
||
|
||
/******************** Phlo resource test cases *********************/ | ||
|
||
// Resume Call - Phlo Member | ||
phloClient = new PhloClient(authId, authToken); | ||
phloClient.phlo(phloId).multiPartyCall(mpcId).member(mpcSourceNo).resumeCall().then(function (result) { | ||
console.log('resume call result', result); | ||
}).catch(function (err) { | ||
console.log('resume call failed', err); | ||
}); | ||
|
||
|
||
// Voice mail drop - Phlo Member | ||
phloClient = new PhloClient(authId, authToken); | ||
phloClient.phlo(phloId).multiPartyCall(mpcId).member(mpcSourceNo).voicemailDrop().then(function (result) { | ||
console.log('voicemail Drop call result -', result); | ||
}).catch(function (err) { | ||
console.log('voicemail Drop call failed', err); | ||
}); | ||
|
||
|
||
// Hangup - Phlo Member | ||
phloClient = new PhloClient(authId, authToken); | ||
phloClient.phlo(phloId).multiPartyCall(mpcId).member(mpcSourceNo).hangup().then(function (result) { | ||
console.log('hangup result - ', result); | ||
}).catch(function (err) { | ||
console.log('hangup failed', err); | ||
}); | ||
|
||
|
||
// Hold - Phlo Member | ||
phloClient = new PhloClient(authId, authToken); | ||
phloClient.phlo(phloId).multiPartyCall(mpcId).member(mpcSourceNo).hold().then(function (result) { | ||
console.log('hold result -', result); | ||
}).catch(function (err) { | ||
console.log('hold failed', err); | ||
}); | ||
|
||
|
||
// Unhold - Phlo Member | ||
phloClient = new PhloClient(authId, authToken); | ||
phloClient.phlo(phloId).multiPartyCall(mpcId).member(mpcSourceNo).unhold().then(function (result) { | ||
console.log('unhold result -', result); | ||
}).catch(function (err) { | ||
console.log('unhold failed', err); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { extend, validate } from '../utils/common.js'; | ||
import { PlivoResource, PlivoResourceInterface } from '../base'; | ||
import { PhloMultiPartyCall, PhloMultiPartyCallInterface } from "../resources/phloMultipartyCall"; | ||
import * as _ from "lodash"; | ||
|
||
const clientKey = Symbol(); | ||
const action = 'phlo/'; | ||
const idField = 'phloUuid'; | ||
|
||
/** | ||
* Represents a Phlo | ||
* @constructor | ||
* @param {function} client - make api call | ||
* @param {object} [data] - data of phlo | ||
*/ | ||
export class Phlo extends PlivoResource { | ||
constructor(client, data = {}) { | ||
super(action, Phlo, idField, client); | ||
extend(this, data); | ||
|
||
this.client = client; | ||
|
||
// Define multiparty call getters | ||
let item = this; | ||
this.multiPartyCall = function (nodeId) { | ||
let dd = new PhloMultiPartyCall(client, { phloId: item.phloId, nodeId: nodeId }); | ||
return dd; | ||
}; | ||
|
||
this.multiPartyCall.get = function (nodeId) { | ||
let dd = new PhloMultiPartyCallInterface(client, { phloId: item.phloId, nodeId: nodeId }); | ||
return dd.get(item.phloId, nodeId); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* run phlo | ||
* @method | ||
* @promise {Boolean} return true if phlo is complete | ||
* @fail {Error} return Error | ||
*/ | ||
run(params) { | ||
|
||
//Url for phlo running | ||
// https://phlorunner.plivo.com/v1/account/{AUTH_ID}/phlo/{PHLO_ID} | ||
let action = 'account/' + this.authId + '/phlo/' + this.phloId; | ||
return super.executeAction(action, 'POST', params, ''); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Represents a Phlo Interface | ||
* @constructor | ||
* @param {function} client - make api call | ||
* @param {object} [data] - data of call | ||
*/ | ||
export class PhloInterface extends PlivoResourceInterface { | ||
|
||
constructor(client, data = {}) { | ||
super(action, Phlo, idField, client); | ||
extend(this, data); | ||
} | ||
|
||
/** | ||
* Get A Phlo Detail | ||
* @method | ||
* @param {string} id - phlo uuid to get information of. | ||
* @promise {object} returns Phlo Object | ||
* @fail {Error} returns Error | ||
*/ | ||
get(id) { | ||
|
||
//Validate id first | ||
let errors = validate([{ | ||
field: 'id', | ||
value: id, | ||
validators: ['isRequired'] | ||
}]); | ||
|
||
if (errors) { | ||
return errors; | ||
} | ||
|
||
let params = { | ||
phlo_id: id | ||
}; | ||
|
||
// Url pattern for getting phlo resource by id | ||
// https://phlorunner.plivo.com/v1/phlo/{phlo_id} | ||
return super.get(id, params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { extend, validate } from '../utils/common.js'; | ||
import { PlivoResource, PlivoResourceInterface } from '../base'; | ||
|
||
const clientKey = Symbol(); | ||
const action = 'Phlo/'; | ||
const idField = 'phloUuid'; | ||
|
||
/** | ||
* Represents a Multiparty Call Member | ||
* @constructor | ||
* @param {function} client - make api call | ||
* @param {object} [data] - data of phlo | ||
*/ | ||
export class PhloMultiPartyCallMember extends PlivoResource { | ||
|
||
constructor(client, data = {}) { | ||
let action = 'phlo/' + data.phloId + '/multi_party_call/' + data.nodeId + '/members/'; | ||
super(action, PhloMultiPartyCallMember, idField, client); | ||
extend(this, data); | ||
this.action = action; | ||
this.client = client; | ||
} | ||
|
||
resumeCall() { | ||
return this.update('resume_call'); | ||
} | ||
|
||
voicemailDrop() { | ||
return this.update('voicemail_drop'); | ||
} | ||
|
||
hangup() { | ||
return this.update('hangup'); | ||
} | ||
|
||
hold() { | ||
return this.update('hold'); | ||
} | ||
|
||
unhold() { | ||
return this.update('unhold'); | ||
} | ||
|
||
update(action) { | ||
|
||
let params = { | ||
action: action | ||
}; | ||
|
||
// Build Url | ||
// https://phlorunner.plivo.com/v1/phlo/{PHLO_ID}/multi_party_call/{NODE_ID}/members/{MemberAddress} | ||
let task = this.action + this.memberAddress; | ||
|
||
return super.executeAction(task, 'POST', params, ''); | ||
} | ||
|
||
} | ||
|
||
export class PhloMultiPartyCallMemberInterface extends PlivoResourceInterface { | ||
|
||
|
||
constructor(client, data = {}) { | ||
let action = 'phlo/' + data.phloId + '/multi_party_call/' + data.nodeId + '/members/'; | ||
super(action, PhloMultiPartyCallMember, idField, client); | ||
extend(this, data); | ||
this.action = action; | ||
this.client = client; | ||
} | ||
|
||
get(phloId, nodeId, memberAddress) { | ||
|
||
//Validate memberAddress first | ||
let errors = validate([{ | ||
field: 'memberAddress', | ||
value: memberAddress, | ||
validators: ['isRequired'] | ||
}]); | ||
if (errors) { | ||
return errors; | ||
} | ||
|
||
return new PhloMultiPartyCallMember(this.client, { phloId: phloId, nodeId: nodeId, memberAddress: memberAddress }); | ||
|
||
} | ||
} |
Oops, something went wrong.