php - how to make unique intent, entity type and entity value? -
need help. below code have done (webhook) take value api.ai , grab answer database. m have problem if 2 user enter chatbot, webhook not know user asking what. means getting confuse how have each intent, entity type , entity value unique each user webhook not confuse.
<?php $databasehost = 'localhost'; $databasename = 'dialog'; $databaseusername = 'root'; $databasepassword = ''; $mysqli = mysqli_connect($databasehost, $databaseusername, $databasepassword, $databasename); header('content-type: application/json'); ob_start(); $json = file_get_contents('php://input'); $data = json_decode($json, true); $sessionid = $data["sessionid"]; //session id api $intent = $data["result"]["metadata"]["intentname"]; //intent foreach($data["result"]["parameters"] $key => $value) { if($value){ $type = $key; //entity type $value = $value; //entity value } } $array = array(); foreach ($sessionid $arr) { if(in_array($arr, $array)){ } else { $array = array("id"=>$arr, "type"=>$type, "value"=>$value); } } $result = mysqli_query($mysqli, "select * dialog"); while($row = $result->fetch_assoc()) { if($row["etype"] == $type && $row["eval"] == $value && $row["intent"] == $intent) { $outputtext = $row["reply"]; } } $output["speech"] = $outputtext; $output["displaytext"] = $outputtext; ob_end_clean(); echo json_encode($output); ?>
you can asking username/name. in intent, add required parameter. there sample @ https://api.ai/docs/getting-started/basic-fulfillment-conversation#conversation_branching
Comments
Post a Comment