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

acdc fix pickup and exit by dtmf #6745

Open
wants to merge 3 commits into
base: 4.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 26 additions & 0 deletions applications/acdc/src/acdc_agent_fsm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ call_event(ServerRef, <<"error">>, <<"dialplan">>, JObj) ->
gen_statem:cast(ServerRef, {'dialplan_error', kz_json:get_value(<<"Application-Name">>, Req)});
call_event(ServerRef, <<"call_event">>, <<"CHANNEL_REPLACED">>, JObj) ->
gen_statem:cast(ServerRef, {'channel_replaced', JObj});
call_event(ServerRef, <<"call_event">>, <<"CHANNEL_INTERCEPTED">>, JObj) ->
gen_statem:cast(ServerRef, {'channel_intercepted', JObj});
call_event(ServerRef, <<"call_event">>, <<"CHANNEL_TRANSFEREE">>, JObj) ->
Transferor = kz_call_event:other_leg_call_id(JObj),
Transferee = kz_call_event:call_id(JObj),
Expand Down Expand Up @@ -896,6 +898,30 @@ ringing('cast', {'leg_destroyed', _CallId}, State) ->
{'next_state', 'ringing', State};
ringing('cast', {'usurp_control', _CallId}, State) ->
{'next_state', 'ringing', State};

ringing('cast', {'channel_intercepted', JObj}, #state{agent_listener=AgentListener
,account_id=AccountId
,agent_id=AgentId
,member_call_id=CallId
,queue_notifications=Ns
,member_call_queue_id=QueueId
}=State) ->
ACallId = kz_json:get_value(<<"Other-Leg-Call-ID">>, JObj),
lager:debug("channel_intercepted: ~s", [ACallId]),

acdc_agent_listener:hangup_call(AgentListener),
acdc_util:unbind_from_call_events(ACallId),
lager:debug("stopping ringing agent in order to intercept"),
acdc_stats:call_missed(AccountId, QueueId, AgentId, CallId, <<"call intercepted">>),

acdc_agent_listener:presence_update(AgentListener, ?PRESENCE_GREEN),

apply_state_updates(clear_call(State, 'ready')),

maybe_notify(Ns, ?NOTIFY_PICKUP, State),

{'next_state', 'wrapup', State#state{wrapup_ref=hangup_call(State, 'agent')}};

ringing('cast', Evt, State) ->
handle_event(Evt, 'ringing', State);
ringing({'call', From}, 'status', #state{member_call_id=MemberCallId
Expand Down
3 changes: 3 additions & 0 deletions applications/acdc/src/acdc_agent_listener.erl
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ handle_cast({'member_connect_accepted', ACallId}, #state{msg_queue_id=AmqpQueue
,agent_call_ids=ACallIds
}=State) ->
lager:debug("member bridged to agent!"),
_ = kapps_call_command:b_flush(Call),
maybe_start_recording(Call, ShouldRecord, RecordingUrl),

ACallIds1 = filter_agent_calls(ACallIds, ACallId),
Expand Down Expand Up @@ -1032,6 +1033,7 @@ maybe_connect_to_agent(MyQ, EPs, Call, Timeout, AgentId, _CdrUrl) ->
,{<<"Retain-CID">>, <<"true">>}
,{<<"Agent-ID">>, AgentId}
,{<<"Member-Call-ID">>, MCallId}
,{<<"originate_signal_bond">>, MCallId}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't speak to the ACDc-specific portions, but this name should match the format of other keys: Originate-Signal-Bond in this case.

,{<<"Original-Caller-ID-Name">>, OriginalCIDName}
,{<<"Original-Caller-ID-Number">>, OriginalCIDNumber}
]),
Expand All @@ -1058,6 +1060,7 @@ maybe_connect_to_agent(MyQ, EPs, Call, Timeout, AgentId, _CdrUrl) ->
,<<"Retain-CID">>
,<<"Authorizing-ID">>
,<<"Authorizing-Type">>
,<<"originate_signal_bond">>
]}
,{<<"Account-ID">>, AcctId}
,{<<"Resource-Type">>, <<"originate">>}
Expand Down
20 changes: 20 additions & 0 deletions applications/acdc/src/acdc_queue_fsm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ connect_req('cast', {'accepted', AcceptJObj}=Accept, #state{member_call=Call}=St
lager:debug("received (and ignoring) acceptance payload"),
{'next_state', 'connect_req', State}
end;

connect_req('cast', {'channel_bridged', _BridgeJObj}=Accept, State) ->
connecting('cast', Accept, State);

connect_req('cast', {'retry', _RetryJObj}, State) ->
lager:debug("recv retry response before win sent"),
{'next_state', 'connect_req', State};
Expand Down Expand Up @@ -447,6 +451,22 @@ connecting('cast', {'accepted', AcceptJObj}, #state{listener_proc=ListenerSrv
{'next_state', 'connecting', State}
end;

connecting('cast', {'channel_bridged', _BridgeJObj}, #state{listener_proc=ListenerSrv
,member_call=Call
,agent_ring_timer_ref=AgentRef
,collect_ref=CollectRef
}=State) ->
lager:debug("recv channel_bridged from agent"),
CallId = kapps_call:call_id(Call),
webseq:evt(?WSD_ID, self(), CallId, <<"member call - agent acceptance">>),

_ = kapps_call_command:b_flush(Call),
maybe_stop_timer(CollectRef),
maybe_stop_timer(AgentRef),

acdc_queue_listener:finish_member_call(ListenerSrv),
{'next_state', 'ready', clear_member_call(State), 'hibernate'};

connecting('cast', {'retry', RetryJObj}, #state{agent_ring_timer_ref=AgentRef
,collect_ref=CollectRef
,member_call_winner=Winner
Expand Down
26 changes: 23 additions & 3 deletions applications/acdc/src/acdc_queue_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,38 @@ start_queue_call(JObj, Props, Call) ->
lager:debug("answering call"),
kapps_call_command:answer_now(Call),

case kz_media_util:media_path(props:get_value('moh', Props)
Media = case kz_media_util:media_path(props:get_value('moh', Props)
,kapps_call:account_id(Call)
)
of
'undefined' ->
lager:debug("using default moh"),
kapps_call_command:hold(Call);
[<<"${hold_music}">>];
MOH ->
lager:debug("using MOH ~s (~p)", [MOH, Props]),
kapps_call_command:hold(MOH, Call)
[MOH]
end,

{'ok', QueueJObj} = kz_datamgr:open_cache_doc(kapps_call:account_db(Call), QueueId),
NoopId = kapps_call_command:noop_id(),
Commands = [kz_json:from_list([{<<"Application-Name">>, <<"noop">>}
,{<<"Call-ID">>, kapps_call:call_id(Call)}
,{<<"Msg-ID">>, NoopId}
])
,kz_json:from_list([{<<"Application-Name">>, <<"play">>}
,{<<"Call-ID">>, kapps_call:call_id(Call)}
,{<<"Media-Name">>, Media}
,{<<"Insert-At">>, <<"now">>}
,{<<"Endless-Playback">>, <<"true">>}
,{<<"Terminators">>, [kz_json:get_value(<<"caller_exit_key">>, QueueJObj, <<"#">>)]}
])
],
Command = [{<<"Application-Name">>, <<"queue">>}
,{<<"Commands">>, Commands}
],

kapps_call_command:send_command(Command, Call),

JObj2 = kz_json:set_value([<<"Call">>, <<"Custom-Channel-Vars">>, <<"Queue-ID">>], QueueId, JObj),

_ = kapps_call_command:set('undefined'
Expand Down
1 change: 1 addition & 0 deletions applications/acdc/src/cf_acdc_member.erl
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ cancel_member_call(Call, Reason) ->
kapi_acdc_queue:publish_member_call_cancel(Req).

stop_hold_music(Call) ->
_ = kapps_call_command:b_flush(Call),
Cmd = [{<<"Application-Name">>, <<"play">>}
,{<<"Call-ID">>, kapps_call:call_id(Call)}
,{<<"Media-Name">>, <<"silence_stream://50">>}
Expand Down
1 change: 1 addition & 0 deletions applications/ecallmgr/src/ecallmgr.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@
,{<<"sip_rh_X-Redirect-Server">>, <<"sip_rh_X-Redirect-Server">>}
,{<<"tts_engine">>, <<"tts_engine">>}
,{<<"tts_voice">>, <<"tts_voice">>}
,{<<"originate_signal_bond">>, <<"originate_signal_bond">>}
]).

%% [{FreeSWITCH-App-Name, Kazoo-App-Name}] Dialplan-related
Expand Down