首页 文章

在访问webhook URL时收到错误“操作错误:没有匹配的意图处理程序:null”

提问于
浏览
8

我试图从对话框流中调用webhook,而不是从webhook获得响应,我从响应部分得到的响应,我已将其置于意图中 . 我还为每个意图启用了webhook,并且还放置了webhook URL,该URL是从firebase CLI在履行URL部分生成的 . 我附上了firebase日志和JSON响应的屏幕截图,我们在对话框流程“show JSON”和index.js文件中也看到了 . 我被困了2周才解决它 .

'use strict';

process.env.DEBUG = 'actions-on-google:*';
const { DialogflowApp } = require('actions-on-google');
const functions = require('firebase-functions');
let express = require('express');
let bodyParser = require('body-parser');

// Constants for Dialogflow Agent Actions
let app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({type: 'application/json'}));

const BYE_RESPONSE = 'input.search';
const WELCOME = 'input.welcome';

exports.helloAssistant = functions.https.onRequest((req, res) => {
  console.log('Request headers: ' + JSON.stringify(req.headers));
  console.log('Request body: ' + JSON.stringify(req.body));
  const asst = new DialogflowApp({request: req, response: res});


  // Welcome
  function welcome(asst) {
    asst.ask('Want to search product or order history');
    asst.tell('hello Neeraj!');
  }

  // Leave conversation with SimpleResponse

  function byeResponse (asst) {
    app.post('/',function (req, res) {
      var myProduct = req.body.result.parameters["productParameter"];
      //let intent=asst.getIntent();
      var address ="https://ipadress/rest/v2/electronics/products/search";
      var address1="https://ipadress";
      switch(myProduct){
        case 'BYE_RESPONSE':
          req.post(address);
          break;

        case 'WELCOME':
          asst.tell('welcome!');
          break;

        default:
          req.post(address1);
          break;
      }

      asst.tell('We swear to serve the master of the Precious.');
    });
  }

  const actionMap = new Map();
  actionMap.set(WELCOME, welcome);

  actionMap.set(BYE_RESPONSE, byeResponse);
  actionMap.set(WELCOME, welcome);
  asst.handleRequest(actionMap);
});

. json response in dialogflow

. firebase log

3 回答

  • 1

    我刚刚遇到了这个完全相同的错误,这是因为我忘了将我的意图名称放在 Actions 部分的 Enter action name 字段中 .

    所以,由于我没有指定一个,因此将 null 作为意图名称 .

    我只是通过 very carefully 重新阅读https://developers.google.com/actions/dialogflow/first-app来解决它 .

  • 10

    谢谢大家的宝贵回应 . 不知何故,我能够修复此null错误 . 实际上,我在代理的API版本部分启用了“Dialogflow V2 API” . 现在,我已禁用它,它对我有用 .

  • 2

    对于每个代理,都需要一个 unknown Intent处理程序来处理意外情况,例如null等

    'input.unknown': () => {
      // The default fallback intent has been matched, try to recover.
      // Define the response users will hear
      responseJson.speech = 'I\'m having trouble, can you try that again?';
      // Define the response users will see
      responseJson.displayText = 'I\'m having trouble :-/ can you try that again?';
      // Send the response to API.AI
      // response.json(responseJson);
      callback(null, responseJson);
    }
    

相关问题