mirror of
https://github.com/donl/plivo-node.git
synced 2026-05-30 06:12:14 -06:00
* 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
116 lines
3.3 KiB
JavaScript
116 lines
3.3 KiB
JavaScript
import { extend, validate } from '../utils/common.js';
|
||
import { PlivoResource, PlivoResourceInterface } from '../base';
|
||
import { PhloMultiPartyCallMemberInterface, PhloMultiPartyCallMember } from './phloMultiPartyCallMember';
|
||
|
||
const clientKey = Symbol();
|
||
const idField = 'nodeId';
|
||
|
||
export class PhloMultiPartyCall extends PlivoResource {
|
||
constructor(client, data = {}) {
|
||
let action = 'phlo/' + data.phloId + '/multi_party_call/';
|
||
super(action, PhloMultiPartyCall, idField, client);
|
||
extend(this, data);
|
||
this.action = action;
|
||
this.client = client;
|
||
|
||
// Define member getters
|
||
let item = this;
|
||
this.member = function (memberAddress) {
|
||
let dd = new PhloMultiPartyCallMember(client, { phloId: item.phloId, nodeId: item.nodeId, memberAddress: memberAddress });
|
||
return dd;
|
||
};
|
||
|
||
this.member.get = function (memberAddress) {
|
||
let dd = new PhloMultiPartyCallMemberInterface(client, { phloId: item.phloId, nodeId: item.nodeId, memberAddress: memberAddress });
|
||
return dd.get(item.phloId, item.nodeId, memberAddress);
|
||
}
|
||
|
||
}
|
||
|
||
call(triggerSource, to, role) {
|
||
return this.update('call', triggerSource, to, role);
|
||
}
|
||
|
||
warmTransfer(triggerSource, to, role) {
|
||
return this.update('warm_transfer', triggerSource, to, role);
|
||
}
|
||
|
||
coldTransfer(triggerSource, to, role) {
|
||
return this.update('cold_transfer', triggerSource, to, role);
|
||
}
|
||
|
||
abortTransfer(memberAddress) {
|
||
return this.update('abort_transfer', null, memberAddress, null);
|
||
}
|
||
|
||
update(action, triggerSource, to, role) {
|
||
// If role not specified, keep ‘agent’
|
||
if (role === undefined || role == null) {
|
||
role = 'agent';
|
||
}
|
||
|
||
let params = {
|
||
action: action
|
||
};
|
||
|
||
|
||
// Url pattern for mp call update
|
||
// https://phlorunnner.plivo.com/v1/phlo/{phlo_id}/{node_type}/{node_id}
|
||
let task = this.action + this.nodeId;
|
||
if (action == 'abort_transfer') {
|
||
task += '/members/' + to;
|
||
} else {
|
||
params.to = to;
|
||
params.role = role;
|
||
params.trigger_source = triggerSource;
|
||
}
|
||
|
||
return super.executeAction(task, 'POST', params, '');
|
||
|
||
}
|
||
|
||
}
|
||
|
||
export class PhloMultiPartyCallInterface extends PlivoResourceInterface {
|
||
|
||
|
||
constructor(client, data = {}) {
|
||
let action = 'phlo/' + data.phloId + '/multi_party_call/';
|
||
super(action, PhloMultiPartyCall, 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(phloId, id) {
|
||
|
||
//Validate id first
|
||
let errors = validate([{
|
||
field: 'id',
|
||
value: id,
|
||
validators: ['isRequired']
|
||
}]);
|
||
|
||
if (errors) {
|
||
return errors;
|
||
}
|
||
|
||
let params = {
|
||
phlo_id: phloId,
|
||
node_type: 'multi_party_call',
|
||
node_id: id
|
||
};
|
||
|
||
|
||
// Url pattern for getting phlo resource by id
|
||
// https://phlorunner.plivo.com/v1/phlo/{phlo_id}
|
||
// console.log('get multi party call with ', id, params);
|
||
return super.get(id, params);
|
||
|
||
}
|
||
}
|