clockwork

Mediaburst Clockwork API wrapper

npm install clockwork
54 downloads in the last day
280 downloads in the last week
908 downloads in the last month

node-clockwork

Install

npm install clockwork

Simple Usage

var clockwork = require('clockwork')({key:'your clockwork key here'});


// Send a message
clockwork.sendSms({ To: '447123456789', Content: 'Test!'}, function(error, resp) {
    if (error) {
        console.log('Something went wrong', error);
    } else {
        console.log('Message sent',resp.responses[0].id);
    }
});

Sending A Message

You can send a single message as shown above. If you have multiple messages to send, it's much more efficient to send them in bulk by passing an array of messages to sendSms:

clockwork.sendSms([{ To: '447123456789', Content: 'Test!'},
                   { To: '447123456781', Content: 'Another one', From: 'ClockworkSMS'}], function(error, resp) {
    if (error) {
        console.log('Something went wrong', error);
    } else {
        console.log('Messages sent');
    }
});

The second argument to sendSms is callback that you provide. The callback will be called with 2 json objects, error and response. If a general error occurs, then error will look like this:

{
    success: false,
    errNo: X,
    errDesc: 'Error description here'
}

Otherwise, error will be null, and the response will contain an array of sms responses, one for each message sent. In the example above where 2 messages were sent, assuming nothing went wrong, the response will look like this:

{
    responses: [
        {to: '447123456789', success: true, id: 'MessageId', errNo: '', ErrDesc: ''},
        {to: '447123456781', success: true, id: 'MessageId', errNo: '', ErrDesc: ''}
    ]    
}

Currently, the nodejs wrapper only supports setting the to, from and content of sms messages. If you need to set other options, raise an issue in github and we'll try to get it done for you. For more information about sending messages and the responses, see the clockwork sms api documentation

Getting Your Balance

clockwork.getBalance(function(error, credit) {
    if (error) {
        console.log('Something went wrong', error);
    } else {
        console.log('Your balance',resp);
    }
});

Again, if a general error occurs then error will be populated accordingly. Otherwise, the response contains your credit, in a format similar to this:

{
    accountType: 'PAYG',
    currency: {code: 'USD', symbol: '$'},
    balance: '100.0'
}
npm loves you