【发布时间】:2019-03-21 03:33:12
【问题描述】:
我正在尝试使用实现 webhook 创建一个 firebase 函数来将 API 响应发送到 dialogflow,但我遇到了错误:500。
const functions = require('firebase-functions');
var request = require('request')
exports.webhook = functions.https.onRequest((request, response) => {
console.log("request.body.result.parameters: ", request.body.result.parameters);
let params = request.body.result.parameters;
var options = {
url: `https://islam360api.herokuapp.com/${params.find}`,
json:true
}
request(options, function(error, response, body){
if(error) response.send(error);
else response.send(body);
});
});
我在部署时收到的警告是
13:26 warning Unexpected function expression prefer-arrow-callback
✖ 1 problem (0 errors, 1 warning)
0 errors and 1 warning potentially fixable with the `--fix` option.
例如,如果params.find 是evoke,那么解析 API 响应应该给出这个结果
https://islam360api.herokuapp.com/evoke
{"speech":"In Surat-ul-Fateha, Ayat Number: 7, Quran says: not of those who have evoked [Your] anger or of those who are astray. ","displayText":"In Surat-ul-Fateha, Ayat Number: 7, Quran says: not of those who have evoked [Your] anger or of those who are astray. "}
编辑: 这是我在部署 firebase 功能时得到的响应
C:\Users\mnauf\Desktop\IOT\islam360\firebase>firebase deploy --only functions
=== Deploying to 'islam360-3cf18'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint C:\Users\mnauf\Desktop\IOT\islam360\firebase\functions
> eslint .
C:\Users\mnauf\Desktop\IOT\islam360\firebase\functions\index.js
13:26 warning Unexpected function expression prefer-arrow-callback
✖ 1 problem (0 errors, 1 warning)
0 errors and 1 warning potentially fixable with the `--fix` option.
+ functions: Finished running predeploy script.
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (37.98 KB) for uploading
+ functions: functions folder uploaded successfully
i functions: updating Node.js 6 function webhook(us-central1)...
+ functions[webhook(us-central1)]: Successful update operation.
+ Deploy complete!
Please note that it can take up to 30 seconds for your updated functions to propagate.
Project Console: https://console.firebase.google.com/project/islam360-3cf18/overview
日志
原始 API 响应
{
"id": "ed1108a6-a938-4cfb-8fe1-7a1fa0c856e4",
"timestamp": "2019-03-20T18:02:22.676Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "where does Quran talk about evoke",
"action": "",
"actionIncomplete": false,
"parameters": {
"find": "evoke"
},
"contexts": [],
"metadata": {
"isFallbackIntent": "false",
"webhookResponseTime": 129,
"intentName": "find",
"intentId": "dd549c44-25bd-48fa-915f-4810759968eb",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false"
},
"fulfillment": {
"speech": "Something went wrong",
"messages": [
{
"type": 0,
"speech": "Something went wrong"
}
]
},
"score": 1
},
"status": {
"code": 206,
"errorType": "partial_content",
"errorDetails": "Webhook call failed. Error: 500 Internal Server Error"
},
"sessionId": "4d887eaa-2dc1-649d-9ae6-238a6d79f085"
}
履行请求
{
"id": "ed1108a6-a938-4cfb-8fe1-7a1fa0c856e4",
"timestamp": "2019-03-20T18:02:22.676Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "where does Quran talk about evoke",
"action": "",
"actionIncomplete": false,
"parameters": {
"find": "evoke"
},
"contexts": [],
"metadata": {
"isFallbackIntent": "false",
"webhookResponseTime": 129,
"intentName": "find",
"intentId": "dd549c44-25bd-48fa-915f-4810759968eb",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false"
},
"fulfillment": {
"speech": "Something went wrong",
"messages": [
{
"type": 0,
"speech": "Something went wrong"
}
]
},
"score": 1
},
"status": {
"code": 206,
"errorType": "partial_content",
"errorDetails": "Webhook call failed. Error: 500 Internal Server Error"
},
"sessionId": "4d887eaa-2dc1-649d-9ae6-238a6d79f085"
}
履行响应
Error: could not handle the request
履行状态
Webhook call failed. Error: 500 Internal Server Error
控制台截图
Firebase 日志
从 firebase 日志看来,我必须付费。我必须这样做吗?
【问题讨论】:
-
Firebase 日志仍然丢失,转到 firebase 控制台并选择函数,然后选择日志并共享这些日志,我还建议您将整个代码包装在 try catch 块中以捕获每个错误并记录它
标签: node.js firebase dialogflow-es