Callthrough

From SoftIVR

Jump to: navigation, search

Callthrough

Callthrough allows users to call internationally by first calling a number which is charged to them at a premium (such as an 0871 number in the UK) and then dialling the number they wish to call. The operator of the service receives some revenue for the inbound call, and this pays for the outbound call.

// This is the per-minute rate which we receive for the call
inpay = 0.07;
 
answer();
sleep(1);
while (1) {
    say("Please enter the number you wish to call, starting with 00");
    ntd = "";
 
    // Get number to dial from the caller
    while (1) {
        nd = getDTMF(4);
        if ((nd < 0) || (nd == '*') || (nd == '#')) {
            break;
        }
        ntd = ntd + nd;
    }
 
    // Strip off 00
    ntd = ntd.substring(2);
 
    // Get rate
    rate = wget("http://rate.softivr.com/price/getrate.php?number=" + ntd);
 
    // Rate is of form day=0.03&eve=0.02&wkd=0.01&currency=GBP - get day rate
    re = /day=([0-9\.]+)/;
    drate = re.exec(rate);
    if (drate) {
        if (drate[1] < inpay) {
            // Dial out
            say("Thank you.  Connecting now.");
            log("Dialling " + ntd);
            dial("+" + ntd);
        } else {
            // That destination's too expensive
            say("Sorry. You cannot call that number through this service.");
        }
    } else {
        say("Sorry, but that number is invalid.");
    }
}
Personal tools