Show / Hide Table of Contents

    Custom IVR Template: Advanced Praying Time

    Calls can be diverted on a single day (1day only) between given time intervals.

    AdvancedPrayTime only works on a single day of the week between given times but you can freely change what day of the week and between what hours will it be active.

    A few examples:
    Let's assume you want to allow pray-time on Sunday. For this you should create a new variable, call it prayer_day_sun and have the integer value 0 assigned. Then, assign prayer_day_sun to the m_prayer_day parameter. This will provide praytime on Sunday -- and only on Sunday -- between the start/stop times.

    Likewise, if you would like to change the start time to 13:00 and the end time to 14:15, then you would assign string "13:00" to the m_prayer_start_time variable and "14:15" to the m_prayer_stop_time variable. Since these variables are already assigned to the respective parameters of AdvancedPrayTime, you don't need to re-assign them.

    Template Data Sheet

    Name Minimum Engine version Minimum Designer version
    AdvancedPrayTime 2.1 7.5.0

    Parameters

    Name Description
    m_compsrvurl Input: Component server URL: eg. http://127.0.0.1/CompSrv/ceoh.comp
    m_cedomain Input: The name of the affected Contact Expert Domain.
    m_prayer_day Input: Target date.
    m_prayer_start_time Input: Starting time in "hh:mm" (24h) format.
    m_prayer_stop_time Input: End time in "hh:mm" (24h) format.

    Exit Points

    Name Description
    praytime praytime
    open open
    emergency emergency

    JSON

    {
      "name": "AdvancedPrayTime",
      "type": "template",
      "description": "<b>PrayTime</b> description",
      "attributes": [
        {
          "name": "id",
          "type": "integer",
          "defaultvalue": "2000"
        }
      ],
      "parameters": [
        {
          "name": "m_compsrvurl"
        },
        {
          "name": "m_cedomain"
        },
        {
          "name": "m_prayer_day"
        },
        {
          "name": "m_prayer_start_time"
        },
        {
          "name": "m_prayer_stop_time"
        }
      ],
      "connections": [
        {
          "name": "emergency"
        },
        {
          "name": "praytime"
        },
        {
          "name": "open"
        }
      ]
    }
    

    XML

    <template name="AdvancedPrayTime" id="#ID#" version="1.1">
      <parameters>
        <parameter id="m_compsrvurl"><![CDATA[#M_COMPSRVURL#]]></parameter>
        <parameter id="m_cedomain"><![CDATA[#M_CEDOMAIN#]]></parameter>
        <parameter id="m_prayer_day"><![CDATA[#M_PRAYER_DAY#]]></parameter>
        <parameter id="m_prayer_start_time"><![CDATA[#M_PRAYER_START_TIME#]]></parameter>
        <parameter id="m_prayer_stop_time"><![CDATA[#M_PRAYER_STOP_TIME#]]></parameter>
      </parameters>
    
      <connections namedoutputs="true">
        <connection name="emergency" destination="#EMERGENCY#"/>
        <connection name="praytime" destination="#PRAYTIME#"/>
        <connection name="open" destination="#OPEN#"/>
      </connections>
    
      <flow>
        <nodes>
          <script id="10" entrypoint="true">        <!-- EMREGENCY/PRAYTIME check -->
            <parameters>
              <parameter id="m_compsrvurl" type="Variable" datatype="String" direction="Input"><![CDATA[?]]></parameter>
              <parameter id="m_cedomain" type="Variable" datatype="String" direction="Input"><![CDATA[?]]></parameter>
              <parameter id="m_prayer_day" type="Variable" datatype="Int" direction="Input"><![CDATA[?]]></parameter>
              <parameter id="m_prayer_start_time" type="Variable" datatype="String" direction="Input"><![CDATA[?]]></parameter>
              <parameter id="m_prayer_stop_time" type="Variable" datatype="String" direction="Input"><![CDATA[?]]></parameter>
            </parameters>
            <connections namedoutputs="true">
              <connection exitpoint="emergency" name="EMERGENCY" destination="?"/>
              <connection exitpoint="praytime" name="PRAYTIME" destination="?"/>
              <connection exitpoint="open" name="OPEN" 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;
      }
    }
    
    $$nextConnection$$ = 'OPEN';
    var url = '' + LOCALS['m_compsrvurl'];
    var domain = '' + LOCALS['m_cedomain'];
    var tenantid = flowvars['TENANT_ID'];
    var timeout = 10000;
    var mimetype = 'application/jsonrequest';
    
    var start_h = LOCALS['m_prayer_start_time'].split(':')[0];
    var start_m = LOCALS['m_prayer_start_time'].split(':')[1];
    var stop_h = LOCALS['m_prayer_stop_time'].split(':')[0];
    var stop_m = LOCALS['m_prayer_stop_time'].split(':')[1];
    
    log.debug('Init done. CompSrvUrl: ' + url 
      + ', Domain: ' + domain 
      + ', TenantId: ' + tenantid
      + ', StartHour: ' + start_h + ', StartMinute: ' + start_m
      + ', StopHour: ' + stop_h + ', StopMinute: ' + stop_m);
    
    try {
    
      var js = toolkit.getJSonRetriever();
    
      var req = {};
      req['action'] = 'IsEmergency';
      req['domain'] = domain;
      req["tenant"] = parseInt(tenantid);
    
      var resp = js.postData(url, timeout, JSON.stringify(req), mimetype);
    
      if (resp != null) {
    
        log.debug('IsEmergency response received: ' + resp);
    
        var jresp = JSON.parse(resp);
    
        if ((''+jresp['result']) == 'TRUE') {
    
          $$nextConnection$$ = 'EMERGENCY';
          log.debug('There is emergency in the domain');
        }
        else {
        
          log.debug('There is no emergency in the domain');
        }
      }
      else{
    
        log.debug('No response for IsEmergency');
      }
    
      if ($$nextConnection$$ != 'EMERGENCY') {
    
        var now = GetCurrentTimeInTenant(url, tenantid);
    
        if(now != null) {
    
          log.debug('Start to check pray time. now.DayOfWeek: ' + now.DayOfWeek);
    
          if (parseInt(now.DayOfWeek) == LOCALS['m_prayer_day']) {
    
            var dm = now.Hour * 60 + now.Minute;
            var prayer_start = parseInt(start_h) * 60 + parseInt(start_m);
            var prayer_stop = parseInt(stop_h) * 60 + parseInt(stop_m);
    
            log.debug('now.Hour: ' + now.Hour + ', dm:' + dm + ', PrayStart:' + prayer_start + ', PrayStop:' + prayer_stop);
    
            if ((dm >= prayer_start) && (dm < prayer_stop)) {
    
              $$nextConnection$$ = 'PRAYTIME';
            } else {
    
              $$nextConnection$$ = 'OPEN';
            }
          }
          else {
    
            $$nextConnection$$ = 'OPEN';
            log.debug('No pray day');
          }
        }
        else {
    
          $$nextConnection$$ = 'OPEN';
          log.error('Failed to retrieve current time in tenant: ' + tenantid);
        }
      }
    } catch (err) {
    
      $$nextConnection$$ = 'OPEN';
      log.error('Exception during Prayer Time check:' + 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