简体   繁体   English

我正在尝试实现一个对话流电子书以连接到 wordpress api,但出现错误:没有为平台定义响应:null

[英]I am trying to implement a dialogflow webook to connect to wordpress api, but getting a Error: No responses defined for platform: null

Here is my code.这是我的代码。 How can I configure it to return a response for the Google Assistant integration?如何配置它以返回对 Google Assistant 集成的响应? I would like to use this code within the Dialogflow in-line code editor or deploy it to firebase functions.我想在 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);
});

When I run it in Dialogflow in-line editor, I got this error:当我在 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"  
}

The error Error: No responses defined means you haven't defined any response to be sent to dialogflow that can be shown back to the chatbot user.错误Error: No responses defined意味着您尚未定义任何要发送到可以显示回聊天机器人用户的对话流的响应。

For eg.例如。 when the codeflow reaches the function getProjects , there should be a response back to dialogflow before returning from the function, anything like当代码流到达 function getProjects时,应该在从 function 返回之前对对话流做出响应,例如

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

which will in turn show this string back to the user.这将反过来将该字符串显示给用户。

Additonally, in your above example, I cannot see your getPosts function being called anywhere.此外,在您上面的示例中,我看不到您的getPosts function 在任何地方被调用。

暂无
暂无

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

相关问题 地理编码 API 和 DialogFlow 意图获取“错误:没有为平台定义的响应:空” - Geocoding API and DialogFlow intent getting ' Error: No responses defined for platform: null ' 没有为平台定义响应:DIALOGFLOW_CONSOLE - No responses defined for platform: DIALOGFLOW_CONSOLE 我正在尝试为Google登录API调用signOut()函数,但不断收到错误“gapi未定义” - I am trying to call the signOut() function for the Google Sign-in api but keep getting the error “gapi is not defined” 我正在尝试在反应中实现 menuitem 但出现错误 - I am trying to implement menuitem in react but getting error 尝试使用StageWebView在AIR Android应用程序中实现Google Maps JavaScript API时,为什么会出现“ InvalidValueError”错误? - Why am I getting “InvalidValueError” error when trying to implement Google Maps JavaScript API in an AIR Android application using StageWebView? 我正在尝试使用 WebSocket 连接到 API 但我得到了这个 Uncaught ReferenceError: require is not defined - I am trying to connect to an API using WebSocket but I got this Uncaught ReferenceError: require is not defined 试图将 api 响应存储在异步存储中,但我无法存储它 - trying to store api responses in asyncstorage but I am unable to store it 为什么我会收到来自 api 呼叫的重复响应? - Why am I getting repeated responses from api call? 当我尝试在 JavaScript 中将变量从一个函数传递到另一个函数时,我收到 Reference Error: variable is not defined 错误(邮递员) - I am getting Reference Error: variable is not defined error when I am trying to pass variable from one function to another in JavaScript ( postman) 为什么我收到“未定义块”错误? - Why am I getting this error “block is not defined”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM