Search code examples
botschatbotbotium-box

Accessing Environment variables in Botium.json


In Botium.json, "SIMPLEREST_INIT_CONTEXT": { "token": "367439234324243" ,"sessionid":"34546363dfgfg4545"}, This value needs to taken from env variable PROCESS.ENV.token, How can i set in this file so that i can use it in simplerest endpoints ??? example would be great


Solution

  • Environment variables can be access within the moustache templates scripting functions, see Botium Wiki.

    ...
    "SIMPLEREST_INIT_CONTEXT": {
      "token": "{{#fnc.func}}{{process.env.token}}{{/fnc.func}}",
      "sessionid":"34546363dfgfg4545"
    }
    ...
    

    It seems as if you want to use the token from the environment variables, and with this token you want to initialize the session before starting a conversation. Could work like this - first make a "ping" request to initialize the session, then use the session id from the ping response body in the following calls:

    ...
    "SIMPLEREST_PING_URL": "some url",
    "SIMPLEREST_PING_VERB": "POST",
    "SIMPLEREST_PING_HEADERS": {
      "token": "{{#fnc.func}}{{process.env.token}}{{/fnc.func}}"
    },
    "SIMPLEREST_PING_BODY": { some json content for the body },
    ...
    "SIMPLEREST_URL": "...",
    "SIMPLEREST_HEADERS_TEMPLATE": {
      "sessionid":"{{context.message.key}}"
    },
    ...