cjoudrey / wobot

A plugin-based HipChat bot written in Node.js.
https://github.com/cjoudrey/wobot/blob/master/README.md
MIT License
116 stars 48 forks source link

wobot

A plugin-based HipChat bot written in Node.js.

Installation

The easiest way to obtain Wobot is through npm:

npm install wobot

Keep in mind this module depends on node-xmpp which cannot be built without:

Your First Bot

Instantiate the wobot.Bot class by passing it a hash containing:

var wobot = require('wobot');

var bot = new wobot.Bot({
  jid: '????_????@chat.hipchat.com/bot',
  password: '??????'
});

bot.connect();

Events

The following events can be binded to:

onConnect(callback)

Emitted whenever the bot connects to the server.

onMessage(condition, callback)

Emitted whenever a message is sent to a channel the bot is in.

condition can also be omitted i.e. onMessage(callback).

onPrivateMessage(condition, callback)

Emitted whenever a message is sent privately to the bot.

condition can also be omitted i.e. onPrivateMessage(callback).

onInvite(callback)

Emitted whenever invited to a room.

onPing(callback)

Emitted everytime the bot pings the server (roughly every 30 seconds.)

onError(callback)

Emitted whenever an error occurs. disconnect will be emitted afterwards.

onDisconnect(callback)

Emitted whenever the bot disconnects from the server.

Public API

Instances of wobot.Bot have the following methods:

join(roomJid, historyStanzas)

Join a channel.

part(roomJid)

Part a channel.

message(targetJid, message)

Send a message to either a channel or a user.

getRoster(callback)

Fetches the roster (buddy list).

Example return value for roster:

[
  { name: 'Christian Joudrey', jid: '1111_12345@chat.hipchat.com', mention_name: 'ChristianJoudrey' },
  { name: 'The Bot', jid: '1111_12346@chat.hipchat.com', mention_name: 'TheBot' }
]

getRooms(callback)

Fetches the rooms available to the bot user. This is equivalent to what would show up in the HipChat lobby.

connect()

Connect to the server.

disconnect()

Disconnect from the server.

loadPlugin(identifier, plugin, options)

Load a plugin.

sendIq(stanza, callback)

Sends an IQ stanza and stores a callback to be called when its response is received.

Legal stuff

Copyright (c) 2011 Christian Joudrey. See LICENSE for details.

Node.js is an official trademark of Joyent. This module is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.