Ошибка встроенного редактора в DialogFlow «Невозможно прочитать параметры свойства undefined» - PullRequest
0 голосов
/ 13 июля 2020

Когда я провожу тест на самом DialogFlow или Slack, появляется следующее сообщение об ошибке:

TypeError: невозможно прочитать параметры свойства undefined в сообщении (/srv/index.js : 32: 30)

Очевидно, что ошибка в console.log (context.parameters.name); он почему-то не распознает параметры

Мой код в DialogfLow:

index . js:


    const functions = require('firebase-functions');
    const { WebhookClient } = require('dialogflow-fulfillment');
    const { Card, Suggestion } = require('dialogflow-fulfillment');
    const admin = require('firebase-admin');
    admin.initializeApp({
        credential: admin.credential.applicationDefault(),
        databaseURL: 'https://testechatbot-2020.firebaseio.com/'
    });
    process.env.DEBUG = 'dialogflow:debug';
    
    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 Nome(agent) {
            var banco = admin.database().ref('Dados/').push({
                Nome: agent.parameters['nome']
            });
            chave = banco.key;
        }
    
        function Valor(agent) {
            var banco = admin.database().ref('Dados/' + chave).update({
                Valor: agent.parameters['valor']
            });
        }
    
        function Mensagem(agent) {
            var name;
            var context = agent.context.get('awainting_nome');
            console.log (context.parameters.name);
      }
    
        let intentMap = new Map();
        intentMap.set('EntradaNome', Nome);
        intentMap.set('EntradaValores', Valor);
        intentMap.set('EntradaMensagem', Mensagem);
        agent.handleRequest(intentMap);
    });

пакет. json


    {
      "name": "dialogflowFirebaseFulfillment",
      "description": "Fluxo com envio de parametros para o Firebase",
      "version": "1.0.0",
      "private": true,
      "license": "Apache Version 2.0",
      "author": "Google Inc.",
      "engines": {
        "node": ">=10.0.0"
      },
      "scripts": {
        "start": "firebase serve",
        "deploy": "firebase deploy"
      },
      "dependencies": {
        "@google-cloud/firestore": "^0.16.1",
        "firebase-admin": "^8.13.0",
        "actions-on-google": "^2.2.0",
        "firebase-functions": "^3.7.0",
        "dialogflow": "^1.2.0",
        "dialogflow-fulfillment": "^0.6.0",
        "@google-cloud/dialogflow": "^3.0.0"
      }
    }

Ссылки на изображения:

EntradaNome

EntradaValores

EntradaMensagem

Я внес несколько изменений в индекс. js потому что я понял, что в намерении EntradaNome имя параметра было "nome", а не "name", но я все равно сохранил то же сообщение об ошибке

  function Mensagem(agent) {
       var context = agent.context.get('awainting_nome');
       let nome = context.parameters.nome;  
       console.log(nome);
  }
...