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

Understanding Team-based Routing

Consider, the user has come up with an issue on some topic, and he has requested to chat with an agent. With Team-based routing, his issue will be handed over to an agent, from the team that deals with the topic of the users' interest. So, this would help in reducing the delay in response from the agent.

Example: In a Software business, if the user has an issue with installation, then his request to chat with an agent would be directed to the agent who belongs to the installation team, and not the agent from any other team like integration or feedback.

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 requests for chatting with an agent.

Code Step Integration for Team-based Routing

import json
import requests
def main(event, context):
    """
   event['body'] is a string dict with the following keys:
   node, event, user, entities.
   Currently, we pass user_id, user_name, full_name, device_platform and language_code in the user dictionary.
   Args:
       event (dict): Data corresponding to this event
       context
   Returns
       (dict): response with statusCode and the response for the User
   """
    body = json.loads(event['body'])
    entities = body.get('entities')
    user_data = body.get('user')
    user_name = body.get('user')["user_name"]
    user_details = body.get('user_details')
    environment_variables = body.get('env_variables')
    # TODO change default team name
    team_name = user_details.get('team_name', 'Default')
    team_name = "haptik_" + team_name
    transfer_status = transferChatToAgent(user_name, team_name, environment_variables)
    conversation_details = body.get('conversation_details')
    final_response = {
        'status': transfer_status,
        'entities': entities,
        'user_full_name': user_data.get("full_name"),
        'user_device_platform': user_data.get("device_platform"),
        'conversation_details': conversation_details,
        'team_name': team_name
    }
    response = {'statusCode': 200, 'body': json.dumps(final_response), 'headers': {'Content-Type': 'application/json'}}
    return response
def transferChatToAgent(user_name, team_name, environment_variables):
   location = entities.get(‘user_location’)[0].get(‘entity_value’)
   url = environment_variables.get("HAPTIK_API_BASE_URL") + "/integration/external/v2.0/send_chat_to_agent/"
   payload = {"team_name": team_name, "user_name": user_name, "business_id": xxxx, "receiver":"athena"}
   header = {
       'Content-Type': 'application/json',
       'Authorization': f"Bearer {environment_variables.get('HAPTIK_API_TOKEN')}",
       'client-id': 'xxxx'
   }
   try:
       response = requests.request("POST", url, headers=header, json=payload)
       response.raise_for_status()
       print(f"[transferChatToAgent] API schematics headers: {header} payload:{payload} response {response.json()}")
       return True
   except Exception as e:
       print(f'[transferChatToAgent] API failed due to {e} request {header} response {response.json()}')
       return False

team_name = {
mumbai = team_mumbai # team_mumbai is the Team name on Smart Agent Chat
new_York = team_ny
}

In the above code, you would need to add the following variable data:

  • HAPTIK_API_BASE_URL
  • HAPTIK_API_TOKEN
  • client-id

Visit this link, to know how to obtain these values. 

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

  • When the user wants to talk to the agent, in order to get certain information, it is imperative that he is directed to the right agent, from the right team. So that, it saves the user's time and also gives him a good product experience.
  • The above code uses users' locations to find out where the user is operating from. The below-mentioned function is the one used for acquiring users' location-related data.
    location = entities.get(‘user_location’)[0].get(‘entity_value’)

This code deals with location-based data. But you can configure it the way you want by making changes to the code depending on your requirement. So teams could be seniority-based, topic-based, department-based, etc.

Example:

If the bot serves the book publishing business, then the teams could be:

  • Writing team
  • Copywriting team
  • Proofreading team
  • Publishing team

Depending on the user's issue, he would be assigned an agent from any of the teams above. 

  • It would collect the user's location data and would use it for directing the user to the right team based on his location.
  • Consider, the user is working from Mumbai and has put up a request to chat with an agent. Now, with this code's configuration, initially, the user's location would be collected and stored.
  • Now that the bot has the user's location, the bot knows where the user is based and which team the user should be directed to.
  • If there are teams based in Mumbai, New York, London, and so on. Ideally, the team from Mumbai would be able to provide the right resolution to the user, as per the code.
  • This approach would ensure reduced delay in response from the agent. Since, both the user and agent would be from the same geographic location, it would be less likely to have a delay in response from the agent, if we compare it with the agents from the other locations.

Can’t find what you’re looking for? Email us at support@haptik.ai.