<?xml version="1.0" encoding="utf-8"?>
<!--
//  Copyright (C) 2006 Microsoft Corporation.  All rights reserved.
//  The xml file that describes the finite state machine.
-->
<FiniteStateMachine>
	<FsmModule>

		<Menu id="jumpToPlayOnPhoneAA">
			<Transition event="noKey" action="null" refId="playOnPhoneAA"/>
		</Menu>

		<PlayOnPhoneAAManager id="playOnPhoneAA" firstActivityId="CheckFile">
			
			<!-- Uncaught exceptions -->
			<Transition event="timeout" action="null" refId="Error"/>
			<Transition event="xsoError" action="null" refId="Error"/>
			<Transition event="faxtone" action="SetOperationResultFailed" refId="EndCall"/>

			<!-- Check if the file specified already exists -->
			<Menu id="CheckFile" minDtmfSize="0" maxDtmfSize="0" dtmfInputValue="option">
				<Transition event="noKey" condition="NOT FileExists" action="null" refId="RecordGreeting"/>
				<Transition event="noKey" condition="FileExists" action="null" refId="PlayExistingFile"/>
			</Menu>

			<Menu id="PlayExistingFile" minDtmfSize="1" maxDtmfSize="1" dtmfInputValue="option">
				<Prompt type="statement" condition="PlayingExistingGreetingFirstTime" name="tuiPOPAAGreetingExists"/>
				<Prompt type="varwave" name="ExistingFilePath"/>
				<Prompt type="statement" name="tuiPOPAAGreetingExistsOptions"/>
				<Transition event="1" action="null" refId="RecordGreeting"/>
				<Transition event="2" action="ExistingGreetingAlreadyPlayed" refId="PlayExistingFile"/>
			</Menu>		

			<Menu id="RecordGreeting" minDtmfSize="0" maxDtmfSize="1" dtmfInputValue="option">
				<Transition event="noKey" action="null" refId="RecordPrompt"/>
				<Transition event="#" action="null" refId="RecordPrompt"/>
				<Prompt type="statement" name="tuiPPRecordPromptIntro"/>
			</Menu>

			<Record id = "RecordPrompt" dtmfStopTones="#"  type="greeting">
				<Transition event="anyKey" action="null" refId="PlayRecording" />
				<Transition event="silence" action="null" refId="HandleSilence" />
				<Transition event="timeout" action="null" refId="HandleMaxDuration" />
			</Record>

			<Menu id = "HandleSilence">
				<Prompt condition="IsNull(recording)" type="statement" name="tuiAreYouThere"/>
				<Transition condition="IsNull(recording)" event="noKey" action="null" refId="RecordGreeting"/>
				<Transition condition="NOT IsNull(recording)" event="noKey" action="null" refId="PlayRecording"/>
			</Menu>

			<Menu id="HandleMaxDuration">
				<Prompt type="statement" name="tuiGreetingRecordingTooLong"/>
				<Transition event="noKey" action="null" refId="PlayRecording"/>
			</Menu>

			<Menu id="PlayRecording">
				<Prompt condition="NOT IsNull(recording)" type="tempwave" name="recording"/>
				<Transition event="noKey" action="null" refId="AfterRecordingMenu"/>
			</Menu>

			<Menu id="AfterRecordingMenu" minDtmfSize="1" maxDtmfSize="1" dtmfInputValue="option">
				<Prompt type="statement" name="tuiPPAfterRecordingMenu"/>
				<Transition event="*" action="clearRecording" refId="RecordingCancelled"/>
				<Transition event="0" action="null" refId="AfterRecordingMenu"/>
				<Transition event="1" action="SaveGreeting" heavyaction="true" refId="RecordingAccepted"/>
				<Transition event="failedToSaveGreeting" action="null" refId="Error"/>
				<Transition event="2" action="clearRecording" refId="RecordGreeting"/>
			</Menu>

			<Menu id="RecordingCancelled">
				<Prompt type="statement" name="tuiPPRecordingCancelled"/>
				<Transition event="noKey" action="null" refId="Goodbye"/>
			</Menu>

			<Menu id="RecordingAccepted">
				<Prompt type="statement" name="tuiPPRecordingAccepted"/>
				<Transition event="noKey" action="null" refId="Goodbye"/>
			</Menu>

			<Menu id="Error">
				<Prompt type="statement" name="tuiSystemError"/>
				<Transition event="noKey" action="SetOperationResultFailed" refId="EndCall"/>
			</Menu>

			<Menu id="Goodbye">
				<Prompt type="statement" name="tuiGoodbye"/>
				<Transition event="noKey" action="null" refId="EndCall"/>
			</Menu>

			<Menu id="EndCall">
				<Transition event="noKey" action="disconnect" refId="EndCall"/>
			</Menu>

		</PlayOnPhoneAAManager>

	</FsmModule>
</FiniteStateMachine>

