Bot Context Handler

The Context Handler can be used when the visitor engages in a conversation with the bot. Context is a data definition that is used to collect multiple inputs to perform a single action. The conversation is mostly in a question-answer format and can work in association with the Message handlers and trigger handlers i.e., the handlers can return a context instead of a message reply.

So, all the inputs defined in the context will be collected and the context handler will be invoked. In that case, the context handler is a piece of SalesIQ script that is invoked after collecting all the inputs for a particular context. Here are the various attributes passed from a bot to a context handler. To get started with the context handler, you must define a flow as the context map.

Example: Consider, you walk into a cloth store, one way or other you will be interacting with a salesperson and they will ask you a bunch of questions. Based upon your answers, they will provide you with what you need. The context handler works on the same way.

The attributes passed when a context handler is triggered are listed below:

InputsTypeDescription
answersMapAnswers to the questions defined in the context
visitorMapDetails of the website visitor
context_idStringThe ID of the context currently used
requestMapDetails of the request

Note: 

  • Each script handler/function will have an execution timeout of 90 seconds
  • Each API invocation from handlers using the invoke URL task should not exceed 40 seconds to be completed
  • If there is any issue in the execution or response of one of the handlers, as a fallback bot will forward the chats to the department operators. 

Context Handlers in Zoho SalesIQ - Bot

To embed the context handler script:

  • Navigate to Settings > Bot > Zobot, click Add.
  • Enter the name, choose the platform - SalesIQ Scripts, and then choose the brand. 
  • The Deluge code builder will appear.
  • Then, choose the Context Handler in the drop-down.
  • And then draft the script in the Context handler section, click Save and Publish.

Sample Output

Sample Code:

Copiedresponse = Map();
if(context_id.equals("motivational_therapy"))
{
	response.put("action","reply");
	name = answers.get("name").get("text");
	email = answers.get("email").get("text");
	number = answers.get("number").get("text");
	date = answers.get("date").get("text");
	slots = answers.get("slot").get("text");
	customerDetails = Map();
	customerDetails.put("name",name);
	customerDetails.put("email",email);
	customerDetails.put("phone_number",number);
	create_booking = zoho.bookings.createAppointment(112302000000018063,date,customerDetails,112302000000018015,"Asia/Calcutta",true,"booking2");
	info create_booking;
	bookingid = response.get("create_booking").get("returnvalue").get("booking_id");
	response.put("action","end");
	response.put("replies",{"Thank you for choosing our service, Your request for appointment for Movitational Therapy at " + date + slots + " is scheduled Successfully.","Your booking id is "+ bookingid + "Please take a note on it and you will recieve a conformation mail from us shortly :)"});
}
else if(context_id.equals("depression_therapy"))
{
		response.put("action","reply");
	name = answers.get("name").get("text");
	email = answers.get("email").get("text");
	number = answers.get("number").get("text");
	date = answers.get("date").get("text");
	slots = answers.get("slot").get("text");
	customerDetails = Map();
	customerDetails.put("name",name);
	customerDetails.put("email",email);
	customerDetails.put("phone_number",number);
	create_booking = zoho.bookings.createAppointment(112302000000018076,date,customerDetails,112302000000018016,"Asia/Calcutta",true,"booking2");
	info create_booking;
	bookingid = response.get("create_booking").get("returnvalue").get("booking_id");
	response.put("action","end");
	response.put("replies",{"Thank you for choosing our service, Your request for appointment for Movitational Therapy at " + date + slots + " is scheduled Successfully.","Your booking id is "+ bookingid + "Please take a note on it and you will recieve a conformation mail from us shortly :)"});
}
return response;

In this example, once the messages handler receives all the responses from the visitor and stores in a context and this context is returned to the context handler for scheduling an actual appointment using Zoho Booking.