feat: system messages
This commit is contained in:
parent
948ee9dff1
commit
f4b6960047
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"title": "Julius Caesar",
|
"title": "Julius Caesar",
|
||||||
|
"interactive": true,
|
||||||
"characters": [
|
"characters": [
|
||||||
"Mark Antony",
|
"Mark Antony",
|
||||||
"Julius Caesar"
|
"Julius Caesar"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"title": "Operation Ides of March",
|
"title": "Operation Ides of March",
|
||||||
|
"interactive": false,
|
||||||
"characters": [
|
"characters": [
|
||||||
"Mark Antony",
|
"Mark Antony",
|
||||||
"Cassius",
|
"Cassius",
|
||||||
|
@ -9,6 +10,8 @@
|
||||||
"Trebonius"
|
"Trebonius"
|
||||||
],
|
],
|
||||||
"messages": [
|
"messages": [
|
||||||
|
{ "character": -1, "text": "Cassius created Operation Ides of March." },
|
||||||
|
{ "character": -1, "text": "Cassius added Brutus, Casca, Decimus, Trebonius and Mark Antony." },
|
||||||
{ "character": 1, "text": "Alright, it’s time. We need to finalize the plan. Everyone good for tomorrow?" },
|
{ "character": 1, "text": "Alright, it’s time. We need to finalize the plan. Everyone good for tomorrow?" },
|
||||||
{ "character": 2, "text": "Yes, it has to be tomorrow. No more delays." },
|
{ "character": 2, "text": "Yes, it has to be tomorrow. No more delays." },
|
||||||
{ "character": 3, "text": "Do we know exactly where he’s going to be?" },
|
{ "character": 3, "text": "Do we know exactly where he’s going to be?" },
|
||||||
|
@ -30,6 +33,8 @@
|
||||||
{ "character": 2, "text": "For Rome." },
|
{ "character": 2, "text": "For Rome." },
|
||||||
{ "character": 3, "text": "For the Republic." },
|
{ "character": 3, "text": "For the Republic." },
|
||||||
{ "character": 5, "text": "For our future." },
|
{ "character": 5, "text": "For our future." },
|
||||||
{ "character": 0, "text": "uh" }
|
{ "character": 0, "text": "uh" },
|
||||||
|
{ "character": 1, "text": "shit" },
|
||||||
|
{ "character": -1, "text": "You have been removed from Operation Ides of March." }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"title": "Lepidus",
|
"title": "Lepidus",
|
||||||
|
"interactive": true,
|
||||||
"characters": [
|
"characters": [
|
||||||
"Mark Antony",
|
"Mark Antony",
|
||||||
"Lepidus"
|
"Lepidus"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"title": "Lucius Antony",
|
"title": "Lucius Antony",
|
||||||
|
"interactive": true,
|
||||||
"characters": [
|
"characters": [
|
||||||
"Mark Antony",
|
"Mark Antony",
|
||||||
"Lucius Antony"
|
"Lucius Antony"
|
||||||
|
|
31
main.js
31
main.js
|
@ -8,6 +8,13 @@ class Conversation {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setInteractive(isInteractive) {
|
||||||
|
const children = document.getElementById("textbox").children;
|
||||||
|
for (let i = 0; i < children.length; i++) {
|
||||||
|
children[i].disabled = !isInteractive;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initialize(initialMessages) {
|
initialize(initialMessages) {
|
||||||
document.title = this.name;
|
document.title = this.name;
|
||||||
document.getElementById("header-title").innerHTML = this.name;
|
document.getElementById("header-title").innerHTML = this.name;
|
||||||
|
@ -57,6 +64,7 @@ class AgentMessage {
|
||||||
|
|
||||||
getElement() {
|
getElement() {
|
||||||
const liElem = document.createElement("li");
|
const liElem = document.createElement("li");
|
||||||
|
liElem.className = "message";
|
||||||
|
|
||||||
const contentElem = document.createElement("span");
|
const contentElem = document.createElement("span");
|
||||||
contentElem.className = "message-content rounded-rectangle theirs";
|
contentElem.className = "message-content rounded-rectangle theirs";
|
||||||
|
@ -90,6 +98,7 @@ class UserMessage {
|
||||||
|
|
||||||
getElement() {
|
getElement() {
|
||||||
const liElem = document.createElement("li");
|
const liElem = document.createElement("li");
|
||||||
|
liElem.className = "message";
|
||||||
|
|
||||||
const contentElem = document.createElement("span");
|
const contentElem = document.createElement("span");
|
||||||
contentElem.className = "message-content rounded-rectangle ours";
|
contentElem.className = "message-content rounded-rectangle ours";
|
||||||
|
@ -113,6 +122,20 @@ class UserMessage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SystemMessage {
|
||||||
|
constructor(text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
getElement() {
|
||||||
|
const liElem = document.createElement("li");
|
||||||
|
liElem.className = "system-message";
|
||||||
|
liElem.innerHTML = this.text;
|
||||||
|
|
||||||
|
return liElem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setTypingIndicator(isTyping) {
|
function setTypingIndicator(isTyping) {
|
||||||
document.getElementById("typing-indicator").innerHTML = isTyping
|
document.getElementById("typing-indicator").innerHTML = isTyping
|
||||||
? `${conversation.contactName} is typing...`
|
? `${conversation.contactName} is typing...`
|
||||||
|
@ -245,7 +268,10 @@ function showConversation(path) {
|
||||||
for (let i = 0; i < jsonMessages.length; i++) {
|
for (let i = 0; i < jsonMessages.length; i++) {
|
||||||
const data = jsonMessages[i];
|
const data = jsonMessages[i];
|
||||||
const text = data.text;
|
const text = data.text;
|
||||||
if (data.character == 0) {
|
if (data.character == -1) {
|
||||||
|
const message = new SystemMessage(text);
|
||||||
|
initialMessages.push(message);
|
||||||
|
} else if (data.character == 0) {
|
||||||
const message = new UserMessage(text);
|
const message = new UserMessage(text);
|
||||||
message.updateStatus("delivered");
|
message.updateStatus("delivered");
|
||||||
initialMessages.push(message);
|
initialMessages.push(message);
|
||||||
|
@ -258,6 +284,7 @@ function showConversation(path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
conversation.initialize(initialMessages);
|
conversation.initialize(initialMessages);
|
||||||
|
conversation.setInteractive(json.interactive);
|
||||||
conversation.render();
|
conversation.render();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -301,5 +328,5 @@ function populateConversationList() {
|
||||||
setTypingIndicator(false);
|
setTypingIndicator(false);
|
||||||
populateConversationList();
|
populateConversationList();
|
||||||
|
|
||||||
showConversation("lucius.json");
|
showConversation("ides-of-march.json");
|
||||||
|
|
||||||
|
|
15
styles.css
15
styles.css
|
@ -159,6 +159,12 @@ h1 {
|
||||||
color: var(--dark-purple);
|
color: var(--dark-purple);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.system-message {
|
||||||
|
color: color-mix(in hsl, var(--eggshell) 80%, var(--dark-purple) 100%);
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
overflow: scroll;
|
overflow: scroll;
|
||||||
/*height:100%;*/
|
/*height:100%;*/
|
||||||
|
@ -169,15 +175,18 @@ ul {
|
||||||
}
|
}
|
||||||
|
|
||||||
li {
|
li {
|
||||||
|
position: relative;
|
||||||
|
display: inline-table;
|
||||||
|
margin-bottom: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.message {
|
||||||
height: 2.5em;
|
height: 2.5em;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
margin-bottom: 1.5em;
|
margin-bottom: 1.5em;
|
||||||
position: relative;
|
|
||||||
display: inline-table;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#textbox {
|
#textbox {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
Loading…
Reference in New Issue