|
1 | 1 | %%%----------------------------------------------------------------------------- |
2 | | -%%% @copyright (C) 2011-2022, 2600Hz |
| 2 | +%%% @copyright (C) 2011-2026, 2600Hz |
3 | 3 | %%% @doc Conferences module |
4 | 4 | %%% Handle client requests for conference documents |
5 | 5 | %%% |
|
9 | 9 | %%% /v2/accounts/{AccountId}/conferences/{ConferenceID}/participants |
10 | 10 | %%% /v2/accounts/{AccountId}/conferences/{ConferenceID}/participants/{ParticipantId} |
11 | 11 | %%% |
12 | | -%%% |
13 | 12 | %%% @author Karl Anderson |
14 | 13 | %%% @author James Aimonetti |
15 | 14 | %%% @author Roman Galeev |
| 15 | +%%% @author Ruel Tmeizeh for Umojo, Inc. |
16 | 16 | %%% @end |
17 | 17 | %%%----------------------------------------------------------------------------- |
18 | 18 | -module(cb_conferences). |
|
46 | 46 | -define(KICK, <<"kick">>). |
47 | 47 | -define(RELATE, <<"relate">>). |
48 | 48 | -define(PLAY, <<"play">>). |
| 49 | +-define(DTMF, <<"dtmf">>). |
49 | 50 |
|
50 | 51 | -define(PUT_ACTION, <<"action">>). |
51 | 52 |
|
@@ -222,6 +223,9 @@ put(Context, ConferenceId, ?PARTICIPANTS, ParticipantId) -> |
222 | 223 | participant_action(Context, ConferenceId, ParticipantId, ?PLAY) -> |
223 | 224 | play(Context, ConferenceId, ParticipantId, cb_context:req_value(Context, <<"data">>)); |
224 | 225 |
|
| 226 | +participant_action(Context, ConferenceId, ParticipantId, ?DTMF) -> |
| 227 | + dtmf(Context, ConferenceId, ParticipantId, cb_context:req_value(Context, <<"data">>)); |
| 228 | + |
225 | 229 | participant_action(Context, ConferenceId, ParticipantId, Action) -> |
226 | 230 | perform_participant_action(conference(ConferenceId), Action, kz_term:to_integer(ParticipantId)), |
227 | 231 | crossbar_util:response_202(<<"ok">>, Context). |
@@ -374,6 +378,8 @@ handle_conference_action(Context, ConferenceId, <<"unlock">>) -> |
374 | 378 | crossbar_util:response_202(<<"ok">>, Context); |
375 | 379 | handle_conference_action(Context, ConferenceId, ?PLAY) -> |
376 | 380 | play(Context, ConferenceId, cb_context:req_value(Context, <<"data">>)); |
| 381 | +handle_conference_action(Context, ConferenceId, ?DTMF) -> |
| 382 | + dtmf(Context, ConferenceId, cb_context:req_value(Context, <<"data">>)); |
377 | 383 | handle_conference_action(Context, ConferenceId, <<"dial">>) -> |
378 | 384 | dial(Context, ConferenceId, cb_context:req_value(Context, <<"data">>)); |
379 | 385 | handle_conference_action(Context, ConferenceId, Action) -> |
@@ -442,6 +448,43 @@ media_id_required(Context) -> |
442 | 448 | ,Context |
443 | 449 | ). |
444 | 450 |
|
| 451 | +%% send DTMF to all participants in conference (ParticipantId undefined) |
| 452 | +-spec dtmf(cb_context:context(), path_token(), kz_term:api_object()) -> cb_context:context(). |
| 453 | +dtmf(Context, _ConferenceId, 'undefined') -> |
| 454 | + data_required(Context, <<"dtmf">>); |
| 455 | +dtmf(Context, ConferenceId, Data) -> |
| 456 | + dtmf(Context, ConferenceId, 'undefined', Data). |
| 457 | + |
| 458 | +-spec dtmf(cb_context:context(), path_token(), pos_integer(), kz_term:api_object()) -> cb_context:context(). |
| 459 | +dtmf(Context, _ConferenceId, _ParticipantId, 'undefined') -> |
| 460 | + data_required(Context, <<"dtmf">>); |
| 461 | +dtmf(Context, ConferenceId, ParticipantId, Data) -> |
| 462 | + ParticipantMsg = |
| 463 | + case kz_term:to_api_binary(ParticipantId) of |
| 464 | + 'undefined' -> <<>>; |
| 465 | + Participant -> <<" participant ", Participant/binary>> |
| 466 | + end, |
| 467 | + case dtmf_digits(kz_json:get_value(<<"digits">>, Data)) of |
| 468 | + <<>> -> digits_required(Context); |
| 469 | + DTMF -> |
| 470 | + lager:info("sending DTMF ~s to conference ~s~s", [DTMF, ConferenceId, ParticipantMsg]), |
| 471 | + kapps_conference_command:dtmf(DTMF, ParticipantId, conference(ConferenceId)), |
| 472 | + crossbar_util:response_202(<<"ok">>, Context) |
| 473 | + end. |
| 474 | + |
| 475 | +-spec dtmf_digits(any()) -> binary(). |
| 476 | +dtmf_digits('undefined') -> <<>>; |
| 477 | +dtmf_digits(<<>>) -> <<>>; |
| 478 | +dtmf_digits(Digits) -> re:replace(kz_term:to_binary(Digits), "[^a-dA-D0-9*#]", "", [global, {return, binary}]). |
| 479 | + |
| 480 | +-spec digits_required(cb_context:context()) -> cb_context:context(). |
| 481 | +digits_required(Context) -> |
| 482 | + cb_context:add_validation_error([<<"data">>, <<"digits">>] |
| 483 | + ,<<"required">> |
| 484 | + ,kz_json:from_list([{<<"message">>, <<"action 'dtmf' requires digits [0123456789*#ABCD] to be specified">>}]) |
| 485 | + ,Context |
| 486 | + ). |
| 487 | + |
445 | 488 | -spec dial(cb_context:context(), path_token(), kz_term:api_object()) -> cb_context:context(). |
446 | 489 | dial(Context, _ConferenceId, 'undefined') -> |
447 | 490 | data_required(Context, <<"dial">>); |
@@ -779,6 +822,8 @@ handle_participants_action(Context, ConferenceId, Action=?KICK) -> |
779 | 822 | handle_participants_action(Context, ConferenceId, Action, fun kz_term:always_true/1); |
780 | 823 | handle_participants_action(Context, ConferenceId, Action=?PLAY) -> |
781 | 824 | handle_conference_action(Context, ConferenceId, Action); |
| 825 | +handle_participants_action(Context, ConferenceId, Action=?DTMF) -> |
| 826 | + handle_conference_action(Context, ConferenceId, Action); |
782 | 827 | handle_participants_action(Context, ConferenceId, ?RELATE) -> |
783 | 828 | OnSuccess = fun(C) -> handle_participants_relate(C, ConferenceId) end, |
784 | 829 | RelateData = cb_context:req_value(Context, <<"data">>, kz_json:new()), |
|
0 commit comments