Skip to content

josjevv/khabar

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc Build Status Coverage Status Gitter

Khabar

Notifications engine.

It means

the latest information; news.

google it

Table of contents

Concept and idea

How does it work?

Development

$ go get github.com/codegangsta/gin
$ go get github.com/tools/godep
  • gin is used to to automatically compile files while you are developing
  • godep is used to manage dependencies

Then run

$ mkdir -p $GOPATH/src/github.com/bulletind
$ cd $GOPATH/src/github.com/bulletind
$ git clone https://github.com/bulletind/khabar.git # or your fork
$ cd khabar
$ DEBUG=* go get && go install && gin -p 8911 -i # or make dev

Now you should be able to access the below API's on port 8911.

MongoDB config is stored in config/conf.go.

After you make the changes (if you import any new deps), don't forget to run

$ godep save ./... # or make godep

Sanity checks

$ make vet    # https://godoc.org/golang.org/x/tools/cmd/vet
$ make lint   # https://github.com/golang/lint
$ make test

Usage

$ go get github.com/bulletind/khabar
$ khabar

API

  1. Preferences

  2. List all preferences of user or org
```
GET /topics
```

Query params:

- `org`: organization id
- `user`: user id

If org and user are not sent in query params, then it will send global preferences.

If org is sent and user is not, then it will send org preferences.

If org and user are both sent, then it will send user preferences.

Response:
```js
[
  {
    "_id": "",
    "created_on": 1425547531188,
    "updated_on": 1425879125700,
    "user": "",
    "org": "",
    "app_name": "",
    "channels": [
      "",
      ""
    ],
    "ident": ""
  }
]
```
  1. Set an user preference
```
POST /topics/:ident/channels/:channel
```

Query params:

- `org`: (required) organization id
- `user`: (required) user id
  1. Unset an user preference
```
DELETE /topics/:ident/channels/:channel
```

Query params:

- `org`: (required) organization id
- `user`: (required) user id
  1. Set an org preference
```
POST /topics/:type/:ident/channels/:channel
```

`:type` here is either `defaults` or `locked`

Query params:

- `org`: (required) organization id
  1. Unset an org preference
```
DELETE /topics/:type/:ident/channels/:channel
```

`:type` here is either `defaults` or `locked`

Query params:

- `org`: (required) organization id
  1. Notifications

  2. List all notifications
```
GET /notifications
```

Query params:

- `user`: user id
- `org`: organization id

Response:
```js
[
  {
    org: "",
    user: "",
    destination_uri: "",
    text: "",
    topic: "",
    destination_uri: "",
    is_read:false,
    created_on: <milliseconds_since_epoch>
   },
   // and so on...
]
```

This can be polled periodically
  1. Mark a single notification as read
```
PUT /notification/:_id
```

Request Body:
```json
{
  "destination_uri": "http://link-to-entity",
  "text": "Notification text",
  "topic": "Notification topic"
}
```

- `destination_uri`: (required) Link to relevant entity. (i.e action, incident)
- `text`: (required) Notification text (long text)
- `topic`: (required) Notification topic (short text)
  1. Mark all unread notifications as read
```
PUT /notifications
```

Request Body:
```json
{
  "org": "123",
  "user": "456"
}
```

- `org`: (required) org id
- `user`: (required) user id
- `app_name`: (optional) name of the app or category
  1. Get notification stats
```
GET /notifications/stats
```

Query params:

- `user`: (required) user id
- `org`: (required) organization id

Response:
```
{
  "last_seen": "2015-08-03T14:26:05.860Z",
  "total_count": 37,
  "unread_count": 0,
  "total_unread": 32
}
```
  1. Update last seen time stamp
```
PUT /notifications/stats
```

Query params:

- `user`: (required) user id
- `org`: (required) organization id
  1. Send notification
```
POST /notifications?topic=text
```

Request Body:
```js
{
  "created_by" : "5486e02870a0d30200bdcfd3",
  "org" : "5486d3d986ba633a207682b6",
  "app_name" : "myapp", // <- this is the category
  "topic" : "log_incoming",
  "user" : "5486e02870a0d30200bdcfe0",
  "destination_uri" : "http://...",
  "context" : {
    "Organization" : "5486d3d986ba633a207682b6",
    "sender" : "org name",
    "fullname" : "John hopkins",
    "logger" : "Elvis",
    "refnumber" : "IL2958",
    "Collection" : "collection_name",
    "Id" : "554caa744aca430a00de5324",
    "User" : "5486e02870a0d30200bdcfe0",
    "destination_uri" : "http://...",
    "email" : "john.hopkins@email",
    "severity" : "low",
    "subject" : "New log"
  },
  "entity" : "554caa744aca430a00de5324"
}
```

Query params:

- `topic`: Text that is used for sending notification (short text)

Some general conventions:

  • For all of the above request you must pass atleast one of the org or user or both

  • For all the listings, you get a status code of 200

  • When you create a resource you get a status code of 201

  • When you modify/delete a resource you get a status code of 204

  • Response for creation of an entity

    {
      "body": "[ID of entity created]",
      "message": "Created",
      "status": 201
    }
  • Response for modifying/deleting an entity

    {
      "body": "",
      "message": "NoContent",
      "status": 204
    }

Environment variables

We use environment variables to fetch the keys and secrets.

Push notifications

We use parse to send push notifications. When you are sending out a notification using the POST /notifications api call, it looks for certain environment variables. These env variables are based on the categories (app_names) you are using in the topics_available collection.

For example: You have an event (ident) log_incoming configured for the category (app_name) myapp in the topics_available collection. Now, when you make a call to POST /notifications, it looks for PARSE_myapp_API_KEY and PARSE_myapp_APP_ID enviroment variables and uses them to send the push notifications.

You can set them by doing

$ export PARSE_myapp_API_KEY=***
$ export PARSE_myapp_APP_ID=***

Email notifications

You can configure the email notifications by setting the following env variables

$ export SMTP_HOSTNAME=***
$ export SMTP_USERNAME=***
$ export SMTP_PASSWORD=***
$ export SMTP_PORT=***
$ export SMTP_FROM=***

About

Notifications engine

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.4%
  • Makefile 0.6%