First off, I'm new to Google Assistant so I have very little idea about what I am doing. I am trying to make a webhook request with the code below in an external js file on a webserver:
// 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..
{
"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:
app.handle('contacctSearch', async conv => {
// ...
})
exports.fulfillment = app
firebase deploy --only functions
It will be a function in the format, with your project's ID:
https://us-central1-MY_PROJECT_ID.cloudfunctions.net/fulfillment
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.