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.
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
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.
pause
- integer as string, representing how many seconds to pause before sending back an echo. Can be zero for no delay.
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
Currently there is only one type of receiver http
, which will POST the incoming msg to the URL provided on incoming messages.
url
- string, the URL to POST to with new messages
All interactions with Junebug are through HTTP endpoints.
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"
}
}
}
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"
}
}
}
]
}
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
}
}
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"
}
}
}
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"
}
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"
}