In javascript what dispatchClient.createDispatch d...
# ask-ai
b
In javascript what dispatchClient.createDispatch does?
t
Thanks for reaching out, Wesley. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking what
dispatchClient.createDispatch
does in JavaScript. Here's a concise explanation and an example to help. What it does •
createDispatch
explicitly assigns (dispatches) a named agent to a LiveKit room. • If the target room doesn't exist, the call will create it automatically. • You can pass metadata with the dispatch; that metadata becomes available to the agent in its
JobContext
when it starts. • Common uses: initiating outbound calls, routing inbound SIP calls to a specific agent, or programmatically triggering an agent to join a session with contextual information. Example
Copy code
const dispatch = await agentDispatchClient.createDispatch(
  'my-room',
  'test-agent',
  {
    metadata: '{"user_id":"12345"}',
  }
);
Notes • The method is part of the AgentDispatchClient in the LiveKit server SDK and requires proper API key/secret authentication. • If you want, I can show how to read the metadata inside the agent's
JobContext
, or provide a full minimal example including authentication. Which would be most helpful for you? Sources: Agent dispatch | LiveKit Documentation | Outbound Calling Script | LiveKit Documentation