Giter Site home page Giter Site logo

engine's Introduction

Babili Engine Build status

Babili is a real-time chat backend built with Ruby, Rails, Node, Socket.io and Docker.

See https://github.com/Babili/babili for the Getting started guide

The engine is the main service of the API.

Environment variables

Option Default Value Type Required? Description Example
DB_NAME "engine" String Optional "my_db"
DB_HOST "" String Optional "localhost"
DB_USER "postgres" String Optional "localhost"
DB_PORT "5432" String Optional "5432"
DB_PASSWORD "" String Optional "mypwd"
SIDEKIQ_REDIS_URL "" String Required "redis://redis/2"
RABBITMQ_HOST "" String Required "rabbitmq"
RABBITMQ_PORT `` Integer Required 5672
RABBITMQ_USER "" String Required "root"
RABBITMQ_PASSWORD "" String Required "root"
RABBITMQ_EXCHANGE_NAME "" String Required "babili"
RABBITMQ_EXCHANGE_DURABLE "" String Required "true"
SENTRY_DSN "" String Optional "https://.."
API_HOST "" String Optional Comma separated. Added to Rails.configuration.hosts. "babili-engine,api.babili.io"
LOGGER_ENVIRONMENT_NAME "development" String Required  "production"
LOGGER_APPLICATION_NAME "babili-engine" String Optional  "babili"
ENABLE_HSTS "" String Optional Enable the HTTP headers HSTS in the response when enabled  "true"

Rake tasks

List platforms

$ rake platforms:list

Create a new platform

$ rake platforms:create name=<your platform name>

Generate a platform api token (for the /platform scope of the API)

$ rake platforms:generate_api_token name=<your platform name>

Specify the messages digest webhook url (see section Webhooks below)

$ rake platforms:set_messages_webhook url=<your url> name=<your platform name>

Existing api routes:

    GET    /user                                           

    PUT   /user/alive                                      

    GET    /user/rooms                                     
    GET    /user/rooms/:id                                 
    POST   /user/rooms                                     
    PUT    /user/rooms/:id                                 
    DELETE /user/rooms/:id                                 

    GET    /user/rooms/:room_id/messages                   
    POST   /user/rooms/:room_id/messages                   
    DELETE /user/rooms/:room_id/messages/:id               

    POST   /user/rooms/:room_id/memberships                

    PUT    /user/rooms/:room_id/membership                     

    PUT    /user/rooms/:room_id/membership/unread-messages 

    POST   /platform/users/:id/tokens                      
    GET    /platform/users                                 
    POST   /platform/users                                 
    PUT    /platform/users/:id                             
    DELETE /platform/users/:id                             
                  
    GET    /platform/rooms                                 
    GET    /platform/rooms/:id                             
    POST   /platform/rooms                                 
    PUT    /platform/rooms/:id                             
    DELETE /platform/rooms/:id                             

    GET    /platform/rooms/room_id/users                   

    POST   /platform/rooms/:room_id/messages               
    DELETE /platform/rooms/:room_id/messages/:id           

    POST   /platform/rooms/:roomId/users/:userId/membership
    DELETE /platform/rooms/:roomId/users/:userId/membership

    POST   /platform/messages-digests    

Webhooks

Unread messages digests webhook

You can specify a webhook url that babili will call when a user has pending unread messages using:

$ rake platforms:set_messages_webhook url=<your url> name=<your platform name>

An unread message is a message written in a room more thant 30 second ago and in which no other messages have been written since at least 30 seconds. Meaning that you receive one webhook per recipient and per room with all unread messages since the last notification.

Babili will retry the webhook until it receives a 200 OK response code.

The payload you will recieve has the following format:

{
    "type": "unread_messages_digest",
    "id": "2aaf2a45-52ea-460e-856e-ae0a340c6a94",
    "relationships": {
        "recipient": {
            "data": {
                "type": "user",
                "id": "af73c3b5-167e-4aa9-a56d-eaa1ce9ff4af"
            }
        },
        "messages": {
            "data": [
                {
                    "type": "message",
                    "id": "b0fa63cd-c41f-4e19-93e6-8a47bcf70ff7",
                    "attributes": {
                        "content": "Hello world",
                        "contentType": "text",
                        "createdAt": "2017-04-18T14:32:24.661Z"
                    },
                    "relationships": {
                        "room": {
                            "data": {
                                "type": "room",
                                "id": "06455982-1407-44be-8f06-655ef1324638"
                            }
                        },
                        "sender": {
                            "data": {
                                "type": "user",
                                "id": "1e14f98c-72b9-41bf-8468-4e744d2b7c61"
                            }
                        }
                    }
                },
               ...
            ]
        },
        "room": {
            "data": {
                "type": "room",
                "id": "06455982-1407-44be-8f06-655ef1324638",
                "name": null
            }
        }
    }
}

Run tests

$ docker-compose -f docker-compose.test.yml build --pull
$ docker-compose -f docker-compose.test.yml up -d postgres-babili-test
$ sleep 2
$ docker-compose -f docker-compose.test.yml run babili-engine-test rake db:test:prepare
$ docker-compose -f docker-compose.test.yml run babili-engine-test rspec spec

Build and deploy

Since Travis is not supported, builds can be deployed with:

$ docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
$ docker build --pull --build-arg APP_ENV=production -t babili/engine:latest -t babili/engine:`git rev-parse HEAD` . && \
  docker push babili/engine:`git rev-parse HEAD` && \
  docker push babili/engine:latest

Contributors

Babili is the product of the Collaboration of the Spin42 team (http://spin42.com) and the Commuty one (https://www.commuty.net).

engine's People

Contributors

looorent avatar thibaultponcelet avatar loicvigneron avatar gagalago avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

Forkers

gagalago

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.