Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PISTON-1267 add a handler for action 'move' to channel's crossbar API #6728

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion applications/crossbar/doc/channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,25 @@ curl -v -X POST \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/channels/{UUID}
```

Available `action` values are `transfer`, `hangup`, `break`, `callflow`, and `intercept`.
Available `action` values are `transfer`, `hangup`, `break`, `callflow`, `move` and `intercept`.

### Move

```shell
curl -v -x POST \
-H "Content-Type: application/json" \
-H "X-Auth-Token: {AUTH_TOKEN}" \
-d '{"data": {"action": "move", "owner_id": "2e04e3205b36b6291f854995e80985b0", "device_id": "c27b0a86c5e7b0f2a5999967fd8bbf09", "auto_answer": true, "can_call_self": true, "dial_strategy": "simultaneous"}}' \
http://{SERVER}:8000/v2/accounts/{ACCOUNT_ID}/channels/{UUID}
```

Key | Description | Type | Default | Required
--- | ----------- | ---- | ------- | --------
`auto_answer` | Whether to auto-answer the new leg | `boolean()` | `false` | `false`
`can_call_self` | Can intercept devices of the same targeted user | `boolean()` | `true` | `false`
`device_id` | Move the call to a specific device | `string()` | | `false`
`dial_strategy` | How to ring the endpoints, if multiple | `string()` | `simultaneous` | `false`
`owner_id` | User ID to use for finding endpoints | `string()` | | `false`

### Transfer

Expand Down
25 changes: 25 additions & 0 deletions applications/crossbar/src/modules/cb_channels.erl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ maybe_execute_command(Context, CallId, <<"callflow">>) ->
maybe_callflow(Context, CallId);
maybe_execute_command(Context, CallId, <<"intercept">>) ->
maybe_intercept(Context, CallId);
maybe_execute_command(Context, CallId, <<"move">>) ->
maybe_move(Context, CallId);
maybe_execute_command(Context, _CallId, _Command) ->
lager:debug("unknown command: ~s", [_Command]),
crossbar_util:response_invalid_data(cb_context:doc(Context), Context).
Expand Down Expand Up @@ -543,6 +545,29 @@ maybe_intercept(Context, CallId, TargetType, TargetId) ->
kz_amqp_worker:cast(API, fun kapi_metaflow:publish_action/1),
crossbar_util:response_202(<<"intercept initiated">>, Context).

%%------------------------------------------------------------------------------
%% @doc API action for moving a channel.
%% Kazoo dials `device_id'(or all devices for `owner_id') and if a device answers the call
%% it will be bridged with a remote channel instead of the original.
%% All params are optional.
%% @end
%%------------------------------------------------------------------------------
-spec maybe_move(cb_context:context(), kz_term:ne_binary()) -> cb_context:context().
maybe_move(Context, CallId) ->
API = [{<<"Call-ID">>, CallId}
,{<<"Action">>, <<"move">>}
,{<<"Data">>, kz_json:from_list([{<<"auto_answer">>, cb_context:req_value(Context, <<"auto_answer">>, 'false')}
,{<<"can_call_self">>, cb_context:req_value(Context, <<"can_call_self">>, 'true')}
,{<<"device_id">>, cb_context:req_value(Context, <<"device_id">>)}
,{<<"dial_strategy">>, cb_context:req_value(Context, <<"dial_strategy">>, <<"simultaneous">>)}
,{<<"owner_id">>, cb_context:req_value(Context, <<"owner_id">>)}
])}
| kz_api:default_headers(?APP_NAME, ?APP_VERSION)
],
lager:debug("attempting to move ~s", [CallId]),
_ = kz_amqp_worker:cast(API, fun kapi_metaflow:publish_action/1),
crossbar_util:response_202(<<"move initiated">>, Context).

-spec get_account_id(cb_context:context()) -> kz_term:ne_binary().
get_account_id(Context) ->
case cb_context:account_id(Context) of
Expand Down