Voximplant. Blog

Step-by-step call center tutorial part 4

Handling a call disconnect

Since our cloud has separate “incoming” and “outgoing” call legs, we have full control over call disconnects. If a calling user or an operator disconnects, you can make decisions what to do next: play a notification message, call back, disconnect the remaining participants and so on. If the incoming or outgoing call is disconnected, the corresponding call object receives Disconnected event. Please note that an outgoing call can fail to connect (ex user not answered), in such case Failed event will be received instead of Disconnected.

A call can be disconnected by a remote user, by the JavaScript via the call.hangup method or via the VoxEngine.terminate method which will disconnect all calls and will terminate the JavaScript scenario. The scenario will also be automatically terminated after having no active calls for 60 seconds. Upon scenario termination, AppEvents.Terminating and AppEvents.Terminated events are fired. The Terminating event handler is normally used for scenario results reporting. This event is limited to single HTTP request (and every HTTP request is limited to 90 seconds). Terminated is the last event received by the scenario JavaScript code, it is normally used for log and debug purpose. It’s not possible to issue HTTP request from this event handler.

Given all this information about different ways to disconnect calls and different events that are fired during such disconnects and scenario termination, let’s add “gracefull disconnect” to our call center. We will disconnect an operator if a user hangs up, and disconnect a user if an operator hangs up. Modify scenario code by adding Disconnected event handler:

  1. require(Modules.ACD);
  2.  
  3. VoxEngine.addEventListener(AppEvents.CallAlerting, function(e) {
  4. var inc = e.call;
  5. var incId = e.callerid;
  6. var request = null;
  7. var out = null;
  8. inc.answer();
  9. inc.addEventListener(CallEvents.Connected, function() {
  10. request = VoxEngine.enqueueACDRequest("main", incId);
  11. request.addEventListener(ACDEvents.OperatorReached, function (e) {
  12. out = e.operatorCall;
  13. VoxEngine.sendMediaBetween(inc, out);
  14. out.addEventListener(CallEvents.Disconnected, function() {
  15. inc.hangup();
  16. // Some logic can be performed instead of session termination
  17. VoxEngine.terminate();
  18. });
  19. });
  20. });
  21. inc.addEventListener(CallEvents.Disconnected, function() {
  22. // If operator already connected, this also hangs up operator's call.
  23. request.cancel();
  24. // Some logic can be performed instead of session termination
  25. VoxEngine.terminate();
  26. });
  27. });

Now if a user or an operator hangs up the call, other party will be gracefully disconnected. Please note, that you are not obliged to disconnect a call and can do any logic: call back, report some statistics, call other person etc. Flexibility of the Voximplant platform allows to implement any call handling scenario and is not limited to “A calls B, they speak and then the call terminates”.

Tagged in

Comments