SMS VXML Application

This page is dedicated for VXML sample app development for demo of SMS API for Omnichannel.

Try It!
  1. Set your Application URL to http://studio.247-inc.net/library2/code/ex-123/index.vxml
  2. Call the number shown in VXML Tools page
  3. Sign in, and play!

VXML app development is planned with below flow:

  • Call the number where you have hosted the vxml app,a welcome message will be prompted and the user will be asked to record personal greetings.
  • Once the user records the message;vxml app will call Webreco API to convert the user greeting message to text.
  • Message recorded will be played back to user again to let them know that this message will be sent as a text in SMS.
  • The thus converted text will be used as text parameter for twilio API;vxml app will call the SMS API with recorded text and the user will receive the desired SMS.

  • The SMS VXML Application Code for this example follows:

    <?xml version="1.0"?>
    <vxml version="2.1" xmlns="http://www.w3.org/2001/vxml">
    
    <!-- App Purpose : Dictation service to enable speech to text conversion -->
    
    <script src="js/hmac-sha256.js" />
    <script src="js/enc-base64-min.js" />
    <script src="js/lib/xml/XMLObject.js" />
    <script src="js/DictUtil.js" />
      
    <!-- Set these variables with webreco url,  authentication id/key and grammar to be used. -->
    <var name="clientId" expr="'tm-dev'"/>
    <var name="sharedKey" expr="'asHTRE#$#Fasef!'"/>
    <var name="webrecoUrl" expr="'https://webreco.in.tellme.com/reco'"/>
    <var name="grammar1" expr="'http://gs1.tm-dev.reco.tellme.com/websearch'" />
    
    <var name="SmsUrl" expr="'https://twilio-sms.data.247-inc.net/send_sms.pl'"/>
    <var name="MessagingSourceID" expr="'18668001352'"/>
    <var name="to" expr="'919535273449'"/>
    <var name="text" expr="'ab'"/>
    
    <var name="audio" />
       <form id="main">
          <block name="block1">
            <audio src=""> Welcome to dication sample </audio>
            <goto next="#record_user_audio" />
    	  </block>
       </form>
    
       <form id="record_user_audio">
           <record name="user_audio" maxtime="60s" dtmfterm="true" beep="true" type="audio/wav">
             <prompt>
                At the tone, please record your personal greeting. When you're done, press pound. 
             </prompt>
    
             <!-- if the user doesn't say anything 
                within finalsilence, catch the noinput -->
             <noinput>
             Sorry. I didn't hear you. Now returning to the main menu.
             <exit />
             </noinput>
    
             <filled>
                 <!-- demo record shadow variables -->
                 <log>Dict: recording size =  <value expr="user_audio$.size"/> bytes.</log>
                 <log>Dict: recording duration = <value expr="user_audio$.duration"/> milliseconds.</log>
                 <log>Dict: dtmf key = <value expr="(user_audio$.termchar? user_audio$.termchar : 'none')"/></log>
                 <log>Dict: maxtime = <value expr="user_audio$.maxtime"/>.</log>
                 <log>Dict: ALL = <value expr="user_audio"/>.</log>
    
             </filled>
          </record>
    
    	<!-- PlayBack Audio to User-->
    	<block name="playback">
                     A message will be sent to you with content		
    		<break size="small"/>
    		<audio expr="user_audio"/>
    		<assign name="audio" expr="user_audio"/>
    	</block>
    
    	<!-- Use Webreco Api to get Dictation Text--> 
    	<block name="UseWebrecoApi">   
    
    		<script> <![CDATA[
    			 var date = new Date();
    			 var tm = date.toUTCString();
    			 var data = tm+'\n/'+clientId+'/WebReco';
    			 var digest = CryptoJS.HmacSHA256(data,sharedKey);
    			 var auth = CryptoJS.enc.Base64.stringify(digest);
    			 var authorization='SharedKeyLite:'+tm+':'+clientId+':'+auth;
    		]]> </script>
    
    		<data name="dictText" srcexpr="webrecoUrl" namelist="authorization grammar1 audio" method="POST" 
    			enctype="multipart/form-data" fetchtimeout="20s"/>                    
    
    		<script> <![CDATA[
    			 var emmaResult = getEmmaText(dictText);
    			 var emmaResultstate= emmaResult.state;  
    			 var emmaResulterrText = emmaResult.errText ;  
    			 var emmaResultText= emmaResult.text ;  
    
    		]]> </script>
                 <assign name="text" expr="emmaResultText" />
               <data name="dictText1" srcexpr="SmsUrl" namelist="MessagingSourceID to text" method="POST"
                            enctype="application/x-www-form-urlencoded" fetchtimeout="20s"/>
    
    	<!--Printing Result -->
    	<if cond = "emmaResultstate==EmmaResultState.SUCCESS" >
    	  result is success 
    	   <log>Dictation Text: <value expr="emmaResultText"/></log>
    	<elseif cond= "emmaResultstate==EmmaResultState.NO_INPUT" />
    	  result is No Input 
    	<elseif cond = "emmaResultstate==EmmaResultState.UNINTERPRETED" />
    	  result could not be interpreted  
    	<else/>
    	  Error Encountered
    	   <log>Dictation Error :<value expr="emmaResulterrText"/></log>
    	</if>
    
    	</block>
    
       </form>
    </vxml>
    
    
    

    [24]7 Inc.| Terms of Service| Privacy Policy| General Disclaimers