带有输出上下文的Dialogflow响应使PHP/Symfony服务器崩溃

带有输出上下文的Dialogflow响应使PHP/Symfony服务器崩溃,symfony,dialogflow-es,Symfony,Dialogflow Es,TL;DR 当Dialogflow发送带有输出上下文的响应时,我的PHP/Symfony服务器崩溃,但当响应没有任何输出上下文时工作正常。 为什么会这样?如何防止服务器崩溃 某些上下文 { "queryText": "hey", "action": "input.welcome", "parameters": {}, "fulfillmentText": "Salutations !", "fulfillmentMessages": [ { "text":

TL;DR

当Dialogflow发送带有输出上下文的响应时,我的PHP/Symfony服务器崩溃,但当响应没有任何输出上下文时工作正常。 为什么会这样?如何防止服务器崩溃

某些上下文

{
  "queryText": "hey",
  "action": "input.welcome",
  "parameters": {},
  "fulfillmentText": "Salutations !",
  "fulfillmentMessages": [
    {
      "text": {
        "text": [
          "Salutations !"
        ]
      },
      "lang": "fr"
    }
  ],
  "intent": {
    "id": "<id>",
    "displayName": "Default Welcome Intent",
    "priority": 500000,
    "events": [
      "WELCOME"
    ],
    "action": "input.welcome",
    "messages": [
      {
        "text": {
          "text": [
            "Hi! How are you doing?",
            "Hello! How can I help you?",
            "Good day! What can I do for you today?",
            "Greetings! How can I assist?"
          ]
        },
        "lang": "en"
      },
      {
        "text": {
          "text": [
            "Salut !",
            "Bonjour !",
            "Salutations !",
            "Bienvenue !"
          ]
        },
        "lang": "fr"
      }
    ]
  },
  "intentDetectionConfidence": 1,
  "languageCode": "fr",
  "slotfillingMetadata": {
    "allRequiredParamsPresent": true
  },
  "id": "<id>",
  "sessionId": "<id>",
  "timestamp": "2019-07-15T07:41:28.778Z",
  "source": "agent",
  "webhookStatus": {
    "webhookEnabledForAgent": true
  },
  "agentEnvironmentId": {
    "agentId": "<id>",
    "cloudProjectId": "<id>"
  }
}
{
  "queryText": "aide",
  "parameters": {},
  "fulfillmentText": "<long text>",
  "fulfillmentMessages": [
    {
      "text": {
        "text": [
          "<long text>"
        ]
      },
      "lang": "fr"
    }
  ],
  "intent": {
    "id": "<id>",
    "displayName": "Help",
    "priority": 500000,
    "messages": [
      {
        "text": {
          "text": [
            "<long text>"
          ]
        },
        "lang": "fr"
      }
    ]
  },
  "intentDetectionConfidence": 1,
  "languageCode": "fr",
  "slotfillingMetadata": {
    "allRequiredParamsPresent": true
  },
  "id": "<id>",
  "sessionId": "<id>",
  "timestamp": "2019-07-15T13:05:25.255Z",
  "source": "agent",
  "webhookStatus": {
    "webhookEnabledForAgent": true
  },
  "agentEnvironmentId": {
    "agentId": "<id>",
    "cloudProjectId": "<id>"
  }
}
我在做一个老项目,是一个几个月前离开公司的同事做的。 该项目使用Dialogflow和PHP/Symfony服务器创建聊天机器人。 早在一月份,这个项目运行得很好,但是当我上周尝试测试它时,我发现我们的服务器已经从主机上无可挽回地删除了。 我重新加载并重新安装了服务器代码,但我不能100%确定备份代码与托管代码完全相同

正确的行为

  • 我向服务器发送“嘿”
  • 服务器将消息传输到Dialogflow
  • Dialogflow确定意图为“欢迎”
  • Dialogflow向服务器发回“问候语”
  • 我得到的回答是“敬礼”
  • 错误行为

  • 我向服务器发送“帮助”
  • 服务器将消息传输到Dialogflow
  • Dialogflow确定目的是“帮助”
  • Dialogflow将“[一些长文本]”发送回服务器
  • 服务器崩溃并返回一般错误500
  • 如果我发送一个类似“诸如此类”的请求,那么默认的回退意图也是如此

    差异

    <?php
    
    namespace AppBundle\Controller;
    
    use Ramsey\Uuid\Uuid;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\JsonResponse;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\Routing\Annotation\Route;
    use Google\Cloud\Dialogflow\V2\SessionsClient;
    use Google\Cloud\Dialogflow\V2\TextInput;
    use Google\Cloud\Dialogflow\V2\QueryInput;
    
    class DefaultController extends Controller
    {
        /**
         * @Route("/messenger", name="homepage")
         *
         */
        public function indexAction(Request $request)
        {
            return $this->render('@App/messenger.twig', array());
        }
    
        /**
         * @param Request $request
         *
         * @Route("/messenger/call/{intent}", options={"expose"=true}, name="call_assistant")
         * @throws \Google\ApiCore\ValidationException
         * @throws \Google\ApiCore\ApiException
         * @throws \Exception
         */
        public function callAssistantAction(Request $request, $intent) {
            $sessionDialogFlow = $this->get('session')->get('dialogFlow_session');
            if ($sessionDialogFlow === null) {
                $sessionDialogFlow = Uuid::uuid4()->toString();
                $this->get('session')->set('dialogFlow_session', $sessionDialogFlow);
            }
    
            $sessionClient = new SessionsClient(array(
                'credentials' => realpath($this->getParameter('kernel.root_dir'). "/../web/authentDialogFlow.json")
            ));
    
            $session = $sessionClient->sessionName("<my session name>", $sessionDialogFlow);
            $textInput = new TextInput();
            $textInput->setText($intent);
            $textInput->setLanguageCode('fr-FR');
    
            $queryInput = new QueryInput();
            $queryInput->setText($textInput);
    
            $response = $sessionClient->detectIntent($session, $queryInput); // <- this line is where the crash happens
            $queryResult = $response->getQueryResult();
            $fulfillmentText = $queryResult->getFulfillmentText();
    
            return new JsonResponse(array("response" => $fulfillmentText));
        }
    }
    
    欢迎意图不提供输出上下文,也不重置上下文。 帮助意图确实提供了输出上下文。 回退意图不提供输出上下文,但会重置上下文

    我验证过,如果我提供了带有欢迎意图的输出上下文,服务器就会崩溃,如果我从帮助意图中删除了输出上下文,一切都正常

    问题

    这个项目是怎么回事?为什么输出上下文会使我的服务器崩溃?如何修复它?

    当然,我不能从意图中删除输出上下文

    代码

    <?php
    
    namespace AppBundle\Controller;
    
    use Ramsey\Uuid\Uuid;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\JsonResponse;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\Routing\Annotation\Route;
    use Google\Cloud\Dialogflow\V2\SessionsClient;
    use Google\Cloud\Dialogflow\V2\TextInput;
    use Google\Cloud\Dialogflow\V2\QueryInput;
    
    class DefaultController extends Controller
    {
        /**
         * @Route("/messenger", name="homepage")
         *
         */
        public function indexAction(Request $request)
        {
            return $this->render('@App/messenger.twig', array());
        }
    
        /**
         * @param Request $request
         *
         * @Route("/messenger/call/{intent}", options={"expose"=true}, name="call_assistant")
         * @throws \Google\ApiCore\ValidationException
         * @throws \Google\ApiCore\ApiException
         * @throws \Exception
         */
        public function callAssistantAction(Request $request, $intent) {
            $sessionDialogFlow = $this->get('session')->get('dialogFlow_session');
            if ($sessionDialogFlow === null) {
                $sessionDialogFlow = Uuid::uuid4()->toString();
                $this->get('session')->set('dialogFlow_session', $sessionDialogFlow);
            }
    
            $sessionClient = new SessionsClient(array(
                'credentials' => realpath($this->getParameter('kernel.root_dir'). "/../web/authentDialogFlow.json")
            ));
    
            $session = $sessionClient->sessionName("<my session name>", $sessionDialogFlow);
            $textInput = new TextInput();
            $textInput->setText($intent);
            $textInput->setLanguageCode('fr-FR');
    
            $queryInput = new QueryInput();
            $queryInput->setText($textInput);
    
            $response = $sessionClient->detectIntent($session, $queryInput); // <- this line is where the crash happens
            $queryResult = $response->getQueryResult();
            $fulfillmentText = $queryResult->getFulfillmentText();
    
            return new JsonResponse(array("response" => $fulfillmentText));
        }
    }
    

    经过几天的低迷之后,我发现我的服务器缺少
    google/protobuf
    所需的PHP扩展
    bcmath
    。我在我的
    php.ini
    中启用了它,一切正常

    您可以找到有关Github问题的更多信息: