africaistalking
v1.0.7
Published
A promise-based API wrapper with cors enabled for africastalking
Downloads
13
Readme
africaistalking
A promise-based API wrapper with cors enabled for africastalking
Install
npm i africaistalking --save
usage
Sending SMS
import africaistalking from 'africaistalking'
const username='MyAppUsername'
const message='Hello You!'
const to='+254711XXXYYY,+254733YYYZZZ'
const apikey='MyAppApiKey'
const from="MyCompany" //optional parameter,check africastalking.com for documentation on how to use
africaistalking(username, message, to, apikey)
.then(res => console.log(res))
.catch(err => console.log(err))
Usage with Redux/redux-promise-middleware
Dispatch africaistalking API as the value of the payload property of the action.
import africaistalking from 'africaistalking'
const sendMessage = (username, message, to, apikey) => ({
type: 'SEND_MESSAGE',
payload: africaistalking(username, message, to, apikey)
})
A pending action is immediately dispatched.
{
type: 'SEND_MESSAGE_PENDING'
}
Once the promise is settled, a second action will be dispatched. If the promise is resolved a fulfilled action is dispatched.
{
type: 'SEND_MESSAGE_FULFILLED'
payload: {
...
}
}
On the other hand, if the promise is rejected, a rejected action is dispatched.
{
type: 'SEND_MESSAGE_REJECTED'
error: true,
payload: {
...
}
}