1.0.0 • Published 6 years ago

intercom-for-hapi v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

Intercom for Hapi Build Status

A Hapi plugin for quickly accessing the Intercom for Node client.

Installation

npm install intercom-for-hapi --save

yarn add intercom-for-hapi --save

Getting Started

The purpose of this plugin is simply to allow you to instantiate the Intercom client once and then make it accessible to your entire Hapi application.

Example

var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({ host: 'localhost' });

var options = {
    token: '123sds88'   // REQUIRED
};

// Register the plugin
server.register({
    register: require('intercom-for-hapi'),
    options: options
}, function (err) {

    if (err) {
        console.error(err);
    }
    else {
        server.start(function () {

            console.info('Server started at ' + server.info.uri);
        });
    }
});

// Declare a route that uses it
server.route( {
    'method': 'GET',
    'path': '/users',
    'handler': usersHandler
});

function usersHandler (request, reply) {

    var client = request.intercom;     // also available via request.server.app.intercom

    client.users.list(function (res) {
      return reply(res);
    });
};

server.start(function() {

    console.log("Server started at " + server.info.uri);
});