Skip to content

Commit

Permalink
WHISTLE-42: fixes for DISA and call status queries
Browse files Browse the repository at this point in the history
  • Loading branch information
k-anderson committed Mar 13, 2012
1 parent 752db5f commit ef4eea4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
4 changes: 2 additions & 2 deletions ecallmgr/src/ecallmgr_fs_node.erl
Expand Up @@ -78,7 +78,7 @@ fs_node(Srv) ->
-spec uuid_exists/2 :: (pid(), ne_binary()) -> boolean().
uuid_exists(Srv, UUID) ->
case catch(gen_server:call(Srv, {uuid_exists, UUID}, ?FS_TIMEOUT)) of
{'EXIT', _} -> false;
{'EXIT', _} -> timeout;
Else -> Else
end.

Expand Down Expand Up @@ -120,7 +120,7 @@ handle_call({uuid_exists, UUID}, From, #state{node=Node}=State) ->
gen_server:reply(From, wh_util:is_true(Result));
_ ->
lager:debug("failed to get result from uuid_exists(~s)", [UUID]),
gen_server:reply(From, false)
gen_server:reply(From, error)
end
end),
{noreply, State};
Expand Down
59 changes: 35 additions & 24 deletions whistle_apps/apps/callflow/src/module/cf_disa.erl
Expand Up @@ -20,62 +20,73 @@
-spec handle/2 :: (wh_json:json_object(), whapps_call:call()) -> 'ok'.
handle(Data, Call) ->
lager:debug("starting DISA handler"),

whapps_call_command:answer(Call),
Pin = wh_json:get_value(<<"pin">>, Data),
Retries = wh_json:get_integer_value(<<"retries">>, Data, 3),

case try_collect_pin(Call, Pin, Retries) of
allow -> allow_dial(Call, Retries);
_ ->
whapps_call_command:hangup(Call),
cf_exe:stop(Call)
_ -> cf_exe:stop(Call)
end.

%%--------------------------------------------------------------------
%% @private
%% @doc
%% @end
%%--------------------------------------------------------------------
-spec try_collect_pin/3 :: (whapps_call:call(), binary(), non_neg_integer()) -> allow | fail.
try_collect_pin(_Call, <<>>, _) ->
lager:debug("no pin set on DISA object, permitting"),
allow;
try_collect_pin(_Call, _, 0) ->
lager:debug("retries for DISA pin exceeded"),
fail;
try_collect_pin(Call, Pin, Retries) ->
play_enter_pin(Call),
case whapps_call_command:collect_digits(6, Call) of
Prompt = <<"local_stream://en/us/callie/ivr/ivr-please_enter_pin_followed_by_pound.wav">>,
case whapps_call_command:b_play_and_collect_digits(<<"1">>, <<"6">>, Prompt, Call) of
{ok, Pin} ->
lager:debug("pin matches, permitting"),
allow;
{ok, _Digits} ->
lager:debug("caller entered ~s for pin", [_Digits]),
play_invalid_pin(Call),
try_collect_pin(Call, Pin, Retries-1)
whapps_call_command:b_play(<<"local_stream://en/us/callie/ivr/ivr-pin_or_extension_is-invalid.wav">>, Call),
try_collect_pin(Call, Pin, Retries - 1)
end.

%%--------------------------------------------------------------------
%% @private
%% @doc
%% @end
%%--------------------------------------------------------------------
-spec allow_dial/2 :: (whapps_call:call(), non_neg_integer()) -> ok.
allow_dial(Call, 0) ->
lager:debug("retries exceeded for finding a callflow"),
cf_exe:continue(Call);
allow_dial(Call, Retries) ->
_ = play_dialtone(Call),
{ok, Digits} = whapps_call_command:collect_digits(15, Call),
lager:debug("caller is trying to call ~s", [Digits]),

case cf_util:lookup_callflow(Digits, whapps_call:account_id(Call)) of
Number = wnm_util:to_e164(Digits),
lager:debug("caller is trying to call ~s", [Number]),
case cf_util:lookup_callflow(Number, whapps_call:account_id(Call)) of
{ok, Flow, _} ->
lager:debug("callflow ~s satisfies request", [wh_json:get_value(<<"_id">>, Flow)]),
Updates = [fun(C) -> whapps_call:set_request(list_to_binary([Number, "@", whapps_call:request_realm(C)]), C) end
,fun(C) -> whapps_call:set_to(list_to_binary([Number, "@", whapps_call:to_realm(C)]), C) end
],
{ok, C} = cf_exe:get_call(Call),
cf_exe:set_call(whapps_call:exec(Updates, C)),
cf_exe:branch(wh_json:get_value(<<"flow">>, Flow), Call);
_ ->
lager:debug("failed to find a callflow to satisfy ~s", [Digits]),
_ = play_invalid_ext(Call),
allow_dial(Call, Retries-1)
lager:debug("failed to find a callflow to satisfy ~s", [Number]),
whapps_call_command:b_play(<<"local_stream://en/us/callie/ivr/ivr-you_have_dialed_an_invalid_extension.wav">>, Call),
allow_dial(Call, Retries - 1)
end.

play_enter_pin(Call) ->
whapps_call_command:b_play(<<"local_stream://en/us/callie/ivr/ivr-please_enter_pin_followed_by_pound.wav">>, Call).

play_invalid_pin(Call) ->
whapps_call_command:b_play(<<"local_stream://en/us/callie/ivr/ivr-pin_or_extension_is-invalid.wav">>, Call).

play_invalid_ext(Call) ->
whapps_call_command:b_play(<<"local_stream://en/us/callie/ivr/ivr-you_have_dialed_an_invalid_extension.wav">>, Call).

%%--------------------------------------------------------------------
%% @private
%% @doc
%% @end
%%--------------------------------------------------------------------
-spec play_dialtone/1 :: (whapps_call:call()) -> ok.
play_dialtone(Call) ->
Tone = wh_json:from_list([{<<"Frequencies">>, [<<"350">>, <<"440">>]}
,{<<"Duration-ON">>, <<"10000">>}
Expand Down

0 comments on commit ef4eea4

Please sign in to comment.