如何解决来自 webhook 的 Google 助理无效响应:无法将 JSON 转换为 ExecuteHttpResponse
首先,我是 Google 助理的新手,所以我对自己在做什么知之甚少。我正在尝试在网络服务器上的外部 js 文件中使用以下代码发出网络钩子请求:
// Project Requirements
const { conversation } = require('@assistant/conversation');
const functions = require('firebase-functions');
// Constructor
const app = conversation();
// Search Function
app.handle('contacctSearch',async conv => {
// Get Intent Parameters
const query = $session.params.contactName.original;
const pageType = $session.params.pageType.original;
if (pageType.toUpperCase() == 'WHITE PAGES') {
const res = await fetch(`https://www.findyello.com/barbados/white-pages/?search=${query}`);
console.log(res);
// Parse res into text
const text = res;
conv.add(`Here is your first result. ${text}`);
}
else if (pageType.toUpperCase() =='YELLOW PAGES') {
const res = await fetch(`https://www.findyello.com/barbados/?search=${query}`);
console.log(res);
// Parse res into text
const text = res;
conv.add(`Here is your first result. ${text}`);
}
else if (pageType.toUpperCase() =='GOVERNMENT PAGES') {
const res = await fetch(`https://www.findyello.com/barbados/government/?search=${query}`);
console.log(res);
// Parse res into text
const text = res;
conv.add(`Here is your first result. ${text}`);
}
});
但是,我收到一个错误:来自 webhook 的无效响应:无法将 JSON 转换为 ExecuteHttpResponse..
{
"responseJson": "// console.log('Working!');\r\n\r\n// Project Requirements\r\nconst { conversation }
= require('@assistant/conversation');\r\nconst functions = require('firebase-functions');\r\n\r\n//
Constructor\r\nconst app = conversation();\r\n\r\n// Search Function\r\napp.handle('contacctSearch',async conv => {\r\n\r\n // Get Intent Parameters\r\n const query =
$session.params.contactName.original;\r\n const pageType = $session.params.pageType.original;\r\n
if (pageType.toUpperCase() == 'WHITE PAGES') {\r\n const res = await
fetch(`https://www.findyello.com/barbados/white-pages/?search=${query}`);\r\n
console.log(res);\r\n // Parse res into text\r\n const text = res;\r\n
conv.add(`Here is your first result. ${text}`);\r\n } \r\n \r\n else if
(pageType.toUpperCase() =='YELLOW PAGES') {\r\n const res = await
fetch(`https://www.findyello.com/barbados/?search=${query}`);\r\n console.log(res);\r\n
// Parse res into text\r\n const text = res;\r\n conv.add(`Here is your first result.
${text}`);\r\n } \r\n \r\n else if (pageType.toUpperCase() =='GOVERNMENT PAGES') {\r\n
const res = await fetch(`https://www.findyello.com/barbados/government/?search=${query}`);\r\n
console.log(res);\r\n // Parse res into text\r\n const text = res;\r\n
conv.add(`Here is your first result. ${text}`);\r\n }\r\n });\r\n"
}
任何帮助都会很棒!
解决方法
在我看来,您的文件并未被理解为代码,而是纯文本文件。有几件事需要改变:
- 请务必在文件底部declare a Firebase Function:
app.handle('contacctSearch',async conv => {
// ...
})
exports.fulfillment = app
- 似乎您将 webhook 指向文本文件,而不是确保它可作为可执行文件使用。您应该确保您使用的是 Firebase 函数的 deploy your function,然后使用 Firebase 为您提供的网络钩子网址:
firebase deploy --only functions
它将是一个函数,格式为,带有您的项目 ID:
https://us-central1-MY_PROJECT_ID.cloudfunctions.net/fulfillment
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。