The Whispir Node library provides convenient access to the Whispir API from applications written in JavaScript & TypeScript.
You can find the complete documentation of the Whispir API at developers.whispir.com.
Node 12 or higher.
Install the package with:
npm install whispir --save
# or
yarn add whispir
The package needs to be configured with your account's username/password combination and API Key, which can be obtained by following the Obtain an API Key instructions.
const whispirClient = require('whispir')
const whispir = whispirClient({
username: 'username...',
password: 'password...',
apiKey: 'apiKey...',
host: 'https://api.<region>.whispir.com', // e.g. https://api.au.whispir.com
});
whispir.messages.create({
to: '61400400400',
subject: 'My first message',
body: 'Hello from Whispir Node SDK!',
})
.then(message => console.log(message.id))
.catch(error => console.error(error));
Or using ES modules and async
/await
:
import whispirClient from 'whispir';
const whispir = whispirClient({
username: 'username...',
password: 'password...',
apiKey: 'apiKey...',
host: 'https://api.<region>.whispir.com', // e.g. https://api.au.whispir.com
});
(async () => {
const message = await whispir.messages.create({
to: '61400400400',
subject: 'My first message',
body: 'Hello from Whispir Node SDK!',
});
console.log(message.id);
})();
In certain scenarios it can be helpful to intercept the outgoing request and perform querying or mutation on the request object. Both the API Client and each Resource supports configuration for a request inteceptor.
whispir.addInteceptor((request) => {
console.log(request);
})
Or for an individual resource:
whispir.messages.addInteceptor((request) => {
console.log(request);
})
Visit the examples folder for a curated list of examples to help you get started quickly with Whispir.