-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexotel.js
More file actions
72 lines (63 loc) · 2.04 KB
/
Copy pathexotel.js
File metadata and controls
72 lines (63 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var request = require('request');
var parseString = require('xml2js').parseString;
module.exports = {
init : function (S_ID, TOKEN, EXOPHONE) {
this.exotel_sid = S_ID;
this.exotel_token = TOKEN;
this.exophone = EXOPHONE;
},
sendSMS : function(toNumber, message, callback) {
var url = 'https://' + this.exotel_sid + ':' + this.exotel_token + '@twilix.exotel.in/v1/Accounts/' + this.exotel_sid +'/Sms/send';
var params = {
From : this.exophone,
To : toNumber,
Body : message,
}
makeRequest(url, params, function(error, response) {
if (error) {
callback(error, null);
} else {
callback(null, response.TwilioResponse.SMSMessage);
}
});
},
connectCall : function(firstNumber, secondNumber, callback) {
var url = 'https://' + this.exotel_sid + ':' + this.exotel_token + '@twilix.exotel.in/v1/Accounts/' + this.exotel_sid +'/Calls/connect';
var params = {
From : firstNumber,
To : secondNumber,
CallerId : this.exophone,
CallType : 'trans',
}
makeRequest(url, params, function(error, response) {
if (error) {
callback(error, null);
} else {
callback(null, response.TwilioResponse.Call);
}
});
},
getCallDetails : function(id, callback) {
var url = 'https://' + this.exotel_sid + ':' + this.exotel_token + '@twilix.exotel.in/v1/Accounts/' + this.exotel_sid +'/Calls/' + id;
request.get(url, function (error, response, body) {
if (error) {
callback(error, response);
} else {
parseString(response.body, {explicitArray: false}, function(err, result) {
callback(null, result.TwilioResponse.Call);
});
}
});
}
}
function makeRequest(url, params, callback) {
request.post(url, {form: params}, function (error, response, body) {
if (error) {
callback(error, response);
} else {
parseString(response.body, {explicitArray: false}, function(err, result) {
callback(null, result);
});
}
});
}