late-businessperson-58140
10/27/2025, 9:48 AMtall-airline-16756
10/27/2025, 9:48 AMtall-airline-16756
10/27/2025, 9:49 AMlate-businessperson-58140
10/27/2025, 10:03 AMtall-airline-16756
10/27/2025, 10:04 AMlate-businessperson-58140
10/27/2025, 10:19 AMtall-airline-16756
10/27/2025, 10:19 AMimport asyncio
from livekit import rtc, api
class ChatMessageHandler:
def __init__(self):
self.messages = []
def on_message_received(self, message):
# Store the message in a list or save it to a database/file
self.messages.append(message)
print(f"Received message: {message}")
async def main(room_name: str, url: str, api_key: str, api_secret: str):
room = rtc.Room()
token = (
api.AccessToken(api_key, api_secret)
.with_identity("chat-listener")
.with_name("Chat Listener")
.with_grants(
api.VideoGrants(
room_join=True,
room=room_name,
)
)
.to_jwt()
)
await room.connect(url, token)
chat_handler = ChatMessageHandler()
room.register_text_stream_handler(
topic="chat", handler=chat_handler.on_message_received
)
print("Listening for chat messages...")
await room.wait_for_disconnect()
# Replace with your LiveKit server details
room_name = "your_room_name"
url = "your_livekit_server_url"
api_key = "your_api_key"
api_secret = "your_api_secret"
asyncio.run(main(room_name, url, api_key, api_secret))
Here’s what this code does:
• It connects to a LiveKit room using an access token.
• It registers a handler that listens for chat messages in real-time.
• It stores the received messages in a list, but you can easily adjust it to save them to a database or a file if that suits your needs better.
If you'd like, I’m here to help you customize this code to fit your specific situation perfectly—just let me know!late-businessperson-58140
10/27/2025, 10:22 AMtall-airline-16756
10/27/2025, 10:23 AMlk.transcription text stream topic. This includes handy details like the transcribed track ID and the sender's identity.
• Summarization: You can also use KITT (Kaleidoscopic, Interconnected Talking Transformer) to take notes or summarize the meeting discussions effortlessly.
If you'd like any help with setting up transcription or summarization, please don’t hesitate to reach out—I’d be happy to walk you through the process or share some code examples!
Sources: Text and transcriptions | LiveKit Docs | Live Conversations with AI using ChatGPT and WebRTClate-businessperson-58140
10/27/2025, 10:26 AMtall-airline-16756
10/27/2025, 10:26 AMimport asyncio
from livekit import rtc, api
class TranscriptionHandler:
def on_transcription_received(self, transcription):
# Process and store the transcription
print(f"Transcription received: {transcription}")
async def main(room_name: str, url: str, api_key: str, api_secret: str):
room = rtc.Room()
token = (
api.AccessToken(api_key, api_secret)
.with_identity("transcription-listener")
.with_name("Transcription Listener")
.with_grants(
api.VideoGrants(
room_join=True,
room=room_name,
)
)
.to_jwt()
)
await room.connect(url, token)
transcription_handler = TranscriptionHandler()
room.register_text_stream_handler(
topic="lk.transcription", handler=transcription_handler.on_transcription_received
)
print("Listening for transcriptions...")
await room.wait_for_disconnect()
# Replace with your LiveKit server details
room_name = "your_room_name"
url = "your_livekit_server_url"
api_key = "your_api_key"
api_secret = "your_api_secret"
asyncio.run(main(room_name, url, api_key, api_secret))
This script listens for real-time transcriptions using the lk.transcription topic and processes them as they come in.
If you're interested in summarizing these transcriptions, you can integrate KITT (Kaleidoscopic, Interconnected Talking Transformer) to generate helpful summaries. Please feel free to reach out if you'd like assistance setting up summarization or if you have any other questions—I'm here to help!late-businessperson-58140
10/27/2025, 10:27 AMtall-airline-16756
10/27/2025, 10:27 AMwait_for_disconnect isn’t available in the LiveKit Python SDK. No worries though! To handle disconnection smoothly, you can use the disconnect() method on your Room instance. Here’s a simple way to update your code:
await room.disconnect()
Also, if you want to take action right after the room disconnects, you can listen for the "disconnected" event like this:
@room.on("disconnected")
def on_disconnected():
print("Room has been disconnected")
If you have any more questions or need a hand with anything else, just let me know—I’m here to help!
Sources: livekit-rtc/livekit/rtc/room.py | Connecting to LiveKit | LiveKit Docs | Job lifecycle | LiveKit Docslate-businessperson-58140
10/27/2025, 10:34 AMtall-airline-16756
10/27/2025, 10:34 AMawait room.disconnect(). This line will disconnect the room right after connecting, which might not be what you want for a chat listener that’s supposed to stay active. No worries though, I’m here to help you keep the listener running smoothly. Here’s a little tweak you can try:
print(f"Chat listener connected to room: {room_name}")
# Keep the listener alive
try:
while True:
await asyncio.sleep(1) # Keeps the event loop running
except asyncio.CancelledError:
print("Chat listener task cancelled")
finally:
await room.disconnect()
This way, your listener will stay active until you decide to stop it. If you have any questions or want to explore this further, just let me know—I’m happy to help!late-businessperson-58140
10/27/2025, 10:37 AMtall-airline-16756
10/27/2025, 10:38 AMimport asyncio
import json
from livekit import api
async def dispatch_summary_agent():
# Initialize the LiveKit API client
lkapi = api.LiveKitAPI()
# Agent and room details
room_name = "your_room_name"
agent_name = "summary-agent"
# Create summary metadata
summary_data = {
"call_summary": "Customer requested escalation due to billing issue.",
"customer_id": "12345",
"issue_type": "billing",
"priority": "high",
"previous_interactions": 3
}
try:
# Create the dispatch with summary metadata
dispatch = await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(
agent_name=agent_name,
room=room_name,
metadata=json.dumps(summary_data)
)
)
print(f"Summary agent dispatched successfully: {dispatch.id}")
print(f"Agent: {dispatch.agent_name} -> Room: {dispatch.room}")
except Exception as e:
print(f"Failed to dispatch agent: {e}")
raise
finally:
# Always close the API client
await lkapi.aclose()
# Run the dispatch
asyncio.run(dispatch_summary_agent())
This snippet sets up the LiveKit API client, dispatches the summary agent, and includes important metadata like the call summary and customer ID. If you have any questions or want me to walk you through more examples, just let me know—I’m here to help!
Sources: README.md | Agent dispatch | LiveKit Docs | Agents telephony integration | LiveKit Docs | Agent-assisted warm transfer | LiveKit Docs