Client Libraries and SDKs
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.
When migrating to SignalWire, make sure to replace the from numbers with a valid SignalWire number.
Installing the SDK
- Node.js
- PHP
- Python
- Ruby
- C#
Install the package using NPM:
npm install @signalwire/compatibility-api
Install the packaging using Composer:
composer require signalwire-community/signalwire
If your environment does not handle autoloading you must require the autoload file generated by Composer:
<?php
require 'path-to/vendor/autoload.php';
?>
Install the package:
pip install signalwire
Install the package via rubygems:
gem install signalwire
Use nuget to add a reference to the signalwire-dotnet
project.
Initializing the Client
- Node.js
- PHP
- Python
- Ruby
- C#
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:
Explicitly:
const { RestClient } = require("@signalwire/compatibility-api");
const client = RestClient(
"your-project",
"your-token",
{ signalwireSpaceUrl: "example.signalwire.com" }
);
// You can then use client to make calls, send messages, and more.
Using .env
:
Alternatively, you can use an environment variable to pass the Space URL:
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:
const { RestClient } = require("@signalwire/compatibility-api");
const client = RestClient(
"your-project",
"your-token"
);
In order to use the PHP client, you must get your Space URL, Project ID, and API Token from your SignalWire dashboard and initialize the client:
<?php
use SignalWire\Rest\Client;
$client = new Client('your-project', 'your-token', array("signalwireSpaceUrl" => "example.signalwire.com"));
// You can then use $client to make calls, send messages, and more.
?>
Alternatively, you can use an environment variable to set up the Space URL:
Using $_ENV
:
<?php
$_ENV['SIGNALWIRE_SPACE_URL']="example.signalwire.com";
?>
Using putenv
:
<?php
putenv("SIGNALWIRE_SPACE_URL=example.signalwire.com");
?>
With this approach, signalwireSpaceUrl
will be pulled from the .env
for you:
<?php
use SignalWire\Rest\Client;
$client = new Client('your-project', 'your-token');
?>
In order to use the Python client, you must get your Space URL, Project ID, and API Token from your SignalWire dashboard and initialize the client:
from signalwire.rest import Client as signalwire_client
client = signalwire_client('your-project', 'your-token', signalwire_space_url = 'example.signalwire.com')
# You can then use client to make calls, send messages, and more.
Alternatively, you can use an environment variable to set up the Space URL. Place the Space URL in your .env
file:
SIGNALWIRE_SPACE_URL=example.signalwire.com
With this approach, signalwire_space_url
will be pulled from the .env
for you:
from signalwire.rest import Client as signalwire_client
client = signalwire_client('your-project', 'your-token')
In order to use the Ruby client, you must get your Space URL, Project ID, and API Token from your SignalWire dashboard and initialize the client:
require 'signalwire/sdk'
@client = Signalwire::REST::Client.new 'your-project', 'your-token', signalwire_space_url: "example.signalwire.com"
# You can then use @client to make calls, send messages, and more.
Alternatively, you can use an environment variable to set up the Space URL. Place the Space URL in your .env
file:
SIGNALWIRE_SPACE_URL=example.signalwire.com
With this approach, signalwire_space_url
will be pulled from the .env
for you:
require 'signalwire/sdk'
@client = Signalwire::REST::Client.new 'your-project', 'your-token'
Or, you can configure your SignalWire subdomain with an initializer:
require 'signalwire/sdk'
Signalwire::Sdk.configure do |config|
config.hostname = "example.signalwire.com"
end
In order to use the C# client, you must get your Space URL, Project ID, and API Token from your SignalWire dashboard and initialize the client:
TwilioClient.Init("YourProjectID", "YourAuthToken", new Dictionary<string, object> { ["signalwireSpaceUrl"] = "<your-domain>.signalwire.com" });
Migrating from Twilio
You can easily migrate from Twilio with minimal changes. Simply install the package as discussed above, then initialize the client:
- Node.js
- PHP
- Python
- Ruby
- C#
// Replace these lines:
const twilio = require("twilio");
const client = new twilio(sid, token);
// With:
const { RestClient } = require("@signalwire/compatibility-api");
const client = RestClient("your-project", "your-token", {
signalwireSpaceUrl: "example.signalwire.com",
});
// Now use the client variable as you did before!
<?php
// Replace this line:
use Twilio\Rest\Client;
// With:
use SignalWire\Rest\Client;
// Then set up the client with your SignalWire Project ID and API Token:
$client = new Client('your-project', 'your-token', array("signalwireSpaceUrl" => "example.signalwire.com"));
// Now use $client variable like you did before!
?>
# Replace these lines:
from twilio.rest import Client
client = Client('account_sid', 'auth_token')
# With:
from signalwire.rest import Client as signalwire_client
client = signalwire_client('your-project', 'your-token', signalwire_space_url = 'example.signalwire.com')
# Now use client variable like you did before!
# Replace these lines:
require 'twilio-ruby'
@client = Twilio::REST::Client.new('account_sid', 'auth_token')
# With:
require 'signalwire/sdk'
@client = Signalwire::REST::Client.new 'your-project', 'your-token', signalwire_space_url: "example.signalwire.com"
# Now use @client variable like you did before!
// Replace these lines:
TwilioClient.Init("accountSid", "authToken");
// With:
TwilioClient.Init("YourProjectID", "YourAuthToken", new Dictionary<string, object> { ["signalwireSpaceUrl"] = "<your-domain>.signalwire.com" });
// Now use client like you did before!
To generate SignalWire XML:
- Node.js
- PHP
- Python
- Ruby
// Replace these lines:
const twilio = require("twilio");
const response = new twilio.twiml.VoiceResponse();
// With:
const { RestClient } = require("@signalwire/compatibility-api");
const response = RestClient.laml.VoiceResponse();
// Now use response as you did before!
response.say("Hey, welcome to SignalWire!");
<?php
// Replace these lines:
use Twilio\TwiML;
$response = new TwiML;
// With:
use SignalWire\LaML;
$response = new LaML;
// Now use $response like you did before!
$response->say('Hey, welcome to SignalWire!')
?>
# Replace these lines:
from twilio.twiml.voice_response import VoiceResponse
response = VoiceResponse()
# With:
from signalwire.voice_response import VoiceResponse
response = VoiceResponse()
# Now use response like you did before!
response.say('Hey, welcome to SignalWire!')
# Replace these lines:
require 'twilio-ruby'
response = Twilio::TwiML::VoiceResponse.new
# With:
require 'signalwire/sdk'
response = Signalwire::Sdk::VoiceResponse.new do |response|
# Now use response like you did before!
response.say(message: 'Hey, welcome to SignalWire!')