Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAZOO-661: create ringback settings on the number or callflow #12

Merged
merged 2 commits into from
Apr 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ecallmgr/src/ecallmgr.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
,{<<"Origination-UUID">>, <<"origination_uuid">>}
,{<<"Ignore-Display-Updates">>, <<"ignore_display_updates">>}
,{<<"Eavesdrop-Group-ID">>, <<"eavesdrop_group">>}
%% ,{<<"Hold-Media">>, <<"hold_music">>}
,{<<"Loopback-Bowout">>, <<"loopback_bowout_on_execute">>}
,{<<"tts_engine">>, <<"tts_engine">>}
,{<<"tts_voice">>, <<"tts_voice">>}
Expand Down
558 changes: 313 additions & 245 deletions ecallmgr/src/ecallmgr_call_command.erl

Large diffs are not rendered by default.

46 changes: 34 additions & 12 deletions ecallmgr/src/ecallmgr_fs_xml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ route_resp_xml(RespJObj) ->

%% Prop = Route Response
-spec route_resp_xml(ne_binary(), wh_json:objects(), wh_json:object()) -> {'ok', iolist()}.
route_resp_xml(<<"bridge">>, Routes, _JObj) ->
route_resp_xml(<<"bridge">>, Routes, JObj) ->
lager:debug("creating a bridge XML response"),
LogEl = route_resp_log_winning_node(),
RingbackEl = route_resp_ringback(),
RingbackEl = route_resp_ringback(JObj),
TransferEl = route_resp_transfer_ringback(JObj),
%% format the Route based on protocol
{_Idx, Extensions} = lists:foldr(
fun(RouteJObj, {Idx, Acc}) ->
Expand Down Expand Up @@ -170,20 +171,21 @@ route_resp_xml(<<"bridge">>, Routes, _JObj) ->
FailConditionEl = condition_el(FailRespondEl),
FailExtEl = extension_el(<<"failed_bridge">>, <<"false">>, [FailConditionEl]),

ContextEl = context_el(?WHISTLE_CONTEXT, [LogEl, RingbackEl] ++ Extensions ++ [FailExtEl]),
ContextEl = context_el(?WHISTLE_CONTEXT, [LogEl, RingbackEl, TransferEl] ++ 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(),
RingbackEl = route_resp_ringback(JObj),
TransferEl = route_resp_transfer_ringback(JObj),
ParkEl = action_el(<<"park">>),

ParkConditionEl = case route_resp_pre_park_action(JObj) of
undefined ->
condition_el([LogEl, RingbackEl, ParkEl]);
condition_el([LogEl, RingbackEl, TransferEl, ParkEl]);
PreParkEl ->
condition_el([LogEl, RingbackEl, PreParkEl, ParkEl])
condition_el([LogEl, RingbackEl, TransferEl, PreParkEl, ParkEl])
end,

ParkExtEl = extension_el(<<"park">>, undefined, [ParkConditionEl]),
Expand All @@ -195,13 +197,14 @@ route_resp_xml(<<"park">>, _Routes, JObj) ->
route_resp_xml(<<"error">>, _Routes, JObj) ->
LogEl = route_resp_log_winning_node(),

RingbackEl = route_resp_ringback(),
RingbackEl = route_resp_ringback(JObj),
TransferEl = route_resp_transfer_ringback(JObj),

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, RingbackEl, ErrEl]),
ErrCondEl = condition_el([LogEl, RingbackEl, TransferEl, ErrEl]),
ErrExtEl = extension_el([ErrCondEl]),

ContextEl = context_el(?WHISTLE_CONTEXT, [ErrExtEl]),
Expand All @@ -218,10 +221,29 @@ 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() -> xml_el().
route_resp_ringback() ->
{ok, RBSetting} = ecallmgr_util:get_setting(<<"default_ringback">>, <<"%(2000,4000,440,480)">>),
action_el(<<"set">>, <<"ringback=", (wh_util:to_binary(RBSetting))/binary>>).
-spec route_resp_ringback(wh_json:object()) -> xml_el().
route_resp_ringback(JObj) ->
case wh_json:get_value(<<"Ringback-Media">>, JObj) of
'undefined' ->
{ok, RBSetting} = ecallmgr_util:get_setting(<<"default_ringback">>, <<"%(2000,4000,440,480)">>),
action_el(<<"set">>, <<"ringback=", (wh_util:to_binary(RBSetting))/binary>>);
Media ->
MsgId = wh_json:get_value(<<"Msg-ID">>, JObj),
Stream = ecallmgr_util:media_path(Media, extant, MsgId, JObj),
action_el(<<"set">>, <<"ringback=", (wh_util:to_binary(Stream))/binary>>)
end.

-spec route_resp_transfer_ringback(wh_json:object()) -> xml_el().
route_resp_transfer_ringback(JObj) ->
case wh_json:get_value(<<"Transfer-Media">>, JObj) of
'undefined' ->
{ok, RBSetting} = ecallmgr_util:get_setting(<<"default_ringback">>, <<"%(2000,4000,440,480)">>),
action_el(<<"set">>, <<"transfer_ringback=", (wh_util:to_binary(RBSetting))/binary>>);
Media ->
MsgId = wh_json:get_value(<<"Msg-ID">>, JObj),
Stream = ecallmgr_util:media_path(Media, extant, MsgId, JObj),
action_el(<<"set">>, <<"transfer_ringback=", (wh_util:to_binary(Stream))/binary>>)
end.

-spec route_resp_pre_park_action(wh_json:object()) -> 'undefined' | xml_el().
route_resp_pre_park_action(JObj) ->
Expand Down
30 changes: 16 additions & 14 deletions lib/whistle-1.0.0/src/api/wapi_route.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
,<<"Caller-ID-Name">>, <<"Caller-ID-Number">>
]).
-define(OPTIONAL_ROUTE_REQ_HEADERS, [<<"Geo-Location">>, <<"Orig-IP">>
,<<"Max-Call-Length">>, <<"Media">>
,<<"Transcode">>, <<"Codecs">>
,<<"Custom-Channel-Vars">>
,<<"Resource-Type">>, <<"Cost-Parameters">>
,<<"From-Network-Addr">>
,<<"Switch-Hostname">>, <<"Switch-Nodename">>
,<<"Max-Call-Length">>, <<"Media">>
,<<"Transcode">>, <<"Codecs">>
,<<"Custom-Channel-Vars">>
,<<"Resource-Type">>, <<"Cost-Parameters">>
,<<"From-Network-Addr">>
,<<"Switch-Hostname">>, <<"Switch-Nodename">>
,<<"Ringback-Media">>, <<"Transfer-Media">>
]).
-define(ROUTE_REQ_VALUES, [{<<"Event-Category">>, ?EVENT_CATEGORY}
,{<<"Event-Name">>, ?ROUTE_REQ_EVENT_NAME}
Expand Down Expand Up @@ -72,12 +73,12 @@
%% Route Responses
-define(ROUTE_RESP_ROUTE_HEADERS, [<<"Invite-Format">>]).
-define(OPTIONAL_ROUTE_RESP_ROUTE_HEADERS, [<<"Route">>, <<"To-User">>, <<"To-Realm">>, <<"To-DID">>
,<<"Proxy-Via">>, <<"Media">>, <<"Auth-User">>
,<<"Auth-Password">>, <<"Codecs">>, <<"Progress-Timeout">>
,<<"Caller-ID-Name">>, <<"Caller-ID-Number">>, <<"Caller-ID-Type">>
,<<"Rate">>, <<"Rate-Increment">>, <<"Rate-Minimum">>, <<"Surcharge">>
,<<"SIP-Headers">>, <<"Custom-Channel-Vars">>
,<<"Weight-Cost">>, <<"Weight-Location">>
,<<"Proxy-Via">>, <<"Media">>, <<"Auth-User">>
,<<"Auth-Password">>, <<"Codecs">>, <<"Progress-Timeout">>
,<<"Caller-ID-Name">>, <<"Caller-ID-Number">>, <<"Caller-ID-Type">>
,<<"Rate">>, <<"Rate-Increment">>, <<"Rate-Minimum">>, <<"Surcharge">>
,<<"SIP-Headers">>, <<"Custom-Channel-Vars">>
,<<"Weight-Cost">>, <<"Weight-Location">>
]).
-define(ROUTE_RESP_ROUTE_VALUES, [{<<"Media">>, [<<"process">>, <<"bypass">>, <<"auto">>]}
,{<<"Caller-ID-Type">>, [<<"from">>, <<"rpid">>, <<"pid">>]}
Expand All @@ -94,8 +95,9 @@
%% Route Responses
-define(ROUTE_RESP_HEADERS, [<<"Method">>]).
-define(OPTIONAL_ROUTE_RESP_HEADERS, [<<"Custom-Channel-Vars">>, <<"Routes">>
,<<"Route-Error-Code">>, <<"Route-Error-Message">>
,<<"Pre-Park">>
,<<"Route-Error-Code">>, <<"Route-Error-Message">>
,<<"Ringback-Media">>, <<"Transfer-Media">>
,<<"Pre-Park">>
]).
-define(ROUTE_RESP_VALUES, [{<<"Event-Category">>, ?EVENT_CATEGORY}
,{<<"Event-Name">>, <<"route_resp">>}
Expand Down
22 changes: 15 additions & 7 deletions lib/whistle_number_manager-1.0.0/src/wh_number_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ lookup_account_by_number(undefined) ->
{error, not_reconcilable};
lookup_account_by_number(Number) ->
try wnm_number:get(Number) of
#number{assigned_to=undefined} ->
#number{assigned_to=undefined} ->
lager:debug("number ~s not assigned to an account", [Number]),
{error, unassigned};
#number{assigned_to=AssignedTo, state = <<"port_in">>}=N ->
{error, unassigned};
#number{assigned_to=AssignedTo, state = <<"port_in">>}=N ->
lager:debug("number ~s is assigned to ~s in state port_in", [Number, AssignedTo]),
{ok, AssignedTo, number_options(N)};
#number{assigned_to=AssignedTo, state = <<"in_service">>}=N ->
#number{assigned_to=AssignedTo, state = <<"in_service">>}=N ->
lager:debug("number ~s is assigned to ~s in state in_service", [Number, AssignedTo]),
{ok, AssignedTo, number_options(N)};
#number{assigned_to=AssignedTo, state = <<"port_out">>}=N ->
#number{assigned_to=AssignedTo, state = <<"port_out">>}=N ->
lager:debug("number ~s is assigned to ~s in state port_in", [Number, AssignedTo]),
{ok, AssignedTo, number_options(N)};
#number{assigned_to=AssignedTo, state=State} ->
#number{assigned_to=AssignedTo, state=State} ->
lager:debug("number ~s assigned to acccount id ~s but in state ~s", [Number, AssignedTo, State]),
{error, {not_in_service, AssignedTo}}
catch
Expand All @@ -88,14 +88,22 @@ number_options(#number{state=State, features=Features, module_name=Module}=Numbe
,{pending_port, State =:= <<"port_in">>}
,{local, Module =:= wnm_local}
,{inbound_cnam, sets:is_element(<<"inbound_cnam">>, Features)}
,{ringback_media, find_early_ringback(Number)}
,{transfer_media, find_transfer_ringback(Number)}
].

should_force_outbound(#number{module_name=wnm_local}) -> true;
should_force_outbound(#number{state = <<"port_in">>}) -> true;
should_force_outbound(#number{state = <<"port_out">>}) -> true;
should_force_outbound(#number{number_doc=JObj}) ->
should_force_outbound(#number{number_doc=JObj}) ->
wh_json:is_true(<<"force_outbound">>, JObj, false).

find_early_ringback(#number{number_doc=JObj}) ->
wh_json:get_ne_value([<<"ringback">>, <<"early">>], JObj).

find_transfer_ringback(#number{number_doc=JObj}) ->
wh_json:get_ne_value([<<"ringback">>, <<"transfer">>], JObj).

%%--------------------------------------------------------------------
%% @public
%% @doc
Expand Down
36 changes: 27 additions & 9 deletions whistle_apps/apps/callflow/src/cf_route_req.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ handle_req(JObj, Options) ->
,whapps_call:account_id(Call)
]),
cache_call(Flow, NoMatch, ControllerQ, Call),
send_route_response(JObj, ControllerQ, Call);
send_route_response(Flow, JObj, ControllerQ, Call);
{ok, _, true} ->
lager:info("only available callflow is a nomatch for a unauthorized call", []);
{error, R} ->
Expand Down Expand Up @@ -77,19 +77,37 @@ callflow_should_respond(Call) ->
%% process
%% @end
%%-----------------------------------------------------------------------------
-spec send_route_response(wh_json:object(), ne_binary(), whapps_call:call()) -> 'ok'.
send_route_response(JObj, Q, Call) ->
Resp = [{<<"Msg-ID">>, wh_json:get_value(<<"Msg-ID">>, JObj)}
,{<<"Routes">>, []}
,{<<"Method">>, <<"park">>}
,{<<"Pre-Park">>, pre_park_action(Call)}
| wh_api:default_headers(Q, ?APP_NAME, ?APP_VERSION)
],
-spec send_route_response(wh_json:object(), wh_json:object(), ne_binary(), whapps_call:call()) -> 'ok'.
send_route_response(Flow, JObj, Q, Call) ->
Resp = props:filter_undefined([{<<"Msg-ID">>, wh_json:get_value(<<"Msg-ID">>, JObj)}
,{<<"Routes">>, []}
,{<<"Method">>, <<"park">>}
,{<<"Transfer-Media">>, get_transfer_media(Flow, JObj)}
,{<<"Ringback-Media">>, get_ringback_media(Flow, JObj)}
,{<<"Pre-Park">>, pre_park_action(Call)}
| wh_api:default_headers(Q, ?APP_NAME, ?APP_VERSION)
]),
ServerId = wh_json:get_value(<<"Server-ID">>, JObj),
Publisher = fun(P) -> wapi_route:publish_resp(ServerId, P) end,
whapps_util:amqp_pool_send(Resp, Publisher),
lager:info("callflows knows how to route the call! sent park response").

-spec get_transfer_media(wh_json:object(), wh_json:object()) -> api_binary().
get_transfer_media(Flow, JObj) ->
case wh_json:get_value([<<"ringback">>, <<"transfer">>], Flow) of
'undefined' ->
wh_json:get_value(<<"Transfer-Media">>, JObj);
MediaId -> MediaId
end.

-spec get_ringback_media(wh_json:object(), wh_json:object()) -> api_binary().
get_ringback_media(Flow, JObj) ->
case wh_json:get_value([<<"ringback">>, <<"early">>], Flow) of
'undefined' ->
wh_json:get_value(<<"Ringback-Media">>, JObj);
MediaId -> MediaId
end.

%%-----------------------------------------------------------------------------
%% @private
%% @doc
Expand Down
16 changes: 15 additions & 1 deletion whistle_apps/apps/stepswitch/src/stepswitch_inbound.erl
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,26 @@ custom_channel_vars(AccountId, JObj) ->
-spec relay_route_req(ne_binary(), proplist(), wh_json:json_object()) -> 'ok'.
relay_route_req(AccountId, Props, JObj) ->
Routines = [fun(J) -> custom_channel_vars(AccountId, J) end
,fun(J) ->
,fun(J) ->
case props:get_value(inbound_cnam, Props) of
false -> J;
true -> stepswitch_cnam:lookup(J)
end
end
,fun(J) ->
case props:get_value(ringback_media, Props) of
undefined -> J;
MediaId ->
wh_json:set_value(<<"Ringback-Media">>, MediaId, J)
end
end
,fun(J) ->
case props:get_value(transfer_media, Props) of
undefined -> J;
MediaId ->
wh_json:set_value(<<"Transfer-Media">>, MediaId, J)
end
end
],
wapi_route:publish_req(lists:foldl(fun(F, J) -> F(J) end, JObj, Routines)),
lager:debug("relayed route request").