{"id":21866,"date":"2019-07-03T06:11:18","date_gmt":"2019-07-03T05:11:18","guid":{"rendered":"https:\/\/developer.kore.ai\/v7-1\/?p=21866"},"modified":"2019-07-30T13:27:03","modified_gmt":"2019-07-30T12:27:03","slug":"using-bot-variables","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v7-1\/docs\/bots\/bot-admin\/bots-management\/using-bot-variables\/","title":{"rendered":"Using Bot 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><strong>Bot variables<\/strong> help you capture values that are commonly used by different tasks, nodes, and other bot elements. You can configure a bot variable as a key-value pair once in the bot settings and substitute key with value at runtime during the conversation flow.<\/p>\n<p>By capturing frequently used values in a single place, bot variables provide the advantages of reusability and consistency.<\/p>\n<p>For example, let\u2019s say you are testing a flight booking bot using a staging endpoint. If you configure the endpoint as a variable, it helps you to call the API from several places quickly. When you want to change the staging endpoint to production while publishing the bot, it is easy.<\/p>\n<p>Similarly, variables can be used to externalize content for messages and prompts from the dialog flow definition.<\/p>\n<p>Kore.ai platform allows bot developers to define two types of variables &#8211; Global and Content.<\/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=\"Global_Variables\">Global Variables<\/span><\/h3>\n<p>Global variables are a primary type of bot variables where you define a key-value pair and use the variable across the bot. As the variables are declared globally, they can be used at any point in the bot configuration.<\/p>\n<p>Some of the typical use-cases where a developer can use global variables are:<\/p>\n<ul>\n<li>To manage the bot across environments having different endpoint URLs. The bot can be exported and imported based on the environment, and the infrastructure team will need to modify only the variable configuration file.<\/li>\n<li>To define and manage the bot response that is repeated within the bot configuration as variables.<\/li>\n<li>Authorization Token<\/li>\n<li>Channel-related tokens and URLs<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Content_Variables\">Content Variables<\/span><\/h3>\n<p>Bot building essentially requires extensive content management efforts. When it comes to multi-language bots, it also involves tedious coordination efforts between the developers and globally-distributed content authors or copyright team.<\/p>\n<p>Content variables enable you to overcome that by abstracting bot flow development efforts from authoring or editing the content. Using Content Variables, programmers can avoid hard-coding the bot content, such as prompts, messages, or any data presented to the user, into bot components, and instead point to specific variables in centrally managed Content Variables files for each bot language.<br \/>\nYou can export the language-specific content variable files to content editors, without exposing any bot configurations. The writers can author the content in the exported file, which you can import back into the bot.<\/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=\"Defining_Bot_Variables\">Defining Bot Variables<\/span><\/h3>\n<p>Follow these steps to add or edit bot variables:<\/p>\n<ol>\n<li>Open the bot for which you want to add the variables, and go to\u00a0<b>Settings &gt; Config Settings<\/b>.<\/li>\n<li>Select either\u00a0<strong>Global Variables\u00a0<\/strong>or\u00a0<strong>Content Variables<\/strong> section<\/li>\n<li>On the Variables page, click <b>Add Variable<\/b> and enter the following details:\n<ul>\n<li><b>Variable Name<\/b>: Enter a name without any special characters, for example, Bots Environment.<\/li>\n<li><b>Value<\/b>: Add a String expression. This string replaces the variable everywhere it is invoked.\n<div class=\"alert alert-info\">Note: For content variables, you need to enter different values for each bot language. Refer to the next section to learn how.<\/div>\n<\/li>\n<li>Enter developer notes in the <b>Notes <\/b>field. While this is an optional field, entering useful notes can help the developer working on the target bot to understand and provide relevant values.<\/li>\n<li><strong>Group<\/strong> can be used to categorize the variable.<\/li>\n<\/ul>\n<\/li>\n<li>Click <b>Save<\/b>.<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/12\/add-variable-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-17164\" src=\"\/wp-content\/uploads\/sites\/12\/add-variable-1.png\" alt=\"\" width=\"820\" height=\"461\" \/><\/a><\/li>\n<li>Repeat steps 3-5 to add or edit more variables.<\/li>\n<\/ol>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n\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=\"Entering_Language-Specific_Values\">Entering Language-Specific Values<\/span><\/h3>\n<p>To add language-specific values for content variables, you first need to switch the bot language. You can switch the language by clicking the name of the currently-enabled language from the top-right corner of the bot\u2019s page and then selecting another language as follows:<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/12\/switching-language.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15068\" src=\"\/wp-content\/uploads\/sites\/12\/switching-language.png\" alt=\"\" width=\"192\" height=\"144\" \/><\/a><br \/>\nAfter switching the language, go to <b>Settings &gt; Config Settings &gt; Content Variables <\/b>page and click the <b>edit <\/b>icon next to the relevant variable. Replace the text in the <b>Value <\/b>field in the enabled language.<\/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=\"Using_Global_Variables\">Using Global Variables<\/span><\/h3>\n<p>You can invoke a global variable in plain text mode (Standard editor) using the following syntax:<br \/>\n<code>{{env.variableName}}<\/code><\/p>\n<p>If you are using it in JavaScript mode, it is <i>env.variableName<\/i><br \/>\nHere\u2019s an example from a bot that uses two global variables called <i>botType<\/i> and <i>parameters <\/i>to determine different bot environments such as development, testing, and production. The following script node in one of the bot\u2019s tasks captures the <i>base URL<\/i> of the bot, depending on the current bot environment.<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/12\/Example-script.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-15069\" src=\"\/wp-content\/uploads\/sites\/12\/Example-script.png\" alt=\"\" width=\"383\" height=\"288\" \/><\/a><br \/>\nThe URL in the following service node changes based on the captured URL<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/12\/service.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-15070\" src=\"\/wp-content\/uploads\/sites\/12\/service.png\" alt=\"\" width=\"613\" height=\"211\" \/><\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_Content_Variables\">Using Content Variables<\/span><\/h3>\n<p>You can invoke a content variable in plain text mode (Standard editor) using the following syntax.<br \/>\n<code>{{content.variableName}}<\/code><\/p>\n<p>If you are using it in JavaScript mode, it is <i>content.variableName<\/i><br \/>\nHere\u2019s an entity node of a multi-language flight booking bot that captures the source airport of the users. It uses a content variable instead of hard-coded user prompt.<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/12\/source-variable.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15071\" src=\"\/wp-content\/uploads\/sites\/12\/source-variable.png\" alt=\"\" width=\"213\" height=\"97\" \/><\/a><br \/>\nWhen the bot reaches this node as a part of the user interaction, the user prompt changes depending on the language of the interaction (provided you entered the respective variable values for all the enabled languages).<\/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=\"Importing_and_Exporting\">Importing and Exporting<\/span><\/h3>\n<p>You can import and export bot variables between bots.<\/p>\n<ol>\n<li>On any of the Bot Variables page accessible from <b>Settings &gt; Config Settings -&gt; (Global\/Content) Variables<\/b>,<\/li>\n<li>Click the <strong>ellipses next to Add Variables<\/strong><\/li>\n<li><em>To Import<\/em>: Select <strong>Import<\/strong> to import variables from a JSON or CSV file\n<ul>\n<li>Since the import will replace the existing variables, you are advised to take a back up of the same.<\/li>\n<li>After taking a Backup,\u00a0<strong>Proceed<\/strong> with the Import<\/li>\n<li>Select a JSON or CSV file to import (see below for the file format)<\/li>\n<\/ul>\n<\/li>\n<li><em>To Export<\/em>: From\u00a0<strong>Export<\/strong> select the preferred format for the export file:\n<ul>\n<li>Bot variables are exported in the form of a JSON, CSV file based upon your selection.<\/li>\n<li>This file includes both global and content variables.<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/12\/var_importexport.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-21872\" src=\"\/wp-content\/uploads\/sites\/12\/var_importexport.png\" alt=\"\" width=\"247\" height=\"231\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>The <strong>Bot Variable file<\/strong> contains the following information, same needs to be present in your Import file. CSV files need a header row. You are advised to refer to Export (or backup) file and use the same format for the Import file.<\/p>\n<ul>\n<li><strong>key<\/strong> (mandatory) &#8211; name of the variable<\/li>\n<li><strong>scope<\/strong>\u00a0 &#8211; scope of the variable corresponds to the Setup Option at the time of variable declaration (if not provided will be set to prePopulated) and can be\n<ul>\n<li>prePopulated,<\/li>\n<li>askOnInstall, or<\/li>\n<li>hidden<\/li>\n<\/ul>\n<\/li>\n<li><strong>value<\/strong> &#8211; value of the variables<\/li>\n<li><strong>variableType<\/strong> (if not set will default to env)-\n<ul>\n<li>env for Global and<\/li>\n<li>locale for Content Variable<\/li>\n<\/ul>\n<\/li>\n<li><strong>audioTag\u00a0<\/strong>-for the player details in case IVR enabled<\/li>\n<li><strong>group<\/strong> &#8211; group name<\/li>\n<li><strong>hint\u00a0<\/strong>&#8211; description of the variable<\/li>\n<\/ul>\n<p><strong>Sample CSV file<\/strong>:<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/12\/importvariable_csv.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-22258\" src=\"\/wp-content\/uploads\/sites\/12\/importvariable_csv.png\" alt=\"\" width=\"1124\" height=\"39\" srcset=\"https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/wp-content\/uploads\/sites\/12\/20221201094919\/importvariable_csv.png 1124w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/wp-content\/uploads\/sites\/12\/20221201094919\/importvariable_csv-300x10.png 300w, https:\/\/kore-wordpress.s3.us-east-2.amazonaws.com\/developer.kore.ai\/wp-content\/uploads\/sites\/12\/20221201094919\/importvariable_csv-1024x36.png 1024w\" sizes=\"auto, (max-width: 1124px) 100vw, 1124px\" \/><\/a><\/p>\n<p><strong>Sample JSON file<\/strong>:<\/p>\n<pre>[\r\n  {\"key\":\"hosturl\",\r\n   \"value\":\"https:\/\/bots.kore.ai\",\r\n   \"hint\":\"This is the URL of environment which can be used across the endpoints configured in the bot\",\r\n   \"audioTag\":\"\",\r\n   \"variableType\":\"env\",\r\n   \"scope\":\"prePopulated\",\r\n   \"group\":\"URLS\"}\r\n]<\/pre>\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":"Bot variables help you capture values that are commonly used by different tasks, nodes, and other bot elements. You can configure a bot variable as a key-value pair once in the bot settings and substitute key with value at runtime during the conversation flow. By capturing frequently used values in a single place, bot variables...","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-21866","post","type-post","status-publish","format-standard","hentry","category-bots-management"],"_links":{"self":[{"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/posts\/21866","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/comments?post=21866"}],"version-history":[{"count":9,"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/posts\/21866\/revisions"}],"predecessor-version":[{"id":22260,"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/posts\/21866\/revisions\/22260"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/media?parent=21866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/categories?post=21866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v7-1\/wp-json\/wp\/v2\/tags?post=21866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}