curaflow/backend/botLogic.js

41 lines
1.2 KiB
JavaScript

const clinicAgent = require('./clinicAgent');
class BotLogic {
constructor() {
this.states = {}; // Context storage
}
setRescheduleOffer(patientId, offerData) {
this.states[`${patientId}_offer`] = offerData;
}
async handleMessage(patientId, message) {
if (!this.states[patientId]) {
this.states[patientId] = { transcript: [] };
}
const context = this.states[patientId];
context.transcript.push({ role: 'user', content: message });
// Delegate to the Agent
const response = await clinicAgent.processMessage(patientId, context.transcript);
// Update context based on agent response
if (response.reply) {
context.transcript.push({ role: 'assistant', content: response.reply });
}
// Trim history to last 10 messages
if (context.transcript.length > 10) {
context.transcript = context.transcript.slice(-10);
}
return {
reply: response.reply,
buttons: [] // Deprecated in favor of dynamic conversation
};
}
}
module.exports = new BotLogic();