botpress / v12

Botpress OSS – v12
https://v12.botpress.com
GNU Affero General Public License v3.0
68 stars 83 forks source link

[FEATURE]: Unable to access EXPOSED_ variable in builtin call api #1411

Closed Uttam92477 closed 1 year ago

Uttam92477 commented 2 years ago

Describe the bug I have started botpress with environment variable EXPOSED_API_URL. I am able to print the environment variable using bp.logger.info(process.env.EXPOSED_API_URL) in custom action.

However, when I am attempting to access the variable using {{process.env.EXPOSED_API_URL}} in Call API built-in action, I am not getting the variable (an empty for URL hostname is coming because of this)

To Reproduce Steps to reproduce the behavior:

  1. Start botpress with environment variable EXPOSED_API_URL=https://www.google.com
  2. Attempt to call API in a bot using url as {{process.env.EXPOSED_API_URL}}

Expected behavior The variable should be available.

Botpres config information version 12.22.2 Executing as docker using AWS ECS Production flag enabled BPFS storage is database Database is postgre

SaidMarar commented 2 years ago

@Uttam92477 I recommand to use a custom action to save API url in state (bot, temp or session) it depends in your needs, then try to access.

temp.EXPOSED_API_URL = process.env.EXPOSED_API_URL

Uttam92477 commented 2 years ago

@Uttam92477 I recommand to use a custom action to save API url in state (temp or session) it depends in your needs, then try to access.

temp.EXPOSED_API_URL = process.env.EXPOSED_API_URL

That's a workaround and thanks for sharing the same however, I am more interested in knowing why I am not able to directly access the environment variables and how to fix it.

JustusNBB commented 2 years ago

I think (please correct me when I remember incorrectly) that this has to do with the sandboxing of Actions, which may use additional dependencies. To protect all parameters in the env (and most importantly credentials saved in there) from any external scripts and their dependencies. In contrast to that Hooks have a similar sandbox, but they have access to process.env.EXPOSED_* by default, as you usually don't load additional npm modules in Hooks.

So this is a feature, not a bug :P