Recipes← all recipesView on GitHub

Forward calls to a phone and keep the caller's number

Voicecall forwarding with caller ID pass-through

Forward every call on a number to a phone, and show that phone the original caller's number instead of your own.

Also called call forwarding, forward calls to a cell phone, caller ID pass-through

swmlforwardingcaller-id

The claim

Plain forwarding has one flaw: the phone that rings sees the forwarding number, so every call looks the same and callback means checking a log. This document forwards with the caller’s own number as the caller ID, so the mobile shows the customer.

Why it holds

Two facts carry the claim.

  • The vendored REST spec documents the inbound call webhook SignalWire sends when it fetches your document, and its call object requires from, “the number/URI that initiated this call”.
  • The bundled SWML schema’s connect device takes from, described as “the caller ID to use when dialing the number”, and a timeout that defaults to 60 seconds.

The handler reads call.from and writes it back into connect.from. Nothing is templated, so there is no question of which substitution syntax the platform expands; the number the platform sent is the number the platform gets.

How it works

def document(caller):
    service = SWMLService(name="forward", route="/swml")
    connect = {"to": FORWARD_TO, "timeout": RING_FOR}
    if caller:
        connect["from"] = caller
    service.add_verb("connect", connect)
    return json.loads(service.render_document())

What a call from +1 415 555 0123 gets back:

{"version": "1.0.0",
 "sections": {"main": [{"connect": {"to": "+15550100001",
                                    "timeout": 25,
                                    "from": "+14155550123"}}]}}

There is no answer verb. connect bridges the caller to the ringing phone when it picks up, so the caller hears ringing rather than a picked-up line with silence behind it. A call with no caller id leaves from out, and the platform presents its own default rather than an empty string.

Passing a caller’s number through as your caller ID is subject to the rules of the country and carrier the call leaves through. The recipe shows the mechanism. Whether your numbers may present it is a question for your carrier agreement.

Limitations

The verifier proves the document, not the display. Whether the mobile shows the caller’s number depends on the carriers between the platform and that phone.

The forwarding target is one number. Ringing several, in order or at once, is [Dial destinations in order or all at once](../try-destinations-in-order/). The from shown here applies to each of its devices.

What to change first

Change connect["from"] = caller to connect["from"] = FORWARD_TO and run the verifier. The document validates and the assertion fails, which is the point. The schema accepts any caller ID; only the verifier says it must be the caller’s.