Giter Club home page Giter Club logo

bbox's Introduction

bbox

Build Status Go Report Card

Bbox is a Go library for Kannel SMS Gateway Box protocol (Based on Kannel 1.4.4)

Create your own "Custom BOX" for send, receive SMS and handle DLR easily with Kannel Bearerbox .

Install

go get github.com/foril/bbox

Sample Box

The following example can be found in samples.

Connect to the Bearerbox

bb = &bbox.Bearerbox{Addr: "XXX.XXX.XXX.XX:13001", BoxID: "SMSBOX-ID"}
err := bb.Connect()

if err != nil {
  panic(fmt.Sprint(err))
}

// Maintain persistent connection
for {
  msg, err := bb.Read()
  
  ....
 }
...

Receiving messages from the Bearerbox

// Reading all incoming messages
for {
  msg, err := bb.Read()

  if err != nil {
    panic(fmt.Sprint(err))
  }

  // Check received message type from Bearerbox
  switch m := msg.(type) {

  // Is admin message ?
  case *bbox.Admin:
    // Do stuff

  // Is acknowledgment message ?
  case *bbox.Ack:
    // Do stuff

  // Is a short message ?
  case *bbox.Sms:
    // Do stuff
  }
}

Sending SMS to the Bearerbox

sms := &bbox.Sms{
  Sms_type: bbox.Mt_push,
  Sender:   bbox.OCTSTR("GOPHER"),
  Receiver: bbox.OCTSTR("123456789"),
  Msgdata:  bbox.OCTSTR("Mesage sent from Go to Kannel bearerbox"),
  Time:     bbox.INTEGER(time.Now().Unix()),
  Smsc_id:  bbox.OCTSTR("SMPPSim"), // My smsc-id
  Id:       bbox.UUID(uid), // You can use an extrenal library for generate UUID
  Coding:   bbox.Coding_7BIT,
  Dlr_mask: bbox.INTEGER(31),
  Validity: bbox.INTEGER(time.Now().Unix() + (60 * 5)), // Validity 5 minutes
  Dlr_url:  bbox.OCTSTR("My DB ID : " + uid), // Tip - put your own message ID, you'll can then use this ID to update your DB on receipt of the DLR.
}

// Send message
bb.Write(sms)

Filter DLR / MO on messages received from the Bearerbox

// Check short message type *bbox.Sms.Sms_type
switch sms.Sms_type {

// Mo received
case bbox.Mo:

  fmt.Println("#MO received#")
  // Do stuff

  // Write Ack response
  bb.Write(&bbox.Ack{bbox.Success, sms.Time, sms.Id})

// DLR received => dlr-mask on sent message
case bbox.Report_mo:

  fmt.Println("#DLR received#")
  // Do stuff

  // Write Ack response
  bb.Write(&bbox.Ack{bbox.Success, sms.Time, sms.Id})
}

You have built an custom box contributions welcome

Feel free to contribute.

bbox's People

Contributors

foril avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ik5

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.