Can you give me proper syntax for the create dispa...
# ask-ai
a
Can you give me proper syntax for the create dispatch rule via API and cli for self hosted livekit.
t
Thanks for reaching out, Lokesh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To create a dispatch rule for a self-hosted LiveKit instance via the CLI, follow these steps: 1. Create a temporary JSON file with your dispatch rule configuration. For example, create a file named
dispatch-rule.json
with content like:
Copy code
{
  "name": "My dispatch rule",
  "rule": {
    "dispatchRuleIndividual": {
      "roomPrefix": "call"
    }
  },
  "room_config": {
    "agents": [
      {
        "agent_name": "inbound-agent"
      }
    ]
  }
}
2. Use the LiveKit CLI to create the dispatch rule by running the following command:
lk sip dispatch create dispatch-rule.json
This will apply the dispatch rule for your SIP trunk. Let me know if you need further assistance! Sources: Accepting incoming calls | LiveKit Docs | Create and configure SIP trunk | LiveKit Docs
a
can i use dispatch rule direct?
t
Hey there! πŸ‘‹ I totally get what you're looking for, and I'm happy to help you set up a direct dispatch rule in LiveKit. It's actually pretty straightforward! 1. First, you'll want to create a JSON configuration file (like
dispatch-rule.json
) with this simple structure:
Copy code
{
  "rule": {
    "dispatchRuleDirect": {
      "roomName": "open-room"
    }
  }
}
2. Then, just use the LiveKit CLI to create your dispatch rule with this quick command:
lk sip dispatch create dispatch-rule.json
Want to add an extra layer of security with a PIN? No problem! You can modify the JSON file to look like this:
Copy code
{
  "trunk_ids": [],
  "rule": {
    "dispatchRuleDirect": {
      "roomName": "safe-room",
      "pin": "12345"
    }
  }
}
Now, callers will need to enter "12345#" on their phone to connect to the "safe-room." Neat, right? 😊 If you have any questions or need more help, I'm right here – just give me a shout! Sources: SIP dispatch rule | LiveKit Docs
a
when a call comes in to the sip trunk it should be answered by a particular agent. how to achieve this
t
Hey there! πŸ‘‹ Want to set up a specific agent to handle your incoming SIP trunk calls in LiveKit? I'll walk you through it step by step, and it's totally doable! 1. First, let's set up those environment variables for the LiveKit CLI – think of it like preparing your workspace:
Copy code
export LIVEKIT_URL=<your livekit server url>
export LIVEKIT_API_KEY=<your api key>
export LIVEKIT_API_SECRET=<your api secret>
2. Next, create an AI voice agent and give it a friendly name. Pro tip: I'm using "inbound-agent" in this example:
Copy code
if __name__ == "__main__":
    cli.run_app(
        WorkerOptions(
            entrypoint_fnc=entrypoint,
            prewarm_fnc=prewarm,
            # giving this agent a name of: "inbound-agent"
            agent_name="inbound-agent",
        ),
    )
3. Now, create an inbound LiveKit trunk with your phone number – easy peasy:
Copy code
{
  "trunk": {
    "name": "My inbound trunk",
    "numbers": [
      "+15105550100"
    ]
  }
}
4. Create a dispatch rule to make sure your named agent handles those incoming calls:
Copy code
{
  "name": "My dispatch rule",
  "rule": {
    "dispatchRuleIndividual": {
      "roomPrefix": "call"
    }
  },
  "room_config": {
    "agents": [
      {
        "agent_name": "inbound-agent"
      }
    ]
  }
}
5. Finally, apply the dispatch rule using the CLI – and you're all set!
lk sip dispatch create dispatch-rule.json
And just like that, incoming calls to your phone number will be routed to "inbound-agent". Need any help along the way? I'm right here! 😊 Got questions? Just ask! Sources: Accepting incoming calls | LiveKit Docs
a
will this dispatch rule works for all sip trunk? i want it to work only for this trunk. example if there are two trunks having +1112233225 and +1112555555 as two different trunks. i want the first one to be answered by this agent.
t
Hey there! πŸ‘‹ Want to make sure a dispatch rule works only with a specific SIP trunk? No worriesβ€”I've got a super simple way to do that using the LiveKit CLI. 1. First, create a file (like
dispatch-rule.json
) with your dispatch rule setup. 2. Then, use the LiveKit CLI to update your dispatch rule and link it to specific trunks. Just run this command:
Copy code
lk sip dispatch update --id <dispatch-rule-id> \
--trunks "<trunk-id1>, <trunk-id2>" \
dispatch-rule.json
Just swap out <dispatch-rule-id> with your actual dispatch rule ID, and <trunk-id1> with the trunk ID you want to connect. This way, the rule will only apply to calls coming through that specific trunk. Need any help or want me to break this down further? I'm totally here for you! 😊 Sources: SIP dispatch rule | LiveKit Docs
a
even after updating the dispatch with the trunk id. when i run lk sip dispatch list. the trunk is showing as any
t
I don't have the answer you're looking for. You could also try asking your question: β€’ in one of the other Slack channels or β€’ to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!