Chat History: Linking the Conversations Back‐end API to its specific Meeting - RyanL2004/teamlyse GitHub Wiki

Linking Conversations and Meetings

Option A: Embedding the Conversation within the Meeting Document

You could embed the entire conversation directly into your Meeting model. For example, your meeting document might include an array of messages:

const MeetingSchema = new mongoose.Schema({
  title: String,
  scheduledTime: Date,
  participants: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }],
  // Embed chat messages directly:
  chatHistory: [
    {
      sender: { type: String }, // "user" or "AI"
      text: String,
      timestamp: { type: Date, default: Date.now }
    }
  ],
  // Optionally, a final debrief summary:
  summary: String,
});

Option B: Using a Separate Conversation Model

Alternatively, you can create a dedicated Conversation model that stores chat history separately, with a reference to the meeting. This gives you more flexibility, especially if conversations are large or if you want to manage them independently.

const ConversationSchema = new mongoose.Schema({
  meeting: { type: mongoose.Schema.Types.ObjectId, ref: 'Meeting', required: true },
  user: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
  messages: [
    {
      sender: { type: String },
      text: String,
      timestamp: { type: Date, default: Date.now }
    }
  ],
  // Optionally, store a summary or debrief:
  summary: String,
});

In this model, every conversation references the meeting it belongs to (using the meeting’s ObjectId), and you can set up endpoints to fetch a conversation by its meeting ID.


Setting Up Endpoints

After designing your models, you’ll need to create API endpoints for managing these conversations. For example:

  • Create/Start a Conversation:
    When a meeting begins, your backend can create a new Conversation document associated with that meeting.
  • Append Messages:
    As the meeting progresses, each chat message is sent to an endpoint (or via websockets) that updates the conversation’s messages array.
  • Fetch Conversation History:
    Provide an endpoint like GET /api/conversations/:meetingId that retrieves the conversation associated with a given meeting.
  • Debrief or Summarize:
    If you generate a meeting summary or debrief using the conversation data, you can either store that in the Conversation document or in the Meeting document, and have an endpoint to retrieve it.

Benefits of This Approach

Clear Data Relationships

Linking conversations to meetings ensures that when a user looks at a past meeting, they can easily see all the associated chat logs and any debriefs.

Scalability

Using a separate Conversation model allows you to manage large volumes of chat data without bloating your Meeting documents. You can also index conversation fields (like meeting or user) for faster queries.

Flexibility

This approach lets you manage chat history, implement pagination, or even archive old conversations if needed without affecting your meeting records.


Final Thoughts

Linking your conversation model to your meeting model (either by embedding or referencing) is a common pattern in applications like ChatGPT. It allows users to retrieve detailed histories and ensures that your system remains organized and scalable as more data accumulates.

If you have further questions about implementing these models or setting up the endpoints, feel free to ask!