{"id":22521,"date":"2019-09-20T08:57:07","date_gmt":"2019-09-20T07:57:07","guid":{"rendered":"https:\/\/developer.kore.ai\/v7-2\/?p=22521"},"modified":"2020-04-22T07:40:07","modified_gmt":"2020-04-22T06:40:07","slug":"how-to-use-global-variables","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v7-2\/docs\/bots\/how-tos\/how-to-use-global-variables\/","title":{"rendered":"How to use Global Variables"},"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>Kore.ai bots platform provides a way to declare and use variables within the bot. These variables can be used to capture values that are commonly used by different tasks, nodes, and other bot elements<\/p>\n<p>In this How-To, we will explore a scenario in a Banking Bot, where Bot Variables can be used. We will see how Global Variables can be used to pass API endpoints and change them easily when migrating from development to testing to production environments.<\/p>\n<p>For details on what Bot Variables are and how they are implemented in the Kore.ai Bots platform, <a href=\"\/v7-2\/docs\/bots\/bot-admin\/bots-management\/using-bot-variables\/\" target=\"_blank\" rel=\"noopener noreferrer\">refer here<\/a>. For a use case with Content Variables, <a href=\"\/v7-2\/docs\/bots\/how-tos\/how-to-use-content-variables\/\" 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>In our <a href=\"\/v7-2\/docs\/bots\/how-tos\/creating-a-banking-bot\/\">Banking Bot<\/a>, we have two tasks:<\/p>\n<ol>\n<li><a href=\"\/v7-2\/docs\/bots\/how-tos\/creating-a-banking-bot\/#Get_Balance_Intent\" target=\"_blank\" rel=\"noopener noreferrer\">Get Balance<\/a> which makes a service call with a given account number to get the balance in that account<\/li>\n<li><a href=\"\/v7-2\/docs\/bots\/how-tos\/banking-bot-update-balance\/\" target=\"_blank\" rel=\"noopener noreferrer\">Update Balance<\/a> which makes a service call to update a given account with the specified amount.<\/li>\n<li>Both the above tasks call the same service and the service API endpoint changes for development, testing, and production environments.<\/li>\n<li>Changing the service call in both the Dialog Tasks is cumbersome and leading to errors, if the change is not done properly.<\/li>\n<\/ol>\n<p>In this document, we will see how Global Variable can be used to store the API endpoint and use it for the service calls.<\/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 Banking Bot with the dialogs as mentioned below:\n<ul>\n<li><strong>Get Balance<\/strong> &#8211; Dialog task prompting the user for their Account Number and displaying the available balance in the account.<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/13\/getBalance1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-22134\" src=\"\/wp-content\/uploads\/sites\/13\/getBalance1.png\" alt=\"\" width=\"788\" height=\"298\" \/><\/a><\/li>\n<li><strong>Update Account<\/strong> &#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=\"\/wp-content\/uploads\/sites\/13\/updateBalance1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-22136\" src=\"\/wp-content\/uploads\/sites\/13\/updateBalance1.png\" alt=\"\" width=\"1037\" height=\"426\" \/><\/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>Declaring a Global Variable to hold the API endpoint will help the transition easier and faster.<\/p>\n<ol>\n<li>Open the Banking Bot.<\/li>\n<li>From\u00a0<strong>Settings -&gt; Config Settings<\/strong> select\u00a0<strong>Global Variables<\/strong> section.<\/li>\n<li>Click\u00a0<strong>Add Global Variable<\/strong> to open the corresponding window.<\/li>\n<li>Enter\u00a0<strong>Variable Name<\/strong>, and <strong>Variable Value<\/strong>. For this use case were are calling the Variable\u00a0<em>accountURL<\/em>, and for value we are entering the <em>Service API call endpoint.<\/em><\/li>\n<li><strong>Save<\/strong>.<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/13\/envVar-create.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-22524\" src=\"\/wp-content\/uploads\/sites\/13\/envVar-create.png\" alt=\"\" width=\"1366\" height=\"768\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/wp-content\/uploads\/sites\/13\/20221201095127\/envVar-create.png 1366w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/wp-content\/uploads\/sites\/13\/20221201095127\/envVar-create-300x169.png 300w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/wp-content\/uploads\/sites\/13\/20221201095127\/envVar-create-1024x576.png 1024w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/li>\n<li>Now open the\u00a0<strong>Get Balance<\/strong> Dialog Task.<\/li>\n<li>Select the\u00a0<strong>GetAccountBalance<\/strong> Service Node.<\/li>\n<li>Click <strong>Edit Request<\/strong> under the\u00a0<strong>Request Definition<\/strong><\/li>\n<li>Replace the request URL with the Global Variable created above. using the <code>env<\/code> prefix followed by any parameters needed. In this case:<br \/>\n<code>{{env.accountURL}}{{context.entities.AccountNumber}}<\/code><br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/13\/envVar-use1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-23444\" src=\"\/wp-content\/uploads\/sites\/13\/envVar-use1.png\" alt=\"\" width=\"1361\" height=\"353\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/wp-content\/uploads\/sites\/13\/20221201095012\/envVar-use1.png 1361w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/wp-content\/uploads\/sites\/13\/20221201095012\/envVar-use1-300x78.png 300w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/wp-content\/uploads\/sites\/13\/20221201095012\/envVar-use1-1024x266.png 1024w\" sizes=\"auto, (max-width: 1361px) 100vw, 1361px\" \/><\/a><\/li>\n<li>Repeat for\u00a0<strong>Update Balance<\/strong> Dialog Task.<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/13\/envVar-use2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-23443\" src=\"\/wp-content\/uploads\/sites\/13\/envVar-use2.png\" alt=\"\" width=\"1365\" height=\"297\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/wp-content\/uploads\/sites\/13\/20221201095012\/envVar-use2.png 1365w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/wp-content\/uploads\/sites\/13\/20221201095012\/envVar-use2-300x65.png 300w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/wp-content\/uploads\/sites\/13\/20221201095012\/envVar-use2-1024x223.png 1024w\" sizes=\"auto, (max-width: 1365px) 100vw, 1365px\" \/><\/a><\/li>\n<li>Now when you Export and Import the Bot to another environment, all you need to worry about is to change the value of the Global Variable and the changes will be effective in both the Dialog Tasks.<\/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":"Kore.ai bots platform provides a way to declare and use variables within the bot. These variables can be used to capture values that are commonly used by different tasks, nodes, and other bot elements In this How-To, we will explore a scenario in a Banking Bot, where Bot Variables can be used. We will see...","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[],"class_list":["post-22521","post","type-post","status-publish","format-standard","hentry","category-how-tos"],"_links":{"self":[{"href":"https:\/\/developer.kore.ai\/v7-2\/wp-json\/wp\/v2\/posts\/22521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.kore.ai\/v7-2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.kore.ai\/v7-2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-2\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-2\/wp-json\/wp\/v2\/comments?post=22521"}],"version-history":[{"count":8,"href":"https:\/\/developer.kore.ai\/v7-2\/wp-json\/wp\/v2\/posts\/22521\/revisions"}],"predecessor-version":[{"id":23538,"href":"https:\/\/developer.kore.ai\/v7-2\/wp-json\/wp\/v2\/posts\/22521\/revisions\/23538"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v7-2\/wp-json\/wp\/v2\/media?parent=22521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-2\/wp-json\/wp\/v2\/categories?post=22521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-2\/wp-json\/wp\/v2\/tags?post=22521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}