首页 > 解决方案 > Actions-On-Google/Dialogflow:在 agentId 的平台响应中找不到 RichResponse 或 SystemIntent

问题描述

我正在使用 Dialogflow 和一个用 PHP 编写的 webhook 编写代理程序。最近我重新构建了部分代码,现在我总是在“Actions-on-Google-console”中遇到同样的错误:

由于平台响应无效,无法将 Dialogflow 响应解析为 AppResponse。在 agentId 的平台响应中找不到 RichResponse 或 SystemIntent

现在这是我的 webhook 中的部分代码:

if($action == "willkommen")
{
   $google->Speak("Hallo Welt");
}

$google是我创建的包装器 PHP 类的对象。Speak()方法的代码如下所示:

public function Speak($text,$endConversation=false)
{            
   if($endConversation)
      $expectUserResponse = false;
   else
      $expectUserResponse = true;

   $toGoogle["payload"]["google"]["expectUserResponse"] = $expectUserResponse;
   $toGoogle["payload"]["google"]["richResponse"]["items"][0]["simpleResponse"]["textToSpeech"] = $text;

   file_put_contents("test.log",json_encode($toGoogle,JSON_PRETTY_PRINT));

   echo json_encode($toGoogle,JSON_PRETTY_PRINT);
}

出于调试目的,我将生成的 JSON 写入文件test.log。它包含

{
    "payload": {
        "google": {
            "expectUserResponse": true,
            "richResponse": {
                "items": [
                    {
                        "simpleResponse": {
                            "textToSpeech": "Hallo Welt"
                        }
                    }
                ]
            }
        }
    }
}

所有代码都是从头到尾执行的,因为一旦我编辑了传递给Speak()的字符串, 我就可以看到 JSON 字符串的更改写入test.log。但是我不断收到上面的错误消息。我的 JSON 字符串有什么问题?谷歌怎么会找不到RichResponse

非常感谢!任何帮助表示赞赏!

标签: phpdialogflow-esactions-on-googledialogflow-es-fulfillment

解决方案


请检查您的后备意图。

当回退意图未添加到代理时,“Actions-on-Google-console”会出现此错误。


推荐阅读