Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Go to Haptik Website
  • Contact Us
  • Home

How to setup Time-based routing for Smart Agent Chat?

Written by Rasika Purohit

Updated on October 26th, 2021

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Getting Started
    Build Deploy Analyse Manage Account Bot Deactivation
  • Bot Building
    Essentials Smart Skills Steps User Messages Bot Responses Entities Connections Customisations User feedback collection Testing Whatsapp Bots NLU Bot Maintenance
  • Smart Agent Chat
    Set up Admin Settings MyChats Section (Agent Inbox) Live Traffic Section Teams Section Archives Section Analytics Plans on Smart Agent Chat
  • Conversation Design
    Design Basics Design Guides Designing for Platforms Designing WhatsApp Bots
  • Developer Guides
    Code Step Integration Static Step Integration Shopify Integration SETU Integration Exotel Integration CIBIL integration Freshdesk KMS Integration PayU Integration Zendesk Guide Integration Twilio Integration Razorpay Integration LeadSquared Integration USU(Unymira) Integration Helo(VivaConnect) Integration Salesforce KMS Integration Stripe Integration PayPal Integration CleverTap Integration Fynd Integration HubSpot Integration Magento Integration WooCommerce Integration Microsoft Dynamics 365 Integration
  • Deployment
    Web SDK WhatsApp Facebook Instagram Sunshine Conversation LINE Google Business Messages Telegram MS Teams Bot as an API iOS SDK Android SDK
  • External Agent Tool Setup
    Zendesk Chat Salesforce Service Cloud Freshchat Zoho NICE CXOne Gorgias
  • Analytics & Reporting
    Intelligent Analytics
  • Notifications
    SMS Notifications Success Measurement
  • Commerce Plus
    Catalog Integration Bot Building Guide Channel Deployments Unified ML Pipeline Documentation
  • Troubleshooting Guides
    Error Messages FAQs
  • Release Notes
+ More

Table of Contents

Understanding Time-based RoutingImplementation Code Step Integration for Time-based routingHow does the above code work for Time-based Routing?

Understanding Time-based Routing

Consider, a user has requested to chat with an agent. According to the Time-based Routing algorithm, it would first check if the user's request falls in the time range when the agents are online. 

You can add a condition, depending on your agents' working hours. If the user's request falls in working hours, the bot would direct the chat to the agent, else it would respond with "agent is offline".

Implementation 

In order to implement this Team-based routing algorithm, you would have to follow certain steps.

  • In your Bot, you would have to add a Code step. 
  • This code step would serve the user's Chat with an Agent request.
  • You can add the below-mentioned code in that code step. 
  • The code would get implemented every time the user request for chatting with an agent.

Code Step Integration for Time-based routing


import json
import logging
import pytz
from datetime import datetime
from datetime import time 
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def main(event, context):
    body = json.loads(event['body'])
    # set the start and end time
    startTime="09:00 AM"
    initialTime=datetime.strptime(startTime, '%I:%M %p')
    endTime="06:00 PM"
    finalTime=datetime.strptime(endTime, '%I:%M %p')
    # check the actual time
    present = datetime.now(pytz.timezone('America/New_York'))
    # Mention the time zone here
    present_time =present.strftime('%I:%M %p')
    final_present_time=datetime.strptime(present_time,'%I:%M %p')
    # condition to route the user
    if initialTime<= final_present_time <=finalTime:
        status = "agent_online"
    else: 
        status = "agent_offline"
    final_response = {
        'status': status
    } 
    logger.info(f"Final Response Logged is {final_response}")
    response = {'statusCode': 200, 'body': json.dumps(final_response),          
'headers': {'Content-Type': 'application/json'}}
    return response

How does the above code work for Time-based Routing?

  • The above code uses two main libraries of Python:

  • pytz(python timezone)

  • Datetime

  • The datetime library here uses a method called strptime, that checks the user’s actual time. By actual time, it means that it captures the system’s time.

  • When the user asks to chat with an agent, the algorithm would initially check the user's system time and would record it.

  • Also, a Start time, and an End time is defined in the code.

     startTime="09:00 AM"

  initialTime=datetime.strptime(startTime, '%I:%M %p')

     endTime="06:00 PM"

     finalTime=datetime.strptime(endTime, '%I:%M %p')

  • Here, as you can see, the start time is defined as 09:00 AM, whereas the End time is defined as 06:00 PM, which is their working hours. 

  • Also, here initialTime and finalTime function are recording the time, in the string format.

  • The next would be pytz.timezone, where the code would define the timezone in the city that is mentioned. 

  • In this case, America/New York has been entered, so this part of the code would ideally record the timezone details in New York, America, irrespective of what time it is.

     present = datetime.now(pytz.timezone('America/New_York'))

  • The next function here would record the present time in New York. It will store this data for further evaluations. The time would be recorded in the string format here.

          present_time = present.strftime('%I:%M %p')

     Final_present_time = datetime.strptime(present_time,'%I:%M %p')

  • Here, it also records  the Final present time. It would take the time data from the above function and would parse it into the format, which is mentioned in the brackets. 

In this case: %I: %M: %p

  • There is a conditional loop that has been added in the code. It is as follows:

     

     if initialTime<= final_present_time <=finalTime:

           status = "agent_online"

     else: 

           status = "agent_offline"

     final_response = {

          'status': status

     }


  • Here, the logic is quite simple, it says, if the initial time is less than or equal to the final present time, and if that is less than or equal to the final time, which is 06:00 PM, then the status of the agent would be agent_online. 

  • If in any case, the above condition is not met, the status of the agent would be shown as agent_offline.

  • Let's take an example here, consider you are in London and it is 12:00 AM there, and you have put up a query on the bot. So in this case, considering the time zones, the time at New York would be 07:00 PM.

  • In the above scenario, your time clearly doesn’t match the time constraint mentioned, which is 09:00 AM to 06:00 PM, which is why you would receive an agent status to be agent_offline.

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • What is Code Step? How to Use Code Step?
  • Using Logger Support for Debugging
  • Using "conversation_details" Variable
  • What are Different Integration Parameters

Platform

  • Conversation Studio
  • Smart Skills
  • Advanced NLU
  • Intelligent Analytics
  • Omnichannel
  • Smart Agent Chat
  • Enterprise Security
  • Integrations

Solutions

  • Conversational Commerce
  • Lead Generation
  • Customer Care
  • WhatsApp
  • Conversational IVR
  • Google Business Messages

Industries

  • Retail/ E-Commerce
  • Financial Services
  • Travel & Hospitality
  • Telecom

Knowledge

  • ROI Calculator
  • Reports & Research
  • Case Studies
  • Webinars
  • ISAT
  • Tech Blog
  • Business Blog
  • Resources
  • Haptik v/s Yellow
  • Haptik v/s Liveperson
  • Haptik v/s IBM Watson
  • Haptik v/s Verloop
  • Conversations on AI

Company

  • Why Haptik
  • About Us
  • Careers
  • News & Media
  • Awards & Recognition
  • Contact Us
  • Partnerships
  • Investor Relations

Subscribe

Sign up to recieve the latest updates

Find us on

  • Twitter-footer
  • Linkedin-footer
  • YT-footer
  • Insta-footer
  • G2-footer
  • Facebook-footer

Knowledge Base Software powered by Helpjuice

Copyright © jio Haptik Technology Limited 2021 | Data Security & Privacy Policy | GDPR

North America | Asia Pacific | Africa | enterprise@haptik.ai

Definition by Author

0
0