Compare commits

..

No commits in common. "sncf" and "main" have entirely different histories.
sncf ... main

4 changed files with 141 additions and 85 deletions

View File

@ -7,11 +7,12 @@
</head> </head>
<body> <body>
<!--<div id="side-panel"></div>--> <div id="side-panel"></div>
<div id="main-panel"> <div id="main-panel">
<div id="header"> <div id="header">
<button id="conversation-list-button" class="rounded-rectangle" onclick="showSidePanel()"><- back</button>
<h1 id="header-title">NAME</h1> <h1 id="header-title">NAME</h1>
</div> </div>
@ -21,7 +22,7 @@
<div id="input-panel-container"> <div id="input-panel-container">
<div id="input-panel" class="rounded-rectangle"> <div id="input-panel" class="rounded-rectangle">
<input id="textbox-input" type="text" onkeydown="pressSendButton()" placeholder="Veuillez nous demander pour nous vous conseiller..."></input> <input id="textbox-input" type="text" onkeydown="pressSendButton()"></input>
<button onclick="pressSendButton()"><i class="fa fa-arrow-right" style="font-size:2em"></i></button> <button onclick="pressSendButton()"><i class="fa fa-arrow-right" style="font-size:2em"></i></button>
</div> </div>
</div> </div>

111
main.js
View File

@ -5,7 +5,7 @@ var conversation = null;
class Conversation { class Conversation {
constructor(name) { constructor(name) {
this.messages = []; this.messages = [];
this.name = name; this.name = romanize(name);
this.score = 1.0; this.score = 1.0;
} }
@ -36,22 +36,71 @@ class Conversation {
sendUserMessage(text) { sendUserMessage(text) {
const message = new UserMessage(text); const message = new UserMessage(text);
message.updateStatus("envoy&eacute"); message.updateStatus("sent");
this.addMessage(message);
const url = 'http://192.168.1.115:5000/chat';
const data = text;
fetch(url, {
method: 'POST', // Corresponds to -X POST
headers: {
'Content-Type': 'text/plain' // Corresponds to -H "Content-Type: text/plain"
},
body: data // Corresponds to -d "..."
})
.then(response => {
// Check if the request was successful (status code 2xx)
if (!response.ok) {
// If not successful, throw an error to be caught by .catch()
throw new Error(`HTTP error! status: ${response.status}`);
}
// Get the response body as text
return response.text();
})
.then(response => {
// TODO: check JSON
const json = JSON.parse(response);
// Success!
var messageText = json.message;
console.log(json);
var score = parseFloat(json.score);
this.score += score;
console.log(this.score);
if (this.score > 2.0)
{
messageText = "shit they're here D:";
this.setInteractive(false);
}
else if (this.score < 0.0)
{
messageText = "shit u won :D";
this.setInteractive(false);
}
else
{
messageText = json.message;
}
this.addMessage(new AgentMessage(messageText));
this.render();
})
.catch(error => {
// Handle any errors that occurred during the fetch
console.error('Error during fetch:', error);
alert(`Error fetching data: ${error.message}`);
});
setTimeout(() => { setTimeout(() => {
message.updateStatus("livr&eacute"); message.updateStatus("delivered");
this.render(); this.render();
setTimeout(() => { //setTimeout(() => {
message.updateStatus("lu"); // message.updateStatus("read");
this.render(); // this.render();
setTimeout(()=> { //}, 5000);
setTimeout(() => {
this.addMessage(new AgentMessage("merde alors"));
}, 2000);
}, 500);
}, 3000);
}, 1000); }, 1000);
this.addMessage(message);
} }
// update the current HTML based on messages // update the current HTML based on messages
@ -94,6 +143,12 @@ function getMessageList() {
return document.getElementById("messages"); return document.getElementById("messages");
} }
function romanize(text) {
text = text.replaceAll('u', 'v');
text = text.replaceAll('U', 'V');
return text;
}
class AgentMessage { class AgentMessage {
constructor(text, senderName) { constructor(text, senderName) {
this.text = text; this.text = text;
@ -114,13 +169,13 @@ class AgentMessage {
if (this.senderName) { if (this.senderName) {
const nameElem = document.createElement("h3"); const nameElem = document.createElement("h3");
nameElem.innerHTML = this.senderName; nameElem.innerHTML = romanize(this.senderName);
contentElem.appendChild(nameElem); contentElem.appendChild(nameElem);
} }
const textElem = document.createElement("span"); const textElem = document.createElement("span");
textElem.className = "message-text"; textElem.className = "message-text";
textElem.innerHTML = this.text; textElem.innerHTML = romanize(this.text);
contentElem.appendChild(textElem); contentElem.appendChild(textElem);
return liElem; return liElem;
@ -130,7 +185,7 @@ class AgentMessage {
class UserMessage { class UserMessage {
constructor(text) { constructor(text) {
this.createdTime = Date.now(); this.createdTime = Date.now();
this.text = text; this.text = romanize(text);
this.status = ""; this.status = "";
} }
@ -166,7 +221,7 @@ class UserMessage {
class SystemMessage { class SystemMessage {
constructor(text) { constructor(text) {
this.text = text; this.text = romanize(text);
} }
getIsOurs() { getIsOurs() {
@ -233,7 +288,7 @@ function pressSendButton() {
if (event.type == "keydown" && event.key != "Enter") if (event.type == "keydown" && event.key != "Enter")
{ {
textBox.value = text; textBox.value = romanize(text);
return; return;
} }
@ -305,6 +360,8 @@ function showConversation(path) {
const conversationListElem = document.getElementById("side-panel"); const conversationListElem = document.getElementById("side-panel");
setVisibleOnMobile(mainPanel, true); setVisibleOnMobile(mainPanel, true);
setVisibleOnMobile(conversationListElem, false);
readConversationJson(path, json => { readConversationJson(path, json => {
conversation = new Conversation(json.title); conversation = new Conversation(json.title);
@ -359,8 +416,24 @@ function addConversationPreview(path) {
}); });
} }
function populateConversationList() {
const conversationFiles = [
"caesar.json",
"lucius.json",
"ides-of-march.json",
"lepidus.json",
"publius.json",
"sextus.json"
];
for (let i = 0; i < conversationFiles.length; i++) {
const path = conversationFiles[i];
addConversationPreview(path);
}
}
setTypingIndicator(false); setTypingIndicator(false);
populateConversationList();
showConversation("sncf.json"); showConversation("ides-of-march.json");

View File

@ -1,13 +0,0 @@
{
"title": "SNCF Conrad",
"interactive": true,
"characters": [
"you",
"SNCF Conrad"
],
"messages":
[
{ "character": 1, "text": "Bonjour, moi je m'appelle SNCF Conrad et je vais vous aider aujourd'hui. N'hésiter pas à me poser des questions." }
]
}

View File

@ -1,18 +1,18 @@
:root { :root {
--blanc: #fff; --dark-purple: #271f30;
--gris: #666; --light-red: #ff686b;
--noir: #000; --eggshell: #dfe2cf;
--ucla-blue: #4d7298;
--robin-egg-blue: #66ced6;
--vermilion: #ef3e36;
--lapis-lazuli: #235789;
--onyx: #383d3b;
--light-cyan: #e0fbfc;
--buff: #edb88b;
--eeriee-black: #1d201f;
--clear: #00000000; --clear: #00000000;
--bleu: #0055a4;
--rouge: #e1000f;
--rose-de-l-erreur: #f0f;
--navy: #0b131f;
--bluegrey: #232b35;
--sky: #7bbffd;
--bluewhite: #ebebec;
} }
html { html {
@ -24,14 +24,13 @@ body {
margin: 0; margin: 0;
height: 100%; height: 100%;
display: flex; display: flex;
background-color: var(--navy); background-color: var(--buff);
} }
#side-panel { #side-panel {
height: 100%; height: 100%;
color: var(--noir); display: none;
display: block; color: var(--onyx);
width: 100%;
} }
#header button { #header button {
@ -40,6 +39,11 @@ body {
visibility: visible; visibility: visible;
} }
#side-panel {
display: block;
width: 100%;
}
#side-panel.invisible-on-mobile { #side-panel.invisible-on-mobile {
display: none; display: none;
} }
@ -47,10 +51,10 @@ body {
/* on desktop only */ /* on desktop only */
@media only screen and (min-width: 768px) { @media only screen and (min-width: 768px) {
#side-panel { #side-panel {
min-width: 300px; display: block;
width: auto; width: auto;
visibility: visible; visibility: visible;
border-right: 3px solid var(--noir); border-right: 3px solid var(--onyx);
} }
#side-panel.invisible-on-mobile { #side-panel.invisible-on-mobile {
@ -76,8 +80,9 @@ body {
#side-panel .conversation { #side-panel .conversation {
width: 100%; width: 100%;
height: 70px; height: 70px;
border-bottom: solid var(--noir) 3px; border-bottom: solid var(--onyx) 3px;
color: var(--onyx); color: var(--onyx);
padding: .5em;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
@ -85,8 +90,8 @@ body {
} }
#side-panel .conversation:hover { #side-panel .conversation:hover {
background-color: var(--bleu); background-color: var(--vermilion);
color: var(--blanc); color: var(--light-cyan);
} }
#side-panel h2 { #side-panel h2 {
@ -96,7 +101,7 @@ body {
#header { #header {
position: sticky; position: sticky;
top: 0; top: 0;
border-bottom: none var(--navy) 3px; border-bottom: solid var(--onyx) 3px;
} }
#main-panel { #main-panel {
@ -112,7 +117,7 @@ body {
h1 { h1 {
display: inline-block; display: inline-block;
color: var(--bluewhite); color: var(--onyx);
margin-left: 1em; margin-left: 1em;
} }
@ -120,9 +125,9 @@ h1 {
border-width: 2px; border-width: 2px;
border: black; border: black;
border-style: none; border-style: none;
border-radius: 1.5em; border-radius: 1em;
padding: 1em 1.5em; padding: .6em .8em;
} }
.message-content { .message-content {
@ -131,8 +136,8 @@ h1 {
} }
.message-content.theirs { .message-content.theirs {
background-color: var(--bluegrey); background-color: var(--onyx);
color: var(--bluewhite); color: var(--light-cyan);
float: left; float: left;
@ -140,7 +145,7 @@ h1 {
} }
.message-content.theirs h3 { .message-content.theirs h3 {
color: var(--blanc); color: var(--buff);
margin: 0; margin: 0;
margin-bottom: 3px; margin-bottom: 3px;
font-size: .85em; font-size: .85em;
@ -152,26 +157,28 @@ h1 {
} }
.message-content.ours { .message-content.ours {
background-color: var(--sky); background-color: var(--vermilion);
right: 0; right: 0;
margin-bottom: 0.5em; margin-bottom: 0.5em;
border-bottom-right-radius: 0;
border-bottom-right-radius: 0;
} }
.ours .message-text { .ours .message-text {
color: var(--bluegrey); color: var(--light-cyan);
} }
.system-message { .system-message {
color: var(--gris); color: var(--onyx);
width: 100%; width: 100%;
text-align: center; text-align: center;
} }
ul { ul {
margin: 0; margin: 0;
padding: 1em 1.5em 0 1.5em; padding-top: 1em;
padding-right: 2em;
height: 100%; height: 100%;
overflow: scroll; overflow: scroll;
list-style: none; list-style: none;
@ -201,11 +208,8 @@ li.message {
z-index: 1; z-index: 1;
border-radius: 1em; background-color: var(--light-cyan);
border-radius: 100vw;
color: var(--bluewhite);
background-color: var(--bluegrey);
border-color: var(--bluegrey);
} }
#input-panel input { #input-panel input {
@ -218,7 +222,6 @@ li.message {
z-index: 1; z-index: 1;
font-size: 1em; font-size: 1em;
} }
#input-panel input:focus { #input-panel input:focus {
@ -235,12 +238,12 @@ button {
} }
button:hover { button:hover {
color: var(--navy); color: var(--light-cyan);
background-color: var(--sky); background-color: var(--onyx);
} }
#typing-indicator { #typing-indicator {
color: var(--bluewhite); color: var(--eggshell);
margin: 0; margin: 0;
margin-left: 1em; margin-left: 1em;
@ -248,19 +251,11 @@ button:hover {
position: fixed; position: fixed;
bottom: 3em; bottom: 3em;
visibility: hidden;
} }
button {
color: var(--bluewhite);
padding: 1em;
right: 0;
font-size: 1em;
}
.message-status { .message-status {
color: var(--bluewhite); color: var(--onyx);
position: absolute; position: absolute;
bottom: -1.75em; bottom: -1.75em;