From d544c06598949cf4666f43a055454aa52e691508 Mon Sep 17 00:00:00 2001 From: Marc Olivier Chouinard Date: Mon, 26 Dec 2011 11:14:00 -0500 Subject: [PATCH] mod_voicemail_ivr: Fixed issue in settings system. Added initials settings. --- conf/autoload_configs/voicemail_ivr.conf.xml | 20 +- .../applications/mod_voicemail_ivr/config.c | 74 ++++--- .../applications/mod_voicemail_ivr/config.h | 2 + src/mod/applications/mod_voicemail_ivr/menu.c | 184 +++++++++++------- .../applications/mod_voicemail_ivr/utils.c | 5 +- .../applications/mod_voicemail_ivr/utils.h | 6 +- 6 files changed, 178 insertions(+), 113 deletions(-) diff --git a/conf/autoload_configs/voicemail_ivr.conf.xml b/conf/autoload_configs/voicemail_ivr.conf.xml index 5fe06c50ce..2cebac6cfa 100644 --- a/conf/autoload_configs/voicemail_ivr.conf.xml +++ b/conf/autoload_configs/voicemail_ivr.conf.xml @@ -1,12 +1,19 @@ - + + + + + + + - --> @@ -64,12 +71,9 @@ - - --> diff --git a/src/mod/applications/mod_voicemail_ivr/config.c b/src/mod/applications/mod_voicemail_ivr/config.c index 67f9c02c22..d666ebe07f 100644 --- a/src/mod/applications/mod_voicemail_ivr/config.c +++ b/src/mod/applications/mod_voicemail_ivr/config.c @@ -52,12 +52,14 @@ void menu_init(vmivr_profile_t *profile, vmivr_menu_t *menu) { goto end; } - if (profile->event_settings && menu->event_settings) { + if (profile->event_settings) { /* TODO Replace this with a switch_event_merge_not_set(...) */ switch_event_t *menu_default; switch_event_create(&menu_default, SWITCH_EVENT_REQUEST_PARAMS); - switch_event_merge(menu_default, menu->event_settings); - switch_event_destroy(&menu->event_settings); + if (menu->event_settings) { + switch_event_merge(menu_default, menu->event_settings); + switch_event_destroy(&menu->event_settings); + } switch_event_create(&menu->event_settings, SWITCH_EVENT_REQUEST_PARAMS); switch_event_merge(menu->event_settings, profile->event_settings); @@ -65,6 +67,12 @@ void menu_init(vmivr_profile_t *profile, vmivr_menu_t *menu) { switch_event_destroy(&menu_default); } + { + const char *s_max_attempts = switch_event_get_header(menu->event_settings, "IVR-Maximum-Attempts"); + const char *s_entry_timeout = switch_event_get_header(menu->event_settings, "IVR-Entry-Timeout"); + menu->ivr_maximum_attempts = atoi(s_max_attempts); + menu->ivr_entry_timeout = atoi(s_entry_timeout); + } if ((x_profile = switch_xml_find_child(x_profiles, "profile", "name", profile->name))) { if ((x_menus = switch_xml_child(x_profile, "menus"))) { @@ -127,39 +135,37 @@ void menu_free(vmivr_menu_t *menu) { static void append_event_profile(vmivr_menu_t *menu) { - if (!menu->phrase_params) { - switch_event_create(&menu->phrase_params, SWITCH_EVENT_REQUEST_PARAMS); - } + if (!menu->phrase_params) { + switch_event_create(&menu->phrase_params, SWITCH_EVENT_REQUEST_PARAMS); + } - /* Used for some appending function */ - if (menu->profile && menu->profile->name && menu->profile->id && menu->profile->domain) { - switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, "VM-Profile", "%s", menu->profile->name); - switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, "VM-Account-ID", "%s", menu->profile->id); - switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, "VM-Account-Domain", "%s", menu->profile->domain); - } + /* Used for some appending function */ + if (menu->profile && menu->profile->name && menu->profile->id && menu->profile->domain) { + switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, "VM-Profile", "%s", menu->profile->name); + switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, "VM-Account-ID", "%s", menu->profile->id); + switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, "VM-Account-Domain", "%s", menu->profile->domain); + } } static void populate_dtmfa_from_event(vmivr_menu_t *menu) { - int i = 0; - if (menu->event_keys_dtmf) { - switch_event_header_t *hp; + int i = 0; + if (menu->event_keys_dtmf) { + switch_event_header_t *hp; - for (hp = menu->event_keys_dtmf->headers; hp; hp = hp->next) { - if (strlen(hp->name) < 3 && hp->value) { /* TODO This is a hack to discard default FS Events ! */ - const char *varphrasename = switch_event_get_header(menu->event_keys_varname, hp->value); - menu->dtmfa[i++] = hp->name; - - if (varphrasename && !zstr(varphrasename)) { - switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, varphrasename, "%s", hp->name); - } - } - } - } - menu->dtmfa[i++] = '\0'; + for (hp = menu->event_keys_dtmf->headers; hp; hp = hp->next) { + if (strlen(hp->name) < 3 && hp->value) { /* TODO This is a hack to discard default FS Events ! */ + const char *varphrasename = switch_event_get_header(menu->event_keys_varname, hp->value); + menu->dtmfa[i++] = hp->name; + if (varphrasename && !zstr(varphrasename)) { + switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, varphrasename, "%s", hp->name); + } + } + } + } + menu->dtmfa[i++] = '\0'; } - vmivr_profile_t *get_profile(switch_core_session_t *session, const char *profile_name) { vmivr_profile_t *profile = NULL; @@ -193,7 +199,17 @@ vmivr_profile_t *get_profile(switch_core_session_t *session, const char *profile profile->menu_check_main = "std_main_menu"; profile->menu_check_terminate = "std_purge"; - /* TODO Create event_settings and add default settings here */ + /* Populate default general settings */ + switch_event_create(&profile->event_settings, SWITCH_EVENT_REQUEST_PARAMS); + switch_event_add_header(profile->event_settings, SWITCH_STACK_BOTTOM, "IVR-Maximum-Attempts", "%d", 3); + switch_event_add_header(profile->event_settings, SWITCH_STACK_BOTTOM, "IVR-Entry-Timeout", "%d", 3000); + switch_event_add_header(profile->event_settings, SWITCH_STACK_BOTTOM, "Exit-Purge", "%s", "true"); + switch_event_add_header(profile->event_settings, SWITCH_STACK_BOTTOM, "Password-Mask", "%s", "XXX."); + switch_event_add_header(profile->event_settings, SWITCH_STACK_BOTTOM, "User-Mask", "%s", "X."); + switch_event_add_header(profile->event_settings, SWITCH_STACK_BOTTOM, "Record-Format", "%s", "wav"); + switch_event_add_header(profile->event_settings, SWITCH_STACK_BOTTOM, "Record-Silence-Hits", "%d", 4); + switch_event_add_header(profile->event_settings, SWITCH_STACK_BOTTOM, "Record-Silence-Threshold", "%d", 200); + switch_event_add_header(profile->event_settings, SWITCH_STACK_BOTTOM, "Record-Maximum-Length", "%d", 30); if ((x_settings = switch_xml_child(x_profile, "settings"))) { switch_event_import_xml(switch_xml_child(x_settings, "param"), "name", "value", &profile->event_settings); diff --git a/src/mod/applications/mod_voicemail_ivr/config.h b/src/mod/applications/mod_voicemail_ivr/config.h index ce596313bc..f94fdb6f54 100644 --- a/src/mod/applications/mod_voicemail_ivr/config.h +++ b/src/mod/applications/mod_voicemail_ivr/config.h @@ -91,6 +91,8 @@ struct vmivr_menu { switch_event_t *phrase_params; ivre_data_t ivre_d; + int ivr_maximum_attempts; + int ivr_entry_timeout; }; typedef struct vmivr_menu vmivr_menu_t; diff --git a/src/mod/applications/mod_voicemail_ivr/menu.c b/src/mod/applications/mod_voicemail_ivr/menu.c index b83bac07e5..57d8ee6147 100644 --- a/src/mod/applications/mod_voicemail_ivr/menu.c +++ b/src/mod/applications/mod_voicemail_ivr/menu.c @@ -51,16 +51,27 @@ vmivr_menu_function_t menu_list[] = { { NULL, NULL } }; -#define MAX_ATTEMPT 3 /* TODO Make these fields configurable */ -#define DEFAULT_IVR_TIMEOUT 3000 - void vmivr_menu_purge(switch_core_session_t *session, vmivr_profile_t *profile) { + vmivr_menu_t menu = { "std_menu_purge" }; + + /* Initialize Menu Configs */ + menu_init(profile, &menu); + + if (!menu.event_keys_dtmf || !menu.event_phrases) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu.name); + goto end; + } + if (profile->id && profile->authorized) { - if (1==1 /* TODO make Purge email on exit optional ??? */) { + const char *exit_purge = switch_event_get_header(menu.event_settings, "Exit-Purge"); + if (switch_true(exit_purge)) { const char *cmd = switch_core_session_sprintf(session, "%s %s %s", profile->api_profile, profile->domain, profile->id); vmivr_api_execute(session, profile->api_msg_purge, cmd); } } +end: + menu_free(&menu); + } void vmivr_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) { @@ -72,11 +83,11 @@ void vmivr_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) { menu_init(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases and Keys\n"); - return; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu.name); + goto end; } - for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) { + for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { char *cmd = NULL; menu_instance_init(&menu); @@ -88,7 +99,7 @@ void vmivr_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) { //initial_count_played = SWITCH_TRUE; ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "msg_count"), NULL, menu.phrase_params, NULL, 0); - ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, DEFAULT_IVR_TIMEOUT); + ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, menu.ivr_entry_timeout); if (menu.ivre_d.result == RES_TIMEOUT) { /* TODO Ask for the prompt Again IF retry != 0 */ @@ -98,7 +109,7 @@ void vmivr_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) { const char *action = switch_event_get_header(menu.event_keys_dtmf, menu.ivre_d.dtmf_stored); /* Reset the try count */ - retry = MAX_ATTEMPT; + retry = menu.ivr_maximum_attempts; if (action) { if (!strncasecmp(action, "new_msg:", 8)) { @@ -129,6 +140,8 @@ void vmivr_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) { } + +end: menu_free(&menu); } @@ -157,8 +170,8 @@ void vmivr_menu_navigator(switch_core_session_t *session, vmivr_profile_t *profi menu_init(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys\n"); - return; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu.name); + goto done; } /* Get VoiceMail List And update msg count */ @@ -177,7 +190,7 @@ void vmivr_menu_navigator(switch_core_session_t *session, vmivr_profile_t *profi /* TODO Add Detection of new message and notify the user */ - for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) { + for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { switch_core_session_message_t msg = { 0 }; char cid_buf[1024] = ""; @@ -185,16 +198,6 @@ void vmivr_menu_navigator(switch_core_session_t *session, vmivr_profile_t *profi previous_msg = current_msg; - /* Simple Protection to not go out of msg list scope */ - /* TODO: Add Prompt to notify they reached the begining or the end */ - if (next_msg == 0) { - next_msg = 1; - } else if (next_msg > msg_count) { - next_msg = msg_count; - } - - current_msg = next_msg; - ivre_init(&menu.ivre_d, menu.dtmfa); /* Prompt related to previous Message here */ @@ -212,6 +215,18 @@ void vmivr_menu_navigator(switch_core_session_t *session, vmivr_profile_t *profi ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "ack"), "saved", menu.phrase_params, NULL, 0); } switch_event_del_header(menu.phrase_params, "VM-Message-Flags"); + + /* Simple Protection to not go out of msg list scope */ + /* TODO: Add Prompt to notify they reached the begining or the end */ + if (next_msg == 0) { + next_msg = 1; + } else if (next_msg > msg_count) { + next_msg = msg_count; + /*ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "no_more_messages"), NULL, NULL, NULL, 0); */ + } + + current_msg = next_msg; + /* Prompt related the current message */ append_event_message(session, profile, menu.phrase_params, msg_list_params, current_msg); @@ -250,7 +265,7 @@ void vmivr_menu_navigator(switch_core_session_t *session, vmivr_profile_t *profi skip_header = SWITCH_FALSE; skip_playback = SWITCH_FALSE; - ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, DEFAULT_IVR_TIMEOUT); + ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, menu.ivr_entry_timeout); if (menu.ivre_d.result == RES_TIMEOUT) { /* TODO Ask for the prompt Again IF retry != 0 */ @@ -260,30 +275,30 @@ void vmivr_menu_navigator(switch_core_session_t *session, vmivr_profile_t *profi const char *action = switch_event_get_header(menu.event_keys_dtmf, menu.ivre_d.dtmf_stored); /* Reset the try count */ - retry = MAX_ATTEMPT; - + retry = menu.ivr_maximum_attempts; +action: if (action) { if (!strcasecmp(action, "skip_intro")) { /* Skip Header / Play the recording again */ skip_header = SWITCH_TRUE; } else if (!strcasecmp(action, "next_msg")) { /* Next Message */ next_msg++; - if (next_msg > msg_count) { - //ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "no_more_messages"), NULL, NULL, NULL, 0); - retry = -1; - } - } else if (!strcasecmp(action, "prev_msg")) { /* Previous Message */ next_msg--; } else if (!strcasecmp(action, "delete_msg")) { /* Delete / Undelete Message */ const char *msg_flags = switch_event_get_header(menu.phrase_params, "VM-Message-Flags"); if (!msg_flags || strncasecmp(msg_flags, "delete", 6)) { + const char *action_on_delete = switch_event_get_header(menu.event_settings, "Nav-Action-On-Delete"); cmd = switch_core_session_sprintf(session, "%s %s %s %s", profile->api_profile, profile->domain, profile->id, switch_event_get_header(menu.phrase_params, "VM-Message-UUID")); vmivr_api_execute(session, profile->api_msg_delete, cmd); msg_deleted = SWITCH_TRUE; - /* TODO Option for auto going to next message or just return to the menu (So user used to do 76 to delete and next message wont be confused) */ - //next_msg++; - skip_header = skip_playback = SWITCH_TRUE; + + if (action_on_delete) { + action = action_on_delete; + goto action; + } else { + skip_header = skip_playback = SWITCH_TRUE; + } } else { cmd = switch_core_session_sprintf(session, "%s %s %s %s", profile->api_profile, profile->domain, profile->id, switch_event_get_header(menu.phrase_params, "VM-Message-UUID")); vmivr_api_execute(session, profile->api_msg_undelete, cmd); @@ -343,17 +358,17 @@ void vmivr_menu_forward(switch_core_session_t *session, vmivr_profile_t *profile menu_init(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases and Keys\n"); - return; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu.name); + goto end; } - for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) { + for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { menu_instance_init(&menu); ivre_init(&menu.ivre_d, menu.dtmfa); - ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, DEFAULT_IVR_TIMEOUT); + ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, menu.ivr_entry_timeout); if (menu.ivre_d.result == RES_TIMEOUT) { /* TODO Ask for the prompt Again IF retry != 0 */ @@ -363,7 +378,7 @@ void vmivr_menu_forward(switch_core_session_t *session, vmivr_profile_t *profile const char *action = switch_event_get_header(menu.event_keys_dtmf, menu.ivre_d.dtmf_stored); /* Reset the try count */ - retry = MAX_ATTEMPT; + retry = menu.ivr_maximum_attempts; if (action) { if (!strcasecmp(action, "return")) { /* Return to the previous menu */ @@ -371,11 +386,18 @@ void vmivr_menu_forward(switch_core_session_t *session, vmivr_profile_t *profile forward_msg = SWITCH_FALSE; } else if (!strcasecmp(action, "prepend")) { /* Prepend record msg */ vmivr_menu_t sub_menu = { "std_record_message" }; - char *tmp_filepath = generate_random_file_name(session, "voicemail_ivr", "wav" /* TODO make it configurable */); + + const char *tmp_filepath = NULL; + const char *record_format = NULL; + switch_status_t status; /* Initialize Menu Configs */ menu_init(profile, &sub_menu); + + record_format = switch_event_get_header(sub_menu.event_settings, "Record-Format"); + + tmp_filepath = generate_random_file_name(session, "voicemail_ivr", record_format); status = vmivr_menu_record(session, profile, sub_menu, tmp_filepath); @@ -409,7 +431,7 @@ void vmivr_menu_forward(switch_core_session_t *session, vmivr_profile_t *profile } /* Ask Extension to Forward */ if (forward_msg) { - for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) { + for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { const char *id = NULL; vmivr_menu_t sub_menu = { "std_forward_ask_extension" }; @@ -435,6 +457,7 @@ void vmivr_menu_forward(switch_core_session_t *session, vmivr_profile_t *profile } +end: menu_free(&menu); } @@ -443,11 +466,16 @@ void vmivr_menu_record_name(switch_core_session_t *session, vmivr_profile_t *pro switch_status_t status; vmivr_menu_t menu = { "std_record_name" }; - char *tmp_filepath = generate_random_file_name(session, "voicemail_ivr", "wav" /* TODO make it configurable */); + const char *tmp_filepath = NULL; + const char *record_format = NULL; /* Initialize Menu Configs */ menu_init(profile, &menu); + record_format = switch_event_get_header(menu.event_settings, "Record-Format"); + + tmp_filepath = generate_random_file_name(session, "voicemail_ivr", record_format); + status = vmivr_menu_record(session, profile, menu, tmp_filepath); if (status == SWITCH_STATUS_SUCCESS) { @@ -459,11 +487,14 @@ void vmivr_menu_record_name(switch_core_session_t *session, vmivr_profile_t *pro void vmivr_menu_set_password(switch_core_session_t *session, vmivr_profile_t *profile) { char *password; vmivr_menu_t menu = { "std_set_password" }; + const char *password_mask = NULL; /* Initialize Menu Configs */ menu_init(profile, &menu); - password = vmivr_menu_get_input_set(session, profile, menu, "XXX." /* TODO Conf Min 3 Digit */); + password_mask = switch_event_get_header(menu.event_settings, "Password-Mask"); + + password = vmivr_menu_get_input_set(session, profile, menu, password_mask); /* TODO Add Prompts to tell if password was set and if it was not */ if (password) { @@ -487,16 +518,17 @@ void vmivr_menu_authenticate(switch_core_session_t *session, vmivr_profile_t *pr profile->authorized = SWITCH_TRUE; } - for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0 && profile->authorized == SWITCH_FALSE; retry--) { + for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0 && profile->authorized == SWITCH_FALSE; retry--) { const char *id = profile->id, *password = NULL; char *cmd = NULL; - + const char *password_mask = switch_event_get_header(menu.event_settings, "Password-Mask"); + const char *user_mask = switch_event_get_header(menu.event_settings, "User-Mask"); if (!id) { vmivr_menu_t sub_menu = { "std_authenticate_ask_user" }; /* Initialize Menu Configs */ menu_init(profile, &sub_menu); - id = vmivr_menu_get_input_set(session, profile, sub_menu, "X." /* TODO Conf Min 3 Digit */); + id = vmivr_menu_get_input_set(session, profile, sub_menu, user_mask); menu_free(&sub_menu); } if (!password) { @@ -504,7 +536,7 @@ void vmivr_menu_authenticate(switch_core_session_t *session, vmivr_profile_t *pr /* Initialize Menu Configs */ menu_init(profile, &sub_menu); - password = vmivr_menu_get_input_set(session, profile, sub_menu, "X." /* TODO Conf Min 3 Digit */); + password = vmivr_menu_get_input_set(session, profile, sub_menu, password_mask); menu_free(&sub_menu); } cmd = switch_core_session_sprintf(session, "%s %s %s %s", profile->api_profile, profile->domain, id, password); @@ -562,12 +594,18 @@ void vmivr_menu_record_greeting_with_slot(switch_core_session_t *session, vmivr_ /* If user entered 0, we don't accept it */ if (gnum > 0) { vmivr_menu_t sub_menu = { "std_record_greeting" }; - char *tmp_filepath = generate_random_file_name(session, "voicemail_ivr", "wav" /* TODO make it configurable */); + char *tmp_filepath = NULL; + const char *record_format = NULL; + switch_status_t status; /* Initialize Menu Configs */ menu_init(profile, &sub_menu); + record_format = switch_event_get_header(menu.event_settings, "Record-Format"); + + tmp_filepath = generate_random_file_name(session, "voicemail_ivr", record_format); + status = vmivr_menu_record(session, profile, sub_menu, tmp_filepath); if (status == SWITCH_STATUS_SUCCESS) { @@ -595,17 +633,17 @@ void vmivr_menu_preference(switch_core_session_t *session, vmivr_profile_t *prof menu_init(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases and Keys\n"); - return; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu.name); + goto end; } - for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) { + for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { menu_instance_init(&menu); ivre_init(&menu.ivre_d, menu.dtmfa); - ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, DEFAULT_IVR_TIMEOUT); + ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, menu.ivr_entry_timeout); if (menu.ivre_d.result == RES_TIMEOUT) { /* TODO Ask for the prompt Again IF retry != 0 */ @@ -615,7 +653,7 @@ void vmivr_menu_preference(switch_core_session_t *session, vmivr_profile_t *prof const char *action = switch_event_get_header(menu.event_keys_dtmf, menu.ivre_d.dtmf_stored); /* Reset the try count */ - retry = MAX_ATTEMPT; + retry = menu.ivr_maximum_attempts; if (action) { if (!strcasecmp(action, "return")) { /* Return to the previous menu */ @@ -631,6 +669,7 @@ void vmivr_menu_preference(switch_core_session_t *session, vmivr_profile_t *prof menu_instance_free(&menu); } +end: menu_free(&menu); } @@ -641,13 +680,13 @@ char *vmivr_menu_get_input_set(switch_core_session_t *session, vmivr_profile_t * switch_channel_t *channel = switch_core_session_get_channel(session); if (!menu.event_keys_dtmf || !menu.event_phrases) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases and Keys : %s\n", menu.name); - return result; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu.name); + goto end; } terminate_key = switch_event_get_header(menu.event_keys_action, "ivrengine:terminate_entry"); - for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) { + for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { int i; menu_instance_init(&menu); @@ -661,7 +700,7 @@ char *vmivr_menu_get_input_set(switch_core_session_t *session, vmivr_profile_t * if (terminate_key) { menu.ivre_d.terminate_key = terminate_key[0]; } - ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "instructions"), NULL, menu.phrase_params, NULL, DEFAULT_IVR_TIMEOUT); + ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "instructions"), NULL, menu.phrase_params, NULL, menu.ivr_entry_timeout); if (menu.ivre_d.result == RES_TIMEOUT) { /* TODO Ask for the prompt Again IF retry != 0 */ @@ -670,7 +709,7 @@ char *vmivr_menu_get_input_set(switch_core_session_t *session, vmivr_profile_t * } else if (menu.ivre_d.result == RES_FOUND) { /* Matching DTMF Key Pressed */ /* Reset the try count */ - retry = MAX_ATTEMPT; + retry = menu.ivr_maximum_attempts; if (!strncasecmp(menu.ivre_d.completeMatch, input_mask, 1)) { result = switch_core_session_strdup(session, menu.ivre_d.dtmf_stored); @@ -680,7 +719,7 @@ char *vmivr_menu_get_input_set(switch_core_session_t *session, vmivr_profile_t * } menu_instance_free(&menu); } - +end: return result; } @@ -694,17 +733,22 @@ switch_status_t vmivr_menu_record(switch_core_session_t *session, vmivr_profile_ switch_bool_t play_instruction = SWITCH_TRUE; if (!menu.event_keys_dtmf || !menu.event_phrases) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases and Keys\n"); - return status; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu.name); + goto end; } - for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) { + for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { switch_file_handle_t fh = { 0 }; + const char *rec_silence_hits = switch_event_get_header(menu.event_settings, "Record-Silence-Hits"); + const char *rec_silence_threshold = switch_event_get_header(menu.event_settings, "Record-Silence-Threshold"); + const char *rec_silence_samplerate = switch_event_get_header(menu.event_settings, "Record-Sample-Rate"); + const char *rec_maximum_length = switch_event_get_header(menu.event_settings, "Record-Maximum-Length"); - /* TODO Make the following configurable */ - fh.thresh = 200; - fh.silence_hits = 4; - //fh.samplerate = 8000; + fh.thresh = atoi(rec_silence_threshold); + fh.silence_hits = atoi(rec_silence_hits); + if (rec_silence_samplerate) { + fh.samplerate = atoi(rec_silence_samplerate); + } menu_instance_init(&menu); @@ -715,7 +759,7 @@ switch_status_t vmivr_menu_record(switch_core_session_t *session, vmivr_profile_ } play_instruction = SWITCH_TRUE; - ivre_record(session, &menu.ivre_d, menu.phrase_params, file_name, &fh, 30 /* TODO Make max recording configurable */); + ivre_record(session, &menu.ivre_d, menu.phrase_params, file_name, &fh, atoi(rec_maximum_length)); } else { if (listen_recording) { switch_event_add_header(menu.phrase_params, SWITCH_STACK_BOTTOM, "VM-Record-File-Path", "%s", file_name); @@ -723,12 +767,12 @@ switch_status_t vmivr_menu_record(switch_core_session_t *session, vmivr_profile_ listen_recording = SWITCH_FALSE; } - ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, DEFAULT_IVR_TIMEOUT); + ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, menu.ivr_entry_timeout); } if (menu.ivre_d.recorded_audio) { /* Reset the try count */ - retry = MAX_ATTEMPT; + retry = menu.ivr_maximum_attempts; /* TODO Check if message is too short */ @@ -742,7 +786,7 @@ switch_status_t vmivr_menu_record(switch_core_session_t *session, vmivr_profile_ const char *action = switch_event_get_header(menu.event_keys_dtmf, menu.ivre_d.dtmf_stored); /* Reset the try count */ - retry = MAX_ATTEMPT; + retry = menu.ivr_maximum_attempts; if (action) { if (!strcasecmp(action, "listen")) { /* Listen */ @@ -771,6 +815,8 @@ switch_status_t vmivr_menu_record(switch_core_session_t *session, vmivr_profile_ } menu_instance_free(&menu); } + +end: return status; } diff --git a/src/mod/applications/mod_voicemail_ivr/utils.c b/src/mod/applications/mod_voicemail_ivr/utils.c index d21d75cb17..e7b374a325 100644 --- a/src/mod/applications/mod_voicemail_ivr/utils.c +++ b/src/mod/applications/mod_voicemail_ivr/utils.c @@ -33,11 +33,10 @@ #include "utils.h" -switch_status_t vmivr_merge_media_files(const char** inputs, const char *output) { +switch_status_t vmivr_merge_media_files(const char** inputs, const char *output, int rate) { switch_status_t status = SWITCH_STATUS_SUCCESS; switch_file_handle_t fh_output = { 0 }; int channels = 1; - int rate = 8000; /* TODO Make this configurable */ int j = 0; if (switch_core_file_open(&fh_output, output, channels, rate, SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) { @@ -99,7 +98,7 @@ switch_event_t *jsonapi2event(switch_core_session_t *session, switch_event_t *ap return phrases_event; } -char *generate_random_file_name(switch_core_session_t *session, const char *mod_name, char *file_extension) { +char *generate_random_file_name(switch_core_session_t *session, const char *mod_name, const char *file_extension) { char rand_uuid[SWITCH_UUID_FORMATTED_LENGTH + 1] = ""; switch_uuid_t srand_uuid; diff --git a/src/mod/applications/mod_voicemail_ivr/utils.h b/src/mod/applications/mod_voicemail_ivr/utils.h index 50ca4cf5f8..a20dfe806d 100644 --- a/src/mod/applications/mod_voicemail_ivr/utils.h +++ b/src/mod/applications/mod_voicemail_ivr/utils.h @@ -34,12 +34,10 @@ #include "config.h" -switch_status_t vmivr_merge_files(const char** inputs, const char *output); - void append_event_message(switch_core_session_t *session, vmivr_profile_t *profile, switch_event_t *phrase_params, switch_event_t *msg_list_event, size_t current_msg); -char *generate_random_file_name(switch_core_session_t *session, const char *mod_name, char *file_extension); +char *generate_random_file_name(switch_core_session_t *session, const char *mod_name, const char *file_extension); switch_event_t *jsonapi2event(switch_core_session_t *session, switch_event_t *apply_event, const char *api, const char *data); -switch_status_t vmivr_merge_media_files(const char** inputs, const char *output); +switch_status_t vmivr_merge_media_files(const char** inputs, const char *output, int rate); switch_status_t vmivr_api_execute(switch_core_session_t *session, const char *apiname, const char *arguments); #endif /* _UTIL_H_ */