Find me

From SoftIVR

Revision as of 23:51, 27 April 2009 by Dave (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Find me

This "find me" application shows how to launch multiple outbound calls from an inbound call, how the different call legs can communicate with each other, and how to connect arbitrary calls together. When a call comes in, it calls a number of different target numbers simultaneously, and bridges the inbound call to the first one to answer.

Here's a simplified version of the inbound call handler, find_me:

answer();
dial("+44800500005", "service=find_me_b");
while (1) {
    bleg = getMsg(1);
    if (bleg.length > 0) {
        log("Bridge to " + bleg);
        bridge(bleg);
        while (1) {
            sleep(1);
        }
    }
}

The dial command has 'service=find_me_b' in its options parameter. This causes SoftIVR to make the outbound call, and to attach that outbound call to the service called find_me_b. It won't do anything else, such as bridge the inbound call to the outbound call, and the dial command will return immediately.

The outbound call handler, find_me_b, is much simpler:

answer();
sendMsg(call.a_uuid, call.uuid);
while (getMsg(1) != "D") {
    sleep(1);
}
finish();

Each call has a UUID - a globally-unique identifier associated with it, which is available as part of the call object in call.uuid. Outbound calls also have the UUID of the leg which triggered them available, as call.a_uuid. So find_me_b waits for the outbound call to be answered, and, once it's answered, sends its UUID as a message to the inbound leg with the sendMsg command. The outbound call handler then loops until it received a 'D', which tells it to disconnect.

Looking back at find_me, it receives this message using the getMsg function and bridges itself to the outbound call using the bridge command.

The full find_me code is:

function oh() {
    sendMsg(bleg, "D");
}
 
answer();
dial("+44800500005", "service=find_me_b");
dial("+44800500005", "service=find_me_b");
while (1) {
    bleg = getMsg(1);
    if (bleg.length > 0) {
        log("Bridge to " + bleg);
        bridge(bleg);
        onHangup("oh();");
        while (1) {
            b2 = getMsg(1);
            if (b2.length > 0) {
                log("Disconnect " + b2);
                sendMsg(b2, "D");
            }
        }
    }
}

The additional code is:

  • an onHangup routine to send a 'D' to the outbound leg when the inbound call disconnects;
  • additional code which receives messages from other outbound legs once the inbound call is connected to the first outbound leg to be answered, and promptly causes those legs to disconnect by sending them a 'D'.

This is a very basic skeleton for a find-me application: a full one would have more information for the caller as to what's going on, and would deal slightly differently with the outbound legs - for example, when one is selected, the others should stop ringing immediately. For these, see find me 2.