Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,58 @@ description: Use cXML to forward calls

# Forwarding Calls

In [Making and Receiving Phone Calls](../making-and-receiving-phone-calls/index.mdx) we learned how to use XML
bins to define what should happen when a call is received by one of your
In [Making and Receiving Phone Calls](../making-and-receiving-phone-calls/index.mdx) we learned how to use SWML and cXML
to define what should happen when a call is received by one of your
SignalWire numbers. In that case, we just played some audio. In this article,
instead, we will use the same technique to forward the call to a different
number.


## cXML for Call Forwarding
## SWML for call forwarding

We are going to define the forwarding instructions in a SWML script hosted on SignalWire.
To create a new SWML script, navigate to the **Resources** section from your sidebar.
There, create a new script, and select the **SWML Script** option.

### Creating your call forwarding script

Once you are in the menu for creating a SWML script, copy and paste the following script:

```yaml andJson
version: 1.0.0
sections:
main:
- connect:
from: "%{call.from}"
to: "+15551234567"
```

This script will handle the call by making an outbound dial, setting the `from` address to be the address which created the initial call,
and then forwarding that call to the number specified in the `to` field.
You should replace `+15551234567` with a real phone number, for example your personal one.

We used the [`connect`](/swml/methods/connect) method to call the number you would like the call to be forwarded to.
Notice how we used its `from` parameter to ensure that the number of the original caller (stored in the `call.from` variable) is maintained as caller ID for the forwarded call.

### Assigning the script to a SignalWire phone number

The final step is to configure one of your SignalWire phone numbers to answer calls using the SWML script we just created.
You can do that from the **Phone Numbers** section:

![Assign Resource](@image/dashboard/phone-numbers/assign-resource-voice.png)

After clicking on the **Phone Numbers** section, click on the phone number that you'd like to assign, then click **edit settings**.
From there, click **Assign Resource** and assign the newly created SWML script.
Now any calls that are routed to that number will be forwarded, with the caller ID being the original number that called in.

## cXML for call forwarding

We are going to define the forwarding instructions in an cXML bin hosted on
SignalWire. To create a new cXML bin, navigate to the "Resources" section from your sidebar. There, create
a new script, and select the "cXML" option.

### Creating your call forwarding script

Create a new cXML bin, and paste the following XML in it:

```xml
Expand All @@ -44,7 +83,7 @@ import NewLegacy from '/docs/main/_common/dashboard/_ui-accordion.mdx'

If you're still on **Legacy UI**, refer to [Making and Receiving Phone Calls](../making-and-receiving-phone-calls/index.mdx) for detailed instructions.

## Assigning the Bin to a SignalWire Phone Number
### Assigning the Bin to a SignalWire Phone Number

The final step is to configure one of your SignalWire phone numbers to answer calls using the XML bin we just created. You can do that from the "Phone Numbers" section:

Expand All @@ -58,6 +97,6 @@ You are now ready to test call forwarding.

If you are forwarding calls to a personal number, you may wonder how to differentiate incoming calls as either personal or ones forwarded from your SignalWire number. Please see our guide on [Call Whisper](/compatibility-api/guides/voice/general/setting-up-call-whispering-in-cxml) for a handy solution.

XML bins offer a quick and easy way to get started with common use cases. If you are an advanced developer, or you need more
SWML scripts and cXML bins offer a quick and easy way to get started with common use cases. If you are an advanced developer, or you need more
flexibility and real-time control on your calls, you may be interested in our
guide about how to [make and receive calls in Node.js](/sdks/realtime-sdk/guides/voice/first-steps-with-voice).