Best practice for linking appointment IDs to LiveKit room IDs

This question originally came up in our Slack community and the thread has been consolidated here for long-term reference.

We’re building a telehealth application using React.js and LiveKit for video calling.

Our flow:

  • We don’t manually create LiveKit rooms - they’re created when a user initiates a call
  • We use LiveKit webhooks (room_started and participant events) to update our callLog table

Our requirement:

  • When a patient books an appointment, we create a callLog record with the appointmentId
  • When the call starts, we need to update that record with the roomId

We’re considering two approaches:

  1. Update room metadata with appointmentId after room creation, then use RoomMetadataChanged webhook
  2. Manually create the room in the backend with metadata already set, then use room_started webhook

What’s the recommended approach for mapping appointments to rooms?

Since you control the backend that generates participant tokens, you have a couple of options:

  1. Use appointmentId as room name: When issuing the participant token, set the room name to the appointmentId (or a derivative that you can map back). A room with that name will be created automatically when the first participant joins.

  2. Store appointmentId in participant attributes: Add the appointmentId to the participant’s attributes when issuing the token. As long as participants can’t update their own attributes, you’ll know which appointment each participant token refers to.

Both approaches require minimal changes to your existing flow and avoid the complexity of metadata update events.