Volunteer.find({phoneNumber: volunteerQueue[0].phoneNumber}, function(err, result){
      console.log(result);
      if(result[0].available && result[0].online){
        //console.log("calledfind");
        var srcNumber = appNumber;  
        var dstNumber = volunteerQueue[0].phoneNumber;
        Volunteer.update({phoneNumber: volunteerQueue[0].phoneNumber}, {
          $set:{currentCall: req.query.From, 
            available: false
          }}, 
          function (err, result){
            console.log(result);
          }
        );
        //Volunteer.update({phoneNumber: volunteerQueue[0].phoneNumber}, {$set:{available:false}})
        callerCalleeDict[hash(req.query.From)] = dstNumber;
        volunteerQueue.shift();

        var responseForPlivo = plivo.Response();
        var dial = responseForPlivo.addDial({callerId: srcNumber});
        dial.addUser(appEndPoint);
        dial.addNumber(dstNumber);

        //console.log("end");
        res.set({'Content-Type': 'text/xml'});
        res.end(responseForPlivo.toXML());  
      }
      else{
        //console.log("volunteer status changed, trying next volunteer")
        volunteerQueue.shift();
        forwardHelper(req, res);
      }
    })
app.post('/response/sip/digits/', function(req, res) {
    console.log(req.query);
    var digits = req.param('Digits');
    console.log('got digits: ', digits);
    
    var r = plivo.Response();
    r.addSpeak('you entered a digit, ma sun');
    r.addWait({length: 3});
    res.end(r.toXML());
});
 Volunteer.find({available:true, online:true}, function(err, result){
   volunteerQueue = volunteerQueue.concat(result);
   if (volunteerQueue.length == 0){
     var responseForPlivo = plivo.Response();
     responseForPlivo.addSpeak(unavailableText);
     res.set({'Content-Type': 'text/xml'});
     res.end(responseForPlivo.toXML());      
   }
   else{
     forwardHelper(req, res);
   }
 });   
app.all('/response/sip/mobiletalk/', function(req, res) {
    console.log(req.query);
    var hangup = req.param('HangupCause');
    //console.log('hangup: ' + hangup);
    var r = plivo.Response();

    var recordOptions = {
        recordSession: "true",
        //startOnDialAnswer: "true",
        redirect: "false",
        action: "https://mtw-patch-monitor-insanity54.c9.io/response/sip/recording/",
        maxLength: "20"
    };
    
    var digitOptions = {
        action: 'https://mtw-patch-monitor-insanity54.c9.io/response/sip/digits/',
        redirect: "false",
        timeout: 30,
        digitTimeout: 1
    };    
    
    r.addRecord(recordOptions);
    r.addWait({length: "9"});
    //r.addSpeak('enter digits');
    //r.addGetDigits(digitOptions);
    r.addWait({length: "20"});
    //r.addSpeak('end');
    r.addHangup();
    // var dial = r.addDial();
    // dial.addNumber('15099220951');
    //r.addWait({ length: "3" });

    // if (hangup) {
    //     res.end("SIP Route hangup callback");
    //     return;
    // }

    res.set({
        'Content-Type': 'text/xml'
    });
    res.end(r.toXML());

});
Exemple #5
0
var server = http.createServer(function(req, res) {
    var response = plivo.Response();
    var page = url.parse(req.url).pathname;
    var params = querystring.parse(url.parse(req.url).query);

    if (page == '/dial') {
      var toNumber = params['To'] || '';
      var fromNumber = params['CLID'] || (params['From'] || '');
      var callerName = params['CallerName'] || '';

      if (toNumber == "") {
        response.addHangup();
      } else if (toNumber.substring(0, 4) == "sip:") {
        var dial = response.addDial({'callerName' : callerName});
        dial.addUser(toNumber);
      } else {
        var dial = response.addDial({'callerId' : fromNumber});
        dial.addNumber(toNumber);
      };
    }
    res.writeHead(200, {"Content-Type": "text/xml"});
    res.end(response.toXML());
});
app.all('/forward/call', function (req, res) {
	if (req.method == 'POST')
		console.log(req.body);
	else
		console.log(req.query);
    var to_number = req.param('ForwardTo') || "";
	var from_number = req.param('From') || "";
	var call_record = req.param('CallRecord') || "";
    var response = plivo.Response();

	if (to_number && from_number) {
		if (call_record == 'true') {
			response.addRecord({action: util.format('http://%s/call/record', server_name ), startOnDialAnswer: 'true'});
		}
		var dial = response.addDial({callerId: from_number});
		dial.addNumber(to_number);
	}

    res.set({
        'Content-Type': 'text/xml'
    });
    res.end(response.toXML());

});
Exemple #7
0
var express = require('express');
var app = express();
var plivo = require('plivo-node');
var p = plivo.RestAPI(require('./config.json'));

var response = plivo.Response();
response.addSpeak('Hello World',{loop:2});
console.log(response.toXML());

var flag =1; // 1 for phone call ; 0 for sms
if(!flag)
{
	var params = {
    'src': '+919620788167',
    'dst' : '+919945247441', // User Number to Call
    'text' : "Hi, message from Plivo",
    'type' : "sms",
};
}

if(flag)
{
	var params = {};
	params.from = "+919620788167";
	params.to = "+919900970842";
	params.answer_url = "http://frozen-savannah-9731.herokuapp.com/response/speak/";
}

var quotes = [
  { author : 'Audrey Hepburn', text : "Nothing is impossible, the word itself says 'I'm possible'!"},
  { author : 'Walt Disney', text : "You may not realize it when it happens, but a kick in the teeth may be the best thing in the world for you"},