在本地运行Firebase客户端时,如何模拟请求参数



我已经组合了一个Google Dialogflow应用程序,其中有许多我需要使用外部REST API来处理的许多fulillments。我已经设置了客户端并使用firebase serve,使我能够在本地进行测试。我的index.js函数具有以下siganture:

exports.clientEmployeeServiceCodes = functions.https.onRequest(async (req, res)=>{...});

但是,当我在本地运行任何请求参数时,我通过URL会出现不确定。这是一个例子。

http://localhost:5000/arc-caregiver-f8ec9/us-central1/clientEmployeeServiceCodes?phone=%22%%2b12123003939%22

,但是当我通过DialogFlow致电时,我会得到参数。因此,我的问题是我是在做错问题还是有办法在我的URL调用中模拟这些参数,因此该方法的行为就像我从DialogFlow打电话一样。

这是我通过REQ对象获得对话流参数的示例。注意 PIN 的值。

exports.userHours = functions.https.onRequest(async (req, res)=>{
 const start = MyUtils.getDatePlus(-14);
 const end = MyUtils.getDatePlus(14);
 var view = 'API_Pay_Periods';
 var form = 'Pay_Periods';
 var criteria = 'Pay_Period_Date >= "'+start+'" %26%26 Pay_Period_Date <= 
 "'+end+'"'
 const ret = await callRestAPI(Config,view,form,criteria);
 const pp = getPayPeriod(ret);
 const pin = req.query.pin
 console.log('pin',pin)
 const data = await RESTAPI(Config, view,form,criteria);
 res.status(200).send(response);
 ....
 res.end();

}(;

DialogFlow通过请求正文中的JSON对象通过帖子将其履行信息发送到您的Webhook。您无法通过在URL本身中发送查询参数来复制此内容。

使用此操作的一种典型方法是将Ngrok隧道设置为当地环境,并使用它来记录发送的JSON主体。然后,您可以在以后使用相同的身体进行测试。

最新更新