错误:WebhookClient.handleRequest上没有用于请求意图的处理程序 [英] Error: No handler for requested intent at WebhookClient.handleRequest

查看:67
本文介绍了错误:WebhookClient.handleRequest上没有用于请求意图的处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用云函数的默认意图给出错误

Default intent calling a cloud function gives error

Error: No handler for requested intent
at WebhookClient.handleRequest (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:287:29)
at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:73:11)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:57:9)
at /var/tmp/worker/worker.js:783:7
at /var/tmp/worker/worker.js:766:11
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)

,因为我在诊断信息日志中的网络响应显示了这一点。

as my webresponse in diagnostic info log shows this.

             {
              "responseId": "86043a10-8bc2-4ee7-8e8b-1e997289ad7c",
              "queryResult": {
                "queryText": "hi",
                "action": "input.welcome",
                "parameters": {},
                "allRequiredParamsPresent": true,
                "fulfillmentText": "Hi. Am Uma. Kindly let me know your experience facing an issue.",
                "fulfillmentMessages": [
                  {
                    "text": {
                      "text": [
                        "Hi. Am Uma and welcome to support. Kindly let me know your experience facing an issue."
                      ]
                    }
                  }
                ],
                "outputContexts": [
                  {
                    "name": "projects/handymanticketagent/agent/sessions/e416a522-da87-ebd1-348e-9fdea1efbf65/contexts/defaultwelcomeintent-followup",
                    "lifespanCount": 2
                  }
                ],
                "intent": {
                  "name": "projects/handymanticketagent/agent/intents/c58f706f-6cb6-499d-9ce2-459e8054ddc1",
                  "displayName": "Default Welcome Intent"
                },
                "intentDetectionConfidence": 1,
                "diagnosticInfo": {
                  "webhook_latency_ms": 10001
                },
                "languageCode": "en"
              },
              "webhookStatus": {
                "code": 4,
                "message": "Webhook call failed. Error: Request timeout."
              }
            }

基于堆栈溢出答案在这里,已经添加了一个映射到函数的意图,但是仍然会出错并且可能会进一步发展。云功能控制台在哪里以及如何说缺少我的请求的处理程序?

Based on the stack overflow answers here, Have added an intent mapped to function but am still getting error and could progress further. Where and how the cloud function console says am missing a handler for my request?

更新:如@prisoner所说,包括我的云功能代码。

Update : As @prisoner said, including my cloud function code.

            'use strict';

            const functions = require('firebase-functions');
            const admin = require('firebase-admin');
            const { WebhookClient } = require('dialogflow-fulfillment');

            process.env.DEBUG = 'dialogflow:*'; // enables lib debugging statements
            admin.initializeApp(functions.config().firebase);
            const db = admin.firestore();

            exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
                console.log(request.body.queryResult.fulfillmentText);
                console.log(request);
                console.log(response);
                const agent = new WebhookClient({ request, response });
                console.log(agent);
                function writeToDb(agent) {
                    // Get parameter from Dialogflow with the string to add to the database
                    const databaseEntry = agent.parameters.databaseEntry;
                    console.log(databaseEntry);
                    // Get the database collection 'dialogflow' and document 'agent' and store
                    // the document  {entry: "<value of database entry>"} in the 'agent' document
                    const dialogflowAgentRef = db.collection('dialogflow').doc('agent');
                    console.log(dialogflowAgentRef);
                    return db.runTransaction(t => {

                        t.set(dialogflowAgentRef, { entry: databaseEntry });
                        console.log(Promise.resolve('Write complete'));
                        return Promise.resolve('Write complete');
                    }).then(doc => {
                        agent.add('Wrote "${databaseEntry}" to the Firestore database.');
                        return null;
                        }).catch(err => {
                            if (err) {
                                console.log(err.stack);
                            }
                        console.log('Error writing to Firestore: ${err}');
                        agent.add('Failed to write "${databaseEntry}" to the Firestore database.');

                    });
                }

                function readFromDb(agent) {
                    console.log(agent);
                    // Get the database collection 'dialogflow' and document 'agent'
                    const dialogflowAgentDoc = db.collection('dialogflow').doc('agent');
                    console.log(dialogflowAgentDoc);
                    // Get the value of 'entry' in the document and send it to the user
                    return dialogflowAgentDoc.get()
                        .then(doc => {
                            if (!doc.exists) {
                                agent.add('No data found in the database!');
                            } else {
                                agent.add(doc.data().entry);
                            }
                            return Promise.resolve('Read complete');
                        }).catch(() => {
                            agent.add('Error reading entry from the Firestore database.');
                            agent.add('Please add a entry to the database first by saying, "Write <your phrase> to the database"');
                        });
                }
                function defaultwelcomeintent_function(agent) {
                    console.log(agent);
                } 
                // Map from Dialogflow intent names to functions to be run when the intent is matched
                let intentMap = new Map();
                intentMap.set('defaultwelcomeintent-followup', defaultwelcomeintent_function);
                intentMap.set('ReadFromFirestore', readFromDb);
                intentMap.set('WriteToFirestore', writeToDb);
                console.log(intentMap);
                agent.handleRequest(intentMap);
            });


推荐答案

诊断信息表明该意图的显示名称满足是默认的欢迎意图:

The diagnostic info says that the intent's display name for that fulfillment is "Default Welcome Intent":

"intent": {
    "name": "projects/handymanticketagent/agent/intents/c58f706f-6cb6-499d-9ce2-459e8054ddc1",
    "displayName": "Default Welcome Intent"
},

因此,您需要为其创建一个映射,如下所示:
intentMap.set('默认欢迎意图',defaultwelcomeintent_function);

So you'd need to create a mapping for it like this: intentMap.set('Default Welcome Intent', defaultwelcomeintent_function);

其中 defaultwelcomeintent_function 是您在云函数中定义的处理程序。

Where defaultwelcomeintent_function is the handler you have defined within your cloud function.

这篇关于错误:WebhookClient.handleRequest上没有用于请求意图的处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆