Skip to content

Commit

Permalink
HELP-13212: Document vmboxes.include_message_on_notify field (2600hz#…
Browse files Browse the repository at this point in the history
…6360)

* HELP-13212: Document vmboxes.should_include_attachment field

* HELP-13212: use the system_config default as the doc default when not present

* HELP-13212: rename parameter to be more descriptive and add parameters for other content fields that might need to be private

* HELP-13212: make apis

* HELP-13212-schema-update: deprecate should_include_attachment

Co-authored-by: Karl Anderson <[email protected]>
  • Loading branch information
harenson and k-anderson authored Mar 6, 2020
1 parent 21baadf commit 687f875
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 18 deletions.
2 changes: 2 additions & 0 deletions applications/crossbar/doc/ref/vmboxes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Key | Description | Type | Default | Required | Support Level
`delete_after_notify` | Move the voicemail to delete folder after the notification has been sent | `boolean()` | `false` | `false` | `supported`
`flags.[]` | | `string()` | | `false` | `supported`
`flags` | Flags set by external applications | `array(string())` | | `false` | `supported`
`include_message_on_notify` | Whether or not to include the attachment when sending a new voicemail to email notification | `boolean()` | `true` | `false` | `supported`
`include_transcription_on_notify` | Whether or not to include the transcription when sending a new voicemail to email notification | `boolean()` | `true` | `false` | `supported`
`is_setup` | Determines if the user has completed the initial configuration | `boolean()` | `false` | `false` | `supported`
`is_voicemail_ff_rw_enabled` | callflow allow fastforward and rewind during voicemail message playback | `boolean()` | `false` | `false` |
`mailbox` | The voicemail box number | `string(1..30)` | | `true` | `supported`
Expand Down
2 changes: 2 additions & 0 deletions applications/crossbar/doc/voicemail.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Key | Description | Type | Default | Required | Support Level
`delete_after_notify` | Move the voicemail to delete folder after the notification has been sent | `boolean()` | `false` | `false` | `supported`
`flags.[]` | | `string()` | | `false` | `supported`
`flags` | Flags set by external applications | `array(string())` | | `false` | `supported`
`include_message_on_notify` | Whether or not to include the attachment when sending a new voicemail to email notification | `boolean()` | `true` | `false` | `supported`
`include_transcription_on_notify` | Whether or not to include the transcription when sending a new voicemail to email notification | `boolean()` | `true` | `false` | `supported`
`is_setup` | Determines if the user has completed the initial configuration | `boolean()` | `false` | `false` | `supported`
`is_voicemail_ff_rw_enabled` | callflow allow fastforward and rewind during voicemail message playback | `boolean()` | `false` | `false` |
`mailbox` | The voicemail box number | `string(1..30)` | | `true` | `supported`
Expand Down
10 changes: 10 additions & 0 deletions applications/crossbar/priv/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -38914,6 +38914,16 @@
},
"type": "array"
},
"include_message_on_notify": {
"default": true,
"description": "Whether or not to include the attachment when sending a new voicemail to email notification",
"type": "boolean"
},
"include_transcription_on_notify": {
"default": true,
"description": "Whether or not to include the transcription when sending a new voicemail to email notification",
"type": "boolean"
},
"is_setup": {
"default": false,
"description": "Determines if the user has completed the initial configuration",
Expand Down
12 changes: 12 additions & 0 deletions applications/crossbar/priv/couchdb/schemas/vmboxes.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
"support_level": "supported",
"type": "array"
},
"include_message_on_notify": {
"default": true,
"description": "Whether or not to include the attachment when sending a new voicemail to email notification",
"support_level": "supported",
"type": "boolean"
},
"include_transcription_on_notify": {
"default": true,
"description": "Whether or not to include the transcription when sending a new voicemail to email notification",
"support_level": "supported",
"type": "boolean"
},
"is_setup": {
"default": false,
"description": "Determines if the user has completed the initial configuration",
Expand Down
12 changes: 12 additions & 0 deletions applications/crossbar/priv/oas3/oas3-schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14697,6 +14697,18 @@
'type': string
'type': array
'x-support_level': supported
'include_message_on_notify':
'default': true
'description': |-
Whether or not to include the attachment when sending a new voicemail to email notification
'type': boolean
'x-support_level': supported
'include_transcription_on_notify':
'default': true
'description': |-
Whether or not to include the transcription when sending a new voicemail to email notification
'type': boolean
'x-support_level': supported
'is_setup':
'default': false
'description': Determines if the user has completed the initial configuration
Expand Down
40 changes: 28 additions & 12 deletions applications/teletype/src/templates/teletype_voicemail_to_email.erl
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ do_process_req(DataJObj) ->
-spec macros(kz_json:object()) -> kz_term:proplist().
macros(DataJObj) ->
TemplateData = template_data(DataJObj),
IncludeAttachment = kz_json:is_true([<<"vmbox_doc">>, <<"should_include_attachment">>], DataJObj, 'true'),
EmailAttachments = maybe_email_attachments(DataJObj, TemplateData, IncludeAttachment),
EmailAttachments = maybe_email_attachments(DataJObj, TemplateData),
Macros = maybe_add_file_data(TemplateData, EmailAttachments),
props:set_value(<<"attachments">>, EmailAttachments, Macros).

Expand All @@ -186,16 +185,21 @@ template_data(DataJObj) ->
| build_template_data(DataJObj)
].

-spec maybe_email_attachments(kz_json:object(), kz_term:proplist(), boolean()) -> attachments().
maybe_email_attachments(_DataJObj, _Macros, 'false') ->
lager:debug("configured to not include attachments for this VM"),
[];
maybe_email_attachments(DataJObj, Macros, 'true') ->
email_attachments(DataJObj, Macros, teletype_util:is_preview(DataJObj)).
-spec maybe_email_attachments(kz_json:object(), kz_term:proplist()) -> attachments().
maybe_email_attachments(DataJObj, Macros) ->
case kzd_vmboxes:include_message_on_notify(
kz_json:get_json_value(<<"vmbox_doc">>, DataJObj)
)
andalso (not teletype_util:is_preview(DataJObj))
of
'true' -> email_attachments(DataJObj, Macros);
'false' ->
lager:debug("not attaching voicemail message to this email"),
[]
end.

-spec email_attachments(kz_json:object(), kz_term:proplist(), boolean()) -> attachments().
email_attachments(_DataJObj, _Macros, 'true') -> [];
email_attachments(DataJObj, Macros, 'false') ->
-spec email_attachments(kz_json:object(), kz_term:proplist()) -> attachments().
email_attachments(DataJObj, Macros) ->
VMId = kz_json:get_value(<<"voicemail_id">>, DataJObj),
AccountId = kz_json:get_value(<<"account_id">>, DataJObj),
Db = kvm_util:get_db(AccountId, VMId),
Expand Down Expand Up @@ -277,10 +281,22 @@ build_voicemail_data(DataJObj) ->
,{<<"vmbox_number">>, kz_json:get_value([<<"vmbox_doc">>, <<"mailbox">>], DataJObj)}
,{<<"msg_id">>, kz_json:get_value(<<"voicemail_id">>, DataJObj)}
,{<<"name">>, kz_json:get_value(<<"voicemail_id">>, DataJObj)} %% backward compatibility
,{<<"transcription">>, get_transcription(DataJObj)}
,{<<"transcription">>, maybe_get_transcription(DataJObj)}
,{<<"length">>, pretty_print_length(DataJObj)}
]).

-spec maybe_get_transcription(kz_json:object()) -> kz_term:api_ne_binary().
maybe_get_transcription(DataJObj) ->
case kzd_vmboxes:include_transcription_on_notify(
kz_json:get_json_value(<<"vmbox_doc">>, DataJObj)
)
of
'true' -> get_transcription(DataJObj);
'false' ->
lager:debug("not including transcription with this email"),
'undefined'
end.

-spec get_transcription(kz_json:object()) -> kz_term:api_ne_binary().
get_transcription(DataJObj) ->
case kz_json:get_value(<<"voicemail_transcription">>, DataJObj) of
Expand Down
70 changes: 64 additions & 6 deletions core/kazoo_documents/src/kzd_vmboxes.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%%%-----------------------------------------------------------------------------
%%% @copyright (C) 2010-2020, 2600Hz
%%% @doc
%%% @doc Accessors for `vmboxes' document.
%%% 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/.
Expand All @@ -10,6 +10,7 @@
-module(kzd_vmboxes).

-export([new/0]).
-export([announcement_only/1, announcement_only/2, set_announcement_only/2]).
-export([check_if_owner/1, check_if_owner/2, set_check_if_owner/2]).
-export([delete_after_notify/1, delete_after_notify/2, set_delete_after_notify/2]).
-export([flags/1, flags/2, set_flags/2]).
Expand All @@ -31,10 +32,13 @@
-export([require_pin/1, require_pin/2, set_require_pin/2]).
-export([save_after_notify/1, save_after_notify/2, set_save_after_notify/2]).
-export([seek_duration_ms/1, seek_duration_ms/2, set_seek_duration_ms/2]).
-export([include_message_on_notify/1, include_message_on_notify/2, set_include_message_on_notify/2]).
-export([include_transcription_on_notify/1, include_transcription_on_notify/2, set_include_transcription_on_notify/2]).
-export([skip_envelope/1, skip_envelope/2, set_skip_envelope/2]).
-export([skip_greeting/1, skip_greeting/2, set_skip_greeting/2]).
-export([skip_instructions/1, skip_instructions/2, set_skip_instructions/2]).
-export([timezone/1, timezone/2, set_timezone/2]).
-export([transcribe/1, transcribe/2, set_transcribe/2]).


-include("kz_documents.hrl").
Expand All @@ -48,6 +52,18 @@
new() ->
kz_json_schema:default_object(?SCHEMA).

-spec announcement_only(doc()) -> boolean().
announcement_only(Doc) ->
announcement_only(Doc, false).

-spec announcement_only(doc(), Default) -> boolean() | Default.
announcement_only(Doc, Default) ->
kz_json:get_boolean_value([<<"announcement_only">>], Doc, Default).

-spec set_announcement_only(doc(), boolean()) -> doc().
set_announcement_only(Doc, AnnouncementOnly) ->
kz_json:set_value([<<"announcement_only">>], AnnouncementOnly, Doc).

-spec check_if_owner(doc()) -> boolean().
check_if_owner(Doc) ->
check_if_owner(Doc, true).
Expand Down Expand Up @@ -92,9 +108,13 @@ is_setup(Doc) ->
is_setup(Doc, Default) ->
kz_json:get_boolean_value([<<"is_setup">>], Doc, Default).

-spec set_is_setup(doc(), boolean()) -> doc().
set_is_setup(Doc, IsSetup) ->
kz_json:set_value([<<"is_setup">>], IsSetup, Doc).

-spec is_voicemail_ff_rw_enabled(doc()) -> boolean().
is_voicemail_ff_rw_enabled(Doc) ->
is_voicemail_ff_rw_enabled(Doc, 'false').
is_voicemail_ff_rw_enabled(Doc, false).

-spec is_voicemail_ff_rw_enabled(doc(), Default) -> boolean() | Default.
is_voicemail_ff_rw_enabled(Doc, Default) ->
Expand All @@ -104,10 +124,6 @@ is_voicemail_ff_rw_enabled(Doc, Default) ->
set_is_voicemail_ff_rw_enabled(Doc, IsVoicemailFfRwEnabled) ->
kz_json:set_value([<<"is_voicemail_ff_rw_enabled">>], IsVoicemailFfRwEnabled, Doc).

-spec set_is_setup(doc(), boolean()) -> doc().
set_is_setup(Doc, IsSetup) ->
kz_json:set_value([<<"is_setup">>], IsSetup, Doc).

-spec mailbox(doc()) -> kz_term:api_ne_binary().
mailbox(Doc) ->
mailbox(Doc, 'undefined').
Expand Down Expand Up @@ -300,6 +316,36 @@ seek_duration_ms(Doc, Default) ->
set_seek_duration_ms(Doc, SeekDurationMs) ->
kz_json:set_value([<<"seek_duration_ms">>], SeekDurationMs, Doc).

-spec include_message_on_notify(doc()) -> boolean().
include_message_on_notify(Doc) ->
include_message_on_notify(Doc, true).

-spec include_message_on_notify(doc(), Default) -> boolean() | Default.
include_message_on_notify(Doc, Default) ->
case kz_json:get_first_defined([<<"include_message_on_notify">>
,<<"should_include_attachment">>
], Doc)
of
'undefined' -> Default;
Value -> kz_term:is_true(Value)
end.

-spec set_include_message_on_notify(doc(), boolean()) -> doc().
set_include_message_on_notify(Doc, ShouldIncludeAttachment) ->
kz_json:set_value([<<"include_message_on_notify">>], ShouldIncludeAttachment, Doc).

-spec include_transcription_on_notify(doc()) -> boolean().
include_transcription_on_notify(Doc) ->
include_transcription_on_notify(Doc, true).

-spec include_transcription_on_notify(doc(), Default) -> boolean() | Default.
include_transcription_on_notify(Doc, Default) ->
kz_json:get_boolean_value([<<"include_transcription_on_notify">>], Doc, Default).

-spec set_include_transcription_on_notify(doc(), boolean()) -> doc().
set_include_transcription_on_notify(Doc, ShouldIncludeAttachment) ->
kz_json:set_value([<<"include_transcription_on_notify">>], ShouldIncludeAttachment, Doc).

-spec skip_envelope(doc()) -> boolean().
skip_envelope(Doc) ->
skip_envelope(Doc, false).
Expand Down Expand Up @@ -347,3 +393,15 @@ timezone(Doc, Default) ->
-spec set_timezone(doc(), kz_term:ne_binary()) -> doc().
set_timezone(Doc, Timezone) ->
kz_json:set_value([<<"timezone">>], Timezone, Doc).

-spec transcribe(doc()) -> boolean().
transcribe(Doc) ->
transcribe(Doc, kvm_util:transcribe_default()).

-spec transcribe(doc(), Default) -> boolean() | Default.
transcribe(Doc, Default) ->
kz_json:get_boolean_value([<<"transcribe">>], Doc, Default).

-spec set_transcribe(doc(), boolean()) -> doc().
set_transcribe(Doc, Transcribe) ->
kz_json:set_value([<<"transcribe">>], Transcribe, Doc).
26 changes: 26 additions & 0 deletions core/kazoo_documents/src/kzd_vmboxes.erl.src
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
-export([check_if_owner/1, check_if_owner/2, set_check_if_owner/2]).
-export([delete_after_notify/1, delete_after_notify/2, set_delete_after_notify/2]).
-export([flags/1, flags/2, set_flags/2]).
-export([include_message_on_notify/1, include_message_on_notify/2, set_include_message_on_notify/2]).
-export([include_transcription_on_notify/1, include_transcription_on_notify/2, set_include_transcription_on_notify/2]).
-export([is_setup/1, is_setup/2, set_is_setup/2]).
-export([is_voicemail_ff_rw_enabled/1, is_voicemail_ff_rw_enabled/2, set_is_voicemail_ff_rw_enabled/2]).
-export([mailbox/1, mailbox/2, set_mailbox/2]).
Expand Down Expand Up @@ -94,6 +96,30 @@ flags(Doc, Default) ->
set_flags(Doc, Flags) ->
kz_json:set_value([<<"flags">>], Flags, Doc).

-spec include_message_on_notify(doc()) -> boolean().
include_message_on_notify(Doc) ->
include_message_on_notify(Doc, true).

-spec include_message_on_notify(doc(), Default) -> boolean() | Default.
include_message_on_notify(Doc, Default) ->
kz_json:get_boolean_value([<<"include_message_on_notify">>], Doc, Default).

-spec set_include_message_on_notify(doc(), boolean()) -> doc().
set_include_message_on_notify(Doc, IncludeMessageOnNotify) ->
kz_json:set_value([<<"include_message_on_notify">>], IncludeMessageOnNotify, Doc).

-spec include_transcription_on_notify(doc()) -> boolean().
include_transcription_on_notify(Doc) ->
include_transcription_on_notify(Doc, true).

-spec include_transcription_on_notify(doc(), Default) -> boolean() | Default.
include_transcription_on_notify(Doc, Default) ->
kz_json:get_boolean_value([<<"include_transcription_on_notify">>], Doc, Default).

-spec set_include_transcription_on_notify(doc(), boolean()) -> doc().
set_include_transcription_on_notify(Doc, IncludeTranscriptionOnNotify) ->
kz_json:set_value([<<"include_transcription_on_notify">>], IncludeTranscriptionOnNotify, Doc).

-spec is_setup(doc()) -> boolean().
is_setup(Doc) ->
is_setup(Doc, false).
Expand Down

0 comments on commit 687f875

Please sign in to comment.