Compare commits

...

10 Commits

Author SHA1 Message Date
c1e7cc3513 feat: coordinate message padding and input shape 2025-05-02 17:21:40 +01:00
c2e52ff71e feat: improve french 2025-05-02 17:21:13 +01:00
cdec814b66 fix: remove back button 2025-05-02 17:21:13 +01:00
95773bcd74 feat: style send button 2025-05-02 17:21:13 +01:00
7f6c629ca4 fix: improve french 2025-05-02 17:21:13 +01:00
46ae9f56b7 feat: add input placeholder text 2025-05-02 17:21:13 +01:00
175ed7b725 feat: opening message 2025-05-02 17:21:13 +01:00
55d161cc7d feat: sncf theme 2025-05-02 17:21:12 +01:00
c3351ec7e4 feat: merde alors 2025-05-02 17:18:21 +01:00
a07c269f15 feat: scroll to new message 2025-05-02 17:18:02 +01:00
4 changed files with 94 additions and 145 deletions

View File

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

120
main.js
View File

@ -5,7 +5,7 @@ var conversation = null;
class Conversation {
constructor(name) {
this.messages = [];
this.name = romanize(name);
this.name = name;
this.score = 1.0;
}
@ -23,75 +23,35 @@ class Conversation {
this.messages = initialMessages;
}
addMessage(message) {
this.messages.push(message);
this.render();
var elements = document.getElementById("messages").children;
var lastElement = elements[elements.length - 1];
lastElement.scrollIntoView();
}
// for the user to send their own messages
sendUserMessage(text) {
const message = new UserMessage(text);
message.updateStatus("sent");
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.messages.push(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}`);
});
message.updateStatus("envoy&eacute");
this.addMessage(message);
setTimeout(() => {
message.updateStatus("delivered");
message.updateStatus("livr&eacute");
this.render();
//setTimeout(() => {
// message.updateStatus("read");
// this.render();
//}, 5000);
setTimeout(() => {
message.updateStatus("lu");
this.render();
setTimeout(()=> {
setTimeout(() => {
this.addMessage(new AgentMessage("merde alors"));
}, 2000);
}, 500);
}, 3000);
}, 1000);
this.messages.push(message);
}
// update the current HTML based on messages
@ -134,12 +94,6 @@ function getMessageList() {
return document.getElementById("messages");
}
function romanize(text) {
text = text.replaceAll('u', 'v');
text = text.replaceAll('U', 'V');
return text;
}
class AgentMessage {
constructor(text, senderName) {
this.text = text;
@ -160,13 +114,13 @@ class AgentMessage {
if (this.senderName) {
const nameElem = document.createElement("h3");
nameElem.innerHTML = romanize(this.senderName);
nameElem.innerHTML = this.senderName;
contentElem.appendChild(nameElem);
}
const textElem = document.createElement("span");
textElem.className = "message-text";
textElem.innerHTML = romanize(this.text);
textElem.innerHTML = this.text;
contentElem.appendChild(textElem);
return liElem;
@ -176,7 +130,7 @@ class AgentMessage {
class UserMessage {
constructor(text) {
this.createdTime = Date.now();
this.text = romanize(text);
this.text = text;
this.status = "";
}
@ -212,7 +166,7 @@ class UserMessage {
class SystemMessage {
constructor(text) {
this.text = romanize(text);
this.text = text;
}
getIsOurs() {
@ -279,7 +233,7 @@ function pressSendButton() {
if (event.type == "keydown" && event.key != "Enter")
{
textBox.value = romanize(text);
textBox.value = text;
return;
}
@ -351,8 +305,6 @@ function showConversation(path) {
const conversationListElem = document.getElementById("side-panel");
setVisibleOnMobile(mainPanel, true);
setVisibleOnMobile(conversationListElem, false);
readConversationJson(path, json => {
conversation = new Conversation(json.title);
@ -407,24 +359,8 @@ 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);
populateConversationList();
showConversation("ides-of-march.json");
showConversation("sncf.json");

13
sncf.json Normal file
View File

@ -0,0 +1,13 @@
{
"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 {
--dark-purple: #271f30;
--light-red: #ff686b;
--eggshell: #dfe2cf;
--ucla-blue: #4d7298;
--robin-egg-blue: #66ced6;
--vermilion: #ef3e36;
--lapis-lazuli: #235789;
--onyx: #383d3b;
--light-cyan: #e0fbfc;
--buff: #edb88b;
--eeriee-black: #1d201f;
--blanc: #fff;
--gris: #666;
--noir: #000;
--clear: #00000000;
--bleu: #0055a4;
--rouge: #e1000f;
--rose-de-l-erreur: #f0f;
--navy: #0b131f;
--bluegrey: #232b35;
--sky: #7bbffd;
--bluewhite: #ebebec;
}
html {
@ -24,13 +24,14 @@ body {
margin: 0;
height: 100%;
display: flex;
background-color: var(--buff);
background-color: var(--navy);
}
#side-panel {
height: 100%;
display: none;
color: var(--onyx);
color: var(--noir);
display: block;
width: 100%;
}
#header button {
@ -39,11 +40,6 @@ body {
visibility: visible;
}
#side-panel {
display: block;
width: 100%;
}
#side-panel.invisible-on-mobile {
display: none;
}
@ -51,10 +47,10 @@ body {
/* on desktop only */
@media only screen and (min-width: 768px) {
#side-panel {
display: block;
min-width: 300px;
width: auto;
visibility: visible;
border-right: 3px solid var(--onyx);
border-right: 3px solid var(--noir);
}
#side-panel.invisible-on-mobile {
@ -67,19 +63,13 @@ body {
padding: 0;
visibility: hidden;
}
#side-panel .conversation {
max-width: 300px;
}
}
#side-panel .conversation {
width: 100%;
height: 70px;
border-bottom: solid var(--onyx) 3px;
border-bottom: solid var(--noir) 3px;
color: var(--onyx);
padding: .5em;
white-space: nowrap;
overflow: hidden;
@ -87,8 +77,8 @@ body {
}
#side-panel .conversation:hover {
background-color: var(--vermilion);
color: var(--light-cyan);
background-color: var(--bleu);
color: var(--blanc);
}
#side-panel h2 {
@ -98,14 +88,14 @@ body {
#header {
position: sticky;
top: 0;
border-bottom: solid var(--onyx) 3px;
border-bottom: none var(--navy) 3px;
}
#main-panel {
display: flex;
flex-direction: column;
justify-content: flex-end;
width: calc(100% - 300px);
width: 100%;
}
#page {
@ -114,7 +104,7 @@ body {
h1 {
display: inline-block;
color: var(--onyx);
color: var(--bluewhite);
margin-left: 1em;
}
@ -122,9 +112,9 @@ h1 {
border-width: 2px;
border: black;
border-style: none;
border-radius: 1em;
border-radius: 1.5em;
padding: .6em .8em;
padding: 1em 1.5em;
}
.message-content {
@ -133,8 +123,8 @@ h1 {
}
.message-content.theirs {
background-color: var(--onyx);
color: var(--light-cyan);
background-color: var(--bluegrey);
color: var(--bluewhite);
float: left;
@ -142,7 +132,7 @@ h1 {
}
.message-content.theirs h3 {
color: var(--buff);
color: var(--blanc);
margin: 0;
margin-bottom: 3px;
font-size: .85em;
@ -154,7 +144,7 @@ h1 {
}
.message-content.ours {
background-color: var(--vermilion);
background-color: var(--sky);
right: 0;
margin-bottom: 0.5em;
@ -163,19 +153,18 @@ h1 {
}
.ours .message-text {
color: var(--light-cyan);
color: var(--bluegrey);
}
.system-message {
color: var(--onyx);
color: var(--gris);
width: 100%;
text-align: center;
}
ul {
margin: 0;
padding-top: 1em;
padding-right: 2em;
padding: 1em 1.5em 0 1.5em;
height: 100%;
overflow: scroll;
list-style: none;
@ -205,8 +194,11 @@ li.message {
z-index: 1;
background-color: var(--light-cyan);
border-radius: 100vw;
border-radius: 1em;
color: var(--bluewhite);
background-color: var(--bluegrey);
border-color: var(--bluegrey);
}
#input-panel input {
@ -219,6 +211,7 @@ li.message {
z-index: 1;
font-size: 1em;
}
#input-panel input:focus {
@ -235,12 +228,12 @@ button {
}
button:hover {
color: var(--light-cyan);
background-color: var(--onyx);
color: var(--navy);
background-color: var(--sky);
}
#typing-indicator {
color: var(--eggshell);
color: var(--bluewhite);
margin: 0;
margin-left: 1em;
@ -248,11 +241,19 @@ button:hover {
position: fixed;
bottom: 3em;
visibility: hidden;
}
button {
color: var(--bluewhite);
padding: 1em;
right: 0;
font-size: 1em;
}
.message-status {
color: var(--onyx);
color: var(--bluewhite);
position: absolute;
bottom: -1.75em;