我应该在哪里查看错误“MalformedResponse 由于语音响应为空,无法将 Dialogflow 响应解析为 AppResponse

Where should I look into for the error "MalformedResponse Failed to parse Dialogflow response into AppResponse because of empty speech response

收到错误

MalformedResponse Failed to parse Dialogflow response into AppResponse because of empty speech response

已阅读 Failed to parse Dialogflow response into AppResponse because of empty speech response for Ssml response 但仍未理解要点。

我是新手

尝试按照 "Query Data Scalably for Actions on Google using Cloud Firestore" 中提供的代码进行操作,但出现错误。

//Copyright 2018 Google LLC.SPDX-License-Identifier: Apache-2.0

'use strict';

const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const app = dialogflow({debug: true});

admin.initializeApp();

const db = admin.firestore();
const collectionRef = db.collection('restaurants');

app.intent('ask_recipe_intent', (conv, {name}) => {
  const term = name.toLowerCase();
  const termRef = collectionRef.doc(`${term}`);

  return termRef.get()
    .then((snapshot) => {
      const {city, name} = snapshot.data();
      conv.ask(`Here you go, ${name}, ${city}. ` +
            `What else do you want to know?`);

    }).catch((e) => {
      console.log('error:', e);
      conv.close('Sorry, try again and tell me another food.');
    });
});


exports.actionsOracle = functions.https.onRequest(app);

我正在尝试了解什么

`${term}`

是什么以及如何在 Firebase 中使用它?我没有任何名为 "term".

的文档

你有几个不相关的问题。

collectionRef.doc(`${term}`);

过于复杂。您可以安全地将其重写为

collectionRef.doc(term);

因为反引号在这种情况下没有任何作用。 JavaScript 最新版本中的反引号在 ${} 部分内进行表达式扩展。所以评估表达式

`${term}`

只是评估 term 是什么。因此,该函数的结果是在 Firestore 中创建一个由 term 命名的文档的引用,它只是 Dialogflow Intent 中 name 参数的小写版本。

这导致我们遇到您遇到的错误。如果您未能发送回复,通常会发生这种情况。无法发送回复的原因有很多,最常见的两个是

  • 您没有致电 conv.ask()conv.close()
  • 您正在执行异步操作(例如调用数据库)而没有返回 Promise

但是,在您的情况下,您似乎两者都在做。

您的函数似乎有可能在到达数据库调用之前产生错误。在这种情况下最有可能的可能是行

const term = name.toLowerCase();

如果未定义 name,这可能会导致错误,这意味着它不是 Dialogflow Intent 中的参数。

您可能希望参考以下两篇文章,其中还探讨了 Google 意图实现上的调试操作: