Routing is the choice, for each outbound message, of the phone and the SIM that carry it. With a single phone and a single SIM there is nothing to choose. As soon as you have several SIMs, the choice matters: it spreads the load, keeps each SIM under its quota, and can save money when a message stays inside one carrier's network.
By default the gateway chooses on its own. The Routing screen, right under Devices in the sidebar, lets you add prefix rules: "numbers starting with +26134 leave from SIM 1 of the front desk phone".
How a SIM is chosen
For each message, the gateway goes down this list and stops at the first answer:
- A phone named in the send. When you pick a Sending device in quick send or in a
conversation, or pass
deviceIdto the API, that phone carries the message or nothing does. The rules are not consulted. - The SIM of the conversation. A reply in a conversation leaves from the SIM the correspondent already knows, as long as that SIM can send. Your customer always sees the same number.
- The prefix rules. If a rule covers the number, its SIMs are tried in the order you set.
- The automatic routing, over every phone.
A SIM can send when its phone is online, in the routing pool, its SIM is in service, its daily quota and its per-minute limit are not reached, and it has waited its minimum interval since its last SMS. A SIM that cannot send is simply skipped.
Automatic routing
The automatic routing applies to every number no rule covers. Its mode is chosen when the gateway is
installed, with the GATEWAY_ROUTING_MODE variable of the .env file, followed by
sms-gateway restart (see the installation guide):
| Mode | What it prefers | Good for |
|---|---|---|
round_robin (default) |
Each SIM in turn, to spread the traffic evenly | Similar SIMs, similar plans |
quota |
The SIM with the most daily quota left. A SIM without a daily cap always comes first | SIMs with different quotas: the fleet lasts longer |
carrier |
The SIM whose carrier serves the recipient's number, since a message inside one network often costs less. When no SIM matches the recipient's carrier, it falls back to the quota mode |
Several carriers, on-net tariffs cheaper |
The carrier mode needs the table of the prefixes of each carrier, given in
GATEWAY_CARRIER_PREFIXES (for example Telma:+26134,+26138;Orange:+26132). Write each carrier name
exactly as the phone reports it, as shown in the SIM column of Devices: a name spelled
differently matches no SIM. Without the table, the gateway refuses to start rather than silently
routing without carriers.
Changing the mode means changing the variable and restarting the gateway. The prefix rules, on the other hand, change live from the dashboard.
Prefix rules
A rule says: "messages to numbers starting with these prefixes leave from these SIMs, in this order". Typical uses:
- A SIM with an on-net plan for one carrier: send that carrier's numbers from it.
- A phone per country: numbers starting with
+33leave from the French SIM,+261from the Malagasy one. - A dedicated number for a customer segment, so they always see the same sender.
Create a rule
In Routing, click New rule (Superadmin). The dialog asks for:
| Field | What to enter |
|---|---|
| Name | A name you recognise, 1 to 80 characters |
| Number prefixes | One prefix per line, or separated by commas, in international format: + followed by digits, for example +26134. 1 to 50 prefixes |
| SIMs that send | Tick the SIMs in the order they should be tried, then adjust the order with the arrows. 1 to 20 SIMs |
| Wait for these SIMs | What happens when none of these SIMs can send. See below |
| Rule active | Off, the rule is kept but ignored |
The rule applies to the next message, with nothing to restart.
Which rule wins
When several rules cover a number, the longest prefix wins: +26134 beats +261 for
+261341234567. That lets you write a general rule and more specific exceptions. Between two
prefixes of the same length, the rule higher in the list wins.
Inside a rule, the first SIM of the list that can send carries the message. The next ones are there to take over when the first is offline, out of quota or out of service.
When none of the rule's SIMs can send
That is what Wait for these SIMs decides:
| Wait for these SIMs | What happens |
|---|---|
| Off (default) | The message leaves from another SIM through the automatic routing. It leaves on time, but from another number |
| On | The message never leaves from another SIM. It waits for one of the rule's SIMs, see below |
With Wait for these SIMs on, the wait depends on why the SIMs cannot send:
- their daily quota is reached: the message moves to Quota reached and leaves as soon as a quota is raised, or at midnight UTC;
- their per-minute limit is reached, or they have not waited their minimum interval: the message stays Queued and leaves as soon as one of them is free;
- their phone is offline, out of the routing pool, or the SIMs are out of service: the message stays Queued and the gateway tries again every minute, without spending an attempt. It leaves as soon as a SIM of the rule comes back.
Use it when the sender number matters more than the delay: a customer who must always see the same number, a SIM that is the only one allowed to send to a given network. A strict rule can hold messages as long as its phone stays away; you see them in the Queue.
The rules table
The Prefix rules table shows each rule with Numbers starting with, SIMs, in order (phone, SIM, carrier and masked number), If none can send (Wait or Automatic routing), an Active switch, and Actions to edit or delete.
Unpairing a phone removes its SIMs from every rule. A rule left with no SIM shows No SIM left: the rule is ignored. Deleting a rule sends its numbers back to the automatic routing; messages already sent are not affected.
Test a number
The Test a number card tells you which SIM a message to a given number would leave from right now, and why. Nothing is sent, and the test does not disturb the rotation of real traffic. The answer is one of:
| Outcome | Example |
|---|---|
| Rule | "Rule Telma (+26134): leaves from Front desk, SIM 1." |
| Fallback | "Rule Telma matches but none of its SIMs can send: leaves from Warehouse, SIM 0 through the automatic routing." |
| Waiting | "Rule Telma matches and none of its SIMs can send: the message would wait." |
| Automatic | "No rule matches: automatic routing (round_robin), leaves from Warehouse, SIM 0." |
| Unavailable | "No SIM can send right now", with the reason |
Use it after creating a rule, and when a message did not leave from the SIM you expected.
Options
| Option | Where | Default | Allowed values | Effect |
|---|---|---|---|---|
| Automatic mode | GATEWAY_ROUTING_MODE, at installation |
round_robin |
round_robin, quota, carrier |
How numbers no rule covers are spread. Needs a restart |
| Carrier prefixes | GATEWAY_CARRIER_PREFIXES, at installation |
Empty | Carrier:+prefix,+prefix;Carrier:+prefix |
Required by the carrier mode, ignored otherwise |
| Name | Rule dialog; API name |
None | 1 to 80 characters | Display only |
| Number prefixes | Rule dialog; API prefixes |
None | 1 to 50, each + then 1 to 14 digits, not starting with 0; duplicates merged |
The numbers the rule covers. Longest match wins |
| SIMs that send | Rule dialog; API targets (deviceId, slot) |
None | 1 to 20 SIMs, each once | Tried in order; the first that can send carries the message |
| Wait for these SIMs | Rule dialog; API strict |
Off | On or off | Off: fall back to automatic routing. On: the message waits for one of the rule's SIMs |
| Rule active | Rule dialog and Active switch; API enabled |
On | On or off | Off: the rule is ignored, as if deleted, but kept |
| Priority | API only, priority |
After the existing rules | 0 or more, lower first | Decides between two rules whose matching prefixes have the same length. The table lists rules in this order |
Other settings that change which SIM can send: the daily quota, SIM in service and the routing pool in Devices, and the Messages per minute and per SIM limit in Sending messages.
Who can do what: a Superadmin creates, edits and deletes rules. Operators and Read only accounts see the rules and can test a number.
API
| Method and path | Use |
|---|---|
GET /routing/rules |
List the rules, in priority order |
POST /routing/rules |
Create a rule |
GET /routing/rules/{routingRuleId} |
Read one rule |
PATCH /routing/rules/{routingRuleId} |
Change a rule. prefixes and targets replace the whole list |
DELETE /routing/rules/{routingRuleId} |
Delete a rule |
POST /routing/test |
Test a number, without sending |
POST /routing/test answers with an outcome (rule, fallback, held, automatic,
unavailable), the matching rule and prefix, the chosen deviceId, deviceName and slot, and a
reason when nothing can send (NO_DEVICE_AVAILABLE, QUOTA_EXHAUSTED, RATE_LIMITED,
RULE_SIMS_UNAVAILABLE). Writing rules through an API key requires the admin scope.
Troubleshooting
| Symptom | What to check |
|---|---|
| A message did not leave from the rule's SIM | Was it a reply in a conversation (it keeps the conversation's SIM)? Was a phone named in the send? Use Test a number |
| Messages to some numbers stay Queued | A rule with Wait for these SIMs covers them and its phones are offline or its SIMs out of service |
| "Invalid prefix" | A prefix must start with + followed by digits, for example +26134, without spaces |
| The rule seems ignored | Is it Active? Does a longer prefix of another rule cover the number? Does it still have a SIM? |
The gateway refuses to start after choosing carrier |
GATEWAY_CARRIER_PREFIXES is missing or malformed |