plivo
Version:
A Node.js SDK to make voice calls and send SMS using Plivo and to generate Plivo XML
1,086 lines (1,067 loc) • 137 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Request = Request;
var _querystring = require('querystring');
var _querystring2 = _interopRequireDefault(_querystring);
var _request = require('request');
var _request2 = _interopRequireDefault(_request);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function Request(config) {
var auth = 'Basic ' + new Buffer(config.authId + ':' + config.authToken).toString('base64');
var headers = {
Authorization: auth,
'User-Agent': config.userAgent,
'Content-Type': 'application/json'
};
return function (method, action, params) {
params = params || {};
var options = {
url: config.url + '/' + action,
method: method,
formData: params || '',
headers: headers,
json: true
};
if (method == 'GET' && options.formData !== '') {
var query = '?' + _querystring2.default.stringify(params);
options.url += query;
}
if (typeof config.proxy !== 'undefined') {
options.proxy = config.proxy;
}
if (typeof config.timeout !== 'undefined') {
options.timeout = config.timeout;
}
return new Promise(function (resolve, reject) {
// LiveCall - needs to be at top
if (method === 'GET' && action === 'Call/6653422-91b6-4716-9fad-9463daaeeec2' && params['status'] === 'live') {
resolve({
response: {},
body: {
"direction": "inbound",
"from": "15856338537",
"call_status": "in-progress",
"api_id": "45223222-74f8-11e1-8ea7-12313806be9a",
"to": "14154290945",
"caller_name": "+15856338537",
"call_uuid": "6653422-91b6-4716-9fad-9463daaeeec2",
"session_start": "2014-03-23 14:49:39.722551",
"request_uuid": "d0a87a1a-b0e9-4ab2-ac07-c22ee87cd04a",
"stir_verification": "Verified",
"stir_attestation": "A"
}
});
} else if (method === 'GET' && action === 'Call/' && params['status'] === 'live') {
resolve({
response: {},
body: {
"api_id": "c9527676-5839-11e1-86da-6ff39efcb949",
"calls": ["eac94337-b1cd-499b-82d1-b39bca50dc31", "0a70a7fb-168e-4944-a846-4f3f4d2f96f1"]
}
});
} else if (method === 'DELETE' && action === 'Request/aaa-deeiei3-dfddd/') {
resolve({
response: {},
body: {}
});
}
// get all calls
else if (action == 'Call/' && method == 'GET') {
resolve({
response: {},
body: {
"api_id": "8299d094-dc72-11e5-b56c-22000ae90795",
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 4
},
objects: [{
"answer_time": "2015-07-26 15:45:02+05:30",
"api_id": "06ae0f8f-dc72-11e5-b56c-22000ae90795",
"bill_duration": 924,
"billed_duration": 960,
"call_direction": "outbound",
"call_duration": 924,
"call_uuid": "eba53b9e-8fbd-45c1-9444-696d2172fbc8",
"end_time": "2015-07-26 15:45:14+05:30",
"from_number": "+14158572518",
"initiation_time": "2015-07-26 15:44:49+05:30",
"parent_call_uuid": null,
"resource_uri": "/v1/Account/MANWVLYTK4ZWU1YTY4ZT/Call/eba53b9e-8fbd-45c1-9444-696d2172fbc8/",
"to_number": "14153268174",
"total_amount": "0.13600",
"total_rate": "0.00850",
"stir_verification": "Not Verified",
"voice_network_group": "USA All Networks",
"stir_attestation": "",
"cnam_lookup": ""
}, {
"answer_time": "2015-07-26 16:45:02+05:30",
"api_id": "06ae0f8f-dc72-11e5-b56c-22000ae90795",
"bill_duration": 924,
"billed_duration": 960,
"call_direction": "outbound",
"call_duration": 924,
"call_uuid": "eba53b9e-8fbd-45c1-9444-696d2172fbc8",
"end_time": "2015-07-26 16:45:14+05:30",
"from_number": "+14158572518",
"initiation_time": "2015-07-26 16:44:49+05:30",
"parent_call_uuid": null,
"resource_uri": "/v1/Account/MANWVLYTK4ZWU1YTY4ZT/Call/eba53b9e-8fbd-45c1-9444-696d2172fbc8/",
"to_number": "14153268174",
"total_amount": "0.13600",
"total_rate": "0.00850",
"stir_verification": "Verified",
"voice_network_group": "USA All Networks",
"stir_attestation": "A",
"cnam_lookup": ""
}]
}
});
} else if (action == 'Call/' && method == 'POST') {
resolve({
response: {},
body: {
message: 'call fired',
request_uuid: '9834029e-58b6-11e1-b8b7-a5bd0e4e126f',
api_id: '97ceeb52-58b6-11e1-86da-77300b68f8bb'
}
});
}
//Get CDR (Retrieve a call)
else if (action == 'Call/aaa-deeiei3-dfddd/' && method == 'GET') {
resolve({
response: {},
body: {
"id": '1',
"call_uuid": 'aaa-deeiei3-dfddd',
"answer_time": null,
"api_id": "95727cf4-3eeb-11e7-8edf-02ed609bd62b",
"bill_duration": 0,
"billed_duration": 0,
"call_direction": "outbound",
"call_duration": 0,
"end_time": "2017-05-22 17:49:40+05:30",
"from_number": "+919879879876",
"initiation_time": "2017-05-22 17:49:30+05:30",
"parent_call_uuid": null,
"resource_uri": "/v1/Account/MAJHUDTEYWLSIUYTDBCZ/Call/4d04c52e-cea3-4458-bbdb-0bfc314ee7cd/",
"to_number": "919999999999",
"total_amount": "0.00000",
"total_rate": "0.03570",
"stir_verification": "Not Applicable",
"voice_network_group": "India All Networks",
"stir_attestation": "",
"cnam_lookup": ""
}
});
} else if (action == 'Call/aaa-deeiei3-dfddd/' && method == 'POST') {
resolve({
response: {},
body: {
"message": "call transferred",
"api_id": "08c94608-58bd-11e1-86da-adf28403fe48"
}
});
} else if (action == 'Call/aaa-deeiei3-dfddd/' && method == 'DELETE') {
resolve({
response: {},
body: {}
});
} else if (action == 'Call/aaa-deeiei3-dfddd/Record/' && method == 'POST') {
resolve({
response: {},
body: {
url: 'http://s3.amazonaws.com/recordings_2013/48dfaf60-3b2a-11e3.mp3',
message: 'call recording started',
recording_id: '48dfaf60-3b2a-11e3',
api_id: 'c7b69074-58be-11e1-86da-adf28403fe48'
}
});
} else if (action == 'Call/aaa-deeiei3-dfddd/Stream/' && method == 'POST') {
resolve({
response: {},
body: {
message: 'stream started',
stream_id: 'db1d8121-1a75-4b75-bb69-35339bb26240',
api_id: 'c7b69074-58be-11e1-86da-adf28403fe48'
}
});
} else if (method === 'POST' && action === 'Masking/Session/') {
resolve({
response: {},
body: {
"api_id": "b70bb955-0c85-4b12-9ec4-9640b46c4f61",
"session_uuid": "197aa6e0-1abe-4d1c-b887-2b2406764360",
"virtual_number": "+916361728680",
"message": "Session created",
"session": {
"first_party": "917708772011",
"second_party": "918220568648",
"virtual_number": "916361728680",
"status": "active",
"initiate_call_to_first_party": true,
"session_uuid": "197aa6e0-1abe-4d1c-b887-2b2406764360",
"callback_url": "http://plivobin.non-prod.plivops.com/1jvpmrs1",
"callback_method": "GET",
"created_time": "2023-07-17 14:26:02.806041 +0000 UTC",
"modified_time": "2023-07-17 14:26:02.806041 +0000 UTC",
"expiry_time": "2023-07-17 16:06:02.806041 +0000 UTC",
"duration": 6000,
"amount": 0,
"call_time_limit": 14400,
"ring_timeout": 120,
"first_party_play_url": "https://s3.amazonaws.com/plivosamplexml/play_url.xml",
"second_party_play_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"record": false,
"record_file_format": "mp3",
"recording_callback_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"recording_callback_method": "GET",
"interaction": null,
"total_call_amount": 0,
"total_call_count": 0,
"total_call_billed_duration": 0,
"total_session_amount": 0,
"last_interaction_time": ""
}
}
});
} else if (method === 'GET' && action === 'Masking/Session/197aa6e0-1abe-4d1c-b887-2b2406764360') {
resolve({
response: {},
body: {
"api_id": "2d0c2ca6-01d5-43c0-bb72-038e7d84e3b4",
"response": {
"first_party": "917708772011",
"second_party": "918220568648",
"virtual_number": "916361728680",
"status": "active",
"initiate_call_to_first_party": true,
"session_uuid": "197aa6e0-1abe-4d1c-b887-2b2406764360",
"callback_url": "http://plivobin.non-prod.plivops.com/1jvpmrs1",
"callback_method": "GET",
"created_time": "2023-07-17 14:26:02.806041 +0000 UTC",
"modified_time": "2023-07-17 14:26:02.806041 +0000 UTC",
"expiry_time": "2023-07-17 16:06:02.806041 +0000 UTC",
"duration": 6000,
"amount": 0,
"call_time_limit": 14400,
"ring_timeout": 120,
"first_party_play_url": "https://s3.amazonaws.com/plivosamplexml/play_url.xml",
"second_party_play_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"record": false,
"record_file_format": "mp3",
"recording_callback_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"recording_callback_method": "GET",
"interaction": [{
"start_time": "2023-07-17 14:26:03 +0000 UTC",
"end_time": "2023-07-17 14:26:03 +0000 UTC",
"first_party_resource_url": "https://api-qa.voice.plivodev.com/v1/Account/MAZTQXZDYWNZBMMJAZZJ/Call/46bca3f0-e9de-4fa9-a0fc-fff28171527c",
"type": "call",
"total_call_count": 1,
"duration": 0
}],
"total_call_amount": 0,
"total_call_count": 1,
"total_call_billed_duration": 0,
"total_session_amount": 0,
"last_interaction_time": "2023-07-17 14:26:03 +0000 UTC"
}
}
});
} else if (method === 'DELETE' && action === 'Masking/Session/197aa6e0-1abe-4d1c-b887-2b2406764360') {
resolve({
response: {},
body: {
"api_id": "758bf153-a37e-446b-9163-97094bcc0390",
"message": "Session expired"
}
});
} else if (method === 'POST' && action === 'Masking/Session/63690013-52bb-43fa-9b0b-bf81c9f4d766') {
resolve({
response: {},
body: {
"api_id": "2b95070e-5e67-46d0-ba79-2903d423c5b2",
"message": "Session updated",
"session": {
"first_party": "917708772011",
"second_party": "919976106830",
"virtual_number": "916361728680",
"status": "active",
"initiate_call_to_first_party": false,
"session_uuid": "63690013-52bb-43fa-9b0b-bf81c9f4d766",
"callback_url": "http://plivobin.non-prod.plivops.com/1jvpmrs1",
"callback_method": "GET",
"created_time": "2023-07-11 04:02:13.820698 +0000 +0000",
"modified_time": "2023-07-11 04:02:32.594296 +0000 UTC",
"expiry_time": "2023-07-11 04:03:32.59429 +0000 UTC",
"duration": 78,
"amount": 0,
"call_time_limit": 14400,
"ring_timeout": 120,
"first_party_play_url": "https://s3.amazonaws.com/plivosamplexml/play_url.xml",
"second_party_play_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"record": false,
"record_file_format": "mp3",
"recording_callback_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"recording_callback_method": "GET",
"interaction": null,
"total_call_amount": 0,
"total_call_count": 0,
"total_call_billed_duration": 0,
"total_session_amount": 0,
"last_interaction_time": ""
}
}
});
} else if (method === 'GET' && action === 'Masking/Session/') {
resolve({
response: {},
body: {
"api_id": "e7da96fd-755c-44b7-9557-d267abae5ab0",
"response": {
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 2
},
"objects": [{
"amount": 0,
"call_time_limit": 14400,
"callback_method": "GET",
"callback_url": "http://plivobin.non-prod.plivops.com/1jvpmrs1",
"created_time": "2023-07-11 04:02:13.820698 +0000 UTC",
"duration": 78,
"expiry_time": "2023-07-11 04:03:32.59429 +0000 UTC",
"first_party": "917708772011",
"first_party_play_url": "https://s3.amazonaws.com/plivosamplexml/play_url.xml",
"initiate_call_to_first_party": false,
"interaction": null,
"last_interaction_time": "",
"modified_time": "2023-07-11 04:02:32.594296 +0000 UTC",
"record": false,
"record_file_format": "mp3",
"recording_callback_method": "GET",
"recording_callback_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"resource_uri": "/v1/Account/MAZTQXZDYWNZBMMJAZZJ/Masking/Session/63690013-52bb-43fa-9b0b-bf81c9f4d766/",
"ring_timeout": 120,
"second_party": "919976106830",
"second_party_play_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"session_uuid": "63690013-52bb-43fa-9b0b-bf81c9f4d766",
"status": "expired",
"total_call_amount": 0,
"total_call_billed_duration": 0,
"total_call_count": 0,
"total_session_amount": 0,
"virtual_number": "916361728680"
}, {
"amount": 0,
"call_time_limit": 14400,
"callback_method": "GET",
"callback_url": "http://plivobin.non-prod.plivops.com/1jvpmrs1",
"created_time": "2023-07-11 03:38:42.885428 +0000 UTC",
"duration": 109,
"expiry_time": "2023-07-11 03:40:32.408859 +0000 UTC",
"first_party": "917708772011",
"first_party_play_url": "https://s3.amazonaws.com/plivosamplexml/play_url.xml",
"initiate_call_to_first_party": false,
"interaction": null,
"last_interaction_time": "",
"modified_time": "2023-07-11 03:39:32.408908 +0000 UTC",
"record": false,
"record_file_format": "mp3",
"recording_callback_method": "GET",
"recording_callback_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"resource_uri": "/v1/Account/MAZTQXZDYWNZBMMJAZZJ/Masking/Session/cc69df7e-eeb0-4fc5-93e9-f01d35ced9e8/",
"ring_timeout": 120,
"second_party": "919976106830",
"second_party_play_url": "https://plivobin-prod-usw.plivops.com/api/v1/speak.xml",
"session_uuid": "cc69df7e-eeb0-4fc5-93e9-f01d35ced9e8",
"status": "expired",
"total_call_amount": 0,
"total_call_billed_duration": 0,
"total_call_count": 0,
"total_session_amount": 0,
"virtual_number": "916361728680"
}]
}
}
});
} else if (method === 'POST' && action === 'VerifiedCallerId/') {
resolve({
response: {},
body: {
"api_id": "2a5e81d7-deb3-46cd-ac34-c05ca9139b6f",
"message": "Verification code is sent to number +919768368717 which is valid for 15 minutes",
"verification_uuid": "407796a6-1f3e-4607-a9d9-5a5376b59a7b"
}
});
} else if (method === 'POST' && action === 'VerifiedCallerId/Verification/2e68eb73-4d54-4391-bc98-71cd380911a4/') {
resolve({
response: {},
body: {
"alias": "abhishek",
"api_id": "584a97aa-ca1d-44f2-9dd3-e58fbacd6649",
"channel": "call",
"country": "IN",
"created_at": "2023-09-25T13:10:39.968133341Z",
"phone_number": "+919768368717",
"verification_uuid": "2e68eb73-4d54-4391-bc98-71cd380911a4"
}
});
} else if (method === 'POST' && action === 'VerifiedCallerId/+919768368718/') {
resolve({
response: {},
body: {
"alias": "testAbhishek",
"api_id": "6b143cb3-9c8a-42ad-b6b7-412ebd5c60a9",
"country": "IN",
"created_at": "2023-09-22T14:11:03.091534Z",
"modified_at": "2023-09-22T14:11:03.091534Z",
"phone_number": "+919768368718",
"subaccount": "SAMTU0Y2FKNGETYZDKNI",
"verification_uuid": "0f978b20-9e2b-4cfe-99fe-f7087c03b8e1"
}
});
} else if (method === 'DELETE' && action === 'VerifiedCallerId/+919768368718/') {
resolve({
response: {},
body: {}
});
} else if (method === 'GET' && action === 'VerifiedCallerId/+919768368718/') {
resolve({
response: {},
body: {
"alias": "test",
"api_id": "ee7c3cb1-c921-42c9-832b-950fb8344b9b",
"country": "IN",
"created_at": "2023-09-22T14:11:03.091534Z",
"modified_at": "2023-09-22T14:11:03.091534Z",
"phone_number": "+919768368718",
"subaccount": "",
"verification_uuid": "0f978b20-9e2b-4cfe-99fe-f7087c03b8e1"
}
});
} else if (method === 'GET' && action === 'VerifiedCallerId/') {
resolve({
response: {},
body: {
"api_id": "3b21c7d7-09f7-489b-b753-659814a676bf",
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 4
},
"objects": [{
"alias": "abhishek",
"country": "IN",
"created_at": "2023-09-25T14:40:38.68729Z",
"modified_at": "2023-09-25T14:40:38.68729Z",
"phone_number": "+919653244280",
"resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/919653244280",
"subaccount": "",
"verification_uuid": "01be6b07-b106-46e2-8dfc-096d8e22cc0e"
}, {
"alias": "abhishek",
"country": "IN",
"created_at": "2023-09-25T13:10:39.968133Z",
"modified_at": "2023-09-25T13:10:39.968133Z",
"phone_number": "+919768368717",
"resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/919768368717",
"subaccount": "",
"verification_uuid": "2e68eb73-4d54-4391-bc98-71cd380911a4"
}, {
"alias": "test",
"country": "IN",
"created_at": "2023-09-22T14:11:03.091534Z",
"modified_at": "2023-09-22T14:11:03.091534Z",
"phone_number": "+919768368718",
"resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/919768368718",
"subaccount": "",
"verification_uuid": "0f978b20-9e2b-4cfe-99fe-f7087c03b8e1"
}, {
"alias": "Test2",
"country": "",
"created_at": "2023-08-30T07:47:43.87171Z",
"modified_at": "2023-08-30T07:47:43.87171Z",
"phone_number": "+917691021365",
"resource_uri": "/v1/Account/MADCHANDRESH02TANK06/VerifiedCallerId/917691021365",
"subaccount": "SAMTU0Y2FKNGETYZDKNI",
"verification_uuid": "20265c57-2d8e-46fe-8fa8-e8ab4ee58a8c"
}]
}
});
} else if (action == 'Call/aaa-deeiei3-dfddd/Record/' && method == 'DELETE') {
resolve({
response: {},
body: {}
});
} else if (action == 'Call/aaa-deeiei3-dfddd/Play/' && method == 'POST') {
resolve({
response: {},
body: {
message: 'play started',
api_id: '07abfd94-58c0-11e1-86da-adf28403fe48'
}
});
} else if (action == 'Call/aaa-deeiei3-dfddd/Play/' && method == 'DELETE') {
resolve({
response: {},
body: {}
});
} else if (action == 'Call/aaa-deeiei3-dfddd/Speak/' && method == 'DELETE') {
resolve({
response: {},
body: {
message: 'speak stopped',
api_id: 'cf2359c8-f4d6-11e6-b886-067c5485c240'
}
});
} else if (action == 'Call/aaa-deeiei3-dfddd/Speak/' && method == 'POST') {
resolve({
response: {},
body: {
message: 'speak started',
api_id: '07abfd94-58c0-11e1-86da-adf28403fe48'
}
});
} else if (action == 'Call/aaa-deeiei3-dfddd/DTMF/' && method == 'POST') {
resolve({
response: {},
body: {
message: 'digits sent',
api_id: '07abfd94-58c0-11e1-86da-adf28403fe48'
}
});
}
// if(action == 'Call/1/' && method == 'DELETE') {
// resolve({
// response: {},
// body: {}
// })
// }
//
//
// Accounts
else if (action == '/' && method == 'GET') {
resolve({
response: {},
body: {
account_type: 'standard',
address: '340 Pine St, San Francisco, CA - 94104',
api_id: 'c31b36be-0da2-11e4-bd8a-12313f016a39',
auth_id: 'MANWVLYTK4ZWU1YTY4ZT',
auto_recharge: true,
billing_mode: 'prepaid',
cash_credits: '23.79822',
city: 'San Francisco',
name: 'Han Solo',
resource_uri: '/v1/Account/MANWVLYTK4ZWU1YTY4ZT/',
state: 'California',
timezone: 'America/Los_Angeles'
}
});
} else if (action == '/' && method == 'POST') {
resolve({
response: {},
body: {
api_id: 'ea43d134-0db0-11e4-a2d1-22000ac5040c',
message: 'changed'
}
});
} else if (action === 'Subaccount/' && method === 'POST') {
resolve({
response: {},
body: {
"api_id": "97c8d1de-3f08-11e7-b6f4-061564b78b75",
"auth_id": "SANDLHYZBIZMU4ZDEXNM",
"auth_token": "MTMzZTZjNzdiNDVmY2VhZDQyNTUwYWVjNzI2OThk",
"message": "created"
}
});
} else if (action == 'Subaccount/1/' && method == 'GET') {
resolve({
response: {},
body: {
account: '/v1/Account/MANWVLYTK4ZWU1YTY4ZT/',
api_id: '323972b2-0db3-11e4-a2d1-22000ac5040c',
auth_id: '1',
auth_token: 'MTZjYWM0YzVjNjMwZmVmODFiNWJjNWJmOGJjZjgw',
created: '2014-07-17',
enabled: false,
modified: null,
name: 'Chewbacca',
resource_uri: '/v1/Account/MANWVLYTK4ZWU1YTY4ZT/Subaccount/SAMTVIYJDIYWYYMZHLYZ/'
}
});
} else if (action == 'Subaccount/1/' && method == 'POST') {
resolve({
response: {},
body: {
message: 'changed',
api_id: '5a9fcb68-523d-11e1-86da-6ff39efcb949'
}
});
} else if (action == 'Subaccount/' && method == 'GET') {
resolve({
response: {},
body: {
api_id: 'b38bf42e-0db4-11e4-8a4a-123140008edf',
meta: {
limit: 20,
next: null,
offset: 0,
previous: null,
total_count: 2
},
objects: [{
account: '/v1/Account/MANWVLYTK4ZWU1YTY4ZT/',
auth_id: '1',
auth_token: 'MTZjYWM0YzVjNjMwZmVmODFiNWJjNWJmOGJjZjgw',
created: '2014-07-17',
enabled: false,
modified: null,
name: 'Chewbacca',
resource_uri: '/v1/Account/MANWVLYTK4ZWU1YTY4ZT/Subaccount/SAMTVIYJDIYWYYMZHLYZ/'
}, {
account: '/v1/Account/MANWVLYTK4ZWU1YTY4ZT/',
auth_id: '1',
auth_token: 'OTdhMjYwMWYxOGMyNpFjNzUwYWM3YWI3NjY4Y2Ey',
created: '2012-09-23',
enabled: true,
modified: '2012-09-23',
name: 'new',
resource_uri: '/v1/Account/MANWVLYTK4ZWU1YTY4ZT/Subaccount/SANJQ5NWEYNWZJNZE2MZ/'
}]
}
});
} else if (action == 'Subaccount/1/' && method == 'DELETE') {
resolve({
response: {},
body: {}
});
}
// ============= Application ===================
else if (action == 'Application/1/' && method == 'GET') {
resolve({
response: {},
body: {
answer_method: 'GET',
answer_url: 'http://webapp.com/dial.xml',
app_id: '1',
app_name: 'Dial Office',
default_app: false,
enabled: true,
fallback_answer_url: '',
fallback_method: 'POST',
hangup_method: 'POST',
hangup_url: 'http://webapp.com/dial.xml',
message_method: 'POST',
message_url: '',
public_uri: false,
resource_uri: '/v1/Account/MANWVLYTK4ZWU1YTY4ZT/Application/20372631212782780/',
sip_uri: 'sip:20372631212782780@app.plivo.com',
sub_account: null
}
});
} else if (action == 'Application/' && method == 'GET') {
resolve({
response: {},
body: {
api_id: 'e5b05b26-10c4-11e4-a2d1-22000ac5040c',
meta: {
limit: 20,
next: null,
offset: 0,
previous: null,
total_count: 19
},
objects: [{
answer_url: 'http://webapp.com/dial.xml',
answer_method: 'GET',
app_id: '20372631212782780',
app_name: 'Dial Office',
default_app: false,
enabled: true,
fallback_answer_url: '',
fallback_method: 'POST',
hangup_method: 'POST',
hangup_url: 'http://webapp.com/dial.xml',
message_method: 'POST',
message_url: '',
public_uri: false,
resource_uri: '/v1/Account/MANWVLYTK4ZWU1YTY4ZT/Application/20372631212782780/',
sip_uri: 'sip:20372631212782780@app.plivo.com',
sub_account: null
}, {
answer_url: 'https://webapp.com/conference_court.xml',
answer_method: 'GET',
app_id: '14260623927192078',
app_name: 'Conference_Court',
default_app: false,
enabled: true,
fallback_answer_url: '',
fallback_method: 'POST',
hangup_method: 'POST',
hangup_url: 'https://webapp.com/conference_court.xml',
message_method: 'POST',
message_url: '',
public_uri: false,
resource_uri: '/v1/Account/MANWVLYTK4ZWU1YTY4ZT/Application/14260623927192078/',
sip_uri: 'sip:142606239271920703@app.plivo.com',
sub_account: null
}]
}
});
} else if (action == 'Application/1/' && method == 'POST') {
resolve({
response: {},
body: {
message: 'changed',
api_id: '5a9fcb68-582d-11e1-86da-6ff39efcb949'
}
});
} else if (action == 'Application/' && method == 'POST') {
resolve({
response: {},
body: {
message: 'created',
app_id: '15784735442685051',
api_id: '5a9fcb68-582d-11e1-86da-6ff39efcb949'
}
});
} else if (action == 'Application/1/' && method == 'DELETE') {
resolve({
response: {},
body: {}
});
}
// ============= conferences ===================
else if (action == 'Conference/MyConf/' && method == 'GET') {
resolve({
response: {},
body: {
conference_name: 'MyConf',
conference_run_time: '590',
conference_member_count: '1',
members: [{
muted: false,
member_id: '17',
deaf: false,
from: '1456789903',
to: '1677889900',
caller_name: 'John',
direction: 'inbound',
call_uuid: 'acfbf0b5-12e0-4d74-85f7-fce15f8f07ec',
join_time: '590'
}],
api_id: '816e903e-58c4-11e1-86da-adf28403fe48'
}
});
} else if (action == 'Conference/' && method == 'GET') {
resolve({
response: {},
body: {
api_id: '2867b6e2-58c3-11e1-86da-adf28403fe48',
conferences: ['My Conf Room']
}
});
} else if (action == 'Conference/' && method == 'DELETE') {
resolve({
response: {},
body: {
message: 'all conferences hung up',
api_id: '2867b6e2-58c3-11e1-86da-adf28403fe48'
}
});
} else if (action == 'Conference/MyConf/' && method == 'DELETE') {
resolve({
response: {},
body: {
message: 'conference hung up',
api_id: '2867b6e2-58c3-11e1-86da-adf28403fe48'
}
});
} else if (action == 'Conference/MyConf/Member/1/' && method == 'DELETE') {
resolve({
response: {},
body: {
message: 'hangup',
member_id: '10',
api_id: '2867b6e2-58c3-11e1-86da-adf28403fe48'
}
});
} else if (method == 'POST' && action == 'Conference/MyConf/Member/1/Kick/') {
resolve({
response: {},
body: {
message: 'kicked',
member_id: '10',
api_id: '2867b6e2-58c3-11e1-86da-adf28403fe48'
}
});
} else if (method == 'POST' && action == 'Conference/MyConf/Member/1/Mute/') {
resolve({
response: {},
body: {
message: 'muted',
member_id: '10',
api_id: '2867b6e2-58c3-11e1-86da-adf28403fe48'
}
});
} else if (method == 'DELETE' && action == 'Conference/MyConf/Member/1/Mute/') {
resolve({
response: {},
body: {}
});
} else if (method == 'POST' && action == 'Conference/MyConf/Member/1/Deaf/') {
resolve({
response: {},
body: {
message: 'deaf',
member_id: '10',
api_id: '2867b6e2-58c3-11e1-86da-adf28403fe48'
}
});
} else if (method == 'DELETE' && action == 'Conference/MyConf/Member/1/Deaf/') {
resolve({
response: {},
body: {}
});
} else if (method == 'POST' && action == 'Conference/MyConf/Member/1/Play/') {
resolve({
response: {},
body: {
message: 'play queued into conference',
api_id: '4e44bd4e-f830-11e6-b886-067c5485c240',
member_id: '[u\'160005\', u\'160004\', u\'160003\', u\'160002\']'
}
});
} else if (method == 'DELETE' && action == 'Conference/MyConf/Member/1/Play/') {
resolve({
response: {},
body: {
message: 'playing in conference stopped',
member_id: '10',
api_id: '2867b6e2-58c3-11e1-86da-adf28403fe48'
}
});
} else if (method == 'POST' && action == 'Conference/MyConf/Member/1/Speak/') {
resolve({
response: {},
body: {
message: 'speak queued into conference',
api_id: '8dd6820e-fe83-11e6-b6f4-061564b78b75',
member_id: '[u\'all\']'
}
});
} else if (method == 'DELETE' && action == 'Conference/MyConf/Member/1/Speak/') {
resolve({
response: {},
body: {
message: 'speak stopped',
member_id: '10',
api_id: '2867b6e2-58c3-11e1-86da-adf28403fe48'
}
});
} else if (method == 'DELETE' && action == 'Conference/MyConf/Record/') {
resolve({
response: {},
body: {}
});
} else if (method == 'POST' && action == 'Conference/MyConf/Record/') {
resolve({
response: {},
body: {
api_id: '2867b6e2-58c3-11e1-86da-adf28403fe48',
message: 'conference recording started',
recording_id: '93bc7c6a-3b2b-11e3',
url: 'http://s3.amazonaws.com/recordings_2013/93bc7c6a-3b2b-11e3.mp3'
}
});
}
// ============= MultiPartyCalls ===============
else if (method === 'GET' && action === 'MultiPartyCall/') {
resolve({
response: {},
body: {
"api_id": "d53ab14c-eddb-11ea-b02e-0242ac110003",
"meta": {
"count": 6,
"limit": 20,
"next": null,
"offset": 0,
"previous": null
},
"objects": [{
"billed_amount": "0.00500",
"billed_duration": 60,
"creation_time": "2020-08-31 15:12:03+00:00",
"duration": 3,
"end_time": "2020-08-31 15:12:06+00:00",
"friendly_name": "TestMPC",
"mpc_uuid": "ca8e8a44-48e1-445d-afd5-1fcccdbccd9d",
"participants": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_ca8e8a44-48e1-445d-afd5-1fcccdbccd9d/Participant/",
"recording": null,
"resource_uri": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_ca8e8a44-48e1-445d-afd5-1fcccdbccd9d/",
"start_time": null,
"status": "Ended",
"stay_alone": false,
"sub_account": null,
"termination_cause": "No Active Participants",
"termination_cause_code": 1000
}, {
"billed_amount": "0.00500",
"billed_duration": 60,
"creation_time": "2020-08-31 14:32:40+00:00",
"duration": 5,
"end_time": "2020-08-31 14:32:45+00:00",
"friendly_name": "TestMPC",
"mpc_uuid": "9b531a1f-1692-4802-a7d6-3ef25bcfe3fc",
"participants": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_9b531a1f-1692-4802-a7d6-3ef25bcfe3fc/Participant/",
"recording": null,
"resource_uri": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_9b531a1f-1692-4802-a7d6-3ef25bcfe3fc/",
"start_time": null,
"status": "Ended",
"stay_alone": false,
"sub_account": null,
"termination_cause": "No Active Participants",
"termination_cause_code": 1000
}, {
"billed_amount": "0.01000",
"billed_duration": 120,
"creation_time": "2020-08-31 14:32:11+00:00",
"duration": 11,
"end_time": "2020-08-31 14:32:22+00:00",
"friendly_name": "TestMPC",
"mpc_uuid": "6f84d47c-ee82-4172-a155-c6e22f87d874",
"participants": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_6f84d47c-ee82-4172-a155-c6e22f87d874/Participant/",
"recording": null,
"resource_uri": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_6f84d47c-ee82-4172-a155-c6e22f87d874/",
"start_time": null,
"status": "Ended",
"stay_alone": false,
"sub_account": null,
"termination_cause": "Stay Alone Not Permitted",
"termination_cause_code": 1010
}, {
"billed_amount": "0.00500",
"billed_duration": 60,
"creation_time": "2020-08-31 14:31:20+00:00",
"duration": 3,
"end_time": "2020-08-31 14:31:23+00:00",
"friendly_name": "TestMPC",
"mpc_uuid": "0746f6c6-7447-4e0a-9013-186e4220aaf4",
"participants": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_0746f6c6-7447-4e0a-9013-186e4220aaf4/Participant/",
"recording": null,
"resource_uri": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_0746f6c6-7447-4e0a-9013-186e4220aaf4/",
"start_time": "2020-08-31 14:31:20+00:00",
"status": "Ended",
"stay_alone": false,
"sub_account": null,
"termination_cause": "No Active Participants",
"termination_cause_code": 1000
}, {
"billed_amount": "0.00500",
"billed_duration": 60,
"creation_time": "2020-08-31 06:42:50+00:00",
"duration": 36,
"end_time": "2020-08-31 06:43:26+00:00",
"friendly_name": "TestMPC",
"mpc_uuid": "b89150fd-0387-4bf8-bde7-a4fed39601ce",
"participants": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_b89150fd-0387-4bf8-bde7-a4fed39601ce/Participant/",
"recording": null,
"resource_uri": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_b89150fd-0387-4bf8-bde7-a4fed39601ce/",
"start_time": "2020-08-31 06:42:50+00:00",
"status": "Ended",
"stay_alone": false,
"sub_account": null,
"termination_cause": "No Active Participants",
"termination_cause_code": 1000
}, {
"billed_amount": "0.00500",
"billed_duration": 60,
"creation_time": "2020-08-28 17:30:10+00:00",
"duration": 2,
"end_time": "2020-08-28 17:30:12+00:00",
"friendly_name": "tank",
"mpc_uuid": "2999c70d-b635-420f-b6f2-2fd4421f0381",
"participants": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_2999c70d-b635-420f-b6f2-2fd4421f0381/Participant/",
"recording": null,
"resource_uri": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_2999c70d-b635-420f-b6f2-2fd4421f0381/",
"start_time": "2020-08-28 17:30:10+00:00",
"status": "Ended",
"stay_alone": true,
"sub_account": null,
"termination_cause": "No Active Participants",
"termination_cause_code": 1000
}]
}
});
} else if (method === 'GET' && action === 'MultiPartyCall/uuid_ca8e8a44-48e1-445d-afd5-1fcccdbccd9d') {
resolve({
response: {},
body: {
"api_id": "8970c2b3-edfb-11ea-b02e-0242ac110003",
"billed_amount": "0.00500",
"billed_duration": 60,
"creation_time": "2020-08-31 15:12:03+00:00",
"duration": 3,
"end_time": "2020-08-31 15:12:06+00:00",
"friendly_name": "TestMPC",
"mpc_uuid": "ca8e8a44-48e1-445d-afd5-1fcccdbccd9d",
"participants": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_ca8e8a44-48e1-445d-afd5-1fcccdbccd9d/Participant/",
"recording": null,
"resource_uri": "/v1/Account/MAMDJMMTEZOWY0ZMQWM2/MultiPartyCall/uuid_ca8e8a44-48e1-445d-afd5-1fcccdbccd9d/",
"start_time": null,
"status": "Ended",
"stay_alone": false,
"sub_account": null,
"termination_cause": "No Active Participants",
"termination_cause_code": 1000
}
});
} else if (method === 'POST' && action === 'MultiPartyCall/name_Voice/Participant/' && params.role === 'Agent' && params.from === '+919090909090' && params.to === '+918309866821') {
resolve({
response: {},
body: {
"api_id": "1cebd713-ee00-11ea-b02e-0242ac110003",
"calls": [{
"to": "sip:koushikqa119062465586783372208@phone-qa.voice.plivodev.com",
"from": "918888888888",
"call_uuid": "c0267574-5c12-4861-8990-da9404c8cdf6"
}],
"message": "add participant action initiated",
"request_uuid": "c0267574-5c12-4861-8990-da9404c8cdf6"
}
});
} else if (method === 'POST' && action === 'MultiPartyCall/name_Voice/' && params.status === 'active') {
resolve({
response: {},
body: {}
});
} else if (method === 'DELETE' && action === 'MultiPartyCall/name_Voice/') {
resolve({
response: {},
body: {}
});
} else if (method === 'POST' && action === 'MultiPartyCall/name_TestMPC/Record/') {
resolve({
response: {},
body: {
"api_id": "e9b9b0cf-ee0a-11ea-b02e-0242ac110003",
"message": "MPC: TestMPC record started",
"recording_id": "e9bd7634-ee0a-11ea-9ddf-06feebbe3347",
"recording_url": "https://media-qa.voice.plivodev.com/v1/Account/MAMDJMMTEZOWY0ZMQWM2/Recording/e9bd7634-ee0a-11ea-9ddf-06feebbe3347.mp3"
}
});
} else if (method === 'DELETE' && action === 'M