Skip to content

Commit

Permalink
Support Africa's Talking callSessionState parameter (#895)
Browse files Browse the repository at this point in the history
AfT now sends a `callSessionState` parameter on every request.

This used to only appear when calls were already completed, so we
were aborting the calls. We now look for the `completed` state
only.

See #894
matiasgarciaisaia authored Nov 10, 2021
1 parent acdbc8e commit 7cfcdb2
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions broker/src/africas_talking/africas_talking_httpd_module.erl
Original file line number Diff line number Diff line change
@@ -10,7 +10,18 @@ do(#mod{request_uri = "/africas_talking" ++ _, method = "POST", entity_body = Bo
CallSid = proplists:get_value("sessionId", Params),
Pbx = africas_talking_pbx:find(CallSid),
case proplists:get_value("callSessionState", Params) of
undefined ->
% TODO. If the call fails and the session is still active, a user_hangup is logged,
% which is not true. Handle those cases properly.
"Completed" ->
case Pbx of
undefined ->
ok;
FoundPbx ->
FoundPbx:user_hangup()
end,
{proceed, [{response, {200, "OK"}}]};
_ ->
lager:info("Receiving callSessionState ~p", [Params]),
httpd_utils:if_not_already_handled(Data, fun() ->
ResponseBody = case Pbx of
undefined ->
@@ -39,20 +50,7 @@ do(#mod{request_uri = "/africas_talking" ++ _, method = "POST", entity_body = Bo
Head = [{content_type, "text/plain"}, {content_length, Length}, {code, 200}],
Response = [{response, {response, Head, ResponseBody}}],
{proceed, Response}
end);
% TODO. If the call fails and the session is still active, a user_hangup is logged,
% which is not true. Handle those cases properly.
"Completed" ->
case Pbx of
undefined ->
ok;
FoundPbx ->
FoundPbx:user_hangup()
end,
{proceed, [{response, {200, "OK"}}]};
_ ->
lager:info("Receiving callSessionState ~p", [Params]),
{proceed, [{response, {200, "OK"}}]}
end)
end;

do(ModData) ->

0 comments on commit 7cfcdb2

Please sign in to comment.