Bot Variables - How to create and where to use?

(Subrahmanyam Donepudi) #1

Bot variables are classified as Global and Content variables which fetch values during runtime. Global variables remain the same throughout the bot and the value for Content variables change based on how they are defined at each of the languages considering its a multi-language bot.

Below snip shows how developers could create global variables on builder tool.

Below snip shows how developers could create content variables on builder tool.

Global and Content variables can be used throughout the bot. Below are some places where they could be used:

  • Actions, Alerts, Information tasks - At the initializer, Parameters, Processors and Bot response
  • Dialogs - Message node, confirmation node, Entity node, script node, the service node (at url parameters and at body),
  • Faqs - Answers and sub-answers
  • Bot Kit - All events

Below is the syntax to use Bot variables at Standard editor and JS editor:
{{env.key}} - Standard Editor
env.key - Adv JS Editor
{{content.key}} - Standard Editor
content.key - Adv JS Editor

Bot variables can be fetched at the Bot Kit. Below are the event types which gets triggered when onVariableUpdate event is selected at bot kit.

  • sdk_subscription - triggered when the app is subscribed to the event onVariableUpdate
  • variable_create - triggered when a new env or language variable is created
  • variable_updated - triggered when a new env or language variable is updated
  • variable_delete - triggered when a new env or language variable is deleted
  • variable_import - triggered variables are imported
  • bot_import - triggered when variables are imported via bot import
  • language_update - triggered when a new language is enabled for the bot

The languages for which the botkit needs to fetch the variables have to be defined at config.json file as below:


Below is the method used to fetch bot variables at bot kit from bot:

sdk.fetchBotVariable(data, langArr, function(err, response) {
dataStore.saveAllVariables(response, langArr);

Please refer to and for details on how & where the bot variables can be fetched on how they could be updated based on the event type received when onVariableUpdate is turned ON at bot builder.

Please note that the variables have to be fetched are stored in the kit in an array as stated at dataStore.js and Botvariables.js of sample bot kit. They will not be available in context.

Bot variables can also be exported and imported on bot builder using JSON file.


Please refer to below document for any further details:

How to access bot variables from bot kit?
(Subrahmanyam Donepudi) #2

With the implementation of " Granular Control over Bot and Task Publishing Process" , the only event related to bot variables which come to bot kit is variable_update.

Bot kit only receives the event - variable_update when the bot is published.

Please refer to the below link to have more details on publish controls: