-
Notifications
You must be signed in to change notification settings - Fork 692
/
chatbot_memory.js
40 lines (29 loc) · 1.04 KB
/
chatbot_memory.js
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
// chatbot_memory.js
class ChatbotMemory {
constructor() {
this.userConversations = {};
}
storeConversation(userId, message) {
if (!this.userConversations[userId]) {
this.userConversations[userId] = [];
}
this.userConversations[userId].push(message);
}
getConversationHistory(userId) {
return this.userConversations[userId] || [];
}
clearConversationHistory(userId) {
delete this.userConversations[userId];
}
}
// Example usage:
const botMemory = new ChatbotMemory();
// Store a conversation for user with ID 123
botMemory.storeConversation(123, "Hello, how are you?");
botMemory.storeConversation(123, "I'm doing well, thank you.");
// Retrieve the conversation history for user with ID 123
const conversationHistory = botMemory.getConversationHistory(123);
console.log(conversationHistory); // Output: ["Hello, how are you?", "I'm doing well, thank you."]
// Clear the conversation history for user with ID 123
botMemory.clearConversationHistory(123);
// to provide personalized and relevant responses.