{"id":22331,"date":"2019-08-23T12:43:40","date_gmt":"2019-08-23T11:43:40","guid":{"rendered":"https:\/\/developer.kore.ai\/v9-2\/?p=22331"},"modified":"2022-03-30T15:16:30","modified_gmt":"2022-03-30T14:16:30","slug":"context-switching","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v9-2\/docs\/bots\/how-tos\/context-switching\/","title":{"rendered":"Managing Context Switching"},"content":{"rendered":"<section class=\"l-section wpb_row height_auto\"><div class=\"l-section-h i-cf\"><div class=\"g-cols vc_row type_default valign_top\"><div class=\"vc_col-sm-12 wpb_column vc_column_container\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<p>In this How-To, we will explore a scenario in a Banking Bot, where, sharing the context across intents, FAQs helps in improving the user experience and efficiency of the Bot. Also, we will be looking at how the context can be used within a dialog flow to determine the sequence of events.<\/p>\n<p>For details on what Context Management is and how it is implemented in the Kore.ai Bots platform, <a href=\"\/docs\/bots\/bot-intelligence\/context-management\/\" target=\"_blank\" rel=\"noopener noreferrer\">refer here<\/a>.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Problem_Statement\">Problem Statement<\/span><\/h2>\n<p>Consider a Banking Bot trying to address the following scenarios:<\/p>\n<ul>\n<li><strong>Sharing content across intents<\/strong> &#8211; Once the user has entered his\/her account number, they should not be prompted for the same again in the course of the conversation.<br \/>\n<code><em>User:   I want to transfer $200 from my account<\/em><br \/>\n<em>Bot:     Sure, may I have your account number? <\/em><br \/>\n<em>           \/\/ (initiating Transfer Amount task)<\/em><br \/>\n<em>User:   It\u2019s 2343544<\/em><br \/>\n<em>Bot:     What is the payee account number<\/em><br \/>\n<em>User:   Wait, do I have sufficient funds <\/em><br \/>\n<em>           \/\/ (transferring to Get Balance task)<\/em><br \/>\n<em>Bot:     <span style=\"text-decoration: underline\">What is your account number<\/span><\/em><\/code><br \/>\nIdeally, Get Balance should not be asking for the account number.<\/li>\n<li><strong>Context-based dialog flow<\/strong> &#8211; Based upon the context, the flow of a given task might change with the Bot making an explicit call to another task as a sub-dialog.<br \/>\nExtending the above example:<br \/>\n<code><em>User: I want to transfer $200 from my account<\/em><br \/>\n<em>Bot:   Sure, may I have your account number? <\/em><br \/>\n<em>         \/\/ (initiating Transfer Amount task)<\/em><br \/>\n<em>User: It\u2019s 2343544<\/em><br \/>\n<em>Bot:   What is the payee account number<\/em><br \/>\n<em>User:  4355403<\/em><br \/>\n<em>Bot:    <span style=\"text-decoration: underline\">What is your account number<\/span>? <\/em><br \/>\n<em>         \/\/ (transferring to Get Balance task to check for sufficient funds)<\/em><br \/>\n<em>User:  It\u2019s 2343544<\/em><br \/>\n<em>Bot:   <span style=\"text-decoration: underline\">Current balance is $1200<\/span><\/em><br \/>\n<em>Bot:  Amount $200 has been debited from your account.<\/em><br \/>\n<em>        \/\/(resuming Transfer Amount task)<\/em><\/code><br \/>\nIdeally, Get Balance should not ask for the account number and should not display the balance message. It should happen in the background between the two tasks, without user knowledge.<\/li>\n<li><strong>Follow-up Intents<\/strong> &#8211; Access to certain tasks could be restricted due to security reasons or business requirements.<br \/>\nFor example, updating account balances should be restricted to Transfer Amount flow. Update Account task should not be available directly to the User nor any other task in the Bot.<\/li>\n<li><strong>Sharing context between intent and FAQs<\/strong> &#8211; During a task, the user might ask a generic question but within the context.<br \/>\nFor example, while transferring an amount, the user might ask about rates and the Bot needs to respond with the FAQ related to funds transfer rates.<\/li>\n<li><strong>Sharing content across FAQs<\/strong> &#8211; A specific question might be a follow up of a previous query.For example, \u201c<em>What are the interest rated for credit cards?<\/em>\u201d followed by \u201c<em>What are the charges?<\/em>\u201d, the charges reference is to the credit cards.<\/li>\n<\/ul>\n<p>This document gives a detailed step-by-step approach to achieving all the above-mentioned scenarios using &#8211; context tags and variables, input pre-conditions and output context, and emit entity value features of the platform.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Pre-requisites\">Pre-requisites<\/span><\/h2>\n<ul>\n<li>Bot building knowledge<\/li>\n<li>A <a href=\"\/docs\/bots\/how-tos\/creating-a-banking-bot\/\" target=\"_blank\" rel=\"noopener noreferrer\">Banking Bot<\/a> with the dialogs as mentioned below:\n<ul>\n<li><a href=\"\/docs\/bots\/how-tos\/creating-a-banking-bot\/#Get_Balance_Intent\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Get Balance<\/strong><\/a> &#8211; Dialog task prompting the user for their Account Number and displaying the available balance in the account.<br \/>\n<a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827065933\/BankingBot_getBalance-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827065933\/BankingBot_getBalance-1.png\" alt=\"\" width=\"599\" height=\"637\" class=\"alignnone size-full wp-image-31815\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827065933\/BankingBot_getBalance-1.png 599w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827065933\/BankingBot_getBalance-1-282x300.png 282w\" sizes=\"auto, (max-width: 599px) 100vw, 599px\" \/><\/a><\/li>\n<li><a href=\"\/docs\/bots\/how-tos\/banking-bot-transfer-funds\/\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Transfer Funds<\/strong><\/a>\u00a0&#8211; Dialog task prompting the user for Payer and Payee account numbers and the amount to be transferred and transferring the specified amount from the payer account to the payee account.<br \/>\n<a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827065611\/BankingBot_transferFunds.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827065611\/BankingBot_transferFunds.png\" alt=\"\" width=\"601\" height=\"695\" class=\"alignnone size-full wp-image-31812\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827065611\/BankingBot_transferFunds.png 601w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827065611\/BankingBot_transferFunds-259x300.png 259w\" sizes=\"auto, (max-width: 601px) 100vw, 601px\" \/><\/a><\/li>\n<li><a href=\"\/docs\/bots\/how-tos\/banking-bot-update-balance\/\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Update Account<\/strong><\/a> &#8211; Dialog task prompting the user for Account Number that needs to be updated, the Amount to be updated and whether the amount needs to be credited or debited and updating the Account balance accordingly.<br \/>\n<a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827070138\/BankingBot_UpdateBalance-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827070138\/BankingBot_UpdateBalance-2.png\" alt=\"\" width=\"859\" height=\"687\" class=\"alignnone size-full wp-image-31817\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827070138\/BankingBot_UpdateBalance-2.png 859w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827070138\/BankingBot_UpdateBalance-2-300x240.png 300w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/a><\/li>\n<li><a href=\"\/docs\/bots\/how-tos\/how-to-build-knowledge-graph\/\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Knowledge Collection<\/strong><\/a> &#8211; Frequently asked questions related to the bank.<br \/>\n<a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827070530\/BankingBot_kg.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827070530\/BankingBot_kg.png\" alt=\"\" width=\"1365\" height=\"578\" class=\"alignnone size-full wp-image-31819\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827070530\/BankingBot_kg.png 1365w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827070530\/BankingBot_kg-300x127.png 300w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827070530\/BankingBot_kg-1024x434.png 1024w\" sizes=\"auto, (max-width: 1365px) 100vw, 1365px\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"Implementation\">Implementation<\/span><\/h2>\n<p>Let us consider each of the above scenarios one by one.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Sharing_content_across_intents\">Sharing content across intents<\/span><\/h3>\n<p>Sharing content needs to be handled differently in the two cases mentioned:<\/p>\n<ul>\n<li><strong>Bot-driven transition<\/strong> &#8211; This can be handled at the time of Bot development by invoking the corresponding intent and passing the data through entity pre-assignment<\/li>\n<li><strong>User-driven transition<\/strong> &#8211; This is a bit complex since we have no way of knowing when, during the current task flow, the user would make such a request and it requires a combination of tags, entity emission, and extraction.<\/li>\n<\/ul>\n<h4>Task-driven Context switching<\/h4>\n<p>The following is the scenario where the Transfer Amount dialog invokes the Get Balance task to check if the Payer Account has sufficient funds for the transfer.<\/p>\n<p><a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/26\/tt-cs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-22140\" src=\"\/wp-content\/uploads\/sites\/26\/tt-cs.png\" alt=\"\" width=\"453\" height=\"671\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>We will be using the Bot scoped Context Variables and Entity Pre-Assignments to achieve this.<\/p>\n<p><strong>Steps:<\/strong><\/p>\n<p>We need to invoke Get Balance from Transfer Amount, check for funds and proceed accordingly<\/p>\n<ol>\n<li>Open the <strong>Transfer Amount<\/strong> dialog<\/li>\n<li>Add a <em>Dialog Node<\/em>, <em>Bot Action Node<\/em> with a <em>Script Node<\/em>, and a <em>Message Node<\/em> as follows:<br \/><a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827071224\/ht_context_1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827071224\/ht_context_1.png\" alt=\"\" width=\"779\" height=\"699\" class=\"alignnone size-full wp-image-31822\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827071224\/ht_context_1.png 779w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827071224\/ht_context_1-300x269.png 300w\" sizes=\"auto, (max-width: 779px) 100vw, 779px\" \/><\/a>\n<ol>\n<li><strong>Dialog Node<\/strong> will invoke the Get Balance using the Entity Pre-Assignments to populate:\n<ul>\n<li><strong>Account Number<\/strong> &#8211; entity required in the Get Balance dialog set to <em>Payer Account<\/em> number<\/li>\n<li><strong>Add Key\/Value<\/strong> &#8211; pair <code>context.type<\/code> and <em>transfer<\/em> identifying the Transfer Amount intent. This will be checked in the Get Balance dialog as shown in the next step to modify the flow.<\/li>\n<li>Ensure that the <strong>Transition Option<\/strong> is set to Initiate Get_Balance, once complete return to this node<br \/><a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827071642\/ht_context_2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827071642\/ht_context_2.png\" alt=\"\" width=\"457\" height=\"1115\" class=\"alignnone size-full wp-image-31824\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827071642\/ht_context_2.png 457w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827071642\/ht_context_2-123x300.png 123w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827071642\/ht_context_2-420x1024.png 420w\" sizes=\"auto, (max-width: 457px) 100vw, 457px\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li><strong>Script Node<\/strong> &#8211; <em>CheckBalance<\/em> to check the balance in the payer account with the amount to be transferred and proceed accordingly. Balance in the payer account is obtained from a BotContext variable that will be populated by the Get Balance dialog.\n<ul>\n<li><strong>JavaScript:<\/strong>\n<pre class=\"lang:default decode:true\">var nextStep = \u201c\u201d;\r\nif (context.session.BotUserSession.Balance &gt;= context.entities.Amount)\r\n   nextStep = \u201cupdate\u201d;\r\ncontext.nextStep = nextStep;<\/pre>\n<p><a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827072225\/ht_context_3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827072225\/ht_context_3.png\" alt=\"\" width=\"871\" height=\"651\" class=\"alignnone size-full wp-image-31826\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827072225\/ht_context_3.png 871w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827072225\/ht_context_3-300x224.png 300w\" sizes=\"auto, (max-width: 871px) 100vw, 871px\" \/><\/a><\/li>\n<li><strong>Connection Settings<\/strong> Bot Action Connections should indicate to proceed to UpdateBalance in case of sufficient funds (if the <code>context.nextStep<\/code> is <em>update<\/em> from the above script) else go to message node.<br \/><a ref=\"magnificPopup\" href=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827072324\/ht_context_4.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827072324\/ht_context_4.png\" alt=\"\" width=\"863\" height=\"705\" class=\"alignnone size-full wp-image-31828\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827072324\/ht_context_4.png 863w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/v9-2\/wp-content\/uploads\/sites\/26\/20210827072324\/ht_context_4-300x245.png 300w\" sizes=\"auto, (max-width: 863px) 100vw, 863px\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li><strong>Message Node<\/strong> to display the insufficient funds message<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<p>Next, let us modify the <strong>Get Balance<\/strong> dialog to check for transfer tag and populate the Bot Context variable if needed.<\/p>\n<ol>\n<li>Open the <strong>Get Balance<\/strong> dialog<\/li>\n<li>Open the <strong>BalanceMessage<\/strong> (the final message node) node<\/li>\n<li>Under <strong>Bot Responses<\/strong> section open the <strong>Manage Responses<\/strong> dialog<\/li>\n<li>Add the following <strong>JavaScript<\/strong>. This script populates the Bot Context variable with Account Balance if the request comes from Transfer Amount task else displays the usual balance message.\n<pre class=\"lang:default decode:true\">if (context.type == \"transfer\")\r\n  BotUserSession.put('Balance', context.GetAccountBalance.response.body.Balance);\r\nelse\r\n  print ('The Balance in your account is ' + context.GetAccountBalance.response.body.Balance);\r\n<\/pre>\n<\/li>\n<\/ol>\n<p>Test the Bot to see the changes in action.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h4>User triggered context switching<\/h4>\n<p>The following is an example of this use case. Users can at any point and time during the Transfer Amount check account balance before proceeding with the transfer.<\/p>\n<p><a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/26\/ut-cs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-22150\" src=\"\/wp-content\/uploads\/sites\/26\/ut-cs.png\" alt=\"\" width=\"680\" height=\"643\" \/><\/a><\/p>\n<p>Let us see how this can be achieved. We will be using historic tags &#8211; system generated and custom tags. The historic tags get transmitted from one intent to another automatically.<\/p>\n<p><strong>Steps<\/strong>:<br \/>First, modify the Transfer Amount to populate the appropriate tags and configure the Hold and Resume settings:<\/p>\n<ol>\n<li>Open the <strong>Transfer Amount<\/strong> dialog<\/li>\n<li>Open the properties panel of <strong>PayerAccount<\/strong> entity<\/li>\n<li>From the <strong>NLP<\/strong> tab, set the <em>Auto emit the entity values captured<\/em> flag. This will ensure that the Payer Account number is saved in the context. Since it is the first value being emitted by this intent, it would be positioned next to the intent name in the tags array<\/li>\n<li>Next, open the <strong>Manage Interruptions<\/strong> dialog from the <strong>more<\/strong> (vertical ellipses) option<\/li>\n<li>Customize the settings for this task as <strong>Allow hold and resume<\/strong> and set the <strong>Hold Options<\/strong> to <em>Hold the current task and resume back once the new task is completed<\/em> and the <strong>Resume Options<\/strong> to <em>Resume the on hold task without any specific message to the user<\/em>.<\/li>\n<\/ol>\n<p>Next, modify the Get Balance dialog to capture the data sent by the Transfer Amount<\/p>\n<ol>\n<li>Open the <strong>Get Balance<\/strong> dialog<\/li>\n<li>Add a <strong>Script node<\/strong> &#8211; <em>CheckAcId<\/em> to check if the Account Number is available in the context, after the Intent node<\/li>\n<li>Add the following <strong>script<\/strong>. This script checks for the Intent \u201cTransfer Amount\u201d. Captures the account number and populates the AccountNumber entity with that value.\n<pre class=\"lang:default decode:true \">var i = koreUtil._.indexOf(context.historicTags[0].tags, 'Transfer Amount');\r\ncontext.entities.AccountNumber = context.historicTags[0].tags[i+1]\r\n<\/pre>\n<\/li>\n<\/ol>\n<p>Run the Bot and see the changes taking effect.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"Follow_up_Intents\">Follow up Intents<\/span><\/h3>\n<p>The <strong>Update Account<\/strong> intent should be invoked only through Transfer Amount. There are two things that can be done:<\/p>\n<ol>\n<li>Restricting user access:\n<ol>\n<li>Open the <strong>Update Account<\/strong> dialog<\/li>\n<li>Access <strong>Dialog Settings<\/strong> from the <strong>more<\/strong> (vertical ellipses) option<\/li>\n<li>Set <strong>Options<\/strong> to <em>Sub intent only<\/em> dialog<\/li>\n<li>This will restrict user access to this dialog, this dialog will not be available either directly or from the Help option.<\/li>\n<\/ol>\n<\/li>\n<li>Restricting task access:\n<ol>\n<li>Open the <strong>Update Balance<\/strong> dialog<\/li>\n<li>Open the <strong>UpdateBalance<\/strong> intent, <strong>NLP Properties<\/strong> tab<\/li>\n<li>Under the <strong>Manage Context<\/strong> section add \u201c<em>Transfer<\/em>\u201d to the <strong>Intent Preconditions<\/strong>.<br \/>This will ensure that this dialog will be executed only if the Transfer exists in context.<\/li>\n<li>Open <strong>Transfer Amount<\/strong> dialog<\/li>\n<li>Open the <strong>TransferAmount<\/strong> intent node, <strong>NLP Properties<\/strong> tab<\/li>\n<li>Under the <strong>Manage Context<\/strong> section add \u201c<em>Transfer<\/em>\u201d to the <strong>Context Output<\/strong> as expected by the Update Balance dialog<\/li>\n<li>Now the Update Balance can not be triggered by any other dialog.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"Sharing_context_across_FAQs\">Sharing context across FAQs<\/span><\/h3>\n<p>The following Knowledge Collection is used in this scenario:<\/p>\n<p><strong>Primary Question<\/strong>: What are the interest rates for credit cards?<br \/><strong>Primary Question<\/strong>: What are the charges for credit cards?<br \/><strong>Alternate<\/strong>: What are the charges?<\/p>\n<p><a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/26\/FAQ1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-22137\" src=\"\/wp-content\/uploads\/sites\/26\/FAQ1.png\" alt=\"\" width=\"1366\" height=\"768\" \/><\/a><\/p>\n<p>The use case is as follows:<br \/><a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/26\/FAQ-cs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-22159\" src=\"\/wp-content\/uploads\/sites\/26\/FAQ-cs.png\" alt=\"\" width=\"499\" height=\"481\" \/><\/a><\/p>\n<p>In the second question, the word <em>charges<\/em> is in the context of the credit card. To enable it, all you need is set a flag, rest the platform takes care. For each question answered the Context tags are set automatically, we just instruct the platform to use them appropriately.<\/p>\n<ol>\n<li>Go to <strong>Natural Language<\/strong> -&gt; <strong>Thresholds &amp; Configurations<\/strong><\/li>\n<li>Expand the <strong>Knowledge Collection<\/strong> tab<\/li>\n<li>Scroll down and set the <strong>Qualify Contextual Paths<\/strong> tag. With this setting, the KG engine will qualify a question if any of the available context tags are part of that particular FAQ path.<\/li>\n<li>Run the bot and see the effect.<\/li>\n<\/ol>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"Sharing_context_between_intents_and_FAQs\">Sharing context between intents and FAQs<\/span><\/h3>\n<p>The following Knowledge Collection is used in this scenario:<\/p>\n<p><strong>Primary Question<\/strong>: What are your transfer rates?<br \/><strong> Alternate<\/strong>: what are the rates?<\/p>\n<p>The use case here is that the user might, during the transfer amount, ask about the rates. This should result in the appropriate FAQ being triggered to answer the query.<\/p>\n<p><a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/26\/transferRatesFAQ.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-22163\" src=\"\/wp-content\/uploads\/sites\/26\/transferRatesFAQ.png\" alt=\"\" width=\"491\" height=\"641\" \/><\/a><\/p>\n<p>The default setting for the Interruption Behavior for FAQs will ensure that the FAQs are attended to while a Dialog Task is in progress<\/p>\n<p>But this will not solve the use case described. It would answer the direct question &#8211; \u201c<em>What are the transfer rates<\/em>\u201d but not \u201c<em>What are the rates<\/em>\u201d. The reason being the FAQ not picking the context. To ensure that the context is picked by the FAQ:<\/p>\n<ol>\n<li>The <strong>Transfer Amount<\/strong> task is already emitting the <em>transfer<\/em> tag, the same will be used in this case<\/li>\n<li>Go to <strong>Natural Language<\/strong> -&gt; <strong>Thresholds &amp; Configurations<\/strong><\/li>\n<li>Expand the <strong>Knowledge Collection<\/strong> tab<\/li>\n<li>Scroll down and set the <strong>Qualify Contextual Paths<\/strong> tag (if not already set as per previous use case)<\/li>\n<li>Run the Bot and see the changes taking effect<\/li>\n<\/ol>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/section>\n","protected":false},"excerpt":{"rendered":"In this How-To, we will explore a scenario in a Banking Bot, where, sharing the context across intents, FAQs helps in improving the user experience and efficiency of the Bot. Also, we will be looking at how the context can be used within a dialog flow to determine the sequence of events. For details on...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[],"class_list":["post-22331","post","type-post","status-publish","format-standard","hentry","category-how-tos"],"_links":{"self":[{"href":"https:\/\/developer.kore.ai\/v9-2\/wp-json\/wp\/v2\/posts\/22331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.kore.ai\/v9-2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.kore.ai\/v9-2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v9-2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v9-2\/wp-json\/wp\/v2\/comments?post=22331"}],"version-history":[{"count":11,"href":"https:\/\/developer.kore.ai\/v9-2\/wp-json\/wp\/v2\/posts\/22331\/revisions"}],"predecessor-version":[{"id":39321,"href":"https:\/\/developer.kore.ai\/v9-2\/wp-json\/wp\/v2\/posts\/22331\/revisions\/39321"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v9-2\/wp-json\/wp\/v2\/media?parent=22331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v9-2\/wp-json\/wp\/v2\/categories?post=22331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v9-2\/wp-json\/wp\/v2\/tags?post=22331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}