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



TL;博士

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

一些背景

我正在做一个几个月前离开公司的同事做的一个旧项目。 该项目使用Dialogflow和PHP/Symfony服务器来创建聊天机器人。 早在一月份,该项目运行良好,但是当我上周尝试测试它时,我发现我们的服务器已从主机中不可补救地删除。 我重新上传并重新安装了服务器代码,但我不能 100% 确定备份代码与托管代码完全相同。

正确的行为

  1. 我向服务器发送"嘿">
  2. 服务器将消息传输到对话流
  3. 对话流确定意向为"欢迎">
  4. 对话流将"称呼">发送回服务器
  5. 我得到回复"称呼">

错误行为

  1. 我向服务器发送"帮助">
  2. 服务器将消息传输到对话流
  3. 对话流确定意图为"帮助">
  4. 对话流将"[一些长文本]">发回服务器
  5. 服务器崩溃并返回一般错误 500

默认回退意图也是如此,如果我发送像"等等等等">这样的请求。

区别

欢迎意向不提供输出上下文,也不会重置上下文。 帮助意向确实提供了输出上下文。 回退方法不提供输出上下文,但会重置上下文。

我已验证,如果我使用欢迎意图提供输出上下文,服务器将崩溃,并且如果我从帮助意图中删除输出上下文,则一切正常。

问题

这个项目是怎么回事?为什么输出上下文使我的服务器崩溃?我该如何解决?

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

代码

<?php
namespace AppBundleController;
use RamseyUuidUuid;
use SymfonyBundleFrameworkBundleControllerController;
use SymfonyComponentHttpFoundationJsonResponse;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
use GoogleCloudDialogflowV2SessionsClient;
use GoogleCloudDialogflowV2TextInput;
use GoogleCloudDialogflowV2QueryInput;
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 GoogleApiCoreValidationException
* @throws GoogleApiCoreApiException
* @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));
}
}

欢迎对话框流输出

{
"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>"
}
}

请随时询问更多信息。

经过几天的阴霾,事实证明我的服务器缺少 PHP 扩展bcmathgoogle/protobuf需要。我在php.ini中启用了它,一切正常。

您可以找到有关Github问题的更多信息:https://github.com/googleapis/google-cloud-php/issues/2120

最新更新