Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

WHISTLE-967: swap fax gateway direction when forced

  • Loading branch information...
commit 19367fdc28a29e60cd8038c573b4f832f3dbefea 1 parent f4724a9
@k-anderson k-anderson authored
View
24 ecallmgr/src/ecallmgr_call_command.erl
@@ -367,9 +367,7 @@ get_fs_app(Node, UUID, JObj, <<"bridge">>) ->
end
,fun(DP) ->
case wh_json:get_value(<<"Ringback">>, JObj) of
- undefined ->
- {ok, RBSetting} = ecallmgr_util:get_setting(<<"default_ringback">>, <<"%(2000,4000,440,480)">>),
- [{"application", "set ringback=" ++ wh_util:to_list(RBSetting)}|DP];
+ undefined -> DP;
Ringback ->
Stream = ecallmgr_util:media_path(Ringback, extant, UUID, JObj),
lager:debug("bridge has custom ringback: ~s", [Stream]),
@@ -430,22 +428,22 @@ get_fs_app(Node, UUID, JObj, <<"bridge">>) ->
end
end
,fun(DP) ->
- case wh_json:find(<<"Force-Fax">>, Endpoints, wh_json:get_value(<<"Force-Fax">>, JObj)) of
- undefined -> DP;
- Direction ->
- Args = <<Direction/binary, " nocng">>,
- [{"application", wh_util:to_list(<<"t38_gateway ", Args/binary>>)}|DP]
- end
- end
- ,fun(DP) ->
[{"application", "set failure_causes=NORMAL_CLEARING,ORIGINATOR_CANCEL,CRASH"}
,{"application", "set continue_on_fail=true"}
|DP
]
end
,fun(DP) ->
- J = wh_json:set_value([<<"Custom-Channel-Vars">>, <<"Bridge-ID">>], wh_util:rand_hex_binary(16), JObj),
- BridgeCmd = list_to_binary(["bridge ", ecallmgr_fs_xml:get_channel_vars(J), DialStrings]),
+ Props = case wh_json:find(<<"Force-Fax">>, Endpoints, wh_json:get_value(<<"Force-Fax">>, JObj)) of
+ undefined -> [{[<<"Custom-Channel-Vars">>, <<"Bridge-ID">>], wh_util:rand_hex_binary(16)}];
+ Direction -> [{[<<"Custom-Channel-Vars">>, <<"Bridge-ID">>], wh_util:rand_hex_binary(16)}
+ ,{[<<"Custom-Channel-Vars">>, <<"Force-Fax">>], Direction}
+ ]
+ end,
+ BridgeCmd = list_to_binary(["bridge "
+ ,ecallmgr_fs_xml:get_channel_vars(wh_json:set_values(Props, JObj))
+ ,DialStrings
+ ]),
[{"application", BridgeCmd}|DP]
end
,fun(DP) ->
View
28 ecallmgr/src/ecallmgr_fs_xml.erl
@@ -91,6 +91,7 @@ route_resp_xml(RespJObj) ->
route_resp_xml(<<"bridge">>, Routes, _JObj) ->
lager:debug("creating a bridge XML response"),
LogEl = route_resp_log_winning_node(),
+ RingbackEl = route_resp_ringback(),
%% format the Route based on protocol
{_Idx, Extensions} = lists:foldr(
fun(RouteJObj, {Idx, Acc}) ->
@@ -123,25 +124,26 @@ route_resp_xml(<<"bridge">>, Routes, _JObj) ->
{Idx+1, [ExtEl | Acc]}
end
- end, {1, [LogEl]}, Routes),
+ end, {1, []}, Routes),
FailRespondEl = action_el(<<"respond">>, <<"${bridge_hangup_cause}">>),
FailConditionEl = condition_el(FailRespondEl),
FailExtEl = extension_el(<<"failed_bridge">>, <<"false">>, [FailConditionEl]),
- ContextEl = context_el(?WHISTLE_CONTEXT, Extensions ++ [FailExtEl]),
+ ContextEl = context_el(?WHISTLE_CONTEXT, [LogEl, RingbackEl] ++ Extensions ++ [FailExtEl]),
SectionEl = section_el(<<"dialplan">>, <<"Route Bridge Response">>, ContextEl),
{ok, xmerl:export([SectionEl], fs_xml)};
route_resp_xml(<<"park">>, _Routes, JObj) ->
LogEl = route_resp_log_winning_node(),
+ RingbackEl = route_resp_ringback(),
ParkEl = action_el(<<"park">>),
ParkConditionEl = case route_resp_pre_park_action(JObj) of
undefined ->
- condition_el([LogEl, ParkEl]);
+ condition_el([LogEl, RingbackEl, ParkEl]);
PreParkEl ->
- condition_el([LogEl, PreParkEl, ParkEl])
+ condition_el([LogEl, RingbackEl, PreParkEl, ParkEl])
end,
ParkExtEl = extension_el(<<"park">>, undefined, [ParkConditionEl]),
@@ -153,11 +155,13 @@ route_resp_xml(<<"park">>, _Routes, JObj) ->
route_resp_xml(<<"error">>, _Routes, JObj) ->
LogEl = route_resp_log_winning_node(),
+ RingbackEl = route_resp_ringback(),
+
ErrCode = wh_json:get_value(<<"Route-Error-Code">>, JObj),
ErrMsg = [" ", wh_json:get_value(<<"Route-Error-Message">>, JObj, <<"">>)],
ErrEl = action_el(<<"respond">>, [ErrCode, ErrMsg]),
- ErrCondEl = condition_el([LogEl, ErrEl]),
+ ErrCondEl = condition_el([LogEl, RingbackEl, ErrEl]),
ErrExtEl = extension_el([ErrCondEl]),
ContextEl = context_el(?WHISTLE_CONTEXT, [ErrExtEl]),
@@ -174,6 +178,15 @@ route_not_found() ->
route_resp_log_winning_node() ->
action_el(<<"log">>, [<<"NOTICE log|${uuid}|", (wh_util:to_binary(node()))/binary, " won call control">>]).
+-spec route_resp_ringback/0 :: () -> xml_el().
+route_resp_ringback() ->
+ case ecallmgr_util:get_setting(<<"default_ringback">>, <<"%(2000,4000,440,480)">>) of
+ {ok, RBSetting} ->
+ action_el(<<"set">>, <<"ringback=", (wh_util:to_binary(RBSetting))/binary>>);
+ _Else ->
+ action_el(<<"log">>, [<<"NOTICE log|${uuid}|unable to set default ringback">>])
+ end.
+
-spec route_resp_pre_park_action/1 :: (wh_json:json_object()) -> 'undefined' | xml_el().
route_resp_pre_park_action(JObj) ->
case wh_json:get_value(<<"Pre-Park">>, JObj) of
@@ -181,7 +194,6 @@ route_resp_pre_park_action(JObj) ->
<<"answer">> -> action_el(<<"answer">>);
_Else -> undefined
end.
-
-spec build_sip_route/2 :: (api_terms(), ne_binary() | 'undefined') -> ne_binary() |
{'error', 'timeout'}.
@@ -260,7 +272,9 @@ get_channel_vars(JObj) -> get_channel_vars(wh_json:to_proplist(JObj)).
-spec get_channel_vars/2 :: ({binary(), binary() | wh_json:json_object()}, [binary(),...] | []) -> iolist().
get_channel_vars({<<"Custom-Channel-Vars">>, JObj}, Vars) ->
- lists:foldl(fun({K, V}, Acc) ->
+ lists:foldl(fun({<<"Force-Fax">>, Direction}, Acc) ->
+ [<<"execute_on_answer='t38_gateway ", Direction/binary, "'">>|Acc];
+ ({K, V}, Acc) ->
case lists:keyfind(K, 1, ?SPECIAL_CHANNEL_VARS) of
false -> [list_to_binary([?CHANNEL_VAR_PREFIX, wh_util:to_list(K)
,"='", wh_util:to_list(V), "'"]) | Acc];
View
2  whistle_apps/apps/callflow/src/cf_endpoint.erl
@@ -185,7 +185,7 @@ create_sip_endpoint(Endpoint, Properties, Call) ->
ForceFax = case wh_json:is_true([<<"media">>, <<"fax_option">>],Endpoint) of
false -> undefined;
- true -> <<"peer">>
+ true -> <<"self">>
end,
Prop = [{<<"Invite-Format">>, wh_json:get_value([<<"sip">>, <<"invite_format">>], Endpoint, <<"username">>)}
View
2  whistle_apps/apps/callflow/src/module/cf_resources.erl
@@ -102,7 +102,7 @@ create_endpoint(DestNum, JObj, Call) ->
end,
ForceFax = case wh_json:is_true([<<"media">>, <<"fax_option">>], Endpoint) of
false -> undefined;
- true -> <<"self">>
+ true -> <<"peer">>
end,
AccountId = whapps_call:account_id(Call),
CCVs = [{<<"Account-ID">>, AccountId}
View
1  whistle_apps/apps/crossbar/src/modules/cb_phone_numbers.erl
@@ -129,6 +129,7 @@ resource_exists(_) -> true.
resource_exists(_, ?ACTIVATE) -> true;
resource_exists(_, ?RESERVE) -> true;
+resource_exists(_, ?PORT) -> true;
resource_exists(_, ?PORT_DOCS) -> true;
resource_exists(_, _) -> false.
View
2  whistle_apps/apps/stepswitch/src/stepswitch_outbound.erl
@@ -154,7 +154,7 @@ bridge_to_endpoints(Endpoints, IsEmergency, CtrlQ, JObj) ->
ForceFax = case wh_json:is_true(<<"Force-Fax">>, JObj) of
false -> undefined;
- true -> <<"self">>
+ true -> <<"peer">>
end,
Command = [{<<"Application-Name">>, <<"bridge">>}
View
26 whistle_apps/src/whapps_call.erl
@@ -120,6 +120,14 @@
-type call() :: #whapps_call{}.
-export_type([call/0]).
+-define(SPECIAL_VARS, [{<<"Caller-ID-Name">>, #whapps_call.caller_id_name}
+ ,{<<"Caller-ID-Number">>, #whapps_call.caller_id_number}
+ ,{<<"Account-ID">>, #whapps_call.account_id}
+ ,{<<"Owner-ID">>, #whapps_call.owner_id}
+ ,{<<"Authorizing-ID">>, #whapps_call.authorizing_id}
+ ,{<<"Authorizing-Type">>, #whapps_call.authorizing_type}
+ ]).
+
-spec default_helper_function/2 :: (whapps_api_binary(), whapps_call:call()) -> whapps_api_binary().
default_helper_function(Field, #whapps_call{}) ->
Field.
@@ -528,7 +536,7 @@ account_id(#whapps_call{account_id=AccountId}) ->
-spec set_authorizing_id/2 :: (ne_binary(), whapps_call:call()) -> whapps_call:call().
set_authorizing_id(AuthorizingId, #whapps_call{}=Call) when is_binary(AuthorizingId) ->
- set_custom_channel_var(<<"Authorizing-Id">>, AuthorizingId, Call#whapps_call{authorizing_id=AuthorizingId}).
+ set_custom_channel_var(<<"Authorizing-ID">>, AuthorizingId, Call#whapps_call{authorizing_id=AuthorizingId}).
-spec authorizing_id/1 :: (whapps_call:call()) -> whapps_api_binary().
authorizing_id(#whapps_call{authorizing_id=AuthorizingId}) ->
@@ -553,19 +561,19 @@ owner_id(#whapps_call{owner_id=OwnerId}) ->
-spec set_custom_channel_var/3 :: (term(), term(), whapps_call:call()) -> whapps_call:call().
set_custom_channel_var(Key, Value, #whapps_call{ccvs=CCVs}=Call) ->
whapps_call_command:set(wh_json:set_value(Key, Value, wh_json:new()), undefined, Call),
- Call#whapps_call{ccvs=wh_json:set_value(Key, Value, CCVs)}.
+ handle_ccvs_update(wh_json:set_value(Key, Value, CCVs), Call).
-spec set_custom_channel_vars/2 :: (proplist(), whapps_call:call()) -> whapps_call:call().
set_custom_channel_vars(Props, #whapps_call{ccvs=CCVs}=Call) ->
NewCCVs = wh_json:set_values(Props, CCVs),
whapps_call_command:set(NewCCVs, undefined, Call),
- Call#whapps_call{ccvs=NewCCVs}.
+ handle_ccvs_update(NewCCVs, Call).
-spec update_custom_channel_vars/2 :: ([fun((wh_json:json_object()) -> wh_json:json_object()),...], whapps_call:call()) -> whapps_call:call().
update_custom_channel_vars(Updaters, #whapps_call{ccvs=CCVs}=Call) ->
NewCCVs = lists:foldr(fun(F, J) -> F(J) end, CCVs, Updaters),
whapps_call_command:set(NewCCVs, undefined, Call),
- Call#whapps_call{ccvs=NewCCVs}.
+ handle_ccvs_update(NewCCVs, Call).
-spec custom_channel_var/3 :: (term(), Default, whapps_call:call()) -> Default | term().
custom_channel_var(Key, Default, #whapps_call{ccvs=CCVs}) ->
@@ -579,6 +587,16 @@ custom_channel_var(Key, #whapps_call{ccvs=CCVs}) ->
custom_channel_vars(#whapps_call{ccvs=CCVs}) ->
CCVs.
+-spec handle_ccvs_update/2 :: (wh_json:json_object(), whapps_call:call()) -> whapps_call:call().
+handle_ccvs_update(CCVs, #whapps_call{}=Call) ->
+ lists:foldl(fun({Var, Index}, C) ->
+ case wh_json:get_ne_value(Var, CCVs) of
+ undefined -> C;
+ Value ->
+ setelement(Index, C, Value)
+ end
+ end, Call#whapps_call{ccvs=CCVs}, ?SPECIAL_VARS).
+
-spec set_custom_publish_function/2 :: (whapps_custom_publish(), whapps_call:call()) -> whapps_call:call().
set_custom_publish_function(Fun, #whapps_call{}=Call) when is_function(Fun, 2) ->
Call#whapps_call{custom_publish_fun=Fun}.
Please sign in to comment.
Something went wrong with that request. Please try again.