var express = require('express');
var nconf = require('nconf');
var plivo = require('plivo-node');
var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({
extended: true
});
var app = express();
nconf.file('./config.json');
var api = plivo.RestAPI({
authId: nconf.get('PLIVO_ID'),
authToken: nconf.get('PLIVO_TOKEN')
});
app.post('/call/answer', urlencodedParser, function(req, res) {
var uuid = req.body.CallUUID;
var recordAttributes = {
call_uuid: uuid,
time_limit: 30,
file_format: "wav"
};
var r = plivo.Response();
console.log('got call', uuid);
api.record(recordAttributes, function(status, response) {
console.log('got response:', response);
if (status >= 400) {
console.log('could not record', status);
r.addSpeak('could not record');
res.set({
'Content-Type': 'text/xml'
});
return res.end(r.toXML());
}
else {
r.addPlay('https://s3.amazonaws.com/plivocloud/Trumpet.mp3');
res.set({
'Content-Type': 'text/xml'
});
return res.end(r.toXML());
}
});
});
app.listen(process.env.PORT);
got response: { api_id: '847e1bf4-0e11-11e5-b483-22000afb8d0a',
error: 'call not found' }
Message : response error
Status : 404
URI: /v1/Account/xxxxxxxxxxxx/Call/83a03dc0-0e11-11e5-b86c-6f59143e3963/Record/
Method: POST
Params : {
time_limit : 30
file_format : wav
}
Response : {
api_id : 847e1bf4-0e11-11e5-b483-22000afb8d0a
error : call not found
}