Skip to content

Commit

Permalink
KAZOO-240: generate and serve conference profile
Browse files Browse the repository at this point in the history
  • Loading branch information
James Aimonetti committed Apr 4, 2013
1 parent df076a7 commit 126b804
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
,reject_reason/1
,reject_status/1
,reject_code/1
,get_engine/1
,get_voice/1
]).

parse_cmds(XMLString) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exec(Call, [#xmlElement{name='Conference'
gen_listener:add_binding(kzt_util:get_amqp_listener(Call)
,'conference'
,[{'restrict_to', ['config']}
,{'profile', <<"pivot">>}
,{'profile', ConfId}
]),

ConfDoc = build_conference_doc(ConfId, ConfProps),
Expand All @@ -56,7 +56,10 @@ exec(Call, [#xmlElement{name='Conference'
_WaitMethod = kzt_util:http_method(ConfProps),

{'ok', Call1} = kzt_receiver:wait_for_conference(
kzt_util:update_call_status(?STATUS_ANSWERED, setup_call_for_dial(Call, DialProps))
kzt_util:update_call_status(?STATUS_ANSWERED, setup_call_for_dial(
add_conference_profile(Call, ConfProps)
,DialProps
))
),

lager:debug("waited for offnet, maybe ending dial"),
Expand Down Expand Up @@ -295,7 +298,7 @@ build_conference_doc(ConfId, ConfProps) ->
,{<<"require_moderator">>, require_moderator(StartOnEnter)}
,{<<"wait_for_moderator">>, 'true'}
,{<<"max_members">>, get_max_participants(ConfProps)}
,{<<"profile">>, <<"pivot">>}
,{<<"profile">>, ConfId}
]).

require_moderator('undefined') -> 'false';
Expand Down Expand Up @@ -323,3 +326,39 @@ conference_id(Txts) ->
MD5 = wh_util:to_hex_binary(erlang:md5(Id)),
lager:debug("conf name: ~s (~s)", [Id, MD5]),
MD5.


add_conference_profile(Call, ConfProps) ->
Profile = wh_json:from_list(
props:filter_undefined(
[{<<"rate">>, props:get_integer_value('rate', ConfProps, 8000)}
,{<<"caller-controls">>, props:get_integer_value('callerControls', ConfProps, 8000)}
,{<<"interval">>, props:get_integer_value('inteval', ConfProps, 20)}
,{<<"energy-level">>, props:get_integer_value('energyLevel', ConfProps, 20)}
,{<<"member-flags">>, conference_member_flags(ConfProps)}
,{<<"conference-flags">>, conference_flags(ConfProps)}
,{<<"tts-engine">>, kzt_twiml:get_engine(ConfProps)}
,{<<"tts-voice">>, kzt_twiml:get_voice(ConfProps)}
,{<<"max-members">>, get_max_participants(ConfProps)}
,{<<"comfort-noise">>, props:get_integer_value('comfortNoise', ConfProps, 1000)}
,{<<"annouce-count">>, props:get_integer_value('announceCount', ConfProps)}
,{<<"caller-controls">>, props:get_value('callerControls', ConfProps, <<"default">>)}
,{<<"moderator-controls">>, props:get_value('callerControls', ConfProps, <<"default">>)}
,{<<"caller-id-name">>, props:get_value('callerIdName', ConfProps, <<"Kazoo">>)}
,{<<"caller-id-number">>, props:get_value('callerIdNumber', ConfProps, <<"0000000000">>)}
%,{<<"suppress-events">>, <<>>} %% add events to make FS less chatty
,{<<"moh-sound">>, props:get_value('waitUrl', ConfProps, <<"http://com.twilio.music.classical.s3.amazonaws.com/Mellotroniac_-_Flight_Of_Young_Hearts_Flute.mp3">>)}
])),
kzt_util:set_conference_profile(Profile, Call).

conference_flags(ConfProps) ->
case props:get_is_true('startConferenceOnEnter', ConfProps, 'true') of
'true' -> 'undefined';
'false' -> <<"wait-mod">>
end.

conference_member_flags(ConfProps) ->
case props:get_is_true('endConferenceOnExit', ConfProps, 'false') of
'true' -> <<"endconf">>;
'false' -> 'undefined'
end.
14 changes: 4 additions & 10 deletions whistle_apps/lib/kazoo_translator-1.0.0/src/kzt_receiver.erl
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,11 @@ process_conference_event(#dial_req{call=Call
ConfigName = wh_json:get_value(<<"Profile">>, JObj),
lager:debug("conference profile ~s requested", [ConfigName]),

Profile = conference_profile(Call),
Profile = kzt_util:get_conference_profile(Call),
Resp = [{<<"Profiles">>, wh_json:from_list([{ConfigName, Profile}])}
,{<<"Caller-Controls">>, kzt_util:get_caller_controls(Call)}
,{<<"Advertise">>, kzt_util:get_advertise(Call)}
,{<<"Chat-Permissions">>, kzt_util:get_chat_permissions(Call)}
,{<<"Msg-ID">>, wh_json:get_value(<<"Msg-ID">>, JObj)}
| wh_api:default_headers(?APP_NAME, ?APP_VERSION)
],
Expand Down Expand Up @@ -549,12 +552,3 @@ update_offnet_timers(#dial_req{call_timeout=CallTimeout
OffnetReq#dial_req{call_timeout=whapps_util:decr_timeout(CallTimeout, Start)
,start=erlang:now()
}.

conference_profile(Call) ->
wh_json:from_list([{<<"rate">>, 8000}
,{<<"interval">>, 20}
,{<<"energy-level">>, 20}
,{<<"comfort-noise">>, 'true'}
,{<<"caller-id-name">>, whapps_call:caller_id_name(Call)}
,{<<"caller-id-number">>, whapps_call:caller_id_number(Call)}
]).
17 changes: 17 additions & 0 deletions whistle_apps/lib/kazoo_translator-1.0.0/src/kzt_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
,set_media_meta/2, get_media_meta/1
,set_amqp_listener/2, get_amqp_listener/1

,set_conference_profile/2, get_conference_profile/1
,set_caller_controls/2, get_caller_controls/1
,set_advertise/2, get_advertise/1
,set_chat_permissions/2, get_chat_permissions/1

,xml_elements/1
,xml_text_to_binary/1, xml_text_to_binary/2
]).
Expand Down Expand Up @@ -217,6 +222,18 @@ get_media_meta(Call) -> whapps_call:kvs_fetch(<<"media_meta">>, Call).
set_amqp_listener(Pid, Call) -> whapps_call:kvs_store(<<"amqp_listener">>, Pid, Call).
get_amqp_listener(Call) -> whapps_call:kvs_fetch(<<"amqp_listener">>, Call).

set_conference_profile(JObj, Call) -> whapps_call:kvs_store(<<"conference_profile">>, JObj, Call).
get_conference_profile(Call) -> whapps_call:kvs_fetch(<<"conference_profile">>, Call).

set_caller_controls(JObj, Call) -> whapps_call:kvs_store(<<"caller_controls">>, JObj, Call).
get_caller_controls(Call) -> whapps_call:kvs_fetch(<<"caller_controls">>, Call).

set_advertise(JObj, Call) -> whapps_call:kvs_store(<<"advertise">>, JObj, Call).
get_advertise(Call) -> whapps_call:kvs_fetch(<<"advertise">>, Call).

set_chat_permissions(JObj, Call) -> whapps_call:kvs_store(<<"chat_permissions">>, JObj, Call).
get_chat_permissions(Call) -> whapps_call:kvs_fetch(<<"chat_permissions">>, Call).

get_request_vars(Call) ->
wh_json:from_list(
props:filter_empty(
Expand Down

0 comments on commit 126b804

Please sign in to comment.