|
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} |