Compatibility Libraries and SDKs

View as Markdown

SignalWire has clients in a number of different languages that make using the SignalWire Compatibility API possible with your existing application. They are also built to make migrating from other service providers to SignalWire quick and easy.

The Compatibility SDK has two primary components:

  • REST Client: The REST client is used to make API calls for initiating outbound calls and messages, managing phone numbers, retrieving call logs, and other operations. See the REST API documentation for the complete API reference.

  • cXML Builders: The cXML builders do not make API calls directly. Instead, they are helper libraries that enable you to easily generate cXML responses within your language of choice. The SDK provides three response builders for the different channel types:

    • VoiceResponse — Build XML for handling voice calls
    • MessagingResponse — Build XML for handling SMS/MMS messages
    • FaxResponse — Build XML for handling faxes

    See the cXML Specification for technical reference on the XML format and available verbs.


Getting started with the SDKs

Installing the SDK

Install the package using NPM:

1npm install @signalwire/compatibility-api

Initializing the Client

In order to use the NodeJS client, you must get your Space URL, Project ID, and API Token from your SignalWire Dashboard and initialize the client:

1const { RestClient } = require("@signalwire/compatibility-api");
2
3const client = RestClient(
4"your-project",
5"your-token",
6{ signalwireSpaceUrl: "example.signalwire.com" }
7);
8
9// You can then use client to make calls, send messages, and more.

Using Environment Variables

Alternatively, you can use an environment variable to pass the Space URL:

1 SIGNALWIRE_SPACE_URL=example.signalwire.com

With this approach, signalwireSpaceUrl will be pulled from the .env file instead of having to be passed as an argument:

1 const { RestClient } = require("@signalwire/compatibility-api");
2
3 const client = RestClient(
4 "your-project",
5 "your-token"
6 );

Migrating from Twilio

You can easily migrate from Twilio with minimal changes.

To get started, you will need to replace the Twilio client with the SignalWire client and update the from number to a valid SignalWire number.

Make sure to change the 'From' number!

When migrating to SignalWire, make sure to replace the from numbers with a valid SignalWire number.

1// Replace these lines:
2const twilio = require('twilio')
3const response = new twilio.twiml.VoiceResponse()
4
5// With:
6const { RestClient } = require('@signalwire/compatibility-api')
7const response = new RestClient.LaML.VoiceResponse()
8
9// Now use response like you did before!
10response.say('Hey, welcome to SignalWire!')