diff --git a/applications/crossbar/src/modules/cb_clicktocall.erl b/applications/crossbar/src/modules/cb_clicktocall.erl index 9b87722a510..a8391a6efbe 100644 --- a/applications/crossbar/src/modules/cb_clicktocall.erl +++ b/applications/crossbar/src/modules/cb_clicktocall.erl @@ -451,7 +451,7 @@ build_originate_req(Contact, Context) -> ,{<<"Auto-Answer-Loopback">>, AutoAnswer} ,{<<"Authorizing-ID">>, kz_doc:id(JObj)} ,{<<"Inherit-Codec">>, <<"false">>} - ,{<<"Authorizing-Type">>, <<"device">>} + ,{<<"Authorizing-Type">>, <<"clicktocall">>} ,{<<"Loopback-Request-URI">>, <>} ,{<<"From-URI">>, <>} ,{<<"Request-URI">>, <>} @@ -489,8 +489,8 @@ build_originate_req(Contact, Context) -> ,{<<"Custom-SIP-Headers">>, kz_json:get_value(<<"custom_sip_headers">>, JObj)} ,{<<"Custom-Channel-Vars">>, kz_json:from_list(CCVs)} ,{<<"Export-Custom-Channel-Vars">>, [<<"Account-ID">>, <<"Authorizing-ID">>, <<"Authorizing-Type">> - ,<<"Auto-Answer-Loopback">>, <<"Loopback-Request-URI">> - ,<<"From-URI">>, <<"Request-URI">>, <<"Retain-CID">> + ,<<"Loopback-Request-URI">> + ,<<"From-URI">>, <<"Request-URI">> ] } ,{<<"Simplify-Loopback">>, <<"false">>} diff --git a/applications/ecallmgr/src/ecallmgr.hrl b/applications/ecallmgr/src/ecallmgr.hrl index 22746bc4144..bf9175b8bf2 100644 --- a/applications/ecallmgr/src/ecallmgr.hrl +++ b/applications/ecallmgr/src/ecallmgr.hrl @@ -177,6 +177,7 @@ -define(SET_CCV(Key, Value), <>). -define(GET_CCV_HEADER(Key), <<"variable_sip_h_X-", ?CHANNEL_VAR_PREFIX, Key/binary>>). -define(GET_CUSTOM_HEADER(Key), <<"variable_sip_h_X-", Key/binary>>). +-define(CUSTOM_HEADER(Key), <<"sip_h_X-", Key/binary>>). -define(GET_VAR(Key), <<"variable_", Key/binary>>). -define(CREDS_KEY(Realm, Username), {'authn', Username, Realm}). @@ -198,6 +199,10 @@ ,{<<"Caller-ID-Number">>, <<"effective_caller_id_number">>} ,{<<"Callee-ID-Name">>, <<"effective_callee_id_name">>} ,{<<"Callee-ID-Number">>, <<"effective_callee_id_number">>} + ,{<<"Caller-Callee-ID-Name">>, <<"caller_callee_id_name">>} + ,{<<"Caller-Callee-ID-Number">>, <<"caller_callee_id_number">>} + ,{<<"Caller-Caller-ID-Name">>, <<"caller_caller_id_name">>} + ,{<<"Caller-Caller-ID-Number">>, <<"caller_caller_id_number">>} ,{<<"Progress-Timeout">>, <<"progress_timeout">>} ,{<<"Ignore-Early-Media">>, <<"ignore_early_media">>} @@ -289,6 +294,7 @@ ,{<<"To-URI">>, <<"sip_to_uri">>} ,{<<"Request-URI">>, <<"sip_req_uri">>} ,{<<"Loopback-Request-URI">>, <<"sip_loopback_req_uri">>} + ,{<<"Loopback-Export">>, <<"loopback_export">>} ,{<<"Hold-Media">>, <<"hold_music">>} ,{<<"Diversions">>, <<"sip_h_Diversion">>} ,{<<"Bridge-Execute-On-Answer">>, <<"execute_on_answer">>} diff --git a/applications/ecallmgr/src/ecallmgr_fs_event_stream.erl b/applications/ecallmgr/src/ecallmgr_fs_event_stream.erl index 7a234c0a110..e759907df28 100644 --- a/applications/ecallmgr/src/ecallmgr_fs_event_stream.erl +++ b/applications/ecallmgr/src/ecallmgr_fs_event_stream.erl @@ -367,6 +367,12 @@ process_stream(<<"sofia::intercepted">> = EventName, UUID, Props, Node) -> ecallmgr_fs_command:set(Node, InterceptedBy, Vars); _ -> 'ok' end, + ChannelUUID = props:get_value(<<"Channel-Call-UUID">>, Props), + Updates = props:filter_undefined( + [{<<"Caller-Callee-ID-Name">>, props:get_value(<<"Caller-Callee-ID-Name">>, Props)} + ,{<<"Caller-Callee-ID-Number">>, props:get_value(<<"Caller-Callee-ID-Number">>, Props)} + ]), + ecallmgr_fs_command:set(Node, ChannelUUID, Updates), maybe_send_event(EventName, UUID, Props, Node), process_event(EventName, UUID, Props, Node); process_stream(<<"CHANNEL_HOLD">> = EventName, UUID, Props, Node) -> @@ -374,6 +380,7 @@ process_stream(<<"CHANNEL_HOLD">> = EventName, UUID, Props, Node) -> process_stream(<<"CHANNEL_UNHOLD">> = EventName, UUID, Props, Node) -> gproc:send({'p', 'l', ?FS_EVENT_REG_MSG(Node, EventName)}, {'event', [UUID | Props]}); process_stream(EventName, UUID, EventProps, Node) -> + kz_util:put_callid(UUID), maybe_send_event(EventName, UUID, EventProps, Node), process_event(EventName, UUID, EventProps, Node). diff --git a/applications/ecallmgr/src/ecallmgr_util.erl b/applications/ecallmgr/src/ecallmgr_util.erl index 80548892745..4a46232a593 100644 --- a/applications/ecallmgr/src/ecallmgr_util.erl +++ b/applications/ecallmgr/src/ecallmgr_util.erl @@ -178,15 +178,25 @@ get_interface_properties(Node, Interface) -> %% retrieves the sip address for the 'to' field -spec get_sip_to(kz_proplist()) -> ne_binary(). get_sip_to(Props) -> - get_sip_to(Props, kzd_freeswitch:call_direction(Props)). + get_sip_to(Props, kzd_freeswitch:original_call_direction(Props)). get_sip_to(Props, <<"outbound">>) -> case props:get_value(<<"Channel-Presence-ID">>, Props) of - 'undefined' -> get_sip_request(Props); + 'undefined' -> + Number = props:get_first_defined([<<"Other-Leg-ANI">> + ,<<"Other-Leg-Callee-ID-Number">> + ,<<"variable_sip_to_user">> + ], Props, <<"nouser">>), + Realm = props:get_first_defined([?GET_CCV(<<"Realm">>) + ,<<"variable_sip_to_host">> + ], Props, ?DEFAULT_REALM), + <>; PresenceId -> PresenceId end; get_sip_to(Props, _) -> - case props:get_value(<<"variable_sip_to_uri">>, Props) of + case props:get_first_defined([<<"variable_sip_to_uri">> + ,<<"variable_sip_req_uri">> + ], Props) of 'undefined' -> get_sip_request(Props); ToUri -> ToUri end. @@ -195,47 +205,29 @@ get_sip_to(Props, _) -> -spec get_sip_from(kz_proplist()) -> ne_binary(). -spec get_sip_from(kz_proplist(), api_binary()) -> ne_binary(). get_sip_from(Props) -> - get_sip_from(Props, kzd_freeswitch:call_direction(Props)). + get_sip_from(Props, kzd_freeswitch:original_call_direction(Props)). get_sip_from(Props, <<"outbound">>) -> + Num = props:get_first_defined([<<"Other-Leg-RDNIS">> + ,<<"Other-Leg-Caller-ID-Number">> + ,<<"variable_sip_from_user">> + ,<<"variable_sip_from_uri">> + ], Props, <<"nouser">>), + [Number | _] = binary:split(Num, <<"@">>, ['global']), Realm = props:get_first_defined([?GET_CCV(<<"Realm">>) - ,<<"variable_sip_invite_domain">> ,<<"variable_sip_auth_realm">> - ,<<"variable_sip_to_host">> ], Props, ?DEFAULT_REALM), - User = props:get_first_defined([?GET_CCV(<<"Username">>) - ,<<"Hunt-Callee-ID-Number">> - ,<<"variable_sip_contact_user">> - ,<<"Other-Leg-Callee-ID-Number">> - ,<<"Caller-Callee-ID-Number">> - ,<<"variable_sip_from_user">> - ], Props, <<"nouser">>), - props:get_first_defined([<<"variable_presence_id">> - ,<<"variable_sip_req_uri">> - ,<<"variable_sip_from_uri">> - ] - ,Props - ,<> - ); + <>; get_sip_from(Props, _) -> - Default = <<(props:get_value(<<"variable_sip_from_user">>, Props, <<"nouser">>))/binary + Default = <<(props:get_value(<<"sip_from_user">>, Props, <<"nouser">>))/binary ,"@" ,(props:get_first_defined([?GET_CCV(<<"Realm">>) ,<<"variable_sip_from_host">> ,<<"sip_from_host">> - ] - ,Props - ,?DEFAULT_REALM - ) - )/binary + ], Props, ?DEFAULT_REALM))/binary >>, - props:get_first_defined([<<"Channel-Presence-ID">> - ,<<"variable_presence_id">> - ,<<"variable_sip_from_uri">> - ] - ,Props - ,Default - ). + props:get_first_defined([<<"variable_sip_from_uri">> + ], Props, Default). %% retrieves the sip address for the 'request' field -spec get_sip_request(kz_proplist()) -> ne_binary(). @@ -243,26 +235,16 @@ get_sip_request(Props) -> [User | _] = binary:split( props:get_first_defined( [<<"Hunt-Destination-Number">> - ,<<"Caller-Destination-Number">> - ,<<"variable_sip_to_user">> ,<<"variable_sip_req_uri">> ,<<"variable_sip_loopback_req_uri">> - ,<<"sip_req_uri">> - ,<<"sip_to_user">> + ,<<"Caller-Destination-Number">> + ,<<"variable_sip_to_user">> ], Props, <<"nouser">>), <<"@">>, ['global']), - Realm = lists:last(binary:split( - props:get_first_defined([?GET_CCV(<<"Realm">>) - ,<<"variable_sip_auth_realm">> - ,<<"variable_sip_to_host">> - ,<<"sip_auth_realm">> - ,<<"sip_to_host">> - ,<<"variable_sip_req_host">> - ,<<"sip_req_host">> - ,<<"variable_sip_req_uri">> - ,<<"sip_req_uri">> - ,<<"variable_sip_loopback_req_uri">> - ,<<"sip_loopback_req_uri">> - ], Props, ?DEFAULT_REALM), <<"@">>, ['global'])), + Realm = props:get_first_defined([?GET_CCV(<<"Realm">>) + ,<<"variable_sip_auth_realm">> + ,<<"variable_sip_to_host">> + ,<<"variable_sip_req_host">> + ], Props, ?DEFAULT_REALM), <>. -spec get_orig_ip(kz_proplist()) -> api_binary(). @@ -538,6 +520,7 @@ get_fs_kv(Key, Val, _) -> -spec get_fs_key(ne_binary()) -> binary(). get_fs_key(<>) -> get_fs_key(Key); +get_fs_key(<<"X-", _/binary>>=Key) -> <<"sip_h_", Key/binary>>; get_fs_key(Key) -> case lists:keyfind(Key, 1, ?SPECIAL_CHANNEL_VARS) of 'false' -> <>; diff --git a/applications/ecallmgr/src/fs_event_filters.hrl b/applications/ecallmgr/src/fs_event_filters.hrl index cc6941c6f49..efb59026350 100644 --- a/applications/ecallmgr/src/fs_event_filters.hrl +++ b/applications/ecallmgr/src/fs_event_filters.hrl @@ -44,10 +44,10 @@ ,<<"Event-Subclass">> ,<<"FreeSWITCH-Hostname">> ,<<"Hangup-Cause">> - ,<<"Hunt-Callee-ID-Number">> ,<<"Hunt-Context">> ,<<"Hunt-Destination-Number">> ,<<"Join-Time">> + ,<<"Other-Leg-ANI">> ,<<"Other-Leg-Call-ID">> ,<<"Other-Leg-Callee-ID-Number">> ,<<"Other-Leg-Caller-ID-Name">> @@ -55,6 +55,7 @@ ,<<"Other-Leg-Channel-Name">> ,<<"Other-Leg-Destination-Number">> ,<<"Other-Leg-Direction">> + ,<<"Other-Leg-RDNIS">> ,<<"Other-Leg-Unique-ID">> ,<<"Publish-Channel-State">> ,<<"Record-File-Path">> @@ -88,12 +89,8 @@ ,<<"sip_auth_response">> ,<<"sip_auth_uri">> ,<<"sip_call_id">> - ,<<"sip_loopback_req_uri">> - ,<<"sip_req_host">> - ,<<"sip_req_uri">> ,<<"sip_request_host">> ,<<"sip_to_host">> - ,<<"sip_to_user">> ,<<"sip_user_agent">> ,<<"technology">> ,<<"to_user">> @@ -149,6 +146,10 @@ ,<<"variable_loopback_leg">> ,<<"variable_media_group_id">> ,<<"variable_originate_disposition">> + ,<<"variable_origination_callee_id_name">> + ,<<"variable_origination_callee_id_number">> + ,<<"variable_origination_caller_id_name">> + ,<<"variable_origination_caller_id_number">> ,<<"variable_origination_uuid">> ,<<"variable_other_loopback_leg_uuid">> ,<<"variable_playback_terminator_used">> @@ -163,11 +164,9 @@ ,<<"variable_silence_hits_exhausted">> ,<<"variable_sip_auth_realm">> ,<<"variable_sip_call_id">> - ,<<"variable_sip_contact_user">> ,<<"variable_sip_from_tag">> ,<<"variable_sip_from_uri">> ,<<"variable_sip_from_user">> - ,<<"variable_sip_invite_domain">> ,<<"variable_sip_loopback_req_uri">> ,<<"variable_sip_received_ip">> ,<<"variable_sip_received_port">> diff --git a/applications/stepswitch/src/stepswitch_bridge.erl b/applications/stepswitch/src/stepswitch_bridge.erl index 378824eb57d..c9a0c5aa580 100644 --- a/applications/stepswitch/src/stepswitch_bridge.erl +++ b/applications/stepswitch/src/stepswitch_bridge.erl @@ -367,6 +367,7 @@ build_bridge(#state{endpoints=Endpoints kz_json:set_values(props:filter_undefined([{<<"Ignore-Display-Updates">>, <<"true">>} ,{<<"Account-ID">>, AccountId} ,{<<"From-URI">>, bridge_from_uri(Number, OffnetReq)} + ,{<<"Realm">>, stepswitch_util:default_realm(OffnetReq)} ,{<<"Reseller-ID">>, kz_services:find_reseller_id(AccountId)} ]) ,kapi_offnet_resource:custom_channel_vars(OffnetReq, kz_json:new()) diff --git a/applications/stepswitch/src/stepswitch_originate.erl b/applications/stepswitch/src/stepswitch_originate.erl index 72a03c1d1a0..8264c2bb889 100644 --- a/applications/stepswitch/src/stepswitch_originate.erl +++ b/applications/stepswitch/src/stepswitch_originate.erl @@ -263,6 +263,7 @@ build_originate(#state{endpoints=Endpoints [{<<"Global-Resource">>, <<"true">>} ,{<<"Account-ID">>, AccountId} ,{<<"From-URI">>, originate_from_uri(CIDNum, OffnetReq)} + ,{<<"Realm">>, stepswitch_util:default_realm(OffnetReq)} ,{<<"Reseller-ID">>, kz_services:find_reseller_id(AccountId)} ]), Application = kz_json:get_value(<<"Application-Name">>, OffnetReq, <<"park">>), diff --git a/core/kazoo_call/src/kapps_call.erl b/core/kazoo_call/src/kapps_call.erl index f45acb17345..33d73081500 100644 --- a/core/kazoo_call/src/kapps_call.erl +++ b/core/kazoo_call/src/kapps_call.erl @@ -41,6 +41,8 @@ -export([set_caller_id_number/2, caller_id_number/1]). -export([set_callee_id_name/2, callee_id_name/1]). -export([set_callee_id_number/2, callee_id_number/1]). +-export([set_callee_id/3, callee_id/1]). +-export([set_caller_id/3, caller_id/1]). -export([set_request/2, request/1, request_user/1, request_realm/1]). -export([set_from/2, from/1, from_user/1, from_realm/1]). @@ -640,6 +642,31 @@ maybe_append_caller_id(CallerId, Suffix) -> lager:info("appending cid with ~s~n", [BinSuffix]), <>. +-spec set_caller_id(ne_binary(), ne_binary(), call()) -> call(). +-ifdef(TEST). +set_caller_id(CIDNumber, CIDName, #kapps_call{}=Call) + when is_binary(CIDNumber) + andalso is_binary(CIDName) -> + Call#kapps_call{caller_id_number=CIDNumber + ,callee_id_name=CIDName + }. +-else. +set_caller_id(CIDNumber, CIDName, #kapps_call{}=Call) + when is_binary(CIDNumber) + andalso is_binary(CIDName) -> + JObj = kz_json:from_list([{<<"Caller-ID-Number">>, CIDNumber} + ,{<<"Caller-ID-Name">>, CIDName} + ]), + kapps_call_command:set(JObj, 'undefined', Call), + Call#kapps_call{caller_id_number=CIDNumber + ,callee_id_name=CIDName + }. +-endif. + +-spec caller_id(call()) -> {ne_binary(), ne_binary()}. +caller_id(Call) -> + {caller_id_number(Call), caller_id_name(Call)}. + -spec set_caller_id_name(ne_binary(), call()) -> call(). -ifdef(TEST). set_caller_id_name(CIDName, Call) -> @@ -674,13 +701,37 @@ caller_id_number(#kapps_call{caller_id_number=CIDNumber}) -> 'false' -> CIDNumber end. +-spec set_callee_id(ne_binary(), ne_binary(), call()) -> call(). +-ifdef(TEST). +set_callee_id(CIDNumber, CIDName, #kapps_call{}=Call) + when is_binary(CIDNumber) + andalso is_binary(CIDName) -> + Call#kapps_call{callee_id_number=CIDNumber + ,callee_id_name=CIDName + }. +-else. +set_callee_id(CIDNumber, CIDName, #kapps_call{}=Call) + when is_binary(CIDNumber) + andalso is_binary(CIDName) -> + kapps_call_command:set(kz_json:from_list([{<<"Callee-ID-Number">>, CIDNumber} + ,{<<"Callee-ID-Name">>, CIDName} + ]), 'undefined', Call), + Call#kapps_call{callee_id_number=CIDNumber + ,callee_id_name=CIDName + }. +-endif. + +-spec callee_id(call()) -> {ne_binary(), ne_binary()}. +callee_id(Call) -> + {callee_id_number(Call), callee_id_name(Call)}. + -spec set_callee_id_name(ne_binary(), call()) -> call(). -ifdef(TEST). set_callee_id_name(CIDName, Call) -> Call#kapps_call{callee_id_name=CIDName}. -else. set_callee_id_name(CIDName, #kapps_call{}=Call) when is_binary(CIDName) -> - kapps_call_command:set(kz_json:from_list([{<<"Callee-ID-Number">>, CIDName}]), 'undefined', Call), + kapps_call_command:set(kz_json:from_list([{<<"Callee-ID-Name">>, CIDName}]), 'undefined', Call), Call#kapps_call{callee_id_name=CIDName}. -endif. diff --git a/core/kazoo_documents/src/kzd_freeswitch.erl b/core/kazoo_documents/src/kzd_freeswitch.erl index ddd4466d2dc..06c960c3559 100644 --- a/core/kazoo_documents/src/kzd_freeswitch.erl +++ b/core/kazoo_documents/src/kzd_freeswitch.erl @@ -15,7 +15,7 @@ ,dialed_number/1 ,call_id/1 ,other_leg_call_id/1 - ,call_direction/1 + ,call_direction/1, original_call_direction/1 ,resource_type/1, resource_type/2 ,channel_authorized/1 ,hunt_destination_number/1 @@ -63,7 +63,8 @@ caller_id_name(Props) -> caller_id_name(Props, 'undefined'). caller_id_name(Props, Default) -> - props:get_first_defined([<<"variable_effective_caller_id_name">> + props:get_first_defined([<<"variable_origination_caller_id_name">> + ,<<"variable_effective_caller_id_name">> ,<<"Caller-Caller-ID-Name">> ] ,Props @@ -75,7 +76,8 @@ caller_id_name(Props, Default) -> caller_id_number(Props) -> caller_id_number(Props, 'undefined'). caller_id_number(Props, Default) -> - props:get_first_defined([<<"variable_effective_caller_id_number">> + props:get_first_defined([<<"variable_origination_caller_id_number">> + ,<<"variable_effective_caller_id_number">> ,<<"Caller-Caller-ID-Number">> ] ,Props @@ -87,7 +89,8 @@ caller_id_number(Props, Default) -> callee_id_name(Props) -> callee_id_name(Props, 'undefined'). callee_id_name(Props, Default) -> - props:get_first_defined([<<"variable_effective_callee_id_name">> + props:get_first_defined([<<"variable_origination_callee_id_name">> + ,<<"variable_effective_callee_id_name">> ,<<"Caller-Callee-ID-Name">> ] ,Props @@ -99,7 +102,8 @@ callee_id_name(Props, Default) -> callee_id_number(Props) -> callee_id_number(Props, 'undefined'). callee_id_number(Props, Default) -> - props:get_first_defined([<<"variable_effective_callee_id_number">> + props:get_first_defined([<<"variable_origination_callee_id_number">> + ,<<"variable_effective_callee_id_number">> ,<<"Caller-Callee-ID-Number">> ] ,Props @@ -129,6 +133,10 @@ call_id(Props) -> other_leg_call_id(Props) -> props:get_value(<<"Other-Leg-Unique-ID">>, Props). +-spec original_call_direction(data()) -> api_binary(). +original_call_direction(Props) -> + props:get_value(<<"Call-Direction">>, Props). + -spec call_direction(data()) -> api_binary(). call_direction(Props) -> props:get_first_defined([<<"Application-Logical-Direction">>