Find me 2
From SoftIVR
Find Me (part 2)
The first find me system works, but it lacks in a couple of areas:
- the first outbound leg which is answered gets the call
- all of the other legs will then carry on ringing until they're answered.
These are both quite easily rectified. Firstly, a revised outbound script:
// Tell the originating leg that we've started sendMsg(call.a_uuid, "C " + call.uuid); // Wait for an answer; quit if told to while waiting while (answer(1) == "TIMEOUT") { if (getMsg(0) == "D") { finish(); } } // Connected. Let's see if the callee wants to talk sleep(1); say("Press pound to accept this call.", "background"); if (getDTMF(10) == "#") { sendMsg(call.a_uuid, "V " + call.uuid); while (getMsg(1) != "D") { sleep(1); } }
The major changes are that we send a message to the originating call when the outbound script starts and then check for a disconnect command while waiting for the call to be answered, and that we prompt the recipient as to whether they wish to accept this call or not.
The inbound script has had a bit of a re-write:
function oh() { sendMsg(bleg, "D"); } answer(); dial("+44800500005", "caller_id=" + call.callerID + ",service=find_me_b"); dial("+44800500005", "caller_id=" + call.callerID + ",service=find_me_b"); bridged = 0; b_legs = []; say("Please wait while we connect you.", "background"); while (1) { cmd = getMsg(1); if (cmd.length > 0) { // Process inbound message. First split in to state and UUID msg = cmd.split(" "); if (msg[0] == "C") { // Outbound call connecting - disconnect if bridged, otherwise note UUID if (bridged) { sendMsg(msg[1], "D"); } else { b_legs.push(msg[1]); } } if (msg[0] == "V") { // Outbound call connected - bridge to it, and drop all of the rest if (!bridged) { bridged = 1; bleg = msg[1]; bridge(bleg); onHangup("oh();"); // Drop all of the other outbound legs while (b_legs.length > 0) { b = b_legs.pop(); if (b != bleg) { sendMsg(b, "D"); } } } else { // We're already connected.. sendMsg(msg[1], "D"); } } } }
- in particular, everything is now handled in one main loop. This received messages from the outbound legs, and deals with them as follows:
- Outbound leg starting, not briged: add outbound UUID to the b_legs array
- Outbound leg starting, already bridged: disconnect outbound leg
- Outbound leg successful, not bridged: connect inbound call to that leg and disconnect the others in the b_leg array
- Outbound leg successful, bridged: disconnect that outbound leg.
What next? We'll add functionality to ask the caller who's calling (and remember for future occasions), and to pass that over to the callee.