instedd / verboice

Open source toolkit for voice services; with special focus to the needs of medium- and low-income countries, scalable services, and interacting with vulnerable populations
http://verboice.instedd.org/
GNU General Public License v3.0
43 stars 18 forks source link

Active calls GC performing callbacks #916

Closed leandroradusky closed 2 years ago

leandroradusky commented 2 years ago

Closes #913.

The active calls GC now perform callbacks to the callback URL. To accomplish this, now the call_logs are storing the callback_url and the js_context, which are needed to perform these callbacks.

The callback_url is defined in the prepare_session method of each session since it will have no changes along the state transitions. For the js_context, it needs to be updated each time that the FSM state of the session changes, then is updated in the notify_status_to_callback_url, that will be called with each change.

In the GC, before updating the call_logs table entries, a callback is performed establishing CallDuration=0 and CallStatus="failed" on an ad-hoc function called notify_failed_to_callback_url executed foreach active call active for too long.

This commit was tested against surveda calls, and the callback is performed. From surveda logs we can trace them:

2022-07-06T08:46:38.274Z request_id=Fv8xH0VvilFaBFcAAAID [debug] Processing with AskWeb.CallbackController.callback/2
  Parameters: %{"CallDuration" => "0", "CallSid" => "374", "CallStatus" => "failed", "path" => ["status", "62", "18e416cc-7781-4837-920f-1fdd3922cbea"], "provider" => "verboice"}

Then the callback was properly made.

A PR documenting the callbacks cycle will be made to close the twin issue in Surveda, 2085.