@cmpsr/signalwire
v2.0.29
Published
[![npm version](https://img.shields.io/npm/v/@cmpsr/signalwire.svg?style=flat-square)](https://www.npmjs.com/package/@cmpsr/signalwire)
Downloads
609
Readme
@cmpsr/signalwire
Wrapper over Signalwire API
Features
- Send sms using the Signalwire API
Installing
Using npm:
$ npm install @cmpsr/signalwire
Using yarn:
$ yarn add @cmpsr/signalwire
Examples
CommonJS usage
const { useSignalwireSms } = require("@cmpsr/signalwire");
ES usage
import { useSignalwireSms } from "@cmpsr/signalwire";
Sending a sms
with ExpressJS
const express = require("express");
const { useSignalwireSms } = require("@cmpsr/signalwire");
const app = express();
app.use(express.json());
const signalwireSms = useSignalwireSms();
app.post("/send-sms", async (req, res) => {
const { message, from, to } = req.body;
const response = await signalwireSms.send(message, from, to);
res.json(response);
});
API
useSignalwireSms([, project[, token[, contexts]]])
const project = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const contexts = ["1", "2"];
const useSignalwireSms = useSignalwireSms(project, token, contexts);
NOTE
If you don't pass the optional parameters it will take those values from your environment variables, so you may want to create a .env
file or set global variables into your OS.
# in your .env file
SIGNALWIRE_PROJECT = ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SIGNALWIRE_TOKEN = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SIGNALWIRE_CONTEXTS = 1,2
Now, load your variables using the dotenv
package
require("dotenv").config();
const { useSignalwireSms } = require("@cmpsr/signalwire");
const signalwireSms = useSignalwireSms();
SMS Instance methods
The available instance methods are listed below.