Skip to content

Commit

Permalink
Various and sundry fixes (2600hz#6046)
Browse files Browse the repository at this point in the history
- add anti-action for use in `dialplan condition`
- allows correlation on the inbound leg
- fixes connecting leg
- verifies node split in kz_dist
- conference events bind fix
- add callflow modules for composition
  - answer, wait_for_noop, wait_for_hangup

quick doc
  • Loading branch information
lazedo authored and jamesaimonetti committed Sep 23, 2019
1 parent a4ad34e commit fa51ab5
Show file tree
Hide file tree
Showing 31 changed files with 370 additions and 46 deletions.
15 changes: 15 additions & 0 deletions applications/callflow/doc/answer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Answer

### About Answer

Attempts to answer the call; will block callflow execution until the call is answered (`CHANNEL_ANSWER` received).

#### Schema

Validator for the answer callflow data object



Key | Description | Type | Default | Required | Support Level
--- | ----------- | ---- | ------- | -------- | -------------
`skip_module` | When set to true this callflow action is skipped, advancing to the wildcard branch (if any) | `boolean()` | | `false` |
15 changes: 15 additions & 0 deletions applications/callflow/doc/noop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Noop

### About Noop

A NO-op (no operator) will send a `noop` into the call's command queue. When executed, it will generate a no-op event. This callflow action will block until the noop has been received (effectively telling you when the command queue is empty).

#### Schema

Validator for the noop callflow data object



Key | Description | Type | Default | Required | Support Level
--- | ----------- | ---- | ------- | -------- | -------------
`skip_module` | When set to true this callflow action is skipped, advancing to the wildcard branch (if any) | `boolean()` | | `false` |
16 changes: 16 additions & 0 deletions applications/callflow/doc/ref/answer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Answer

### About Answer

#### Schema

Validator for the answer callflow data object



Key | Description | Type | Default | Required | Support Level
--- | ----------- | ---- | ------- | -------- | -------------
`skip_module` | When set to true this callflow action is skipped, advancing to the wildcard branch (if any) | `boolean()` | | `false` |



16 changes: 16 additions & 0 deletions applications/callflow/doc/ref/noop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Noop

### About Noop

#### Schema

Validator for the noop callflow data object



Key | Description | Type | Default | Required | Support Level
--- | ----------- | ---- | ------- | -------- | -------------
`skip_module` | When set to true this callflow action is skipped, advancing to the wildcard branch (if any) | `boolean()` | | `false` |



16 changes: 16 additions & 0 deletions applications/callflow/doc/ref/wait_for_hangup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Wait For Hangup

### About Wait For Hangup

#### Schema

Validator for the wait_for_hangup callflow data object



Key | Description | Type | Default | Required | Support Level
--- | ----------- | ---- | ------- | -------- | -------------
`skip_module` | When set to true this callflow action is skipped, advancing to the wildcard branch (if any) | `boolean()` | | `false` |



15 changes: 15 additions & 0 deletions applications/callflow/doc/wait_for_hangup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Wait For Hangup

### About Wait For Hangup

Blocks callflow execution until the call is hungup (`CHANNEL_HANGUP` event received).

#### Schema

Validator for the wait_for_hangup callflow data object



Key | Description | Type | Default | Required | Support Level
--- | ----------- | ---- | ------- | -------- | -------------
`skip_module` | When set to true this callflow action is skipped, advancing to the wildcard branch (if any) | `boolean()` | | `false` |
49 changes: 27 additions & 22 deletions applications/callflow/src/cf_exe.erl
Original file line number Diff line number Diff line change
Expand Up @@ -891,48 +891,48 @@ handle_channel_destroyed(Self, Notify, JObj) ->
channel_destroyed(Self, kz_json:from_list(Prop)),
relay_message(Notify, JObj).

-spec handle_channel_transfer(kapps_call:call(), kz_json:object()) -> 'ok'.
handle_channel_transfer(Call, JObj) ->
-spec handle_channel_transfer(kapps_call:call(), kz_call_event:doc()) -> 'ok'.
handle_channel_transfer(Call, CallEvent) ->
OrgFetchId = kapps_call:custom_channel_var(<<"Fetch-ID">>, Call),
NewFetchId = kz_json:get_value([<<"Custom-Channel-Vars">>, <<"Fetch-ID">>], JObj),
NewFetchId = kz_call_event:custom_channel_var(CallEvent, <<"Fetch-ID">>),
case OrgFetchId =:= NewFetchId of
'true' -> transfer(Call);
'false' -> 'ok'
end.

-spec handle_channel_replaced(kapps_call:call(), kz_json:object(), kz_term:pids()) -> 'ok'.
handle_channel_replaced(Call, JObj, Notify) ->
-spec handle_channel_replaced(kapps_call:call(), kz_call_event:doc(), kz_term:pids()) -> 'ok'.
handle_channel_replaced(Call, CallEvent, Notify) ->
OrgFetchId = kapps_call:custom_channel_var(<<"Fetch-ID">>, Call),
NewFetchId = kz_json:get_value([<<"Custom-Channel-Vars">>, <<"Fetch-ID">>], JObj),
NewFetchId = kz_call_event:custom_channel_var(CallEvent, <<"Fetch-ID">>),
case OrgFetchId =:= NewFetchId of
'true' ->
ReplacedBy = kz_json:get_value(<<"Replaced-By">>, JObj),
ReplacedBy = kz_call_event:replaced_by(CallEvent),
callid_update(ReplacedBy, Call),
relay_message(Notify, JObj);
relay_message(Notify, CallEvent);
'false' -> 'ok'
end.

-spec handle_channel_direct(kapps_call:call(), kz_json:object(), kz_term:pids()) -> 'ok'.
handle_channel_direct(Call, JObj, Notify) ->
-spec handle_channel_direct(kapps_call:call(), kz_call_event:doc(), kz_term:pids()) -> 'ok'.
handle_channel_direct(Call, CallEvent, Notify) ->
OrgFetchId = kapps_call:custom_channel_var(<<"Fetch-ID">>, Call),
NewFetchId = kz_json:get_value([<<"Custom-Channel-Vars">>, <<"Fetch-ID">>], JObj),
NewFetchId = kz_call_event:custom_channel_var(CallEvent, <<"Fetch-ID">>),
case OrgFetchId =:= NewFetchId of
'true' ->
ReplacedBy = kz_json:get_value(<<"Connecting-Leg-A-UUID">>, JObj),
ReplacedBy = kz_call_event:connecting_b_leg_id(CallEvent),
callid_update(ReplacedBy, Call),
relay_message(Notify, JObj);
relay_message(Notify, CallEvent);
'false' -> 'ok'
end.

-spec handle_channel_bridged(pid(), kz_term:pids(), kz_json:object(), kapps_call:call()) -> 'ok'.
handle_channel_bridged(Self, Notify, JObj, Call) ->
-spec handle_channel_bridged(pid(), kz_term:pids(), kz_call_event:doc(), kapps_call:call()) -> 'ok'.
handle_channel_bridged(Self, Notify, CallEvent, Call) ->
gen_server:cast(Self, {'set_call', kapps_call:set_call_bridged('true', Call)}),
relay_message(Notify, JObj).
relay_message(Notify, CallEvent).

-spec handle_usurp(pid(), kapps_call:call(), kz_json:object()) -> 'ok'.
handle_usurp(Self, Call, JObj) ->
-spec handle_usurp(pid(), kapps_call:call(), kz_call_event:doc()) -> 'ok'.
handle_usurp(Self, Call, CallEvent) ->
OrgFetchId = kapps_call:custom_channel_var(<<"Fetch-ID">>, Call),
NewFetchId = kz_json:get_value(<<"Fetch-ID">>, JObj),
NewFetchId = kz_call_event:custom_channel_var(CallEvent, <<"Fetch-ID">>),
case OrgFetchId =:= NewFetchId of
'false' -> control_usurped(Self);
'true' -> 'ok'
Expand Down Expand Up @@ -992,13 +992,18 @@ send_command(Command, AMQPWorker, ControlQ, CallId) ->

-spec handle_channel_pivoted(kz_types:server_ref(), kz_term:api_pid_ref(), kz_call_event:doc(), kapps_call:call()) -> 'ok'.
handle_channel_pivoted(Self, PidRef, JObj, Call) ->
case kz_json:get_ne_binary_value(<<"Application-Data">>, JObj) of
case kz_json:get_value(<<"Application-Data">>, JObj) of
'undefined' -> lager:info("no app data to pivot");
FlowBin ->
<<FlowBin/binary>> ->
_ = maybe_stop_action(PidRef),
lager:debug("pivoting to ~s", [FlowBin]),
cf_util:flush_control_queue(Call),
continue_with_flow(kz_json:decode(FlowBin), Self)
continue_with_flow(kz_json:decode(FlowBin), Self);
FlowJObj ->
_ = maybe_stop_action(PidRef),
lager:debug("pivoting to ~p", [FlowJObj]),
cf_util:flush_control_queue(Call),
continue_with_flow(FlowJObj, Self)
end.

-spec maybe_stop_action(kz_term:api_pid_ref()) -> 'ok'.
Expand Down
26 changes: 26 additions & 0 deletions applications/callflow/src/module/cf_answer.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
%%%-----------------------------------------------------------------------------
%%% @copyright (C) 2012-2019, 2600Hz
%%% @doc Answers to the call
%%%
%%% "data":{}
%%%
%%%
%%% This Source Code Form is subject to the terms of the Mozilla Public
%%% License, v. 2.0. If a copy of the MPL was not distributed with this
%%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%%
%%% @end
%%%-----------------------------------------------------------------------------
-module(cf_answer).

-behaviour(gen_cf_action).

-export([handle/2]).

-include("callflow.hrl").

-spec handle(kz_json:object(), kapps_call:call()) -> 'ok'.
handle(_Data, Call) ->
lager:info("answering call"),
_ = kapps_call_command:b_answer(Call),
cf_exe:continue(Call).
33 changes: 33 additions & 0 deletions applications/callflow/src/module/cf_noop.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
%%%-----------------------------------------------------------------------------
%%% @copyright (C) 2012-2019, 2600Hz
%%% @doc sends a noop
%%%
%%% "data":{}
%%%
%%%
%%% This Source Code Form is subject to the terms of the Mozilla Public
%%% License, v. 2.0. If a copy of the MPL was not distributed with this
%%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%%
%%% @end
%%%-----------------------------------------------------------------------------
-module(cf_noop).

-behaviour(gen_cf_action).

-export([handle/2]).

-include("callflow.hrl").

-spec handle(kz_json:object(), kapps_call:call()) -> 'ok'.
handle(_Data, Call) ->
NoopId = kapps_call_command:noop(Call),
lager:info("noop ~s sent", [NoopId]),
case kapps_call_command:wait_for_noop(Call, NoopId) of
{'error', _E} ->
lager:info("noop failed to be received: ~p", [_E]),
cf_exe:stop(Call);
{'ok', _} ->
lager:info("noop received"),
cf_exe:continue(Call)
end.
26 changes: 26 additions & 0 deletions applications/callflow/src/module/cf_wait_for_hangup.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
%%%-----------------------------------------------------------------------------
%%% @copyright (C) 2012-2019, 2600Hz
%%% @doc waits for hangup
%%%
%%% "data":{}
%%%
%%%
%%% This Source Code Form is subject to the terms of the Mozilla Public
%%% License, v. 2.0. If a copy of the MPL was not distributed with this
%%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%%
%%% @end
%%%-----------------------------------------------------------------------------
-module(cf_wait_for_hangup).

-behaviour(gen_cf_action).

-export([handle/2]).

-include("callflow.hrl").

-spec handle(kz_json:object(), kapps_call:call()) -> 'ok'.
handle(_Data, Call) ->
lager:info("waiting for hangup"),
{'ok', 'channel_hungup'} = kapps_call_command:wait_for_hangup(),
cf_exe:stop(Call).
30 changes: 30 additions & 0 deletions applications/crossbar/priv/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,16 @@
},
"type": "object"
},
"callflows.answer": {
"description": "Validator for the answer callflow data object",
"properties": {
"skip_module": {
"description": "When set to true this callflow action is skipped, advancing to the wildcard branch (if any)",
"type": "boolean"
}
},
"type": "object"
},
"callflows.audio_macro": {
"description": "Validator for the audio_macro callflow data object",
"properties": {
Expand Down Expand Up @@ -2887,6 +2897,16 @@
],
"type": "object"
},
"callflows.noop": {
"description": "Validator for the noop callflow data object",
"properties": {
"skip_module": {
"description": "When set to true this callflow action is skipped, advancing to the wildcard branch (if any)",
"type": "boolean"
}
},
"type": "object"
},
"callflows.notification": {
"description": "Validator for the 'notification' callflow's data object",
"properties": {
Expand Down Expand Up @@ -4260,6 +4280,16 @@
},
"type": "object"
},
"callflows.wait_for_hangup": {
"description": "Validator for the wait_for_hangup callflow data object",
"properties": {
"skip_module": {
"description": "When set to true this callflow action is skipped, advancing to the wildcard branch (if any)",
"type": "boolean"
}
},
"type": "object"
},
"callflows.webhook": {
"description": "Validator for the webhook callflow data object",
"properties": {
Expand Down
12 changes: 12 additions & 0 deletions applications/crossbar/priv/couchdb/schemas/callflows.answer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"_id": "callflows.answer",
"description": "Validator for the answer callflow data object",
"properties": {
"skip_module": {
"description": "When set to true this callflow action is skipped, advancing to the wildcard branch (if any)",
"type": "boolean"
}
},
"type": "object"
}
12 changes: 12 additions & 0 deletions applications/crossbar/priv/couchdb/schemas/callflows.noop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"_id": "callflows.noop",
"description": "Validator for the noop callflow data object",
"properties": {
"skip_module": {
"description": "When set to true this callflow action is skipped, advancing to the wildcard branch (if any)",
"type": "boolean"
}
},
"type": "object"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"_id": "callflows.wait_for_hangup",
"description": "Validator for the wait_for_hangup callflow data object",
"properties": {
"skip_module": {
"description": "When set to true this callflow action is skipped, advancing to the wildcard branch (if any)",
"type": "boolean"
}
},
"type": "object"
}
Loading

0 comments on commit fa51ab5

Please sign in to comment.