Skip to content

Commit

Permalink
fixing caller-id/callee-id (2600hz#3031)
Browse files Browse the repository at this point in the history
* add realm in stepswitch requests

* add caller-id/callee-id to kapps_call and fix set_calle_name

* add original_call_direction and alternative names for caller-id

* add more definitions to SPECIAL_CHANNEL_VARS and macro definition

* handle sofia::intercepted in event_stream to update callee

* updated event-filters

* set authorizing-type and do not propagate auto-anwer / retain-cid

* rework get_sip_from/to/request

* formatting
  • Loading branch information
lazedo authored and k-anderson committed Dec 23, 2016
1 parent af9e6e0 commit 9f5d60f
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 66 deletions.
6 changes: 3 additions & 3 deletions applications/crossbar/src/modules/cb_clicktocall.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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">>, <<OutboundNumber/binary, "@", (kz_account:realm(AccountDoc))/binary>>}
,{<<"From-URI">>, <<CalleeNumber/binary, "@", (kz_account:realm(AccountDoc))/binary>>}
,{<<"Request-URI">>, <<OutboundNumber/binary, "@", (kz_account:realm(AccountDoc))/binary>>}
Expand Down Expand Up @@ -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">>}
Expand Down
6 changes: 6 additions & 0 deletions applications/ecallmgr/src/ecallmgr.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
-define(SET_CCV(Key, Value), <<?CHANNEL_VAR_PREFIX, Key/binary, "=", Value/binary>>).
-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}).
Expand All @@ -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">>}
Expand Down Expand Up @@ -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">>}
Expand Down
7 changes: 7 additions & 0 deletions applications/ecallmgr/src/ecallmgr_fs_event_stream.erl
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,20 @@ 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) ->
gproc:send({'p', 'l', ?FS_EVENT_REG_MSG(Node, EventName)}, {'event', [UUID | Props]});
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).

Expand Down
83 changes: 33 additions & 50 deletions applications/ecallmgr/src/ecallmgr_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
<<Number/binary, "@", Realm/binary>>;
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.
Expand All @@ -195,74 +205,46 @@ 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
,<<User/binary, "@", Realm/binary>>
);
<<Number/binary, "@", Realm/binary>>;
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().
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),
<<User/binary, "@", Realm/binary>>.

-spec get_orig_ip(kz_proplist()) -> api_binary().
Expand Down Expand Up @@ -538,6 +520,7 @@ get_fs_kv(Key, Val, _) ->

-spec get_fs_key(ne_binary()) -> binary().
get_fs_key(<<?CHANNEL_VAR_PREFIX, Key/binary>>) -> 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' -> <<?CHANNEL_VAR_PREFIX, Key/binary>>;
Expand Down
13 changes: 6 additions & 7 deletions applications/ecallmgr/src/fs_event_filters.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@
,<<"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">>
,<<"Other-Leg-Caller-ID-Number">>
,<<"Other-Leg-Channel-Name">>
,<<"Other-Leg-Destination-Number">>
,<<"Other-Leg-Direction">>
,<<"Other-Leg-RDNIS">>
,<<"Other-Leg-Unique-ID">>
,<<"Publish-Channel-State">>
,<<"Record-File-Path">>
Expand Down Expand Up @@ -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">>
Expand Down Expand Up @@ -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">>
Expand All @@ -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">>
Expand Down
1 change: 1 addition & 0 deletions applications/stepswitch/src/stepswitch_bridge.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions applications/stepswitch/src/stepswitch_originate.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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">>),
Expand Down
53 changes: 52 additions & 1 deletion core/kazoo_call/src/kapps_call.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down Expand Up @@ -640,6 +642,31 @@ maybe_append_caller_id(CallerId, Suffix) ->
lager:info("appending cid with ~s~n", [BinSuffix]),
<<CallerId/binary, BinSuffix/binary>>.

-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) ->
Expand Down Expand Up @@ -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.

Expand Down
Loading

0 comments on commit 9f5d60f

Please sign in to comment.