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
45 stars 18 forks source link

Send error code in status callback if the call is rejected #809

Closed spalladino closed 7 years ago

spalladino commented 7 years ago

Send the error description and code in the status callback if the call is rejected.

Required by https://github.com/instedd/ask/issues/821

spalladino commented 7 years ago

Added a Reason parameter to the notify_status function in session.erl to include a description and, if available, the code, as CallStatusReason and CallStatusCode parameters. See commit 090618297f0b148e01be1f867d5292af0fe692c1.

However, the parameter never gets to session. This is because the error code and description are received by the asterisk_event_handler in the hangup event, which is decoded by the asterisk_pbx_log_srv to extract the cause. The entire packet received looks like the following, where cause and cause-txt are the interesting parameters.

<<"Cause-txt: Interworking, unspecified">>,<<"Cause: 127">>,
<<"Linkedid: 1491516263.1">>,<<"Uniqueid: 1491516263.1">>,
<<"Priority: 1">>,<<"Exten: s">>,<<"Context: verboice">>,
<<"AccountCode: ">>,<<"Language: en">>,
<<"ConnectedLineName: <unknown>">>,<<"ConnectedLineNum: <unknown>">>,
<<"CallerIDName: <unknown>">>,<<"CallerIDNum: <unknown>">>,
<<"ChannelStateDesc: Down">>,<<"ChannelState: 0">>,
<<"Channel: PJSIP/verboice_7-00000001">>,<<"Privilege: call,all">>

However, the session.erl is not notified at all in the hangup event handler. The session receives the reject event on the originateresponse event from the asterisk_event_handler. And it is in the reject event that the session actually performs the notify_status action, which would require the cause info. Note that the only info available on the originateresponse event in the asterisk_event_handler is the following.

[{privilege,<<"call,all">>},
{actionid,<<"ba2ca703-c5dd-4e7c-9534-afffe06d246b">>},
{response,<<"Failure">>},
{channel,<<"PJSIP/verboice_7/sip:99999999999@callcentric.com">>},
{application,<<"AGI">>},
{data,<<"agi://localhost:19000,ba2ca703-c5dd-4e7c-9534-afffe06d246b">>},
{reason,<<"0">>},
{uniqueid,<<"<unknown>">>},
{calleridnum,<<"<unknown>">>},
{calleridname,<<"<unknown>">>}]

We should look for a way for the cause and cause-txt to reach the session, so it can be sent along with the rest of the params in the notify_status_to_callback_url method.

As for Twilio, I haven't been able to look into it.