npm.io
0.2.1 • Published 10 years ago

hipbot

Licence
Version
0.2.1
Deps
2
Vulns
0
Weekly
0

HipBot

A library that makes it easy to write bots for HipChat!

HipBot uses the XMPP API to listen to incoming private messages and uses the HipChat REST API v2 to send outgoing private messages.

Source is available at https://bitbucket.org/shamid/hipbot.

Note: This is a work in progress, contributions welcome :)

Installation

In your project folder:

    npm install hipbot --save

Once you create a user to be your bot, you will need to:

  1. Get the bot user's Jabber ID from https://atlassian.hipchat.com/account/xmpp
  2. Create an API token using https://atlassian.hipchat.com/account/api

In your project's JS file create a HipBot:

    var HipBot = require('hipbot');

    var hipBot = new HipBot({
        jabberid: "1234_5678@chat.hipchat.com",
        password: "secret",
        token:    "abc123",
        status:   "How can I help?"
    });

Usage

Basic Mapping
    hipBot.hears('hi').thenSays('hello');
    hipBot.hears('hello').thenSays('hi');
Matching Regular Expressions
    hipBot.hears(/gday .*/).thenSays('gday mate');
Custom Reply Logic
    hipBot.hears(/where is (.*)\?/).then(function(responder, msg, matches) {
        var place = matches[1];
        responder.say(place + ' is in the building');
    });
HTML Replies
    hipBot.hears(/what is (.*)\?/).then(function(responder, msg, matches) {
        var thing = matches[1];
        responder.sayHtml('Google has a few things to say about: <a href="https://www.google.com.au/search?q=' + thing + '">' + thing + '</a>');
    });
Catch All
    hipBot.hears().thenSays("Sorry I'm not smart enough to understand that :(");

Examples in action

You can try out the examples by running examples/basic.js

Here's what the output could look like: