Context Handler

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 which 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.

InputsTypeDescription
answersMapAnswers to the questions defined in the context
visitorMapDetails of the website visitor
context_idStringID of the context currently used

Context Handlers in Zoho SalesIQ - Bot

To embed the context handler script:

  • Navigate to Settings > Bots, click Add Bot.
  • Enter the name, description, choose a website, departments and then select SalesIQ Script.
  • Then, choose the Context Handler in the drop-down.
  • And then draft the script in the respective section, click Save and Publish.

Sample Syntax For Bot Context Handler

In this example, we have used a travel website called Zylker travels. And the bot acts as a travel assistant and guides the visitors visiting the website. Here, the context handler will be invoked once the bot gets a reply from the visitor for the trigger initiated or while the message handler is executed. This handler is used to engage the visitor in the conversation and collect inputs.


response = Map();
info answers;
if(context_id.equals("information"))
{
ans = answers.get("info").get("text");
if(ans.containsIgnoreCase("Services"))
{
response.put("action","context");
response.put("context_id","services");
questions = Collection();
question1 = {"name":"service","replies":{{"text":"Tickets and Bookings"}},"input":{"type":"select","options":{"Airlines","HotelBooking","HolidayPackages","CruiseBooking"}}}; 
questions.insert(question1);
response.put("questions",questions);
}
else if(ans.containsIgnoreCase("SpecialDeals"))
{
response.put("action","context");
response.put("context_id","specialdeals");
questions = Collection();
question2 = {"name":"special","replies":[{"text":"Special Deal links","type":"links","links":[{"url":"http://europetravels.me/package-detail/kuala-lumpur-and-sunway-lagoon-tours-package-03-nights-4-days-/4","text":"SUNWAY LAGOON TOURS PACKAGE QAR680","image":"http://europetravels.me/media_library/original_europe-travels-packages-ai3jnx.jpg"},{"url":"http://europetravels.me/package-detail/kuala-lumpur-genting-highland-3-nights-4-days-/6","text":"GENTING HIGHLAND QAR 750","image":"http://europetravels.me/media_library/original_europe-travels-packages-0ho4y8.jpg"},{"url":"http://europetravels.me/package-detail/georgia-package-03-nights-04days-/8","text":" GORGEOUS GEORGIA QAR 1120","image":"http://europetravels.me/media_library/original_europe-travels-packages-ockjhb.jpg"}]}]};
questions.insert(question2);
response.put("questions",questions);
}
else if(ans.containsIgnoreCase("Packages"))
{
response.put("action","context");
response.put("context_id","packages");
questions = Collection();
question3 = {"name":"package","replies":[{"text":"Package links","type":"links","links":[{"url":"http://europetravels.me/package-detail/wonders-of-austria/11","text":" AUSTRIA WONDERS QAR 565","image":"http://europetravels.me/media_library/original_europe-travels-packages-3hjjrt.jpg"},{"url":"http://europetravels.me/package-detail/langkawi-packages/10","text":" KUALA LUMPUR & LANGKAWI TOUR PACKAGES QAR 880","image":"http://europetravels.me/media_library/original_europe-travels-packages-kkoacz.jpg"},{"url":"http://europetravels.me/package-detail/bali-package-3-nights-04-da ys-/7","text":"BALI EXTRAVENZA QAR 1250","image":"http://europetravels.me/media_library/original_europe-travels-packages-k48wcd.jpg"}]}]};
questions.insert(question3);
response.put("questions",questions);
}
}
if(context_id.equals("services") || context_id.equals("specialdeals") || context_id.equals("packages"))
{
response.put("action","context");
response.put("context_id","calendardetails");
questions = Collection();
question1 = {"name":"calendar","replies":{{"text":"Please choose date and time to travel"}},"input":{"type":"calendar","time":true,"tz":true}};
questions.insert(question1);
response.put("questions",questions);
}
else if(context_id.equals("calendardetails"))
{
response.put("action","end");
response.put("replies",{{"text":"We are re-directing you to the booking site."}});
}
return response;

Share this post : FacebookTwitter

Still can't find what you're looking for?

Write to us: support@zohosalesiq.com