Skip to content

Commit

Permalink
KAZOO-3292: when recording menu greeting set media_source and desc on…
Browse files Browse the repository at this point in the history
… media document
  • Loading branch information
Peter Defebvre committed Feb 12, 2015
1 parent c185b92 commit 614eb6a
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion applications/callflow/src/module/cf_menu.erl
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,14 @@ get_prompt(#cf_menu_data{greeting_id=Id}, Call) ->
{'error', wh_json:object()}.
store_recording(AttachmentName, MediaId, Call) ->
lager:info("storing recording ~s as media ~s", [AttachmentName, MediaId]),
'ok' = update_doc(<<"content_type">>, <<"audio/mpeg">>, MediaId, Call),
CallerIdName = whapps_call:caller_id_name(Call),
Description = <<"recorded by ", CallerIdName/binary>>,
Updates = [
{<<"content_type">>, <<"audio/mpeg">>}
,{<<"media_source">>, <<"recording">>}
,{<<"description">>, Description}
],
'ok' = update_doc(Updates, MediaId, Call),
whapps_call_command:b_store(AttachmentName, get_new_attachment_url(AttachmentName, MediaId, Call), Call).

%%--------------------------------------------------------------------
Expand Down Expand Up @@ -443,6 +450,7 @@ recording_media_doc(Type, #cf_menu_data{name=MenuName
%%--------------------------------------------------------------------
-spec update_doc(text(), wh_json:json_term(), menu() | binary(), whapps_call:call() | binary()) ->
'ok' | {'error', atom()}.
-spec update_doc(wh_proplist(), ne_binary(), whapps_call:call() | binary()) -> 'ok' | {'error', atom()}.
update_doc(Key, Value, #cf_menu_data{menu_id=Id}, Db) ->
update_doc(Key, Value, Id, Db);
update_doc(Key, Value, Id, Call) when is_tuple(Call) ->
Expand All @@ -458,6 +466,19 @@ update_doc(Key, Value, Id, Db) ->
end
end.

update_doc(Updates, Id, Call) when is_tuple(Call) ->
update_doc(Updates, Id, whapps_call:account_db(Call));
update_doc(Updates, Id, Db) ->
case couch_mgr:open_doc(Db, Id) of
{'error', _}=E -> lager:info("unable to update ~s in ~s, ~p", [Id, Db, E]);
{'ok', JObj} ->
case couch_mgr:save_doc(Db, wh_json:set_values(Updates, JObj)) of
{'error', 'conflict'} -> update_doc(Updates, Id, Db);
{'ok', _} -> 'ok';
{'error', _}=E -> lager:info("unable to update ~s in ~s, ~p", [Id, Db, E])
end
end.

%%--------------------------------------------------------------------
%% @private
%% @doc
Expand Down

0 comments on commit 614eb6a

Please sign in to comment.