Show / Hide Table of Contents

    Custom IVR Template: Interval Check Template

    Purpose of the Template


    Provides two exit points based on whether the current time is inside or outside of a defined time interval.

    Template Data Sheet

    Name Minimum Engine version Minimum Designer version
    IntervalCheck 3.1 7.5.0

    Parameters

    Name Description
    starttime the start time of the interval
    endtime the end time of the interval

    Exit Points

    Name Description
    inside The current time is between starttime and endtime.
    outside When the current time is outside of the interval.
    error An error happened

    JSON

    {
      "name": "Intervalcheck",
      "type": "template",
      "description": "<b>Intervalcheck</b> template:<br/> Intervalcheck.",
      "attributes": [
        {
          "name": "id",
          "type": "integer",
          "defaultvalue": "2000"
        }
      ],
      "parameters": [
        {
          "name": "m_compsrvurl"
        },
        {
          "name": "starttime"
        },
        {
          "name": "endtime"
        }
      ],
      "connections": [
        {
          "name": "outside"
        },
        {
          "name": "inside"
        },
        {
          "name": "error"
        }
      ]
    }
    

    XML

    <template name="Intervalcheck" id="#ID#" version='1.0'>
      <constraints>
        <errors />
        <warnings MinIncomingConnections="1" AllConnectionsRequired="true" AllAttributesRequired="true" />
      </constraints>
    
      <parameters>
        <parameter id="m_compsrvurl"><![CDATA[#M_COMPSRVURL#]]></parameter>
        <parameter id="starttime"><![CDATA[#STARTTIME#]]></parameter>
        <parameter id="endtime"><![CDATA[#ENDTIME#]]></parameter>
      </parameters>
    
      <connections namedoutputs="true">
        <connection name="outside" destination="#OUTSIDE#" />
        <connection name="inside" destination="#INSIDE#" />
        <connection name="error" destination="#ERROR#" />
      </connections>
    
      <flow>
        <nodes>
          <script id="1" entrypoint="true">
            <parameters>
              <parameter id="m_compsrvurl" type="Variable" datatype="String" direction="Input"><![CDATA[?]]></parameter>
              <parameter id="starttime" type="Variable" datatype="string" direction="Input"><![CDATA[?]]></parameter>
              <parameter id="endtime" type="Variable" datatype="string" direction="Input"><![CDATA[?]]></parameter>
            </parameters>
            <connections namedoutputs="true">
              <connection exitpoint="outside" name="OUTSIDE" destination="?" />
              <connection exitpoint="inside" name="INSIDE" destination="?" />
              <connection exitpoint="error" name="ERROR" destination="?" />
            </connections>
            <data>
              <![CDATA[
    
    function GetCurrentTimeInTenant(compSrvUrl, tenantId) {
    
      var timeoutMs = 10000;
      var mimeType = 'application/jsonrequest';
    
      try {
      
        var client = toolkit.getJSonRetriever();
    
        var currentTimeReq = {};
        currentTimeReq['action'] = 'CurrentTime';
        currentTimeReq["tenant"] = parseInt(tenantId);
    
        var currentTimeResp = client.postData(compSrvUrl, timeoutMs, 
          JSON.stringify(currentTimeReq), mimeType);
    
        if(currentTimeResp != null) {
    
          log.debug('Current time response: ' + currentTimeResp);
        
          var jCurrentTimeResp = JSON.parse(currentTimeResp);
    
          if ((''+jCurrentTimeResp['result']) == 'TRUE') {
    
            var now = System.DateTime.Parse(jCurrentTimeResp['currenttime']);
            return now;
          }
        }
    
        return null;
      }
      catch(ex){
      
        log.error('Failed to get current time in the specified tenant:' + ex);
        return null;
      }
    }
    
    try {
    
      var url = '' + LOCALS['m_compsrvurl'];
      var sstarttime = LOCALS["starttime"];
      var sendtime = LOCALS["endtime"];
      var tenantid = flowvars['TENANT_ID'];
    
      log.debug('Init done. CompSrvUrl: ' + url 
        + ', TenantId: ' + tenantid 
        + ', StartTime: ' + sstarttime
        + ', EndTime: ' + sendtime);
    
      var now = GetCurrentTimeInTenant(url, tenantid);
    
      if(now != null) {
    
        var minutes = now.getHours() * 60 + now.getMinutes();
    
        var a = sstarttime.split(":");
        var st = parseInt(a[0]) * 60 + parseInt(a[1]);
        a = sendtime.split(":");
        var et = parseInt(a[0]) * 60 + parseInt(a[1]);
    
        log.debug("current minutes:" + minutes);
        log.debug("starttime:" + st);
        log.debug("endtime:" + et);
          
        if (isNaN(st) || isNaN(et)) {
    
          $$nextConnection$$ = "OUTSIDE";
        } 
        else {
    
          if (minutes < st) {
    
                $$nextConnection$$ = "OUTSIDE";
          } 
          else if (minutes > et) {
    
                $$nextConnection$$ = "OUTSIDE";
          } 
          else {
    
                $$nextConnection$$ = "INSIDE";
          }
        }
      }
      else {
      
        $$nextConnection$$ = 'ERROR';
        log.error('Failed to retrieve current time in tenant: ' + tenantid);
      }
    } 
    catch (err) {
    
      $$nextConnection$$ = 'ERROR';
      log.error('Error in script:' + err);
    }
    
    log.debug('Script Done: nextConnection=' + $$nextConnection$$);
              ]]>
            </data>
          </script>
        </nodes>
      </flow>
    </template>
    
    Sorry, your browser does not support inline SVG. article updatedarticle updated2/21/2024 3:19:17 PM (UTC)2/21/2024 3:19:17 PM (UTC)
    Feedback     Back to top Copyright © Geomant