Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JosefPRajmon committed Feb 29, 2024
0 parents commit f438ad6
Show file tree
Hide file tree
Showing 8 changed files with 478 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/config.php
26 changes: 26 additions & 0 deletions chat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
DowlSlide();
function DowlSlide(){
var messagesDiv = document.querySelector('.messages');
messagesDiv.scrollTop = messagesDiv.scrollHeight;
}

// Najděte textovou oblast pomocí její třídy nebo ID
var textarea = document.querySelector('.message');

// Přidejte posluchače událostí 'focus', který se spustí, když uživatel klikne na textovou oblast
textarea.addEventListener('focus', function() {
// Změňte šířku a výšku textové oblasti
textarea.style.width = '180px';
textarea.style.height = '45px';
document.querySelector('.checkbox').style.display = "none";
document.querySelector('.send').style.display = "none";
});

textarea.addEventListener('blur', function() {
textarea.style.width = 'auto';
textarea.style.height = '20px';
document.querySelector('.checkbox').style.display = "inline-block";
document.querySelector('.send').style.display = "inline-block";
});


36 changes: 36 additions & 0 deletions css.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.chat{
border: 1px black solid;
width: 200px;
height: 400px;
border-radius: 10px;
position: fixed;
right: 20px;
bottom: 20px;
}
.messages{
margin: 5px;
width: 190px;
height: 330px;
overflow-y: scroll;
}
.chat form{
height: 70px;
}
.checkbox{
position: relative;
bottom: 3px;
}
.send{
position: relative;
bottom: 5px;
}
.user{
text-align: right;
}
.messages::-webkit-scrollbar{
display: none;
}
.message{
margin: 5px;
margin-right: 0px;
}
107 changes: 107 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
include_once("openAiObject.php");

?>
<?php
/*
session_start();
//pod jmenem chatbota
$chatBotID ="asst_qwNsFaZ9AQVNHOKNqC8wRDoz";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!isset($_SESSION['array'])) {
$_SESSION['array'] = [];
}
else{
$array = $_SESSION["array"];
}
if (isset($array)) {
$array = $test->continue($array,$chatBotID);
}else{
$array = $test->continue(array(),$chatBotID);
$_SESSION["array"] = $array;
}
}
*/
?>

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css.css">
<title>Jednoduchý chat</title>
</head>

<body>
<div class="chat">
<div class="messages">
<?php
if (isset($_POST['message'])) {
if (strlen($_POST['message'])>1) {
$sendMessage = $_POST["message"];
//$test->AddInstruction($sendMessage,isset($_POST["table"]));

//$test->NewMessage($sendMessage);
//$a= $test->CheckReply();
//var_dump($a[0]->content[0]->text);
//var_dump($a);
$a=array(
new Message("zprava jedna","user"),
new Message("zprava dva","assistent"),
new Message("zprava tři","user"),
new Message("zprava čtiři","assistent"),
new Message("zprava pět","user"),
new Message("zprava sest","assistent"),
new Message("zprava sedm","user"),
new Message("zprava osm","assistent"),
new Message("zprava devet","user"),
new Message("zprava deset","assistent")
);
foreach (array_reverse($a) as $key => $value) {
$role = $value->role;
//$message =$value->content[0]->text->value;
//$message = $test->ReplaceInResponse($message,$role);
// $message=preg_replace('/\[(https:\/\/.*?)]\((https:\/\/.*?)\)/i', '<a href="\1">\2</a>', $message);

$message =$value->message;
echo("<p class=\"$role\"><strong> $role<br></strong> $message</p>");
}

}
}
?>
</div>
<form method="post">


<textarea class="message" name="message" cols="23" rows="1"></textarea>
<input type="checkbox" name="table" class="checkbox" title="do tabulky">
<input type="submit" class="send" value="Odeslat">
</form>


</div>

<script src="chat.js"></script>
<script>
/* var userId = 'x'; // Nahraďte 'x' ID uživatele, kterého chcete sledovat

setInterval(function() {
$.ajax({
url: 'get_messages.php',
data: { 'user_id': userId }, // Přidejte ID uživatele jako parametr požadavku
success: function(data) {
$('.messages').html(data);

var messagesDiv = document.querySelector('.messages');
messagesDiv.scrollTop = messagesDiv.scrollHeight;
}
});
}, 1000);
*/
</script>
</body>
</html>

Loading

0 comments on commit f438ad6

Please sign in to comment.