简体   繁体   English

来自 webhook 的 Google Assistant 响应无效:无法将 JSON 转换为 ExecuteHttpResponse

[英]Google Assistant Invalid response from webhook: Failed to translate JSON to ExecuteHttpResponse

First off, I'm new to Google Assistant so I have very little idea about what I am doing.首先,我是 Google Assistant 的新手,所以我对自己在做什么一无所知。 I am trying to make a webhook request with the code below in an external js file on a webserver:我正在尝试使用以下代码在网络服务器上的外部 js 文件中发出 webhook 请求:

// 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}`);
}
});

But, I am receiving an error: Invalid response from webhook: Failed to translate JSON to ExecuteHttpResponse..但是,我收到一个错误:来自 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"
}

Any help would be amazing!任何帮助都会很棒!

It seems to me that your file is not being understood as code, but rather a plain text file.在我看来,您的文件并未被理解为代码,而是纯文本文件。 There are several things to change:有几件事要改变:

  1. Be sure to declare a Firebase Function at the bottom of your file:请务必在文件底部声明 Firebase Function
app.handle('contacctSearch', async conv => {
  // ...
})

exports.fulfillment = app
  1. It seems like you're pointing your webhook to your textfile rather than ensuring it is available as something executable.似乎您将 webhook 指向您的文本文件,而不是确保它可以作为可执行文件使用。 You should make sure you deploy your function , which you're using Firebase Functions, then use the webhook URL that Firebase gives you: You should make sure you deploy your function , which you're using Firebase Functions, then use the webhook URL that Firebase gives you:
firebase deploy --only functions

It will be a function in the format, with your project's ID:它将是 function 格式,您的项目 ID:

https://us-central1-MY_PROJECT_ID.cloudfunctions.net/fulfillment

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 网络钩子调用失败。 错误:无法解析 webhook JSON 响应:找不到字段:消息 google.cloud.dialogflow.v2.Intent.Message 中的消息 - Webhook call failed. Error: Failed to parse webhook JSON response: Cannot find field: messages in message google.cloud.dialogflow.v2.Intent.Message 从Mandrill Webhook接收到无效的JSON字符串 - Invalid JSON String Received from Mandrill Webhook 带有API2 webhook的Google Dialogflow:无法解析响应 - Google Dialogflow with API2 webhook: Failed to Parse response DialogFlow Cx webhook 响应导致“ErrorCode”:“INVALID_ARGUMENT”、“ErrorMessage”:无法解析 webhook 响应: - DialogFlow Cx webhook response results in "ErrorCode": "INVALID_ARGUMENT", "ErrorMessage": Failed to parse webhook response: 无效的 URL 用于在 webhook URL 上使用 IP 地址 - Watson Assistant - Invalid URL for using an IP adress on webhook URL - Watson Assistant 如何从POST请求(Webhook)“查看” JSON响应 - How to “see” json response from POST request (webhook) 从获取 webhook 响应嵌套的 json 创建数组 - Creating an array from a get webhook response nested json 如何使用谷歌助手 IFTTT 发送网络钩子以不和谐 - How do I send a webhook to discord using google assistant IFTTT 如何收听来自 webhook 的响应? - how to listen to response from a webhook? Dialogflow 无法解析来自 Google Apps 脚本的 Webhook 响应 - Dialogflow fails to parse Webhook response from Google Apps Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM