File size: 1,329 Bytes
d7dfeff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
const updateChathistory = (transcript, backup , session) => {
try {
if (backup) {
if (
session.chathistorybackup.length > 0 &&
session.chathistorybackup[session.chathistorybackup.length - 1]
.speaker === "USER"
) {
session.chathistorybackup.push({
speaker: "AI",
content: ``,
});
}
if (
session.chathistory &&
session.chathistory.length > 0 &&
session.chathistory[session.chathistory.length - 1].speaker === "AI"
) {
session.chathistorybackup[
session.chathistorybackup.length - 1
].content += ` ${transcript}`;
}
} else if (!backup) {
if (
session.chathistory.length > 0 &&
session.chathistory[session.chathistory.length - 1].speaker === "USER"
) {
session.chathistory.push({ speaker: "AI", content: `` });
}
if (
session.chathistory &&
session.chathistory.length > 0 &&
session.chathistory[session.chathistory.length - 1].speaker === "AI"
) {
session.chathistory[
session.chathistory.length - 1
].content += ` ${transcript}`;
}
}
} catch (error) {
console.log("Error in updating chathistory : ", error);
}
};
module.exports = {updateChathistory} |