dialogflow使用php客户端库更新意图培训短语

时间:2018-10-29 09:44:18

标签: php dialogflow client-library

我正在使用dialogflow php客户端库来访问dialogflow的v2 rest api。我可以打电话给detectIntent和其他东西,它正在工作。但是有时我应该搜索特定的trainingPhrase,如果不存在,则为检测到的意图添加新的训练短语。我如何使用php客户端库执行此操作?我厌倦了对此的搜索。请帮我。任何答案将不胜感激。我使用的带有一些文本的getIntent函数如下所示,

function detect_intent_texts($projectId, $text, $sessionId, $languageCode = 'en-US')
{
    global $common;
    // new session
    $test = array('credentials' => 'key_file.json');
    $sessionsClient = new SessionsClient($test);
    $session = $sessionsClient->sessionName($projectId, $sessionId ?: uniqid());
    //printf('Session path: %s' . PHP_EOL, $session);

    // create text input
    $textInput = new TextInput();
    $textInput->setText($text);
    $textInput->setLanguageCode($languageCode);

    // create query input
    $queryInput = new QueryInput();
    $queryInput->setText($textInput);

    // get response and relevant info
    $response = $sessionsClient->detectIntent($session, $queryInput);
    $queryResult = $response->getQueryResult();
    $queryText = $queryResult->getQueryText();
    $intent = $queryResult->getIntent();
    $displayName = $intent->getDisplayName();
    $common->write_to_log("intent displayName : ".$displayName);
    if($displayName == "Default Fallback Intent")
    {
        $result = json_encode(array("result"=>false));
        $common->write_to_log("No matching intent found");
    }
    else
    {

        $confidence = $queryResult->getIntentDetectionConfidence();
        $fulfilmentText = $queryResult->getFulfillmentText();
        $common->write_to_log("intent response : ".$fulfilmentText);
        $result = json_encode(array("result"=>true,"message"=>$fulfilmentText));

    }

    echo $result;

    $sessionsClient->close();
}

0 个答案:

没有答案