Hi all, I’d like to assign different phone numbers...
# telephony
c
Hi all, I’d like to assign different phone numbers to different agents. My plan was to use a single inbound trunk with one dispatch rule per agent, specifying the agent’s phone number via the
inbound_numbers
parameter. The documentation for
inbound_numbers
states: “if set, the dispatch rule only accepts calls made to numbers in the list”. However, what I’m observing is that calls are being filtered by the calling number, not the called number. Should the documentation instead read “the dispatch rule only accepts calls made from numbers in the list”, or is this a possible implementation issue? This behavior was also reported here: https://github.com/livekit/sip/issues/362
r
In your Trunk set the number you want it to answer for. Then associate a dispatch rule with the agent_name you want for that trunk. If you need more specific advise please provide your SIP trunk id and dispatch rule in question. They start with
ST_
and
SD_
c
I would like to support multiple agents, each one of them with their number, using a single inbound trunk. Is that possible with dispatch rules?
r
I thought you wanted 1 agent per set of inbound phone numbers.
There are a couple of common ways other folks have accomplished this use case. 1. Use a trunk for a given set of numbers that points at a dispatch rule that is associated with the agent you want to have answer. 2. Have all calls go to an agent and at the top of your entry point determine what prompts and behavior you need to load to be the agent that call needs.
c
In option 1. how do you configure with dispatch rules the mapping between agents and phone numbers? I thought I could use the
inbound_numbers
parameter, but from my tests it seems it is checking the calling number (i.e. the user's number) and not the called number (i.e. the agent's number).
r
you configure the trunk.
What is the ID of the dispatch rule you are configuring?
c
It's on a self hosted instance of livekit
👍 1
I am still a bit confused how you configure the mapping from phone numbers to agents... Sorry, I might be missing something. I have one trunk, with several numbers. I would like to "assign" these numbers to agents. I thought I could do that using multiple dispatch rules...
r
This is for cloud but I think it should help your understanding: https://docs.livekit.io/agents/start/telephony/
c
Thanks. In https://docs.livekit.io/sip/api/#createsipdispatchrule I can see that when creating a dispatch rule I can specify an array of numbers in the
inbound_numbers
parameter. Am I supposed to use that to associate a number to a dispatch rule which in turn is associated to an agent?
r
Yes, if you want to filter by who is calling you can use that. But that is not how I understood what you are trying to do. The
inbound_numbers
field in the SIP dispatch rule is used to specify which phone numbers the dispatch rule will accept calls from. This means that the numbers listed in
inbound_numbers
are the phone numbers that the dispatch rule will respond to when a call is made. In the context of your question, the
inbound_numbers
are for the caller's phone numbers, not the agent's number. If a call comes in from a number that is not included in the
inbound_numbers
list, the dispatch rule will not accept that call. Here is a relevant excerpt from the documentation:
Copy code
| inbound_numbers | array<string> | If this list is included, the dispatch rule only accepts calls made to the numbers in the list. |
This indicates that the dispatch rule will only accept calls from the numbers specified in the
inbound_numbers
array. Example of Handling Inbound Numbers When creating a dispatch rule, you might specify the `inbound_numbers`like this:
Copy code
{
  "name": "My Dispatch Rule",
  "inbound_numbers": [
    "+14155550100",
    "+17145550100"
  ],
  "hide_phone_number": false,
  "metadata": "example-metadata"
}
In this example, only calls coming from
+14155550100
or
+17145550100
will be accepted by this dispatch rule. Code Handling The actual handling of the
inbound_numbers
would typically occur in the backend logic where the dispatch rules are evaluated. For example, when a call is received, the system checks if the calling number is in the
inbound_numbers
list before proceeding with the dispatch logic. Here is a simplified example of how this might look in code:
Copy code
func EvaluateDispatchRule(call Call) (DispatchResult, error) {
    for _, number := range dispatchRule.InboundNumbers {
        if call.CallingNumber == number {
            // Accept the call
            return DispatchResult{Accepted: true}, nil
        }
    }
    // Reject the call
    return DispatchResult{Accepted: false}, nil
}
In this code, the
EvaluateDispatchRule
function checks if the
CallingNumber
from the incoming call matches any of the numbers in the
InboundNumbers
list. Conclusion To summarize, the
inbound_numbers
are for the caller's phone numbers, and they determine which calls the dispatch rule will accept. The handling of these numbers occurs in the backend logic that evaluates incoming calls against the dispatch rules.
We will update the doc to be more clear.
c
Ok, thank you very much for the clarification.