Environment variables

You can provide environment variables to your app. The environment variables can be added into the app that you publish in two ways.

Add in your code

You can pass the environment variables into your code as constants. Like simply adding a file on the workspace with the environment variables and accessing them through your code. If your environment variables have sensitive information, we do not recommend this approach as it would be hard coded into your code. And every time the environment changes, you will have to manually make the change and publish your new build.

Add on the fly

You can also add the environment variables from the Chatlayer platform. The environment variables set from there are dynamic which means that you can update them on the fly, and it does not require new builds and publishes. This makes your life a lot easier.

The environment variables in Chatlayer can be added as key value pairs and can be accessed from your app with the bundle object provided.

Copy
Copied
const YOUR_VARIABLE_NAME = bundle.env.YOUR_VARIABLE_NAME

To set up the environment variables into your app, follow the following steps:

  1. Go to Chatlayer
  2. Login with your credentials
  3. Select App Integrations from the left menu app_integrations_page.png
  4. Select the app on which you want to provide the environment variable for Screenshot 2022.02.02 at 13.15.06.png
  5. Select Environment Variables
  6. Add the key value pairs for your environment - key is the name of the variable - value is the actual value of the variable

Screenshot 2022.02.02 at 13.16.24.png

If you want to access the environment variable defined above in your app, you can access it with

Copy
Copied
const authKey = bundle.env.OAUTH2_KEY;

If you want to change it on the fly, you can do it simply by updating the value from the chatlayer platform.

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.