Skip to content

Commit

Permalink
Merge pull request 2600hz#1296 from 2600hz/KAZOO-4179
Browse files Browse the repository at this point in the history
KAZOO-4179: return ordered list of entities appearing in the SIP dialog
  • Loading branch information
k-anderson committed Sep 11, 2015
2 parents 662655c + b257f8c commit da8dceb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
8 changes: 5 additions & 3 deletions applications/call_inspector/src/ci_lookup_req.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ handle_req(JObj, _Props) ->
send_response(Props, Q, MessageId) ->
JObj = wh_json:from_list(
[{<<"Chunks">>, chunks_as_json(Props)}
,{<<"Dialog-Entities">>, ci_chunk:get_dialog_entities(get_chunks(Props))}
,{<<"Analysis">>, analysis_as_json(Props)}
,{<<"Msg-ID">>, MessageId}
| wh_api:default_headers(?APP_NAME, ?APP_VERSION)
]
),
wapi_inspector:publish_lookup_resp(Q, JObj).

get_chunks(Props) ->
props:get_value('chunks', Props, []).

-spec chunks_as_json(ci_datastore:data()) -> wh_json:objects().
chunks_as_json(Props) ->
[ci_chunk:to_json(Chunk)
|| Chunk <- props:get_value('chunks', Props, [])
].
[ci_chunk:to_json(Chunk) || Chunk <- get_chunks(Props)].

-spec analysis_as_json(ci_datastore:data()) -> wh_json:objects().
analysis_as_json(Props) ->
Expand Down
27 changes: 27 additions & 0 deletions applications/call_inspector/src/parsers/ci_chunk.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
-export([sort_by_timestamp/1
,reorder_dialog/1
]).
-export([get_dialog_entities/1]).

-record(ci_chunk, {call_id :: ne_binary()
,data = [] :: ne_binaries()
Expand Down Expand Up @@ -169,6 +170,32 @@ dst(Bin = <<_/binary>>) ->
is_chunk(#ci_chunk{}) -> 'true';
is_chunk(_) -> 'false'.

%%--------------------------------------------------------------------
%% @public
%% @doc
%% Gives back an ordered list of entities participating in the SIP dialog.
%%
%% `Chunks` needs to be ordered (e.g. using reorder_dialog/1).
%% @end
%%--------------------------------------------------------------------
-spec get_dialog_entities([chunk()]) -> ne_binaries().
get_dialog_entities(Chunks) ->
get_dialog_entities(Chunks, []).
get_dialog_entities([], Acc) ->
lists:reverse(Acc);
get_dialog_entities([Chunk|Chunks], Acc) ->
Src = src(Chunk),
Dst = dst(Chunk),
Acc1 = case lists:member(Src, Acc) of
'true' -> Acc;
'false' -> [Src|Acc]
end,
Acc2 = case lists:member(Dst, Acc1) of
'true' -> Acc1;
'false' -> [Dst|Acc1]
end,
get_dialog_entities(Chunks, Acc2).

-spec sort_by_timestamp([chunk()]) -> [chunk()].
sort_by_timestamp(Chunks) ->
lists:keysort(#ci_chunk.ref_timestamp, Chunks).
Expand Down
2 changes: 1 addition & 1 deletion applications/call_inspector/src/wapi_inspector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
-define(LOOKUP_REQ_TYPES, []).

-define(LOOKUP_RESP_HEADERS, [<<"Chunks">>]).
-define(OPTIONAL_LOOKUP_RESP_HEADERS, [<<"Chunks">>, <<"Analysis">>]).
-define(OPTIONAL_LOOKUP_RESP_HEADERS, [<<"Chunks">>, <<"Analysis">>, <<"Dialog-Entities">>]).
-define(LOOKUP_RESP_VALUES, [{<<"Event-Category">>, <<"call_inspector">>}
,{<<"Event-Name">>, <<"lookup_resp">>}
]).
Expand Down
1 change: 1 addition & 0 deletions applications/crossbar/src/modules/cb_call_inspector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ inspect_call_id(CallId, Context) ->
Response = wh_json:from_list(
[{<<"call-id">>, CallId}
,{<<"messages">>, Chunks}
,{<<"dialog_entities">>, wh_json:get_value(<<"Dialog-Entities">>, JObj, [])}
,{<<"analysis">>, Analysis}
]
),
Expand Down

0 comments on commit da8dceb

Please sign in to comment.