Room Started and Room Finished webhook events both...
# ask-ai
a
Room Started and Room Finished webhook events both have the Room in the payload, but in practice, in the Room Started Room, I receive the metadata, whereas in the Room finished one, I do not
t
Thanks for reaching out, Anne. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for reaching out! I want to help clarify the payload structures for the Room Started and Room Finished webhook events. They are actually identical, including the metadata field, which shows the state of the room at the moment the event happens. This metadata should stay the same unless you’ve made updates to it during the room’s lifecycle. If you’re noticing differences in the metadata, it might be because the room’s metadata was updated after the room was created. To help us get to the bottom of this, could you please check: • Are you updating the room’s metadata at any point while the room is active? • Are you sure you’re comparing the exact same room in both events? • Would it be helpful for you to track changes to the room metadata over time using the RoomMetadataChanged event? Please feel free to reach out if you want me to walk you through any of this or if you have more questions. I’m here to help! Sources: Handling events | LiveKit Docs | src/room/events.ts | livekit-rtc/livekit/rtc/_proto/room_pb2.pyi | Webhooks | LiveKit Docs | livekit-protocol/src/livekit.rs
a
no we never update the metadata and yes, positive it is the same room. in the Room Finished event, there is just no metadata key
Copy code
room: {
creationTime: "1758883504",
creationTimeMs: "1758883504715",
departureTimeout: 20,
emptyTimeout: 300,

enabledCodecs: [
6 items
],
name: "gAAAAABo1m0BSl7RSZplHS5T9TE1c1VtWsvywszZV0e9mhCwcZPrzww3EvsSl5VO412nI2XxH4Iqa9WA5z7OMXkAJzBCrRqQBkbpy8ncS8GtP5t_SIxvWEzX2ks5z8favZ7ykNo9mYYxlmBhASzkGhXTWFiiXUoJDg",
sid: "RM_5eNorHBRQ96D",

version: {
1 item
}
}
t
Thank you for reaching out! I wanted to share that the Room Finished webhook event doesn’t include the
metadata
key in its payload. This is expected behavior since the Room Finished event only provides standard room properties like
sid
,
name
, and
creationTime
. But don’t worry — if you need to access the metadata when the Room Finished event fires, you can easily retrieve it using the RoomService API. Here’s a helpful example in Node.js to guide you:
Copy code
import { RoomServiceClient } from 'livekit-server-sdk';

const roomService = new RoomServiceClient(
  'wss://your-project.livekit.cloud',
  'api-key',
  'api-secret'
);

app.post('/webhook', async (req, res) => {
  const event = await receiver.receive(req.body, req.get('Authorization'));
  
  if (event.event === 'room_finished') {
    try {
      const room = await roomService.getRoom(event.room.name);
      const metadata = room.metadata; // Access the room's metadata
      console.log('Room metadata at finish:', metadata);
      
      // Process metadata as needed
    } catch (error) {
      console.error('Failed to fetch room metadata:', error);
    }
  }
});
If you’d like, I’m here to help with more examples or assist you in another programming language—just let me know! Sources: packages/livekit-server-sdk/src/WebhookReceiver.ts | Runtime/Scripts/Room/Room.cs | Runtime/Scripts/Room.cs | src/room/Room.ts | agent-console/lib/event-definitions.tsx
a
can I do that with the python server api
t
Absolutely! You can definitely retrieve the metadata using the Python Server API. Here’s a little example to help you get started:
Copy code
from livekit.api import RoomServiceClient

client = RoomServiceClient(
    url='wss://your-project.livekit.cloud',
    api_key='api-key',
    api_secret='api-secret'
)

@webhook_receiver.route('/webhook', methods=['POST'])
def handle_webhook():
    event = webhook_receiver.receive(request.data, request.headers.get('Authorization'))
    
    if event.event == 'room_finished':
        try:
            room = client.get_room(room_name=event.room.name)
            metadata = room.metadata
            print(f"Room metadata at finish: {metadata}")
        except Exception as e:
            print(f"Failed to fetch room metadata: {e}")
Just be sure to swap out
api-key
,
api-secret
, and
your-project.livekit.cloud
with your actual LiveKit credentials and server URL. If you run into any questions or need a hand with anything else, I’m here to help!