I am needing to have RC export a detailed call log for our business every hour or so (more frequently if possible) into either excel or Google Sheets and I would like this to be as automated a process as possible. I have very little coding experience but I think this might be the best way to get this done with about breaking the bank on zapier. Would someone be able to help get us set-up with something like this or at least walk me through how I could do it?
Absolute novice needing help with an API. Help?
Hi Matthew,
What you need is really doable with the call log API. If you are familiar with Node JS and can run it locally on your machine, this little code can help you to see how it works. You just need to login the developer portal and create an app with the read call log permission. App platform type will be Server only (no UI). Copy your app Client ID and Client Secret to use in
+ Phong Vu
What you need is really doable with the call log API. If you are familiar with Node JS and can run it locally on your machine, this little code can help you to see how it works. You just need to login the developer portal and create an app with the read call log permission. App platform type will be Server only (no UI). Copy your app Client ID and Client Secret to use in
var RC = require('ringcentral')Let me know if you want in other programming languages.
var rcsdk = new RC({
server:"https://platform.devtest.ringcentral.com",
appKey: YOU_APP_CLIENT_ID,
appSecret:YOUR_APP_CLIENT_SECRET
})
var platform = rcsdk.platform()
login()
function login() {
platform.login({
username:process.env.USERNAME,
password:process.env.PASSWORD
})
.then(function(resp){
console.log("readCallLog by timer")
readCallLog()
setInterval(function(){
readCallLog()
}, 60 * 60 * 1000); // repeat reading call-log every 60 mins
})
.catch(function(e){
console.log(e)
throw e
})
}
function readCallLog(){
console.log("timed")
var date = new Date()
var time = date.getTime()
// 60-min period
var lessXXMin = time - (60 * 60 * 1000)
var from = new Date(lessXXMin)
var dateFrom = from.toISOString()
var dateTo = date.toISOString()
var params = {}
// See the API reference for more request parameters
params['type'] = 'Voice'
params['view'] = 'Detailed'
params['dateFrom'] = dateFrom.replace('/', ':')
params['dateTo'] = dateTo.replace('/', ':')
console.log("date from: " + params.dateFrom)
console.log("date to: " + params.dateTo)
var recordingId = ""
platform.get('/account/~/extension/~/call-log', params)
.then(function(resp){
var json = resp.json()
if (json.records.length > 0){
var fs = require('fs')
// Check the API documentation for call log data fields then add whatever you are interested
var cvs = 'uri,startTime,duration,type,direction,action,result,to_name,from_name,transport'
for (var record of json.records){
//console.log(JSON.stringify(record))
cvs += " "
cvs += record.uri + ','
cvs += record.startTime + ','
cvs += record.duration + ','
cvs += record.type + ','
cvs += record.direction + ','
cvs += record.action + ','
cvs += record.result + ','
if (record.to.hasOwnProperty('name'))
cvs += record.to.name + ','
else
cvs += 'null,'
if (record.hasOwnProperty('from')){
if (record.from.hasOwnProperty('name'))
cvs += record.from.name + ','
else
cvs += 'null,'
}else
cvs += 'null,'
cvs += record.transport
if (record.recording != undefined) {
console.log("contentUri: " + record.recording.contentUri)
recordingId = record.recording.id
console.log(record.recording.contentUri)
platform.get(record.recording.contentUri)
.then(function(res) {
console.log("ok")
return res.response().buffer();
})
.then(function(buffer) {
console.log("buffer")
fs.writeFileSync(recordingId + '.mp3', buffer);
})
.catch(function(e){
console.log(e)
throw e
})
}
}
// add to your CRM or other db
// for demo, I write to a file
fs.writeFile('call_log_'+dateTo+'.csv', cvs, function(err) {
if(err)
console.log(err);
else
console.log("call log is saved.");
})
}else {
console.log("No log");
}
})
.catch(function(e){
throw e
})
}
+ Phong Vu
Thank you so much. This will be extremely helpful I believe. I have started the creation of the application. I am trying to get it to hook up to the existing accounts of our business and I am honestly a bit lost there.
Honestly, with enough time and effort put in, I am sure that I could get this in the long run, especially since you have done all the heavy lifting already it looks like but is this something we would potentially be able to hire you to provide a finished product for us or are there folks with RC that offer that service?
Honestly, with enough time and effort put in, I am sure that I could get this in the long run, especially since you have done all the heavy lifting already it looks like but is this something we would potentially be able to hire you to provide a finished product for us or are there folks with RC that offer that service?
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.