Giter VIP home page Giter VIP logo

node-goip's Introduction

This package allow to send and receive SMS messages using GSM / VOIP Goip1, Goip4, Goip8, Goip16 gateways from Hybertone / Dbltek company. SMS can be received via the UDP protocol. The SMS can be sent via UDP or HTTP. Additionally, it is possible to receive basic information about the state and status of individual GSM gates (lines).

Installation

npm install goip

Server usage instruction

To start receiving messages from Goip gateways you need to create and start a server.

Example 1

const {ServerFactory, HttpSms, SocketSms} = require('goip');

const server = ServerFactory.make(333);

server.onAll( (message) => {
    console.log(message);
});

server.run();

Example 2

const {ServerFactory, MessageDispatcher, MessageFactory} = require('goip');

const server = ServerFactory.make(333, {
    'address': '0.0.0.0', // server address
    'messageDispatcher': new MessageDispatcher(), // Message Dispatcher implementation
    'messageFactory': new MessageFactory() // Message Factory implementation
});

server.onAll( (message) => {
    console.log(message);
});

server.run();

Register message listener

const {ServerFactory} = require('goip');

const server = ServerFactory.make(333);

// All messages
server.onAll( (message) => {
    console.log(message);
});

// Goip not supported message
server.onNotSupported( (message) => {
    console.log(message);
});

// Keep Alive packets with gateway (line) information
server.onRequest( (message) => {
    console.log(message);
});

// Incoming SMS
server.onReceive( (message) => {
    console.log(message);
});

// SMS delivery report
server.onDeliver( (message) => {
    console.log(message);
});

// End telephone call
server.onHangup( (message) => {
    console.log(message);
});

// Start a phone call
server.onRecord( (message) => {
    console.log(message);
});

// Change of gate (line) status
server.onState( (message) => {
    console.log(message);
});

// Socket server error message
server.onServerError( (message) => {
    console.log(message);
});

server.run();

Sending a message

Sending via UDP socket

Example 1 - sending one message and close the connection
const {SocketSms} = require('goip');

const sms = new SocketSms(
	'192.168.0.11', // Goip address
	9991, // Goip port
	'goip_password' // Goip password
);

sms.sendOne('999999999','test sms message').then( response => {
    console.log(response);
}).catch(error => {
    console.log(error);
});
Example 2 - sending many messages
const {SocketSms} = require('goip');

const sms = new SocketSms(
	'192.168.0.11', // Goip address
	9991, // Goip port
	'goip_password' // Goip password
);

( async () => {

    try {

        const response1 = await sms.send('999999999','test sms message 1');
        const response2 = await sms.send('999999999','test sms message 2');

        console.log(response1);
        console.log(response2);

    } catch (error) {

        console.log(error);

    }

    sms.close();
})();

Sending via HTTP

Example 1 - sending one message
const {HttpSms} = require('goip');

const sms = new HttpSms(
    'http://192.168.0.11', // Goip http address
    1, // Line number
    'login', // Goip login
    'password', // Goip password
    {
		'waitForStatus': false, // Wait and check sending status
		'waitTries': 10, // Number of attempts
		'waitTime': 1000 // Time in  milliseconds
	});

sms.send('999999999', 'test message').then((response) => {
    console.log(response);
}).catch((error) => {
    console.log(error);
});
Example 2 - sending many messages
const {HttpSms} = require('goip');

const sms = new HttpSms('http://192.168.0.11',1,'login','password',{
    'waitForStatus': true
});

(async () => {

    try {
        const response1 = await sms.send('999999999','test sms message 1');
        const response2 = await sms.send('999999999','test sms message 2');
        console.log(response1);
        console.log(response2);
    } catch (error) {
        console.log(error);
    }

})();
Example 3 - checking status by id
const {HttpSms} = require('goip');
const sms = new HttpSms(
    'http://192.168.0.11', // Goip http address
    1, // Line number
    'login', // Goip login
    'password', // Goip password
);

( async () => {

    try {
        const response = await sms.send('999999999', 'test message');

        console.log(response);

        setTimeout(async () => {
            const isSend = await sms.isSend( response.id );

            if( isSend ) {
                console.log('sms sent')
            }
        
            if( !isSend ) {
                console.log('sms not sent')
            }

        }, 5000);

    } catch (error) {
        console.log(error);
    }

})();

node-goip's People

Contributors

styryl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.