diff --git a/applications/acdc/src/acdc_agent_fsm.erl b/applications/acdc/src/acdc_agent_fsm.erl index ee37e3b0b53..b629ed365cb 100644 --- a/applications/acdc/src/acdc_agent_fsm.erl +++ b/applications/acdc/src/acdc_agent_fsm.erl @@ -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), @@ -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 diff --git a/applications/acdc/src/acdc_agent_listener.erl b/applications/acdc/src/acdc_agent_listener.erl index f0dcd7a34cc..70058f519cf 100644 --- a/applications/acdc/src/acdc_agent_listener.erl +++ b/applications/acdc/src/acdc_agent_listener.erl @@ -1032,6 +1032,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} ,{<<"Original-Caller-ID-Name">>, OriginalCIDName} ,{<<"Original-Caller-ID-Number">>, OriginalCIDNumber} ]), @@ -1058,6 +1059,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">>} diff --git a/applications/acdc/src/acdc_queue_fsm.erl b/applications/acdc/src/acdc_queue_fsm.erl index 67f6d03e8a0..f3841d0faf5 100644 --- a/applications/acdc/src/acdc_queue_fsm.erl +++ b/applications/acdc/src/acdc_queue_fsm.erl @@ -293,7 +293,10 @@ ready({'call', From}, Event, State) -> handle_sync_event(Event, From, ready, State); ready('info', {'timeout', _, ?COLLECT_RESP_MESSAGE}, State) -> - {'next_state', 'ready', State}. + {'next_state', 'ready', State}; + +ready('info', Event, State) -> + handle_event(Event, ready, State). %%------------------------------------------------------------------------------ %% @doc @@ -330,6 +333,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}; @@ -447,6 +454,21 @@ 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">>), + + 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 diff --git a/applications/acdc/src/acdc_queue_manager.erl b/applications/acdc/src/acdc_queue_manager.erl index d828721b0f3..bcd327d5415 100644 --- a/applications/acdc/src/acdc_queue_manager.erl +++ b/applications/acdc/src/acdc_queue_manager.erl @@ -963,7 +963,7 @@ sort_agent(A, B) -> %% Otherwise CRs will never be empty -spec remove_unknown_agents(pid(), kz_json:objects()) -> kz_json:objects(). remove_unknown_agents(Mgr, CRs) -> - case gen_listener:call(Mgr, 'current_agents') of + case gen_listener:call(Mgr, 'agents') of [] -> []; Agents -> [CR || CR <- CRs, diff --git a/applications/ecallmgr/src/ecallmgr.hrl b/applications/ecallmgr/src/ecallmgr.hrl index a79adc1d1ba..fd62bb33d7c 100644 --- a/applications/ecallmgr/src/ecallmgr.hrl +++ b/applications/ecallmgr/src/ecallmgr.hrl @@ -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