Jump to: navigation, search

request-inbound-immediate

<scxml version="1.0" xmlns="http://www.w3.org/2005/07/scxml"
	xmlns:queue="www.genesyslab.com/modules/queue"
	xmlns:ixn="http://www.genesyslab.com/modules/interaction"
	xmlns:service="http://www.genesyslab.com/modules/dfm/gsgBasedServices/v1"
	xmlns:ws="http://www.genesyslab.com/modules/ws"
	xmlns:session="www.genesyslab.com/modules/session"
	initial="initial">
	<!--
		This is a basic service which helps an application/end user contact the contact center.  It allows the service developer to customize this logic easily.
		It has the following characteristics:
			It supports only customer initiated voice contacts.
			It stores and maintains application data with the service.
			It returns access information in the response of the Create API.
			It supports very basic access number allocation (random and locking)
			It supports reserving the access information when allocated for the application for a configurable period of time.
			It support the following types of access information:
			Access Number (DNIS) which is to be called by the application
			Access code which is to be supplied by the customer/application when the contact is being established. This provides an extra level of authentication.
	-->
	<datamodel>
		<data id="reqid"/>
		<data id="startSendId" />
	</datamodel>
	<state id="initial">
		<transition event="gms.start" target="handleStart">
			<script>
				<!-- Save this event id so we can respond to it --> 
				_data.startSendId = _event.sendid;
			</script>
		</transition>
	</state>
	<state id="handleStart">
		<onentry>
			<script>
				__Log("ResourceGroup: " + _data._resource_group);
				__Log("ProvideCode: " + _data._provide_code);
				__Log("ANI: " + _data._phone_number);
			</script>
			<!-- Request a resource for this user; that is a phone number and perhaps an access code -->
			<service:reserve requestid="_data.requestId" _id="_sessionid"
				_resource_group="_data._resource_group" _provide_code="_data._provide_code" _phone_number="_data._phone_number" />
		</onentry>
		<transition event="gsgBasedServices.reserve.done" target="waitForCall" >
			<!--
				Build a response to the request; it may include access_number, access_code and/or expiration time
			-->
			<script>
				var myResultSetObject = eval('(' + _event.data.content + ')');
				var result = { _id: _sessionid };
				if ( myResultSetObject.hasOwnProperty( '_access_number' ) )
				result._access_number = myResultSetObject._access_number;
				if ( myResultSetObject.hasOwnProperty( '_access_code' ) )
				result._access_code = myResultSetObject._access_code;
				if ( myResultSetObject.hasOwnProperty( '_expiration_time' ) )
				result._expiration_time = myResultSetObject._expiration_time;
			</script>
			<ws:response requestid="_data.startSendId" resultcode="JSON.stringify( result )" />
			
			<!-- Start an internal timer in case the user doesn't call within the specified time -->
			<send target="'_internal'" event="'timer'" delay="(myResultSetObject.hasOwnProperty( '_expiration_time' ) ? result._expiration_time : _data._ttl) + 's'" />
		</transition>
		<transition event="error.*" target="error" >
			<script>
				var result = { error: uneval( _event ) };
			</script>
			<!-- Send a response to the client indicating that we had some kind of error -->
			<ws:response requestid="_data.startSendId" resultcode="JSON.stringify( result )" />
		</transition>
	</state>
	<state id="waitForCall">
		<transition event="interaction.present" target="ConnectToAgent">
			<!-- 
				When this event is received, it means that the call has been 'attached' to this session by the inboudn scxml;
				It is now under the control of this session and can be handled in any way desired.
			 -->
			<!--
				This would disconnect the caller, but that wouldn't make any sense!
				<ixn:terminate requestid="_data.reqid" interactionid="_genesys.ixn.interactions[0].g_uid" reason="'finished service'" resource="_genesys.ixn.interactions[0].voice.dnis"/>
			-->
		</transition>
		
		<!-- If this event is received it means the caller didn't match into the system withing the expiration time -->
		<transition event="timer" target="exit" />
	</state>
	<!-- The below code is where you would put your routing logic	-->
	<state id="ConnectToAgent">
		<onentry>
			<log expr="'Checking for agent availability in agent group: Billing'"/>
			<!-- Ask Router to find an agent -->
			<queue:submit route="true" timeout="300">
				<queue:targets>
					<queue:target name="'Billing'" type="agentgroup" statserver="'Stat_Server'" />
				</queue:targets>
			</queue:submit>
		</onentry>
		<!-- Agents are available for the DNIS and call is being routed to an agent -->
		<transition event="queue.submit.done" target="AgentConnected"/>
		<!-- Could not get and agent for a period of time so let's try again - NEED TO ADD LOGIC TO NOT RETRY FOREVER -->
		<transition event="error.queue.submit">
			<session:fetch srcexpr="_data.callback_url" method="'post'" type="'application/json'" enctype="'application/x-www-form-urlencoded'">
				<param name="event" expr="'AgentNotAvailable'"/>
				<param name="sessionid" expr="_sessionid"/>
				<param name="end_state" expr="'waiting for voice agent'"/>
				<param name="dialog" expr="'wait_for_agent.html'"/>
			</session:fetch>
			<log expr="'Again checking for agent availability in agent group: Billing'"/>
			<queue:submit route="true" timeout="30">
				<queue:targets>
					<queue:target name="'Billing'" type="agentgroup" statserver="'Stat_Server'" />
				</queue:targets>
			</queue:submit>
		</transition>
	</state>
	<state id="AgentConnected">
		<onentry>
			<send event="'CallTimeout'" delay="'300s'"/>
		</onentry>
		<!-- Interaction is gone so clean up -->
		<transition event="interaction.deleted" target="exit">
			<assign location="_data.ixnid" expr="''"/>
		</transition>
		<!-- The call has been over 5 minutes -->
		<transition event="CallTimeout" target="exit"/>
	</state>
	<final id="exit"/>
	<final id="error"/>
</scxml>
This page was last modified on February 28, 2013, at 10:28.

Feedback

Comment on this article:

blog comments powered by Disqus