Giter Site home page Giter Site logo

node-gitter's Introduction

node-gitter Gitter chat

Node.js client for the Gitter API. For more info visit: Gitter Developers website.

If you have any questions, click on the badge to join the conversation.

Installation

$ npm install --save node-gitter

Basics

var Gitter = require('node-gitter');

var gitter = new Gitter(token);

gitter.currentUser()
.then(function(user) {
  console.log('You are logged in as:', user.username);
});

Authentication

It's mandatory to provide a valid Gitter OAuth token in order to use the client. You can obtain one from https://developer.gitter.im/apps.

Promises or Callbacks

The client implements both. The following code is equivalent:

Using promises:

gitter.rooms.join('gitterhq/sandbox')
.then(function(room) {
  console.log('Joined room: ', room.name);
})
.fail(function(err) {
  console.log('Not possible to join the room: ', err);
})

Using node-style callbacks:

gitter.rooms.join('gitterhq/sandbox', function(err, room) {
  if (err) {
    console.log('Not possible to join the room: ', err);
    return;
  }

  console.log('Joined room: ', room.name);
});

Users

Current user

gitter.currentUser()

Current user rooms, repos, orgs and channels

gitter.currentUser()
.then(function(user) {
  user.rooms()
  user.repos()
  user.orgs()
  user.channels()
})

Find a user

gitter.users.find(userId)

Rooms

Join a room

gitter.rooms.join('gitterhq/sandbox')

Post a message to a room

gitter.rooms.join('gitterhq/sandbox')
.then(function(room) {
  room.send('Hello world!');
});

Listen for chatMessages, Events or Users in a room

gitter.rooms.find(roomId).then(function(room) {

  var events = room.streaming().chatMessages();

  // The 'snapshot' event is emitted once, with the last messages in the room
  events.on('snapshot', function(snapshot) {
    console.log(snapshot.length + ' messages in the snapshot');
  });

  // The 'chatMessages' event is emitted on each new message
  events.on('chatMessages', function(message) {
    console.log('A message was ' + message.operation);
    console.log('Text: ', message.model.text);
  });
});

Listen for messages in a room

gitter.rooms.join('gitterhq/sandbox').then(function(room) {
  var events = room.listen();

  events.on('message', function(message) {
    console.log('New message:', message.text);
  });
});

Room users, channels and messages

gitter.rooms.find(roomId)
.then(function(room) {
  room.users()
  room.channels()
  room.chatMessages()
});

Leave a room

gitter.rooms.find(roomId)
.then(function(room) {
  room.leave()
});

License

BSD

node-gitter's People

Contributors

suprememoocow avatar malditogeek avatar trevorah avatar huafu avatar kcjpop avatar

Watchers

James Cloos avatar  avatar

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.