Giter VIP home page Giter VIP logo

hipchatter's Introduction

HipChatter

Node.js wrapper for the HipChat API (v2)

See the full HipChat API v2 Documentation at https://www.hipchat.com/docs/apiv2

You can generate an API token by going to https://hipchat.com/account/api. You must have admin access.

Source is available at http://github.com/charltoons/hipchatter.git. Pull requests welcome!

Note: This is a work-in-progress, and will improve over time.

NPM

How to Install

In your project folder:

    npm install hipchatter --save

In your project's js file:

    var Hipchatter = require('hipchatter');
    var hipchatter = new Hipchatter(your_auth_token [, hipchat_api_root]);

    // this will list all of your rooms
    hipchatter.rooms(function(err, rooms){
        if(!err) console.log(rooms)
    });

Usage

    hipchatter.<endpoint>(params, callback(err, response){
        console.log(response);
    });
  • <endpoint> is the hipchatter function you are using.
  • params are the parameter required by the function
  • err error object if there is an error, null otherwise
  • response the direct response from the HipChat API (JSON)

Documentation

hipchatter.capabilities

Returns the capabilities descriptor for HipChat.

Parameters: None

Results:

  • err, error object if the request failed, null otherwise
  • capabilities, an object containing the capabilities of the HipChat API

Usage

hipchatter.capabilities(function(err, capabilities){
    console.log(capabilities);
});

hipchatter.rooms

Returns all of the rooms you have access to.

Parameters: None

Results: err, array of rooms

Usage

hipchatter.rooms(function(err, rooms){
    console.log(rooms);
});

hipchatter.get_room

Returns the details of a single room.

Parameters: room (string) - the room name or id

Results:

  • err, array of rooms
  • room_details, an object of the rooms details

hipchatter.create_room

Creates a new room.

Parameters:

  • params (object) - Required. Options for the new room.
    • 'guest_access': <bool> - Optional. Whether or not to enable guest access for this room. Defaults to false.
    • 'name': <string> - Required. Name of the room
    • 'owner_user_id': <string> - User ID or email address of the room's owner.
    • 'privacy': <string> - Whether the room is available for access by other users or not. (public or private)

Results:

  • err, array of rooms
  • room_details, an object of the rooms details

Usage

hipchatter.create_room({name: 'Such Room'}, function(err, room){
    console.log(room);
});

hipchatter.delete_room

Delete a room.

Parameters:

  • room_name (string) - Required. The name of the new room.

Results:

  • err

Usage

hipchatter.delete_room('Such Room', function(err){
    if(!err) console.log('"Such Room" successfully deleted.');
});

hipchatter.history

The history of one room.

Parameters: room (string) — the room name or id

Results: err, history (object) — the history object, the messages are in history.items (array)

Usage

hipchatter.history('Hipchatter Room', function(err, history){
    // print the last message
    console.log(history.items[history.items.length-1].message);
});

hipchatter.users

Returns all of the users.

Parameters:

  • param (object) - Optional. query string parameters (optional)
    • 'start-index': <int> - Optional. The start index for the result set. Defaults to 0.
    • 'max-results': <int> - Optional. The maximum number of results. Defaults to 100.
    • 'include-guests': <boolean> - Optional. Include active guest users in response. Otherwise, no guest users will be included. Defaults to 'false'.
    • 'include-deleted': <boolean> - Optional. Include deleted users in response. Defaults to'false'.

Results: err, response (array: list of users)

Usage

// default: returns array of all emoticons
hipchatter.users(function(err, users){
    console.log(users);
});

hipchatter.emoticons({'start-index': 20, 'max-results': 40}, function(err, users){
   console.log(users);
});

hipchatter.emoticons

Returns up to 100 emoticons.

HipChat API reference

Parameters:

  • param (object) - Optional. query string parameters (optional)
    • 'start-index': <int> - Optional. The start index for the result set. Defaults to 0.
    • 'max-results': <int> - Optional. The maximum number of results. Defaults to 100.
    • 'type': <string> - Optional. The type of emoticons to get. Defaults to 'all'.
  • param (int) - Optional. id for single emoticon.
  • param (string) - Optional. shortcut for single emoticon.

Results: err, response (array: list of emoticons) (object: single emoticon)

Usage

// default: returns array of all emoticons
hipchatter.emoticons(function(err, emoticons){
    console.log(emoticons);
});

hipchatter.emoticons({'start-index': 20, 'max-results': 40, 'type': 'group'}, function(err, emoticons){
   console.log(emoticons); 
});

hipchatter.emoticons(34, function(err, emoticon){
    console.log(emoticon);
});

hipchatter.emoticons('fonzie', function(err, emoticon){
    console.log(emoticon);
});

hipchatter.get_emoticon

Get an emoticon by id or shortcut.

HipChat API reference

Parameters:

  • param (int) - Required. id for single emoticon. or
  • param (string) - Required. shortcut for single emoticon.

Results: err, response (object) - single emoticon details

Usage

hipchatter.get_emoticon(34, function(err, emoticon){
    console.log(emoticon);
});

hipchatter.get_emoticon('fonzie', function(err, emoticon){
    console.log(emoticon);
});
}

hipchatter.notify

Send a room notification.

Parameters:

  • room (string) — the room name or id
  • options (object)
    • message (string) - Required. Message to be sent
    • token (string) - Required. The Room notification auth token. You can generate one by going to HipChat.com > Rooms tab > Click the room you want > Select Tokens [BETA] on the left-hand side > generate a new token
    • color (string) - yellow (default), red, green, purple, gray, random
    • message_format - html (default), text
    • notify (boolean) - false (default), true

Results: err

Usage

hipchatter.notify('Hipchatter Room', 
    {
        message: 'Hello World',
        color: 'green',
        token: '<room notification token>'
    }, function(err){
        if (err == null) console.log('Successfully notified the room.');
});

hipchatter.create_webhook

Create a webhook for HipChat to ping when a certain event happens in a room.

Parameters:

  • room (string) — the room name or id
  • options (object)
    • url - for HipChat to ping
    • pattern - regex to match message against
    • event - the event to listen for.
      • Valid values: room_message, room_notification, room_exit, room_enter, room_topic_change
    • name - name for this webhook

Results: err

Usage

hipchatter.create_webhook('Hipchatter Room', 
    {
        url: 'http://yourdomain.com',
        event: 'room_message'
    }, function(err, webhook){
        if (err == null) console.log('Successfully created webhook id:'+webhook.id+'.');
});

hipchatter.get_webhook

Get the details of a specific webhook.

Parameters:

  • room (string) — the room name or id
  • webhook_id (string) - the id for the webhook that was returned from create_webhook

Results: err, webhook_info

Usage

hipchatter.get_webhook('Hipchatter Room', '12345', function(err, hook){
        console.log(hook);
});

hipchatter.webhooks

Get all webhooks for a room.

Parameters: room (string) — the room name or id

Results: err, webhooks (array)

Usage

hipchatter.webhooks('Hipchatter Room', function(err, hooks){
    console.log(hooks);
});

hipchatter.delete_webhook

Remove a webhook.

Parameters:

  • room (string) - the room name or id
  • webhook_id (string) - the id for the webhook that was returned from create_webhook

Results: err

Usage

hipchatter.delete_webhook('Hipchatter Room', '12345', function(err){
        if (err == null) console.log('Webhook sucessfully deleted');
});

hipchatter.delete_all_webhooks

A convenience function to delete all webhooks associated with a room.

Parameters: room (string) - the room name or id

Results: err

Usage

hipchatter.delete_all_webhooks('Hipchatter Room', function(err){
    if (err == null) console.log('All webhooks sucessfully deleted');
});

hipchatter.set_topic

Set the topic of a room.

Parameters:

  • room (string) - Required. The room name or id.
  • topic (string) - Required. The topic that this room will be set to.

Results: err

Usage

hipchatter.set_topic('Hipchatter Room', 'We Are All Talking About This', function(err){
    if (err == null) console.log('New Topic Set');
});

TODO

  • [] Get all tests to pass
  • [] Migrate docs to the wiki
  • [] Error events for things like rate limits
  • [] Addon helpers
  • [] Add support for expand (https://www.hipchat.com/docs/apiv2/expansion)
  • [] Get the tests to check if the required stubs exist before running

How to Test

  • Clone this repo
  • Copy /test/settings.example.json to /test/settings.json
  • Fill out your creds and strip comments from the JSON
  • npm install
  • grunt stub which creates the test room and test user
  • npm test

hipchatter's People

Contributors

brianhubbell avatar charltoons avatar dbreese avatar ozten avatar phgrey avatar pilotnyc avatar reiz avatar shotat avatar terinjokes avatar thepont avatar tresni avatar wrexroad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hipchatter's Issues

HipChat status api endpoint?

Hello!

Can't wait to try out the v2 api!

Would it be possible to include a method for pulling down the current system status reported on http://status.hipchat.com/ ?

We have a vendor/dependency dashboard that shows statuses of API states (Github, PagerDuty, RubyGems, etc..) and would love to see a current status for the HipChat API since we depend on it for lots of notifications.

Thank you!
Chris

Add emoticons

Hello! I would like to add emoticons to this project. I've forked it and started working on an emoticons function that I wanted to run by you.

hipchatter.emoticons(params, callback);

When retrieving a specific emoticon

hipchatter.emoticons(34, function(err, results){} );

or

hipchatter.emoticons('fonzie', function(err, results){} );

When retrieving all emoticons
You could pass in an optional object that will set the query string parameters. Below is an object with the default query string params.

hipchatter.emoticons({start_index: 0, max_results: 100, type: 'all'}, function(err, results){} );

Or you could just leave it blank to get all emoticons with the default params (meaning the first 100).

hipchatter.emoticons(function(err, results){} );

However...

Elsewhere in the API, you use different functions to retrieve an array of objects vs. that specific object, like hipchatter.webhooks() vs. hipchatter.get_webhook()`. So instead, this could be:

hipchatter.emoticons(params, callback); // params optional
hipchatter.get_emoticon(id, callback); // id required

Thoughts on which one makes more sense? Thanks!

Update NPM

There are a few useful changes missing from the published version.

Thanks!

Promise

Would be nice if you had everything return promises.

Invalid OAuth session

Hi,

I am using hipchatter api and trying to hit room list but getting this error

Invalid OAuth session

Please guide me what is wrong with my implementation.

                           var authKey = "5127be0d2b4e119058ade9251ada5b";
            var notifyKey = "83iYDzb1I8U4CZfTtDO058hH08w9zHq8ZRC6wsmh";
            var hipchatter = new Hipchatter(authKey);
            // this will list all of your rooms
            hipchatter.rooms(function(err, rooms) {
                if (!err) {
                    console.log(rooms)
                }else{
                    console.log(err);
                }
            });

Upgrade needle dependency

the version of needle this uses is quite old and causes a problem with pre-node 4.

/Users/blimmer/code/oss/ember-cli-deploy-hipchat/node_modules/hipchatter/node_modules/needle/node_modules/qs/lib/index.js:5
const Stringify = require('./stringify');
^^^^^
Use of const in strict mode.
/Users/blimmer/code/oss/ember-cli-deploy-hipchat/node_modules/hipchatter/node_modules/needle/node_modules/qs/lib/index.js:5
const Stringify = require('./stringify');
^^^^^
SyntaxError: Use of const in strict mode.
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)

I worked around this by pegging qs to a lower version (^5.2.0), but this might cause other folks problems too.

Hipchat Beta API v2 errors with self signed certificate

Hiya. First up thanks for writing this package!

Not sure if you've seen but if you have a self signed root CA hipchatter silently fails with v2 api requests. I turned on debug=true and get an error back from openssl saying [self signed cert in chain]. Not sure if you've encountered the same issue on your hipchat beta instance but I'm 99% this is because atlassian don't allow you to add your own CA's to /usr/share/ca-certificates on the HipChat server.

Maybe until Atlassian deploy a fix is there a way to disable strict checking of the certificates? (at least so I can play around with the hipchat API!)

Can't set proxy.

needle.post(url, payload, {json: true, headers:{'Content-Type': 'application/json; charset=utf-8'}}, requestCallback);

This code is fixing request option, and this library is using needle.
needle is fixing default request option. So user can't use environment argument to set proxy.
Thereby, user can't access hipchat api through proxy.

Update NPM

The latest version on NPM doesn't seem to have the create_user function and others. Can you please update NPM so we can deploy successfully :)

add existing users to room ?

is there a way to add a user to a room ? I wasn't able to find it. is it a limitation of the wrapper or a limitation (by design) of hipchat v2 API ?

regards,

Connect to a room?

Hello,

thanks for this library :-)
Through the doc (and HipChat API doc), I cannot find a way to understand how to join a room/send a message.

I'd like to have a bot which joins a room and can respond to user public messages.

Even through the webhook mechanism I don't see how my user/bot would be part of the list of the room members.

Thanks!

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.