Skip to product menu
close
  • Recent Launches
    Press Space or Enter to display list of options
EXPLORE ALL PRODUCTS

Recent Launches

New

Payroll software with automated tax payments and filing.

Try now
New

Robotic process automation software to automate high-volume, rule-based tasks.

Try for free
New

Low-code IoT platform and solutions for connected businesses.

Try now
New

Business formation service to launch and grow your businesses.

Try now
New

Privacy-friendly application analytics solution.

Try for free

Sales

 
CRM

Comprehensive CRM platform for customer-facing teams.

CRM
 
Bigin

Simple CRM for small businesses moving from spreadsheets.

Bigin
 
Forms

Build online forms for every business need.

Forms
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
Sign

Digital signature app for businesses.

Sign
 
RouteIQ

Comprehensive sales map visualization and optimal route planning solution.

RouteIQ
 
Thrive

Complete loyalty and affiliate management platform.

Thrive
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
Suites
CRM Plus

Unified platform to deliver top-notch customer experience.

CRM Plus

Marketing

 
Social

All-in-one social media management software.

Social
 
Campaigns

Create, send, and track targeted email campaigns that drive sales.

Campaigns
 
Forms

Build online forms for every business need.

Forms
 
Survey

Design surveys to reach and interact with your audience.

Survey
 
Sites

Online website builder with extensive customisation options.

Sites
 
PageSense

Website conversion optimization and personalisation platform.

PageSense
 
Backstage

End-to-end event management software.

Backstage
 
Webinar

Webinar platform for webcasting online webinars.

Webinar
 
Marketing Automation

All-in-one marketing automation software.

Marketing Automation
 
LandingPage

Smart landing page builder to increase conversion rates

LandingPage
 
Publish

Manage all your local business listings on a single platform.

Publish
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Sign

Digital signature app for businesses.

Sign
 
Thrive

Complete loyalty and affiliate management platform.

Thrive
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
NEW
LeadChain

Sync, manage, and convert leads across channels seamlessly.

LeadChain
 
NEW
CommunitySpaces

Online community platform for individuals and businesses to grow their network and brand.

CommunitySpaces
 
Suites
Marketing Plus

Unified marketing platform for marketing teams.

Marketing Plus

Commerce and POS

 
Commerce

eCommerce platform to manage and market your online store.

Commerce

Service

 
Desk

Helpdesk software to deliver great customer support.

Desk
 
Assist

Remote support and unattended remote access software.

Assist
 
Lens

Interactive remote assistance software with augmented reality.

Lens
 
FSM

End-to-end field service management platform for service businesses.

FSM
 
SalesIQ

Live chat app to engage and convert website visitors.

SalesIQ
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
NEW
Solo

The all-in-one toolkit for solopreneurs.

Solo
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
Suites
Service Plus

Unified platform for customer service and support teams.

Service Plus

Finance

 
Books

Powerful accounting platform for growing businesses.

Books
 
FREE
Invoice

100% Free invoicing solution.

Invoice
 
Expense

Effortless expense reporting platform.

Expense
 
Inventory

Powerful stock management and inventory control software.

Inventory
 
Billing

End-to-end billing solution for your business.

Billing
 
Checkout

Collect payments online with custom branded pages.

Checkout
 
NEW
Payroll

Payroll software with automated tax payments and filing.

Payroll
 
NEW
Solo

The all-in-one toolkit for solopreneurs.

Solo
 
Practice

Practice management software for accounting firms.

Practice
 
Sign

Digital signature app for businesses.

Sign
 
Commerce

eCommerce platform to manage and market your online store.

Commerce
 
Suites
Finance Plus

All-in-one suite to manage your operations and finances.

Finance Plus

Email and Collaboration

 
Mail

Secure email service for teams of all sizes.

Mail
 
Meeting

Online meeting software for all your video conferencing & webinar needs.

Meeting
 
Writer

Word processor for focused writing and discussions.

Writer
 
Sheet

Spreadsheet software for collaborative teams.

Sheet
 
Show

Create, edit, and share slides with a sleek presentation app.

Show
 
Notebook

Beautiful home for all your notes.

Notebook
 
Cliq

Stay in touch with teams no matter where you are.

Cliq
 
Connect

Employee experience platform to communicate, engage, and build positive employee relations.

Connect
 
Bookings

Appointment scheduling app for consultations with customers.

Bookings
 
TeamInbox

Shared inboxes for teams.

TeamInbox
 
WorkDrive

Online file management for teams.

WorkDrive
 
Sign

Digital signature app for businesses.

Sign
 
Office Suite

Powerful collaborative work platform for teams.

Office Suite
 
Office Integrator

Built in document editors for web apps.

Office Integrator
 
ZeptoMail

Secure and reliable transactional email sending service.

ZeptoMail
 
Calendar

Online business calendar to manage events and schedule appointments.

Calendar
 
Learn

Knowledge and learning management platform.

Learn
 
Voice

Cloud Contact Center Software for businesses.

Voice
 
ToDo

Collaborative task management for individuals and teams.

ToDo
 
Tables

Work management tool to connect people, processes, and information.

Tables
 
FREE
PDF Editor

Collaborative online PDF editing tool.

PDF Editor
 
Suites
Workplace

Application suite built to improve team productivity and collaboration.

Workplace

Human Resources

 
People

Organize, automate, and simplify your HR processes.

People
 
Recruit

Intuitive recruiting platform built to provide hiring solutions.

Recruit
 
Expense

Effortless expense reporting platform.

Expense
 
Workerly

Manage temporary staffing with an employee scheduling solution.

Workerly
 
NEW
Payroll

Payroll software with automated tax payments and filing.

Payroll
 
Shifts

Employee scheduling and time tracking app.

Shifts
 
Sign

Digital signature app for businesses.

Sign
 
Suites
People Plus

Comprehensive HR platform for seamless employee experiences.

People Plus

Security and IT Management

 
Creator

Build custom apps to simplify business processes.

Creator
 
Directory

Workforce identity and access management solution for cloud businesses.

Directory
 
FREE
OneAuth

Secure multi-factor authenticator (MFA) for all your online accounts.

OneAuth
 
Vault

Online password manager for teams.

Vault
 
Catalyst

Pro-code platform to build and deploy your apps.

Catalyst
 
Toolkit

Complete resource for any admin-related lookup queries.

Toolkit
 
Lens

Interactive remote assistance software with augmented reality.

Lens
 
Assist

Remote support and unattended remote access software.

Assist
 
QEngine

Test automation software to build, manage, execute, and report testcases.

QEngine
 
NEW
RPA

Automate manual, tedious, and repetitive tasks easily.

RPA

BI and Analytics

 
Analytics

Modern self-service BI and analytics platform.

Analytics
 
Embedded BI

Embedded analytics and white label BI solutions, tailored for your needs.

Embedded BI
 
DataPrep

AI-powered data preparation service for your data-driven organization.

DataPrep
 
NEW
IoT

Harnessing IoT analytics for real-time operational intelligence.

IoT

Project Management

 
Projects

Manage, track, and collaborate on projects with teams.

Projects
 
Sprints

Planning and tracking tool for scrum teams.

Sprints
 
BugTracker

Automatic bug tracking software for managing bugs.

BugTracker
 
NEW
Solo

The all-in-one toolkit for solopreneurs.

Solo

Developer Platforms

 
Creator

Build custom apps to simplify business processes.

Creator
 
Flow

Automate business workflows by creating smart integrations.

Flow
 
Catalyst

Pro-code platform to build and deploy your apps.

Catalyst
 
Office Integrator

Built in document editors for web apps.

Office Integrator
 
ZeptoMail

Secure and reliable transactional email sending service.

ZeptoMail
 
QEngine

Test automation software to build, manage, execute, and report testcases.

QEngine
 
Tables

Work management tool to connect people, processes, and information.

Tables
 
NEW
RPA

Automate manual, tedious, and repetitive tasks easily.

RPA
 
NEW
Apptics

Application analytics for all apps.

Apptics
 
Embedded BI

Embedded analytics and white label BI solutions, tailored for your needs.

Embedded BI
 
NEW
IoT

Build, deploy, and scale IoT solutions for connected businesses.

IoT
 
DataPrep

AI-powered data preparation service for your data-driven organization.

DataPrep

IoT

 
NEW
IoT

Low-code IoT platform and solutions for connected businesses.

IoT

Search Result

 
CRM Plus

Unified platform to deliver top-notch customer experience.

Try now
CRM Plus
 
Service Plus

Unified platform for customer service and support teams.

Try now
Service Plus
 
Finance Plus

All-in-one suite to manage your operations and finances.

Try now
Finance Plus
 
People Plus

Comprehensive HR platform for seamless employee experiences.

Try now
People Plus
 
Workplace

Application suite built to improve team productivity and collaboration.

Try now
Workplace
 
Marketing Plus

Unified marketing platform for marketing teams.

Try now
Marketing Plus
 
All-in-one suite

Zoho One

The Operating System for Business

Run your entire business on Zoho with our unified cloud software, designed to help you break down silos between departments and increase organizational efficiency.

TRY ZOHO ONE
Zoho One
Zoho Marketplace

With over 2000 ready-to-use extensions across 40+ categories, connect your favorite business tools with the Zoho products you already use.

EXPLORE MARKETPLACE
Marketplace
Skip to main content

Bot Context Handler

The bot context handler can be used by the bot creator to engage the bot with the user in a conversational manner. To get started with the context handler, you must define a conversation flow as a context map. The keys that need to be used in the context map are explained in a table below. But before that take a look at the below-given examples where the context handler will come in handy.

  1.  A service-desk bot is a good example to understand the working of the bot context handler easily. This bot can be used to handle simple service-desk roles such as handling asset requests, replying to queries and also raise a request for the user. For example, if a user would like to raise a request to install a particular software, the bot can get the necessary information from the user with a series of questions and raise the request! The bot will collect the response to each question before the final action. 
  2. You can ask your bot to create a lead for you in CRM or create an issue in Projects and this definitely cannot be done with a single message! Instances like these can be easily handled using the context handler. 

The context map should have the following keys :

Key TypeDescription
idstring (100)

A string to uniquely identify any context. 

Note: This ID can be used to associate the context with an action to be performed. 

timeoutinteger(seconds)The active period in seconds for a context before it expires. Default timeout value is taken as 1 day.
paramslist (10 questions)List of inputs to be collected from the user to perform an action for a context. A context can have a maximum of 10 questions.  Each entry in the params list can have the following attributes given in the table below.

Every entry in the params list can have the following attributes:

KeyTypeDescriptionPre-requisite
namestring (100)Unique identifier for a param. The answers collected for the param will be associated with this identifier in the context handler. The name field also acts a unique ID for each question. Mandatory
questionstring (1000)The question to be asked by the bot to the user to collect the value for params.Mandatory
valuemapValue field can be used when the answer to the question asked is already known. If the value field is specified, the bot skips asking the question. The string representation of the list should not exceed more than 1000 characters.Optional
suggestionsarrayA list of options to be shown as answers to the questions asked. Take a look at the bot message handler suggestions.Optional

Sample syntax for params map


"params":[
  {
    "name": "movie",
    "question": "Give me the movie name!"
  },
  {
    "name": "seats",
    "question": "Number of seats?",
    "value": {
      "text": "3"
    }
  },
  {
    "name": "place",
    "question": "This movie is available in the following theatres! Choose an option, for me to proceed.",
    "suggestions": {
      "list": [
        {
          "text": "Regal IMAX"
        },
        {
          "text": "Livermore Cinemas"
        }
      ]
    }
  }
]

 

Note:

The limit for the number of questions in the context handler is 10.

The following attributes are passed to the context handler which will be triggered after collecting all the inputs in the params map :

Attribute NameDescription
userDetails of the user having a conversation with the bot.
chatChat details in which the context handler is triggered.
context_idA unique identifier for each context map. 
answersThe answers map will contain the responses made by the user to each question. The response for the answers map is shown in the below-given code snippet.

Sample response for the context map


  {  
      "movie":{  
         "text":"Justice League"
      },
      "seats":{  
         "text":"3"
      },
      "place":{  
         "text":"Regal IMAX"
      }
   }

Sample Use Case

Let us consider a hotel bot, which helps the customers with the Wi-Fi password, cab bookings, room service and other related queries. The bot shows a list of options to the user as suggestions and when the user selects an option, moves on to further questions on the topic. The message handler is triggered to show the initial list of suggestions. The responses made by the user are passed to the context handler through the context map, and any further action is performed using the bot context handler. Take a look at the sample code snippet shown below! 

Sample Message Handler Code


response = Map();
if(message.containsIgnoreCase("ROOM SERVICE"))
{
	context = {"id":"Room Service","timeout":"300","params":[{"name":"room service","question":"Great! Here is a list of options for you to choose from.","suggestions": {"list":[{"text":"House Keeping"},{"text":"Maintenance"}]}},{"name":"time","question":"Okay cool. When can I send them over?","suggestions":{"list":[{"text":"Now"},{"text":"In half hour"}]}}, {"name":"confirmation","question": "Please confirm your request once!", "suggestions": {"list":[{"text":"Yes"},{"text":"No"}]}}]};
	response.put("context", context);
}
else if(message.containsIgnoreCase("WIFI"))
{
	context = {"id": "Wifi", "timeout":"300","params":[{"name":"Wi-fi","question":"Confirm if you are in Room 307!", "suggestions":{"list":[{"text":"Yes"},{"text":"No"}]}}]};
	response.put("context",context);
}
else if(message.containsIgnoreCase("CAB"))
{
	context = {"id": "Cab","timeout":"300","params":[{"name":"Cab","question": "When can I book the cab for you?","suggestions":{"list":[{"text":"Now"},{ "text": "After 1 hour"}]}}]};
	response.put("context",context);
}
else
{
	response = {"text": "Hi! I am Lyte, the Room Service Bot. Heres what I can help you with! :happy!:", "suggestions":{"list":[{"text":"Room Service"},{"text":"Wifi"},{"text":"Cab"}]}};
}
return response;

Sample Context Handler Code


response = Map();
info answers;
if(context_id.matches("Room Service"))
{
	confirm = "Please check our other options then!";
	if(answers.get("confirmation").containsIgnoreCase("YES"))
	{
		// Make api calls for the room service options!
		confirm = "Great! I've arranged for the " + answers.get("room service").get("text") + " to be there " + answers.get("time").get("text") + ". :thumbsup:";
	}
	response.put("text",confirm);
}
else if(context_id.matches("Wifi"))
{
	txt = 'Please try again or call 0000 for more information!';
	if(answers.get("Wi-fi").containsIgnoreCase("YES"))
	{
		txt = 'Here is your wifi ID and password. \n ID - Room_307 \n Password - Hotel123';
	}
	response.put("text",txt);
}
else if(context_id.matches("Cab"))
{
	if(answers.containKey("cabconfirm"))
	{
		if(answers.get("cabconfirm").containsIgnoreCase("Yes, Please"))
		{
			txts = 'Your cab has been booked. :smile:';
		}
		else
		{
			txts = 'Umm, try again then!';
		}
		response.put("text",txts);	
		return response;
	}
	if(answers.get("Cab").containsIgnoreCase("Now"))
	{
		book_cab = {"id":"Cab","timeout":"100","params":[{"name":"cabconfirm","question":"There are no cabs to book now. Can I try after 15 mins?","suggestions":{"list":[{"text":"Yes, Please!"},{"text":"No,Thanks!"}]}}]};
		response.put("context",book_cab);
	}
	else
	{
		txt = "Your Cab has been booked. Please meet the driver at the hotel lobby. :thumbsup:";
		response.put("text",txt);
	}
	
}
return response;

Here's how this code gets executed to unfold the conversation between the bot and the user.

Continuation of a conversation in the context handler:

When the handler returns a context, it can be considered in two ways:

  • As a new context.  
  • Continuation of the existing context.

In case of continuation of the existing context, then all you've to do is use the ID of the context. This context can contain new questions or can act as a checkpoint for questions you might want to confirm once again with the user

A case in point is the movie bot, that can book tickets for the user once it gets the necessary information. The catch here is, this bot can book only up to 5 tickets for the user. So when a user tries to enter an option which is not present in the bot options. The can easily rephrase the question and let the user know the ticket quantity restrictions.  This particular question is rephrased in the context handler. The existing context in the message handler can be continued from the context handler by using the same 'id' param. ("id":"movies") The code snippet is shown below - 


//Map defined in the message handler : 

response = Map();
if(message.containsIgnoreCase("Yes"))
{
	context = {"id":"movies","timeout":"300","params":{{"name":"movie","question":"Please select the movie!","suggestions":{"list":{{"text":"Iron Man"},{"text":"Batman"},{"text":"Justice League"}}}},{"name":"quantity","question":"Awesome. How many tickets do you need?","suggestions":{"list":{{"text":"1"},{"text":"2"},{"text":"3"},{"text":"4"},{"text":"5"}}}}}};
	response.put("context",context);
	response.put("text","Welcome To *Movie Booking* \n Please answer the following questions!");
}
else if(message.containsIgnoreCase("No"))
{
	response.put("text","Oh! But I can help you with only that right now :upset:");
}
else if(message.containsIgnoreCase("OK"))
{
	response.put("text","Great! I'll book the tickets right away!");
}
else
{
	response = {"text":"Hi! Would you like to book a movie?","suggestions":{"list":{{"text":"Yes"},{"text":"No"}}}};
}
return response;

// Map defined in the context handler:

response = Map();
if(context_id.matches("movies"))
{
	ticket_quantity = {"1","2","3","4","5"};
	if(answers.contains("confirm"))
	{
		if(answers.get("confirm").get("text").containsIgnoreCase("yes"))
		{
			text = "Here's the booking details: \n Movie: *" + answers.get("movie").get("text") + "* \n Tickets: *" + answers.get("quantity").get("text") + "* \n Multiplex: *" + answers.get("multiplex").get("text") + "* \n Send an *OK* for me to proceed booking!";
		}
		else
		{
			text = 'Okay then. I will book the tickets. :thumbsup:';
		}
		response.put("text",text);
		return response;
	}
	if(!ticket_quantity.contains(answers.get("quantity").get("text")))
	{
		context = {"id": "movies","timeout":"30","params":[{ "name":"quantity","question":"I am sorry! But you can only choose from the list of options given.","suggestions":{"list":[{"text":"1"},{"text":"2"},{"text":"3"},{"text":"4"},{"text":"5"}]}}]};
	}
	else
	{
		context = {"id":"movies","timeout":"30","params":{{"name":"multiplex","question":"These multiplexes are playing the movie *" + answers.get("movie").get("text") + "*","suggestions":{"list":{{"text":"Regal IMAX"},{"text":"Livermore Cinemas"}}}},{"name":"confirm","question":"Great! You are done. Can you confirm before I proceed?","suggestions":{"list":{{"text":"Yes"},{"text":"Just book!"}}}}}};

	}
	response.put("context", context);
}
else
{
	response = {"text":"Hi! Would you like to book a movie?","suggestions":{"list":{{"text":"Yes"},{"text":"No"}}}};
}
return response;

 

Below is a GIF illustrating the conversation flow, when the user response is from the list of options for the 'Number of tickets' question.

Now, let's see how the bot reacts when the user's response is not from the list of suggestions for the same question.

Related Articles:

Cliq Bots - Building conversational bots with a series of questions and user inputs!

The above article takes you through the process of using the bot context handler to build a Quiz Bot