-
Notifications
You must be signed in to change notification settings - Fork 2
/
twilio.js
39 lines (33 loc) · 1.03 KB
/
twilio.js
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
const config = require( './config.json' );
const axios = require( 'axios' );
const { accountSid, authToken, applicationSid, incomingNumber } = config;
const ClientCapability = require('twilio').jwt.ClientCapability;
class Twilio {
getToken( username ) {
if ( username == null || username.trim() === '' ) {
username = 'support_agent';
}
const capability = new ClientCapability({
accountSid,
authToken
});
capability.addScope(new ClientCapability.IncomingClientScope(username));
capability.addScope(new ClientCapability.OutgoingClientScope({
applicationSid,
}));
return capability.toJwt();
}
getCalls( callback ) {
axios({
method: 'get',
url: `https://api.twilio.com/2010-04-01/Accounts/${accountSid}/Calls.json?Status=Completed&To=${incomingNumber}&Direction=inbound&PageSize=25`,
auth: {
username: accountSid,
password: authToken,
},
}).then( response => {
callback( response.data.calls );
});
}
}
module.exports = new Twilio();