Actions on google 如何在google助手中添加会话属性

Actions on google 如何在google助手中添加会话属性,actions-on-google,dialogflow-es,Actions On Google,Dialogflow Es,我想在api请求中添加一些属性,以便进一步使用它们。我发送的请求如下: $data = array( "source" => "My text", "speech" => "My text", "displayText" =>"My text", "contextOut" => array() ) header('Content-Type: application/json'); echo json_encode($data

我想在api请求中添加一些属性,以便进一步使用它们。我发送的请求如下:

$data = array(
     "source" =>  "My text",
     "speech" =>  "My text",
     "displayText" =>"My text",
     "contextOut" => array()
 )

header('Content-Type: application/json');
echo json_encode($data);
$context = array(
    "name" => "my-context",
    "lifespan" => 99,
    "parameters" => array(
        "parameter_one" => "value_one",
        "parameter_two" => "value_two"
    )
);

$contexts = [$context];

$data = array(
     "source" =>  "My text",
     "speech" =>  "My text",
     "displayText" =>"My text",
     "contextOut" => $contexts
 )

如何将我自己的自定义参数添加到此请求中?

因为您自己处理JSON,所以最好的方法是将您想要的参数添加到请求中。此上下文将在上下文的生命周期(用户请求数)内发送回webhook。您可以随时重新发送上下文并延长其生命周期,也可以将其设置为较长的生命周期。上下文只适用于同一个会话-它们不跨会话

您可以创建一个上下文,并在回复中发送,如下所示:

$data = array(
     "source" =>  "My text",
     "speech" =>  "My text",
     "displayText" =>"My text",
     "contextOut" => array()
 )

header('Content-Type: application/json');
echo json_encode($data);
$context = array(
    "name" => "my-context",
    "lifespan" => 99,
    "parameters" => array(
        "parameter_one" => "value_one",
        "parameter_two" => "value_two"
    )
);

$contexts = [$context];

$data = array(
     "source" =>  "My text",
     "speech" =>  "My text",
     "displayText" =>"My text",
     "contextOut" => $contexts
 )
在请求中,您将在
result.contexts
的数组中查找提取的JSON正文中的值