Giter Club home page Giter Club logo

gojunebug's Introduction

GoJunebug

This is a proof of concept of using golang for an SMPP gateway like Kannel. It doesn't do much of anything yet, it is mostly for me learning Go.

Running

First update junebug.conf to have the appropriate settings. Specifically make sure all the relevant directories exist.

% export GOPATH=`pwd`
% go install github.com/nyaruka/junebug
% ./bin/junebug --settings=junebug.conf
2015/07/19 16:35:25 Starting server on http://localhost:8000
2015/07/19 16:35:25 	POST /connection                      - Add a connection
2015/07/19 16:35:25 	GET  /connection                      - List Connections
2015/07/19 16:35:25 	GET  /connection/[uuid]               - Read Connection Status
2015/07/19 16:35:25 	POST /connection/[uuid]/send          - Send Message
2015/07/19 16:35:25 	GET  /connection/[uuid]/status/[id]   - Get Message Status

Sender Types

Currently there are two types of senders: echo which after a configurable pause, will send the message back, and twitter that will send and receive Twitter DMs.

Echo Config

pause - integer as string, representing how many seconds to pause before sending back an echo. Can be zero for no delay.

Twitter Config

username - string, the username of the user sending and receiving DMs access_token - string, the access token for the user sending and receiving DMs access_token_secret - string, the access token secret for the user sending and receiving DMs

Receiver Types

Currently there is only one type of receiver http, which will POST the incoming msg to the URL provided on incoming messages.

HTTP Config

url - string, the URL to POST to with new messages

Endpoints

All interactions with Junebug are through HTTP endpoints.

Creating Connection

PUT /connection
{
  "senders": {
    "type": "echo",
    "count": 5,
    "config": {
      "pause": "1"
    }
  },
  "receivers": {
    "receiver_type": "http",
    "count": 5,
    "config": {
      "url": "http://myhost.com/receive"
    }
  }
}

You will receive a response containing the connection created, and its UUID:

{
  "uuid": "3958bba4-8eae-43b8-b30c-534db207b279",
  "Senders": {
    "type": "echo",
    "count": 5,
    "config": {
      "pause": "1"
    }
  },
  "Receivers": {
    "type": "http",
    "count": 5,
    "config": {
      "url": "http://myhost.com/receive"
    }
  }
}

Listing Connections

GET /connection

You will receive a list of the active connections:

{
  "connections": [
    {
      "uuid": "3958bba4-8eae-43b8-b30c-534db207b279",
      "senders": {
        "type": "echo",
        "count": 5,
        "config": {
          "pause": "1"
        }
      },
      "receivers": {
        "type": "http",
        "count": 5,
        "config": {
          "url": "http://myhost.com/receive"
        }
      }
    }
  ]
}

Getting the status of a connection

GET /connection/[connection_uuid]

You will receive the connection configuration as well as its status of queued incoming and outgoing messages:

{
  "connection": {
  "uuid": "3958bba4-8eae-43b8-b30c-534db207b279",
  "Senders": {
    "type": "echo",
    "count": 5,
    "config": {
      "pause": "1"
    }
  },
  "Receivers": {
    "type": "http",
    "count": 5,
    "config": {
      "url": "http://myhost.com/receive"
    }
   }
  },
  "status": {
    "outgoing_queued": 0,
    "incoming_queued": 0,
    "handled_results": 1050,
    "sent_results": 1050
  }
}

Deleting a Connection

DELETE /connection/[connection_uuid]

You will receive a response containing the connection status when it was closed. Note that this call blocks until all workers have stopped sending, so may take a bit of time.

{
  "uuid": "3958bba4-8eae-43b8-b30c-534db207b279",
  "Senders": {
    "type": "echo",
    "count": 5,
    "config": {
      "pause": "1"
    }
  },
  "Receivers": {
    "type": "http",
    "count": 5,
    "config": {
      "url": "http://myhost.com/receive"
    }
  }
}

Sending a message

PUT /connection/[connection_uuid]/send
{
  "text": "Hello World",
  "address": "+250788383383",
  "priority": "H"
}

You can pick either H (high) or L (low) as a priority. All high priority messages will be sent before any low priority messages.

You will receive the message created and its UUID:

{
  "id": 2047,
  "conn_uuid": "54b7647b-924d-4ba0-b248-1145b96aefc9",
  "address": "+250788383383",
  "text": "Hello World",
  "priority": "H",
  "status": "Q",
  "log": "",
  "created": "2015-07-21T12:53:02.670865736-04:00",
  "finished": "0001-01-01T00:00:00Z"
}

Checking the status of a message

GET /connection/[connection_uuid]/status/[id]

You will receive the message content, its current status, when we finished handling it as well as any log set by the sender or receiver.

{
  "id": 2047,
  "conn_uuid": "a0b46933-aab8-4907-bee6-db6db8057bec",
  "address": "+250788383383",
  "text": "Hello world",
  "priority": "H",
  "status": "S",
  "log": "XXXX YYYY ZZZZ AAAA This is a log.\\\nXXXX YYYY ZZZZ BBBB It is fake.",
  "created": "2015-07-21T13:08:36.214434765-04:00",
  "finished": "2015-07-21T13:11:08.88047792-04:00"
}

gojunebug's People

Contributors

nicpottier avatar ericnewcomer avatar rowanseymour avatar

Stargazers

Geofrey Ernest avatar  avatar

Watchers

 avatar  avatar  avatar James Cloos avatar Norbert Kwizera avatar  avatar

Forkers

digideskio

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.