plivo-node/examples/phlo.js
nixonsam a4e3f9fd47
Add PHLO support (#112)
* 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
2019-03-11 15:43:57 +05:30

127 lines
4.1 KiB
JavaScript

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);
});