Sign inGet Started

Route incoming trunk calls by caller origin and number

A SIP trunk's Routing rules can treat calls differently depending on who is calling and which number they dialed. Rules check facts about each call, such as the caller's line type or country, and pick what happens: send the call to a group of gateways, change the number your equipment receives, reject it, or forward it. This page gives working setups for the most common cases.

Before you start

  • A SIP trunk with inbound calling on, its gateways in at least one group, and your numbers pointed at it. Set up a SIP trunk covers all three.
  • Open Voice > SIP Trunks, open the trunk, and select Routing rules.

How rules work

Bird checks up to 50 rules in order across all caller types. Set data passes values to the next rule. Reject ends routing. If the call reaches the end of the list, Bird uses Default route once. Add rule puts a rule at the bottom. When an example needs to run before an existing catch-all rule, use Move up to put it there.

A Dial rule stops routing unless you select an outcome under Continue on. Select Busy, No answer or Failure to try the next rule when the dial attempt ends with that outcome. For a gateway group, the outcome is the result of the whole hunt. For example, select No answer to try a backup after the group finishes ringing. An answered call stays connected.

When a Sequence dials through the trunk, the attempts share one ringing timeout. Before trying a backup, Bird waits for the previous attempt to finish handling late SIP responses. Even if the destination returns Busy immediately and you selected Busy, that wait can use the full 30-second default. The Sequence then takes its No answer path without dialing the backup.

On a new rule, select Add condition, then Edit expression. Enter a CEL expression and select Done. Include an inbound caller condition when a rule should apply only to calls arriving on your numbers.

Overdial is available when the incoming carrier supports it. The suffix contains 1 to 16 digits after the allocated destination number; overdial calls with longer suffixes or from unsupported carriers do not reach these rules.

FactWhat it holds
caller.line_typeThe caller's line type: LINE_FIXED, LINE_MOBILE, LINE_TOLL_FREE, LINE_PAYPHONE or LINE_UNKNOWN
orig.countryThe caller's two-letter country code, such as GB. Empty when the caller withheld their number
caller.anonymoustrue when the caller withheld their number
orig.numberThe caller's number in E.164, with +
orig.digitsThe caller's number without the leading +
orig.overdial_suffixDigits dialed after the called number, including leading zeroes, or empty when absent
dest.numberThe destination number in E.164, with +; the allocated base number for overdial calls
dest.digitsThe destination number without the leading +; the allocated base number for overdial calls
call.local_hourThe hour of the call, 0 to 23, in the routing's time zone
call.weekdayThe day of the call, in the routing's time zone

Write line types as constants, such as caller.line_type == LINE_MOBILE. An unknown constant fails when you save, while a misspelled string such as "LINE_MOBLE" is accepted and never matches.

Send mobile and landline callers to different gateways

Use this when, for example, mobile callers should reach one SBC and everyone else another.

  1. Open Gateways > Groups. Create a group named mobile and another named landline, add the receiving gateways and select Review and save.
  2. Open Routing rules and select Add rule. Name it Mobile callers. Select Add condition, then Edit expression. Enter caller.type == "inbound" && caller.line_type == LINE_MOBILE and select Done.
  3. Choose Dial and select mobile under Gateway group. To see the groups, select Gateway Group under Dial via.
  4. Add a second rule with caller.type == "inbound", choose Dial and select landline. Keep it below the mobile rule and above any existing rule that decides all incoming calls. This preserves routing for other caller types.
  5. Select Review and save.

To route incoming calls by country, use a condition such as caller.type == "inbound" && orig.country == GB.

Add a prefix by caller origin

Your SBC may expect a prefix in front of the dialed number that tells it the caller's origin, for example 801 for landline, 802 for mobile and 800 for anything else. Bird changes the user part of the Request-URI it sends to your gateway; the gateway's host and port stay the same. For a call to +44 808 157 0123, a mobile caller then arrives as sip:802448081570123@198.51.100.20.

You can set this up in two equivalent ways.

One rule per origin

Use this when each origin should show as its own entry in the editor, or when origins differ by more than the prefix, such as a different group.

  1. In Routing rules, add a rule named Landline with the condition caller.type == "inbound" && caller.line_type == LINE_FIXED.
  2. Choose Dial and a Gateway group. In Override Destination, enter the literal prefix 801, followed by the expressions dest.digits and orig.overdial_suffix.
  3. Repeat for Mobile (LINE_MOBILE, prefix 802).
  4. Below those rules, add an inbound rule with caller.type == "inbound" for other callers. Use the same group and destination with the prefix 800. Keep all three above any existing rule that decides incoming calls.
  5. Select Review and save.

For overdial, dest.digits contains the base number. The default gateway destination includes the suffix automatically, including with a fixed prefix in its number format. An explicit route override controls the full user part: insert orig.overdial_suffix after dest.digits to preserve the extra digits. Use a route override when the prefix depends on an expression.

One expression

For a single prefix rule, use caller.type == "inbound", choose Dial and your Gateway group. Under Override Destination, insert this expression followed by dest.digits and orig.overdial_suffix:

Code example
caller.line_type == LINE_FIXED ? "801" : caller.line_type == LINE_MOBILE ? "802" : "800"

Place this rule above any existing rule that decides all incoming calls. Both setups deliver the same INVITE.

Check your setup

  1. Call one of your numbers from a mobile phone, from a landline and with your number withheld. At your SBC, compare the Request-URI of each received INVITE with what you expect.
  2. Open each call under Voice > Legs and use its SIP Call-ID to find the same call in your SBC's logs.

Next steps

PageWhat it covers
Receiving callsNumber routes, groups, the default route and refused calls
Set up a SIP trunkA whole trunk setup in order, from creation to a test call
Placing callsWhat Bird expects on the INVITE your equipment sends

Continue with the documentation, guides and examples for this topic.