【问题标题】:Accessing Environment variables in Botium.json在 Botium.json 中访问环境变量
【发布时间】:2020-06-17 00:12:20
【问题描述】:

在 Botium.json, "SIMPLEREST_INIT_CONTEXT": { "token": "367439234324243" ,"sessionid":"34546363dfgfg4545"}, 这个值需要取自环境变量 PROCESS.ENV.token, 我该如何设置文件,以便我可以在最简单的端点中使用它???例子会很棒

【问题讨论】:

  • 我也尝试过使用带有 js 文件的 SIMPLEREST_START_HOOK,但是 botium 只是执行了钩子并停止了,没有运行任何测试const request = require('request') var myJSONObject = json data here; module.exports = ({ context }) => {return new Promise((resolve, reject) => { request({url: "http end point here",method: "POST",json: true,headers: {"token": "0jdfhjdfho8re4545340f2"}, body: myJSONObject }, function (error, response, body){context.sessionid=response.body.message.key; context.client=response.body.client; context.token='45435634534jhj45j4j3343; })})}

标签: bots chatbot botium-box


【解决方案1】:

可以在 mustache 模板脚本函数中访问环境变量,请参阅 Botium Wiki

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

似乎您想使用环境变量中的令牌,并且您希望使用此令牌在开始对话之前初始化会话。可以这样工作 - 首先发出“ping”请求来初始化会话,然后在以下调用中使用 ping 响应正文中的会话 ID:

...
"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}}"
},
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多