]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
mod_protovm: Add Message Forwarding Capability (Require a mod_voicemail patch that...
authorMarc Olivier Chouinard <mochouinard@moctel.com>
Fri, 8 Jul 2011 23:26:43 +0000 (19:26 -0400)
committerMarc Olivier Chouinard <mochouinard@moctel.com>
Fri, 8 Jul 2011 23:26:43 +0000 (19:26 -0400)
src/mod/applications/mod_protovm/config.c
src/mod/applications/mod_protovm/config.h
src/mod/applications/mod_protovm/menu.c
src/mod/applications/mod_protovm/menu.h
src/mod/applications/mod_protovm/protovm.conf.xml
src/mod/applications/mod_protovm/sounds.xml

index feec69b79eaa01cbb06933fc043254bdc5f8174e..6a2573b83ab4ab03aab77dcd02ffa185ea2c878b 100644 (file)
@@ -76,6 +76,9 @@ vmivr_profile_t *get_profile(switch_core_session_t *session, const char *profile
 
                profile->name = profile_name;
 
+               profile->current_msg = 0;
+               profile->current_msg_uuid = NULL;
+
                /* TODO Make the following configurable */
                profile->api_profile = profile->name;
                profile->menu_check_auth = "std_authenticate";
@@ -102,6 +105,8 @@ vmivr_profile_t *get_profile(switch_core_session_t *session, const char *profile
                                                profile->api_msg_purge = switch_core_session_strdup(session, val);
                                        else if (!strcasecmp(var, "msg_get") && !profile->api_msg_get)
                                                profile->api_msg_get = switch_core_session_strdup(session, val);
+                                       else if (!strcasecmp(var, "msg_forward") && !profile->api_msg_forward)
+                                               profile->api_msg_forward = switch_core_session_strdup(session, val);
                                        else if (!strcasecmp(var, "pref_greeting_set") && !profile->api_pref_greeting_set)
                                                profile->api_pref_greeting_set = switch_core_session_strdup(session, val);
                                        else if (!strcasecmp(var, "pref_recname_set") && !profile->api_pref_recname_set)
@@ -115,7 +120,7 @@ vmivr_profile_t *get_profile(switch_core_session_t *session, const char *profile
                                        total_options++;
                                }
                        }
-                       if (total_options - total_invalid_options != 11) {
+                       if (total_options - total_invalid_options != 12) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing api definition for profile '%s'\n", profile_name);
                                profile = NULL;
                        }
index 04713fb7ae33bd670cbd46a4042cd64f3e92c7db..b5beeeaca1fcab945d3b4efbec81a9c76a674250 100644 (file)
@@ -9,6 +9,9 @@ struct vmivr_profile {
        const char *domain;
        const char *id;
 
+       int current_msg;
+       const char *current_msg_uuid;
+
        const char *menu_check_auth;
        const char *menu_check_main;
        const char *menu_check_terminate;
@@ -24,6 +27,7 @@ struct vmivr_profile {
        const char *api_msg_save;
        const char *api_msg_purge;
        const char *api_msg_get;
+       const char *api_msg_forward;
        const char *api_pref_greeting_set;
        const char *api_pref_recname_set;
        const char *api_pref_password_set;
index 4dc3e19e780f3e2664912b1e0f793d9ab20d1fb8..d6eb3d1576229438f8bc045a42a5918760dc2870 100644 (file)
@@ -46,6 +46,7 @@ vmivr_menu_function_t menu_list[] = {
        {"std_record_greeting_with_slot", mtvm_menu_record_greeting_with_slot},
        {"std_preference", mtvm_menu_preference},
        {"std_purge", mtvm_menu_purge},
+       {"std_forward", mtvm_menu_forward},
        { NULL, NULL }
 };
 
@@ -83,7 +84,7 @@ void mtvm_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) {
        populate_profile_menu_event(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");
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys\n");
                return;
        }
 
@@ -137,6 +138,10 @@ void mtvm_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) {
                /* Prompt related the current message */
                append_event_message(session, profile, phrase_params, msg_list_params, current_msg);
 
+               /* Save in profile the current msg info for other menu processing AND restoration of our current position */
+               profile->current_msg = current_msg;
+               profile->current_msg_uuid = switch_core_session_strdup(session, switch_event_get_header(phrase_params, "VM-Message-UUID"));
+               
                /* TODO check if msg is gone (purged by another session, notify user and auto jump to next message or something) */
                if (!skip_header) {
                        if (!initial_count_played) {
@@ -176,7 +181,8 @@ void mtvm_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) {
                                } else if (!strcasecmp(action, "prev_msg")) { /* Previous Message */
                                        next_msg--;
                                } else if (!strcasecmp(action, "delete_msg")) { /* Delete / Undelete Message */
-                                       if (strncasecmp(switch_event_get_header(phrase_params, "VM-Message-Flags"), "delete", 6)) {
+                                       const char *msg_flags = switch_event_get_header(phrase_params, "VM-Message-Flags");
+                                       if (!msg_flags || strncasecmp(msg_flags, "delete", 6)) {
                                                cmd = switch_core_session_sprintf(session, "%s %s %s %s", profile->api_profile, profile->domain, profile->id, switch_event_get_header(phrase_params, "VM-Message-UUID"));
                                                mt_api_execute(session, profile->api_msg_delete, cmd);
 
@@ -222,6 +228,120 @@ void mtvm_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) {
        return;
 }
 
+void mtvm_menu_forward(switch_core_session_t *session, vmivr_profile_t *profile) {
+
+       vmivr_menu_profile_t menu = { "std_forward_ask_prepend" };
+       switch_channel_t *channel = switch_core_session_get_channel(session);
+       const char *prepend_filepath = NULL;
+       int retry;
+       switch_bool_t forward_msg = SWITCH_FALSE;
+
+       /* Initialize Menu Configs */
+       populate_profile_menu_event(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;
+       }
+
+       for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) {
+               dtmf_ss_t loc;
+               char *dtmfa[16] = { 0 };
+               switch_event_t *phrase_params = NULL;
+
+               switch_event_create(&phrase_params, SWITCH_EVENT_REQUEST_PARAMS);
+               append_event_profile(phrase_params, profile, menu);
+
+               populate_dtmfa_from_event(phrase_params, profile, menu, dtmfa);
+
+               captureMenuInitialize(&loc, dtmfa);
+
+               captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, phrase_params, NULL, DEFAULT_IVR_TIMEOUT);
+
+               if (loc.result == RES_TIMEOUT) {
+                       /* TODO Ask for the prompt Again IF retry != 0 */
+               } else if (loc.result == RES_INVALID) {
+                       /* TODO Say invalid option, and ask for the prompt again IF retry != 0 */
+               } else if (loc.result == RES_FOUND) {  /* Matching DTMF Key Pressed */
+                       const char *action = switch_event_get_header(menu.event_keys_dtmf, loc.dtmf_stored);
+
+                       /* Reset the try count */
+                       retry = MAX_ATTEMPT;
+
+                       if (action) {
+                               if (!strcasecmp(action, "return")) { /* Return to the previous menu */
+                                       retry = -1;
+                                       forward_msg = SWITCH_FALSE;
+                               } else if (!strcasecmp(action, "prepend")) { /* Prepend record msg */
+                                       vmivr_menu_profile_t sub_menu = { "std_record_message" };
+                                       char *tmp_filepath = generate_random_file_name(session, "protovm", "wav" /* TODO make it configurable */);
+                                       switch_status_t status;
+
+                                       /* Initialize Menu Configs */
+                                       populate_profile_menu_event(profile, &sub_menu);
+
+                                       status =  mtvm_menu_record(session, profile, sub_menu, tmp_filepath);
+
+                                       if (status == SWITCH_STATUS_SUCCESS) {
+                                               //char *cmd = switch_core_session_sprintf(session, "%s %s %s %d %s", profile->api_profile, profile->domain, profile->id, gnum, tmp_filepath);
+                                               //char *str_num = switch_core_session_sprintf(session, "%d", gnum);
+                                               //mt_api_execute(session, profile->api_pref_greeting_set, cmd);
+                                               //playbackBufferDTMF(session, switch_event_get_header(menu.event_phrases, "selected_slot"), str_num, NULL, NULL, 0);
+                                               prepend_filepath = tmp_filepath;
+                                               retry = -1;
+                                               forward_msg = SWITCH_TRUE;
+                                       } else {
+                                               /* TODO Error Recording msg */
+                                       }
+                                       free_profile_menu_event(&sub_menu);
+
+                               } else if (!strcasecmp(action, "forward")) { /* Forward without prepend msg */
+                                       retry = -1;
+                                       forward_msg = SWITCH_TRUE;
+                               } else if (!strncasecmp(action, "menu:", 5)) { /* Sub Menu */
+                                       void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = mtvm_get_menu_function(action+5);
+                                       if (fPtr) {
+                                               fPtr(session, profile);
+                                       }
+                               }
+                       }
+               }
+               switch_event_destroy(&phrase_params);
+
+
+       }
+       /* Ask Extension to Forward */
+       if (forward_msg) {
+               for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) {
+                       const char *id = NULL;
+                       vmivr_menu_profile_t sub_menu = { "std_forward_ask_extension" };
+
+                       /* Initialize Menu Configs */
+                       populate_profile_menu_event(profile, &sub_menu);
+
+                       id = mtvm_menu_get_input_set(session, profile, sub_menu, "X.", "#" /* TODO Conf terminate input key */);
+                       if (id) {
+                               const char *cmd = switch_core_session_sprintf(session, "%s %s %s %s %s %s %s%s%s", profile->api_profile, profile->domain, profile->id, profile->current_msg_uuid, profile->domain, id, prepend_filepath?" ":"", prepend_filepath?prepend_filepath:"" );
+                               if (mt_api_execute(session, profile->api_msg_forward, cmd) == SWITCH_STATUS_SUCCESS) {
+                                       playbackBufferDTMF(session, switch_event_get_header(sub_menu.event_phrases, "ack"), "saved", NULL, NULL, 0);
+                                       retry = -1;
+                               } else {
+                                       playbackBufferDTMF(session, switch_event_get_header(sub_menu.event_phrases, "invalid_extension"), NULL, NULL, NULL, 0);
+                               }
+                       } else {
+                               /* TODO Prompt about input not valid */
+                       }
+                       free_profile_menu_event(&sub_menu);
+                       /* TODO add Confirmation of the transfered number */
+               }
+               /* TODO Ask if we want to transfer the msg to more person */
+
+       }
+
+       free_profile_menu_event(&menu);
+}
+
+
 void mtvm_menu_record_name(switch_core_session_t *session, vmivr_profile_t *profile) {
        switch_status_t status;
        vmivr_menu_profile_t menu = { "std_record_name" };
@@ -298,7 +418,6 @@ void mtvm_menu_authenticate(switch_core_session_t *session, vmivr_profile_t *pro
        free_profile_menu_event(&menu);
 }
 
-
 void mtvm_menu_select_greeting_slot(switch_core_session_t *session, vmivr_profile_t *profile) {
        vmivr_menu_profile_t menu = { "std_select_greeting_slot" };
 
index a2d8cb09f5fa53c20e25feba2ca08fd1bd4cff31..0ef4e532e682df6cdd5069e6e82b5be8261f9aa7 100644 (file)
@@ -11,6 +11,7 @@ void mtvm_menu_set_password(switch_core_session_t *session, vmivr_profile_t *pro
 void mtvm_menu_select_greeting_slot(switch_core_session_t *session, vmivr_profile_t *profile);
 void mtvm_menu_record_greeting_with_slot(switch_core_session_t *session, vmivr_profile_t *profile);
 void mtvm_menu_preference(switch_core_session_t *session, vmivr_profile_t *profile);
+void mtvm_menu_forward(switch_core_session_t *session, vmivr_profile_t *profile);
 
 switch_status_t mtvm_menu_record(switch_core_session_t *session, vmivr_profile_t *profile, vmivr_menu_profile_t menu, const char *file_name);
 char *mtvm_menu_get_input_set(switch_core_session_t *session, vmivr_profile_t *profile, vmivr_menu_profile_t menu, const char *input_mask, const char *terminate_key);
index e25b8760c864b3785985acf2d069992f2a275b90..852f6686e1451c3c917093457b5976787d51f743 100644 (file)
@@ -10,6 +10,7 @@
                        <api name="msg_save" value="vm_fsdb_msg_save" />
                        <api name="msg_purge" value="vm_fsdb_msg_purge" />
                        <api name="msg_get" value="vm_fsdb_msg_get" />
+                       <api name="msg_forward" value="vm_fsdb_msg_forward" />
                        <api name="pref_greeting_set" value="vm_fsdb_pref_greeting_set" />
                        <api name="pref_recname_set" value="vm_fsdb_pref_recname_set" />
                        <api name="pref_password_set" value="vm_fsdb_pref_password_set" />
@@ -55,6 +56,7 @@
                                <key dtmf="6" action="next_msg" variable="VM-Key-Main-Next-Msg" />
                                <key dtmf="4" action="prev_msg" />
                                <key dtmf="7" action="delete_msg" variable="VM-Key-Main-Delete-File" /> <!-- Same key for undelete if it already deleted -->
+                               <key dtmf="8" action="menu:std_forward" variable="VM-Key-Main-Forward" />
                                <key dtmf="3" action="save_msg" variable="VM-Key-Main-Save-File" />
                                <key dtmf="5" action="menu:std_preference" />
                        </keys>
                        </keys>
                        </menu>
 
-                   
+                       <menu name="std_record_message">
+                       <phrases>
+                               <phrase name="instructions" value="record_message@protovm" />
+                               <phrase name="play_recording" value="play_recording@protovm" />
+                               <phrase name="menu_options" value="record_file_check@protovm" />
+                       </phrases>
+                       <keys>
+                               <key dtmf="1" action="listen" variable="VM-Key-Listen-File" />
+                               <key dtmf="3" action="save" variable="VM-Key-Save-File" />
+                               <key dtmf="4" action="rerecord" variable="VM-Key-ReRecord-File" />
+                               <key dtmf="#" action="skip_instruction" />
+                       </keys>
+                       </menu>                 
+
+                       <menu name="std_forward_ask_prepend">
+                       <phrases>
+                               <phrase name="menu_options" value="forward_ask_prepend@protovm" />
+                       </phrases>
+                       <keys>
+                               <key dtmf="1" action="prepend" variable="VM-Key-Prepend" />
+                               <key dtmf="8" action="forward" variable="VM-Key-Forward" />
+                               <key dtmf="#" action="return" variable="VM-Key-Return" />
+                       </keys>
+                       </menu>
+
+                       <menu name="std_forward_ask_extension">
+                       <phrases>
+                               <phrase name="instructions" value="forward_ask_extension@protovm" />
+                               <phrase name="ack" value="ack@protovm" />
+                               <phrase name="invalid_extension" value="invalid_extension@protovm" />
+                       </phrases>
+                       <keys>
+                       </keys>
+                       </menu>
 
                        <menu name="std_select_greeting_slot">
                        <phrases>
index 1760e7cc0764f7b66b5ff40a34c1058e8c4da305..45f5767ef918f4597eccd0c7986d2c593c8daa2a 100644 (file)
@@ -1,5 +1,5 @@
 <include><!--This line will be ignored it's here to validate the xml and is optional -->
-  <macros name="protovm" sound-prefix="$${sounds_dir}/fr/ca/june"> 
+  <macros name="protovm" sound-prefix="$${sounds_dir}/en/us/callie"> 
     <macro name="press_key">
       <input pattern="^(.*):(.*)$">
         <match>
         </match>
       </input>
     </macro>
+
+    <macro name="forward_ask_prepend">
+      <input>
+        <match>
+        <action function="phrase" phrase="press_key@protovm" data="${VM-Key-Prepend}:voicemail/vm-forward_add_intro.wav"/>
+        <action function="phrase" phrase="press_key@protovm" data="${VM-Key-Forward}:voicemail/vm-send_message_now.wav"/>
+        </match>
+      </input>
+    </macro>
+
+    <macro name="forward_ask_extension">
+      <input>
+        <match>
+        <action function="play-file" data="voicemail/vm-forward_enter_ext.wav"/>
+<!--   <action function="phrase" phrase="play-file" data="voicemail/vm-followed_by.wav"/>
+       <action function="say" data="${VM-Key-Terminate}" method="pronounced" type="name_spelled"/>-->
+        </match>
+      </input>
+    </macro>
   
     <macro name="record_file_check">
       <input>
         </match>
       </input>
     </macro>
+
   
     <macro name="record_urgent_check">
       <input>
        <action function="phrase" phrase="press_key@protovm" data="${VM-Key-Main-Listen-File}:voicemail/vm-listen_to_recording.wav"/>
        <action function="phrase" phrase="press_key@protovm" data="${VM-Key-Main-Save-File}:voicemail/vm-save_recording.wav"/>
        <action function="phrase" phrase="press_key@protovm" data="${VM-Key-Main-Delete-File}:voicemail/vm-delete_recording.wav"/>
+       <action function="phrase" phrase="press_key@protovm" data="${VM-Key-Main-Forward}:voicemail/vm-to_forward.wav"/>
        </match>
       </input>
       <input field="${VM-Message-Email}" pattern="^$">