Route incoming trunk calls by caller origin and number
A SIP trunk's Inbound routing 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 go to Inbound routing > Rules.
How rules work
Bird checks the rules from top to bottom for each incoming call. The first rule whose When matches decides the call; a call that matches no rule uses the Default route (No rule above matched). Each rule and the default route has a Then: Route to group, Reject, or Forward to number. A trunk holds up to 50 rules.
A When is a condition over these call facts. Select a fact from the list, or use Edit expression to write the condition yourself.
| Fact | What it holds |
|---|---|
orig.line_type | The caller's line type: LINE_FIXED, LINE_MOBILE, LINE_TOLL_FREE, LINE_PAYPHONE or LINE_UNKNOWN |
orig.country | The caller's two-letter country code, such as GB. Empty when the caller withheld their number |
orig.anonymous | true when the caller withheld their number |
orig.number | The caller's number in E.164, with + |
orig.digits | The caller's number without the leading + |
dest.number | The number that was dialed, in E.164, with + |
dest.digits | The number that was dialed, without the leading + |
call.local_hour | The hour of the call, 0 to 23, in the routing's time zone |
call.weekday | The day of the call, in the routing's time zone |
Write line types as constants, such as orig.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.
- In Groups, create a group for each destination, for example
mobilewith your mobile SBC andlandlinewith the other. - In Rules, select Add rule and name it Mobile callers. Set When to Line type with the value
LINE_MOBILE. - Set Then to Route to group and choose
mobile. - Set the Default route to Route to group and choose
landline. It takes every call the rule did not match. - Select Review and save, then confirm.
The same pattern routes by country: set When with Edit expression to a condition such as 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.
- In Rules, select Add rule, name it Landline, and set When to Line type with the value
LINE_FIXED. - Set Then to Route to group, choose your group under Group, then select Override R-URI user part. Type
801, then use Insert to adddest.digitsafter it. - Repeat for Mobile (
LINE_MOBILE, prefix802). - Set the Default route to Route to group with the user part
800followed bydest.digits. - Select Review and save, then confirm.
One expression
Use this when only the prefix changes. Leave Rules empty, set the Default route to Route to group with your group, select Override R-URI user part, insert this expression, and add dest.digits after it:
orig.line_type == LINE_FIXED ? "801" : orig.line_type == LINE_MOBILE ? "802" : "800"Both setups deliver the same INVITE. A gateway's own R-URI user part accepts only fixed text around the dialed number, so put a prefix that depends on the caller in a rule or in the default route, as above.
Check your setup
- Review and save checks every condition and template and lists the errors with where they are. Nothing is saved until they are fixed.
- 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
INVITEwith what you expect. - Open each call under Voice > Legs and use its SIP Call-ID to find the same call in your SBC's logs.
Next steps
| Page | What it covers |
|---|---|
| Receiving calls | Number routes, groups, the default route and refused calls |
| Set up a SIP trunk | A whole trunk setup in order, from creation to a test call |
| Placing calls | What Bird expects on the INVITE your equipment sends |
संबंधित संसाधन
इस विषय के लिए दस्तावेज़, गाइड और उदाहरणों के साथ आगे बढ़ें।