gpt4 book ai didi

javascript - 我正在尝试实现一个dialogflow webook来连接到wordpress api,但收到错误: No responses defined for platform: null

转载 作者:行者123 更新时间:2023-12-02 20:52:34 24 4
gpt4 key购买 nike

这是我的代码。如何配置它以返回 Google Assistant 集成的响应?我想在 Dialogflow 内联代码编辑器中使用此代码或将其部署到 firebase 函数。

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));



function getProjects(agent){
const api = 'https://playhacker.com/wp-json/wp/v2';
const tag = agent.parameters.tag;
//let url = `${api}/posts?tags=${tag}&_embed`;


let getPosts = (tag, callback) => {
let url = `${api}/posts?tags=${tag}&_embed`;
request({url}, (err, res, body) => {
if (err) {
callback('Sorry, there was an error getting posts from our blog', err);
return;
} else {
let posts = JSON.parse(body);
if (posts.length === 0) {
callback(`It does not seem like there is any content available on this topic`);
return;
} else {
let formattedPosts = posts.map((post) => {

return {
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Here is a project we found for you"
}
},
{
"basicCard": {
"title": post.title.rendered,
"subtitle": "Project",
"formattedText": post.excerpt.rendered.replace(/<(?:.|\\n)*?>/gm, '').replace(/&[^\\s]*/, ''),
"image": {
"url": post._embedded['wp:featuredmedia'][0].media_details.sizes.listing.source_url,
"accessibilityText": "featured image"
},
"buttons": [
{
"title": "Read more",
"openUrlAction": {
"url": post.link
}
}
],
"imageDisplayOptions": "CROPPED"
}
}
]
}
}
}
};
});

formattedPosts.unshift({
type: 0,
platform: 'google',
speech: 'Sure, here are some helpful projects'
});

callback(undefined, formattedPosts);
return;
}
}
});
};


}

let intentMap = new Map();

intentMap.set('getProjects',getProjects);
agent.handleRequest(intentMap);
});

当我在 Dialogflow 内联编辑器中运行它时,出现此错误:

{
insertId: "000001-ec48afd6-c286-47e4-8c75-43a2c6f1fc08"
labels: {…}
logName: "projects/apologetic-robot-fiajxe/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2020-05-03T06:38:00.862369842Z"
resource: {
labels: {…}
type: "cloud_function"
}
severity: "ERROR"
textPayload: "Error: No responses defined for platform: null
at V2Agent.sendResponses_ (/srv/node_modules/dialogflow-fulfillment/src/v2-agent.js:243:13)
at WebhookClient.send_ (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:505:17)
at promise.then (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:316:38)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)"
timestamp: "2020-05-03T06:37:59.833Z"
trace: "projects/apologetic-robot-fiajxe/traces/29d9241c46088463269b00ecf3558974"
}

最佳答案

错误错误:未定义响应表示您尚未定义任何要发送到可显示给聊天机器人用户的对话流的响应。

例如。当代码流到达函数 getProjects 时,在从函数返回之前,应该有一个对对话框流的响应,类似于

agent.add(`There seems to be some error`);

这将依次向用户显示该字符串。

此外,在上面的示例中,我看不到您的 getPosts 函数在任何地方被调用。

关于javascript - 我正在尝试实现一个dialogflow webook来连接到wordpress api,但收到错误: No responses defined for platform: null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61571442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com