This package has been deprecated

Author message:

SignalWire has been split in multiple packages. Read: https://developer.signalwire.com/client-sdk/docs

signalwire

1.0.4 • Public • Published

SignalWire NodeJs


This package has been split in multiple packages!

If you are looking for the latest version of SignalWire for Node.js, please visit the package @signalwire/node.


This library provides a client for the Signalwire LaML and REST services.

It allows you to create calls, send messages, and generate LAML responses.

Installation

Install the package using NPM:

npm install signalwire

Usage

In order to use the client you must set the environment variable SIGNALWIRE_API_HOSTNAME!

Puts in your .env file your SignalWire host, project and token:

SIGNALWIRE_API_HOSTNAME=changeme.signalwire.com
SIGNALWIRE_API_PROJECT=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
SIGNALWIRE_API_TOKEN=PTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Setup Client

// Here we are using Project and Token from ENV
const RestClient = require('signalwire').RestClient
const client = new RestClient(process.env.SIGNALWIRE_API_PROJECT, process.env.SIGNALWIRE_API_TOKEN)

Make Call

client.calls.create({
  to: '+19999999999', // Call this number
  from: '+18888888888', // From a valid SignalWire number
  url: 'https://example.com/laml/voice.xml' // Valid LaML
}).then(call => {
  process.stdout.write('Call ID: ' + call.sid)
}).catch(error => {
  // Inspecting error...
})

Send Message

client.messages.create({
  body: 'Welcome to SignalWire!',
  to: '+19999999999', // Text this number
  from: '+18888888888' // From a valid SignalWire number
}).then(message => {
  process.stdout.write('Message ID: ' + message.sid)
}).catch(error => {
  // Inspecting error...
})

Generating LaML

const RestClient = require('signalwire').RestClient
const response = new RestClient.LaML.VoiceResponse()
response.dial({ callerId: '+18888888888' }, '+19999999999')
response.say("Welcome to SignalWire!")
process.stdout.write(response.toString())

LaML output:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Dial callerId="+18888888888">+19999999999</Dial>
  <Say>Welcome to SignalWire!</Say>
</Response>

Migration

Do you want to start using SignalWire in your current application? You can easily migrate the code with minimal changes!

Make sure you've set the env variable SIGNALWIRE_API_HOSTNAME as described in Usage and then:

To use the Rest client:

// Replace these lines:
const twilio = require('twilio')
const client = new twilio(sid, token)
 
// With ...
const signalwire = require('signalwire')
const client = new signalwire.RestClient(project, token)
 
// Now use client variable like you did before!

For calls and messages you should also change the from numbers with a valid SignalWire number!

To generate LaML:

// Replace these lines..
const twilio = require('twilio')
const response = new twilio.twiml.VoiceResponse()
 
// With ..
const signalwire = require('signalwire')
const response = new signalwire.RestClient.LaML.VoiceResponse()
 
// Now use response like you did before!
response.say('Hey, Welcome at SignalWire!')

Running tests in Docker

A Dockerfile is provided for testing purposes. Run docker run -it $(docker build -q .) to execute the test suite.

Copyright

Copyright (c) 2018 SignalWire Inc. See LICENSE for further details.

Readme

Keywords

Package Sidebar

Install

npm i signalwire

Weekly Downloads

50

Version

1.0.4

License

MIT

Unpacked Size

24.5 kB

Total Files

19

Last publish

Collaborators

  • bryanrite
  • jpsantosbhz
  • iammaransari
  • littorwired
  • startledmarmot