|
| 1 | +--- |
| 2 | +title: Send outbound calls from LiveKit |
| 3 | +sidebar_label: Outbound |
| 4 | +description: Route LiveKit Calls onto the PSTN with SignalWire. |
| 5 | +slug: /ai/guides/integrations/livekit/outbound |
| 6 | +--- |
| 7 | + |
| 8 | +import CreateSWML from '/docs/main/_common/dashboard/create-swml-script.mdx' |
| 9 | + |
| 10 | +# Make outbound LiveKit Agent calls via SignalWire |
| 11 | + |
| 12 | +<Subtitle>Route LiveKit calls onto the PSTN with SignalWire</Subtitle> |
| 13 | + |
| 14 | +This guide will help you set up outbound SIP calls using LiveKit and SignalWire. |
| 15 | +Follow these steps to configure your SIP domain, SWML script, and LiveKit settings efficiently. |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +Before getting started, you'll need the following: |
| 20 | + |
| 21 | + - a [SignalWire Space][signup] |
| 22 | + - a [LiveKit account][livekit] |
| 23 | + - a [SignalWire phone number][buy-phone] |
| 24 | + |
| 25 | +## Setup |
| 26 | + |
| 27 | +<Steps> |
| 28 | + |
| 29 | +### Create a SWML Script |
| 30 | + |
| 31 | +<CreateSWML/> |
| 32 | + |
| 33 | + - Log in to your SignalWire Dashboard and navigate to the [**Resources**](https://my.signalwire.com/?page=resources) tab on the left-hand sidebar. |
| 34 | + - Click **Add**, select **Script**, and then choose **SWML Script**. |
| 35 | + - Paste the following SWML code snippet into the editor: |
| 36 | + |
| 37 | +```yaml title="SWML" |
| 38 | +version: 1.0.0 |
| 39 | +sections: |
| 40 | + main: |
| 41 | + - connect: |
| 42 | + answer_on_bridge: true |
| 43 | + from: "+1XXXXXXXXXX" |
| 44 | + to: "%{call.to.replace(/^sip:/i, '').replace(/@.*/, '')}" |
| 45 | +``` |
| 46 | +
|
| 47 | +Be sure to replace `"+1XXXXXXXXXX"` with a phone number from your SignalWire account. |
| 48 | +
|
| 49 | +### Add SIP address |
| 50 | +
|
| 51 | + - Save the SWML script and navigate to the **Addresses & Phone Numbers** section within the script. |
| 52 | + - Click **Add** and select **SIP Address** to add your SIP domain application. |
| 53 | + - Configure this SIP address based on your requirements, and save it. |
| 54 | + - After configuration, note down your unique SIP domain. |
| 55 | +
|
| 56 | + Example SIP domain: `test-space-live-kit.dapp.signalwire.com`. |
| 57 | + |
| 58 | +</Steps> |
| 59 | + |
| 60 | +Now, let’s configure LiveKit for outbound SIP calling. |
| 61 | +Follow along with LiveKit’s documentation for [outbound SIP trunk setup](https://docs.livekit.io/sip/trunk-outbound/). |
| 62 | + |
| 63 | +<Steps> |
| 64 | + |
| 65 | +### Create an outbound trunk |
| 66 | + |
| 67 | +Use the following JSON configuration for creating an outbound SIP trunk, ensuring you update the given fields: |
| 68 | + |
| 69 | +```json |
| 70 | +{ |
| 71 | + "trunk": { |
| 72 | + "name": "My Outbound SIP Trunk", |
| 73 | + "address": "test-space-livekit.dapp.signalwire.com", |
| 74 | + "numbers": ["+15105550100"], |
| 75 | + "auth_username": "<username>", |
| 76 | + "auth_password": "<password>", |
| 77 | + "transport": 3 |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +Update placeholders in the above JSON with the following: |
| 83 | + |
| 84 | +| Placeholder | Replace with | |
| 85 | +| :---------- | :----------- | |
| 86 | +| `"address"` | The SIP domain you created previously (e.g., `test-space-live-kit.dapp.signalwire.com`). | |
| 87 | +| `numbers` | A SignalWire phone number. | |
| 88 | +| `<username>` and `<password>` | The credentials provided by SignalWire Support. Contact Support if needed. | |
| 89 | + |
| 90 | +Submit this request and save the generated `Trunk ID`. |
| 91 | +If you forget to save the Trunk ID, use LiveKit’s CLI tool to retrieve the trunk configurations. |
| 92 | + |
| 93 | +### Create SIP participant |
| 94 | + |
| 95 | +To initiate outbound calls through your configured trunk, you'll need to create a SIP participant in LiveKit. |
| 96 | +This process establishes the connection and manages the call flow. |
| 97 | +For detailed instructions on creating SIP participants and handling outbound calls, |
| 98 | +refer to LiveKit's comprehensive guide to |
| 99 | +[Creating a SIP Participant](https://docs.livekit.io/sip/outbound-calls/#creating-a-sip-participant). |
| 100 | + |
| 101 | +If you're working with LiveKit AI agents for outbound calls, please see |
| 102 | +the [LiveKit AI Agent Telephony Guide](https://docs.livekit.io/agents/start/telephony/). |
| 103 | + |
| 104 | +### Final checks |
| 105 | +- Ensure the trunk address matches exactly with the one created previously. |
| 106 | +- Phone numbers must be in E.164 format (e.g., "+15105550100") to ensure proper routing and connectivity. |
| 107 | + |
| 108 | +</Steps> |
| 109 | + |
| 110 | +You’re now ready to make your first outbound SIP call using LiveKit and SignalWire. |
| 111 | +If you encounter any issues, verify the configurations for both SignalWire and LiveKit. |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## Next steps |
| 116 | + |
| 117 | +### Record calls |
| 118 | + |
| 119 | +Record calls by creating a SWML script with recording logic and slightly modifying your outbound SWML script. |
| 120 | + |
| 121 | +<Steps> |
| 122 | + |
| 123 | +### Create a second script |
| 124 | + |
| 125 | +In your new script, paste the following SWML: |
| 126 | + |
| 127 | + ```yaml title="record.yaml" |
| 128 | + version: 1.0.0 |
| 129 | + sections: |
| 130 | + main: |
| 131 | + - record_call: |
| 132 | + format: mp3 |
| 133 | + ``` |
| 134 | + |
| 135 | +### Update the outbound SWML script |
| 136 | + |
| 137 | +Then, modify your existing outbound SWML script by adding the `confirm` parameter under the `connect` method, |
| 138 | +and setting its value to the URL for the new recording script. |
| 139 | + |
| 140 | +The result should look like this: |
| 141 | + |
| 142 | +```yaml title="outbound.yaml" |
| 143 | +version: 1.0.0 |
| 144 | +sections: |
| 145 | + main: |
| 146 | + - connect: |
| 147 | + answer_on_bridge: true |
| 148 | + confirm: "your-recording-script-url" |
| 149 | + from: "+1XXXXXXXXXX" |
| 150 | + to: "%{call.to.replace(/^sip:/i, '').replace(/@.*/, '')}" |
| 151 | +``` |
| 152 | + |
| 153 | +</Steps> |
| 154 | + |
| 155 | +These recordings can be accessed in the Dashboard in **Storage > Recordings**, |
| 156 | +or using the |
| 157 | +[Recordings List API endpoint](/rest/signalwire-rest/endpoints/space/recordings-list). |
| 158 | + |
| 159 | +### View logs |
| 160 | + |
| 161 | +Access call logs in the |
| 162 | +[Logs](https://my.signalwire.com/?page=logs) |
| 163 | +tab of your SignalWire Dashboard. |
| 164 | + |
| 165 | +{/* Links */} |
| 166 | + |
| 167 | +[signup]: https://signalwire.com/signup "Sign up for a SignalWire Space." |
| 168 | +[livekit]: https://cloud.livekit.io/login "Sign up for a LiveKit account." |
| 169 | +[buy-phone]: /platform/phone-numbers/getting-started/buying-a-phone-number/ "Buy a phone number in the SignalWire dashboard." |
0 commit comments