diff --git a/applications/stepswitch/src/stepswitch_resources.erl b/applications/stepswitch/src/stepswitch_resources.erl index a23713e1823..dbec9ee1900 100644 --- a/applications/stepswitch/src/stepswitch_resources.erl +++ b/applications/stepswitch/src/stepswitch_resources.erl @@ -553,12 +553,14 @@ maybe_resource_to_endpoints(#resrc{id=Id 'false' -> <<"no_classifier">> end, lager:debug("building resource ~s endpoints (classifier ~s)", [Id, _MaybeClassifier]), - CCVUpdates = [{<<"Global-Resource">>, Global} - ,{<<"Resource-ID">>, Id} - ,{<<"E164-Destination">>, Number} - ,{<<"DID-Classifier">>, knm_converters:classify(Number)} - ,{<<"Original-Number">>, kapi_offnet_resource:to_did(OffnetJObj)} - ], + CCVUpdates = props:filter_empty( + [{<<"Global-Resource">>, Global} + ,{<<"Resource-ID">>, Id} + ,{<<"E164-Destination">>, Number} + ,{<<"E164-Origination">>, stepswitch_util:convert_to_e164_format(CallerIdNumber, 'undefined')} + ,{<<"DID-Classifier">>, knm_converters:classify(Number)} + ,{<<"Original-Number">>, kapi_offnet_resource:to_did(OffnetJObj)} + ]), Updates = [{<<"Name">>, Name} ,{<<"Weight">>, Weight} ], diff --git a/applications/stepswitch/src/stepswitch_util.erl b/applications/stepswitch/src/stepswitch_util.erl index c97e3686ca4..cd108c247c4 100644 --- a/applications/stepswitch/src/stepswitch_util.erl +++ b/applications/stepswitch/src/stepswitch_util.erl @@ -20,6 +20,7 @@ -export([route_by/0]). -export([resources_to_endpoints/3]). -export([json_to_template_props/1]). +-export([convert_to_e164_format/2]). -include("stepswitch.hrl"). -include_lib("kazoo_stdlib/include/kazoo_json.hrl"). @@ -56,6 +57,18 @@ get_inbound_destination(JObj) -> {Number, _} = kapps_util:get_destination(JObj, ?APP_NAME, <<"inbound_user_field">>), convert_to_e164_format(Number, ?SS_CONFIG_CAT, <<"assume_inbound_e164">>). +%%------------------------------------------------------------------------------ +%% @doc Convert Number to e164 format if the number is reconcilable else return +%% the value Default +%% @end +%%------------------------------------------------------------------------------ +-spec convert_to_e164_format(kz_term:ne_binary(), Default) -> kz_term:ne_binary() | Default. +convert_to_e164_format(Number, Default) -> + case knm_converters:is_reconcilable(Number) of + 'true' -> knm_converters:normalize(Number); + 'false' -> Default + end. + %%------------------------------------------------------------------------------ %% @doc Convert number to e164 format depending on config values set in system_config db %% @end