2.0.1 • Published 6 years ago

mobizon.js v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Mobizon.js

npm Codeship npm version

Simple API wrapper for Mobizon sms gateway with zero dependencies.

Installation

$ npm i --save mobizon.js

API

new Mobizon(domain, apiKey, options)

  • domain {string} API domain.
  • apiKey {string} API key.
  • options {object}
    • version {string} API version. Defaults to v1.
    • output {string} The format of the response returned by the service. Defaults to json.
    • timeout {number} The number of milliseconds to wait for a server to respond before aborting the request. Defaults to 60000.
    • verifySsl {boolean} if true requires SSL certificate be valid. Defaults to true.

mobizon.call(module, method, payload)

  • module {string} API module.
  • method {string} Method of API module.
  • payload {object} Optional parameters specified for method.

Example

This example demonstrates sending and tracking sms service with help of zeromq messaging

const zmq = require('zmq');
const Mobizon = require('mobizon.js');

const responder = zmq.socket('rep');
const mobizon = new Mobizon('api.mobizon.tld', 'KKKKKKKKKKKKKKKKK');

responder.on('message', async (payload) => {
  const {action, data} = JSON.parse(payload);

  switch(action) {
    case 'send': {
      try {
        const {recipient, text} = data;
        const {code, data} = await mobizon.call('Message', 'SendSmsMessage', {recipient, text}).then(JSON.parse);
        if (code === 0) {
          responder.send(data.messageId);
        }
      } catch (err) {
        // todo: handle err
      }
      break;
    }
    case 'track': {
      try {
        const {messageId} = data;
        const {code, data} = await mobizon.call('Message', 'GetSMSStatus', {ids: messageId}).then(JSON.parse);
        if (code === 0) {
          responder.send(data[0].status);
        }
      } catch (err) {
        // todo: handle err
      }
      break;
    }
  }
});

responder.bind('tcp://*:5555');

License

MIT

2.0.1

6 years ago

2.0.0

6 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.1.0

8 years ago