コード例 #1
0
void mtvm_menu_preference(switch_core_session_t *session, vmivr_profile_t *profile) {
	switch_channel_t *channel = switch_core_session_get_channel(session);

	int retry;

	vmivr_menu_profile_t menu = { "std_preference" };

	/* 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;
				} 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);
	}

	free_profile_menu_event(&menu);
}
コード例 #2
0
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) {
	char *result = NULL;
	int retry;

	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;
	}

	for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) {
		dtmf_ss_t loc;
		char *dtmfa[16] = { 0 };
		int i;
		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);
		
		/* Find the last entry and append this one to it */
		for (i=0; dtmfa[i] && i < 16; i++){
		}
                dtmfa[i] = (char *) input_mask;

		captureMenuInitialize(&loc, dtmfa);
		if (terminate_key)
			loc.terminate_key = terminate_key[0]; /* TODO Make this load from the configuration */
		captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "instructions"), 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 */

			/* Reset the try count */
			retry = MAX_ATTEMPT;

			if (!strncasecmp(loc.completeMatch, input_mask, 1)) {
				result = switch_core_session_strdup(session, loc.dtmf_stored);
				retry = -1;

			}
		}
		switch_event_destroy(&phrase_params);
	}

	return result;
}
コード例 #3
0
ファイル: config.c プロジェクト: konradwyr/FreeSwitch
void menu_instance_init(vmivr_menu_t *menu) {
	append_event_profile(menu);

	populate_dtmfa_from_event(menu);
}
コード例 #4
0
void mtvm_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) {
	switch_channel_t *channel = switch_core_session_get_channel(session);
	switch_event_t *msg_list_params = NULL;
	size_t msg_count = 0;
	size_t current_msg = 1;
	size_t next_msg = current_msg;
	size_t previous_msg = current_msg;
	char *cmd = NULL;
	int retry;

	/* Different switch to control playback of phrases */
	switch_bool_t initial_count_played = SWITCH_FALSE;
	switch_bool_t skip_header = SWITCH_FALSE;
	switch_bool_t msg_deleted = SWITCH_FALSE;
	switch_bool_t msg_undeleted = SWITCH_FALSE;
	switch_bool_t msg_saved = SWITCH_FALSE;

	vmivr_menu_profile_t menu = { "std_navigator" };

	/* 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;
	}

	/* Get VoiceMail List And update msg count */
	cmd = switch_core_session_sprintf(session, "json %s %s %s", profile->api_profile, profile->domain, profile->id);
	msg_list_params = jsonapi2event(session, NULL, profile->api_msg_list, cmd);
	msg_count = atol(switch_event_get_header(msg_list_params,"VM-List-Count"));

	/* TODO Add Detection of new message and notify the user */

	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);

		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;

		captureMenuInitialize(&loc, dtmfa);

		/* Prompt related to previous Message here */
		append_event_message(session, profile, phrase_params, msg_list_params, previous_msg);
		if (msg_deleted) {
			msg_deleted = SWITCH_FALSE;
			captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "ack"), "deleted", phrase_params, NULL, 0);
		}
		if (msg_undeleted) {
			msg_undeleted = SWITCH_FALSE;
			captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "ack"), "undeleted", phrase_params, NULL, 0);
		} 
		if (msg_saved) {
			msg_saved = SWITCH_FALSE;
			captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "ack"), "saved", phrase_params, NULL, 0);
		}

		/* Prompt related the current message */
		append_event_message(session, profile, phrase_params, msg_list_params, current_msg);

		/* 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) {
				cmd = switch_core_session_sprintf(session, "json %s %s %s", profile->api_profile, profile->domain, profile->id);
				jsonapi2event(session, phrase_params, profile->api_msg_count, cmd);
				initial_count_played = SWITCH_TRUE;
				captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "msg_count"), NULL, phrase_params, NULL, 0);
			}
			if (msg_count > 0) {
				captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "say_msg_number"), NULL, phrase_params, NULL, 0);
				captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "say_date"), NULL, phrase_params, NULL, 0);
			}
		}
		if (msg_count > 0) {
			/* TODO Update the Read date of a message (When msg start, or when it listen compleatly ??? To be determined */
			captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "play_message"), NULL, phrase_params, NULL, 0);
		}
		skip_header = SWITCH_FALSE;

		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, "skip_intro")) { /* Skip Header / Play the recording again */
					skip_header = SWITCH_TRUE;
				} else if (!strcasecmp(action, "next_msg")) { /* Next Message */
					next_msg++;
				} 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)) {
						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);

						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++;
					} else { 
						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_undelete, cmd);

						msg_undeleted = SWITCH_TRUE;
					}
				} else if (!strcasecmp(action, "save_msg")) { /* Save Message */
					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_save, cmd);

					msg_saved = 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);
					}
				} else if (!strcasecmp(action, "return")) { /* Return */
					retry = -1;
				}
			}
		}

		/* IF the API to get the message returned us a COPY of the file locally (temp file create from a DB or from a web server), delete it */
		if (switch_true(switch_event_get_header(phrase_params, "VM-Message-Private-Local-Copy"))) {
			const char *file_path = switch_event_get_header(phrase_params, "VM-Message-File-Path");
			if (file_path && unlink(file_path) != 0) {
				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to delete temp file [%s]\n", file_path);
			}
		}
		switch_event_destroy(&phrase_params);
	}

	switch_event_destroy(&msg_list_params);

	free_profile_menu_event(&menu);

	return;
}
コード例 #5
0
switch_status_t mtvm_menu_record(switch_core_session_t *session, vmivr_profile_t *profile, vmivr_menu_profile_t menu, const char *file_name) {
	switch_status_t status = SWITCH_STATUS_FALSE;
	switch_channel_t *channel = switch_core_session_get_channel(session);
	int retry;

	switch_bool_t record_prompt = SWITCH_TRUE;
	switch_bool_t listen_recording = SWITCH_FALSE;
	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;
	}

	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_file_handle_t fh = { 0 };

		/* TODO Make the following configurable */
		fh.thresh = 200;
		fh.silence_hits = 4;
		//fh.samplerate = 8000;


		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);
		if (record_prompt) {
			if (play_instruction) {
				captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "instructions"), NULL, phrase_params, NULL, 0);
			}
			play_instruction = SWITCH_TRUE;

			captureMenuRecord(session, &loc, phrase_params, file_name, &fh, 30 /* TODO Make max recording configurable */);
		} else {
			if (listen_recording) {
				switch_event_add_header(phrase_params, SWITCH_STACK_BOTTOM, "VM-Record-File-Path", "%s", file_name);
				captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "play_recording"), NULL, phrase_params, NULL, 0);
				listen_recording = SWITCH_FALSE;

			}
			captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, phrase_params, NULL, DEFAULT_IVR_TIMEOUT);
		}

		if (loc.recorded_audio) {
			/* Reset the try count */
			retry = MAX_ATTEMPT;

			/* TODO Check if message is too short */

			record_prompt = SWITCH_FALSE;

		} else 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, "listen")) { /* Listen */
					listen_recording = SWITCH_TRUE;

				} else if (!strcasecmp(action, "save")) {
					retry = -1;
					/* TODO ALLOW SAVE ONLY IF FILE IS RECORDED AND HIGHER THAN MIN SIZE */
					status = SWITCH_STATUS_SUCCESS;

				} else if (!strcasecmp(action, "rerecord")) {
					record_prompt = SWITCH_TRUE;

				} else if (!strcasecmp(action, "skip_instruction")) { /* Skip Recording Greeting */
					play_instruction = SWITCH_FALSE;

				} 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);
					}
				} else if (!strcasecmp(action, "return")) { /* Return */
					retry = -1;
				}
			}
		}
		switch_event_destroy(&phrase_params);
	}
	return status;
}