Skip to content

qeesung/rocketchat-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript RocketChat API for node.js

Join the chat at https://gitter.im/rocketchat-node/Lobby Build Status Codacy Badge dependencies Status

A node.js module, which provides an object oriented wrapper for the RocketChat REST API.

RocketChat official website address can be found here . RocketChat REST API document can be found here.

The Version of this library is in sync with the rocket.chat release. A version of 0.57 means this release was tested against the official docker image of rocket.chat:0.57.

getting started

npm install rocketchat
var RocketChatApi = require('rocketchat').RocketChatApi;
// OR
var RocketChatClient = require('rocketchat').RocketChatClient;

This Lib library package the following functions:

RocketChatApi

Installation

Install with the node package manager npm:

$ npm install rocketchat

or

Install via git clone:

$ git clone https://github.com/qeesung/rocketchat-node.git
$ cd rocketchat-node
$ npm install

Examples

Create the rocket-chat client

// rocketchat api wrapper
var RocketChatApi = require('rocketchat').RocketChatApi;
// alpha-api versions
var rocketChatApi = new RocketChatApi('http', config.host, config.port, config.user, config.password);
// v1-api versions
var rocketChatApi = new RocketChatApi('http', config.host, config.port, config.user, config.password, "v1");

// direct access to new api
var RocketChatClient = require('rocketchat').RocketChatClient;

Obtaining the running rocket-chat version

rocketChatApi.version(function(err,body){
	if(err)
		console.log(err);
	else
		console.log(body);
})

Login rocket-chat

rocketChatApi.login(function(err,body){
	if(err)
		console.log(err);
	else
		console.log(body);
})

You don't have to log in every time, and automatically log on when you call the other interface.

Logoff rocket-chat

rocketChatApi.logout(function(err,body){
	if(err)
		console.log(err);
	else
		console.log(body);
})

Get list of public rooms

rocketChatApi.getPublicRooms(function(err,body){
	if(err)
		console.log(err);
	else
		console.log(body);
})

Join a room

rocketChatApi.joinRoom(roomID ,function(err,body){
	if(err)
		console.log(err);
	else
		console.log(body);
})

Leave a room

rocketChatApi.leaveRoom(roomID ,function(err,body){
	if(err)
		console.log(err);
	else
		console.log(body);
})

Create a room

rocketChatApi.createRoom(roomName ,function(err,body){
	if(err)
		console.log(err);
	else
		console.log(body);
})

Set a rooms topic

rocketChatApi.setTopic(roomID, topicName, function(err, body){
    if(err)
         console.log(err);
    else
        console.log(body);
})

Get all unread messages in a room

rocketChatApi.getUnreadMsg(roomID ,function(err,body){
	if(err)
		console.log(err);
	else
		console.log(body);
})

Sending a message

rocketChatApi.sendMsg(roomID, message, function(err,body){
	if(err)
		console.log(err);
	else
		console.log(body);
})

More information can be found by checking RocektChat REST API

new api

Miscellaneous

Info

A simple method, requires no authentication, that returns information about the server including version information.

this.rocketChatClient.miscellaneous.info(function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/miscellaneous/info)

{
  "success": true,
  "info": {
    "version": "0.47.0-develop",
    "build": {
      "nodeVersion": "v4.6.2",
      "arch": "x64",
      "platform": "linux",
      "cpus": 4
    },
    "commit": {
      "hash": "5901cc7270e3587101631ee222def950d705c611",
      "date": "Thu Dec 1 19:08:01 2016 -0200",
      "author": "Gabriel Engel",
      "subject": "Merge branch 'develop' into experimental",
      "tag": "0.46.0",
      "branch": "experimental"
    }
  }
}

Authentication

The authentication with the API is a process that is handled for you automatically when you create a new instance of the client.

var rocketChatApi = new RocketChatApi('https', 'my-rocket.chat', 443, 'admin', 'password', function () {
    // both rest api and realtime api are succesfully authenticated, given user and password are correct
});

You can, however, use the provided methods to switch user, or - i.e. if you don't have the credentials at startup time - you can choose a late authentication.

Note that the api methods here will only authenticate the Web Api, not the realtime websocket api. For authenticating the realtime api, please Check here.

login

this.rocketChatClient.authentication.login(username, password, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/authentication/login)

{
  "status": "success",
  "data": {
      "authToken": "9HqLlyZOugoStsXCUfD_0YdwnNnunAJF8V47U3QHXSq",
      "userId": "aobEdbYhXfu5hkeqG"
   }
}

logout

this.rocketChatClient.authentication.logout(function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/authentication/logout)

{
  "status": "success",
  "data": {
      "authToken": "9HqLlyZOugoStsXCUfD_0YdwnNnunAJF8V47U3QHXSq",
      "userId": "aobEdbYhXfu5hkeqG"
   }
}

me

Quick information about the authenticated user.

this.rocketChatClient.authentication.me(function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/authentication/me)

{
  "_id": "aobEdbYhXfu5hkeqG",
  "name": "Example User",
  "emails": [
    {
      "address": "example@example.com",
      "verified": true
    }
  ],
  "status": "offline",
  "statusConnection": "offline",
  "username": "example",
  "utcOffset": 0,
  "active": true,
  "success": true
}

Users

create

NOTE Due to a funny behavior of rocket.chat not responding to this call, the result is evaluated with a workaround and will always take minimum 500ms!

var userToAdd = {
    "name": "name",
    "email": "email@example.com",
    "password": "anypassyouwant",
    "username": "uniqueusername",
    "sendWelcomeEmail": false,
    "joinDefaultChannels": false,
    "verified":false,
    "requirePasswordChange":false,
    "roles":["user"]
};
this.rocketChatClient.users.create(userToAdd, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/users/create)

{
   "user": {
      "_id": "BsNr28znDkG8aeo7W",
      "createdAt": "2016-09-13T14:57:56.037Z",
      "services": {
         "password": {
            "bcrypt": "$2a$10$5I5nUzqNEs8jKhi7BFS55uFYRf5TE4ErSUH8HymMNAbpMAvsOcl2C"
         }
      },
      "username": "uniqueusername",
      "emails": [
         {
            "address": "email@user.tld",
            "verified": false
         }
      ],
      "type": "user",
      "status": "offline",
      "active": true,
      "roles": [
         "user"
      ],
      "_updatedAt": "2016-09-13T14:57:56.175Z",
      "name": "name",
      "customFields": {
         "twitter": "@userstwitter"
      }
   },
   "success": true
}

delete

this.rocketChatClient.users.delete(userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/users/delete)

{
  "success": true
}

getPresence

this.rocketChatClient.users.getPresence(userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/users/getpresence)

{
  "presence": "offline",
  "success": true
}

info

this.rocketChatClient.users.info({userId: userId}, function (err, body) {});
//or
this.rocketChatClient.users.info({username: username}, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/users/info)

{
  "user": {
    "_id": "nSYqWzZ4GsKTX4dyK",
    "type": "user",
    "status": "offline",
    "active": true,
    "name": "Example User",
    "utcOffset": 0,
    "username": "example"
  },
  "success": true
}

list

this.rocketChatClient.users.list(offset, count, function (err, body) {});
this.rocketChatClient.users.list(function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/users/list)

{
  "user": [{
    "_id": "nSYqWzZ4GsKTX4dyK",
    "type": "user",
    "status": "offline",
    "active": true,
    "name": "Example User",
    "utcOffset": 0,
    "username": "example"
  }],
  "success": true
}

setAvatar

this.rocketChatClient.users.setAvatar(userId, avatarUrl, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/users/setavatar)

{
    "success": true
}

update

this.rocketChatClient.users.update(userId, updateData, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/users/update)

{
   "user":{
      "_id": "BsNr28znDkG8aeo7W",
      "createdAt": "2016-09-13T14:57:56.037Z",
      "services": {
         "password": {
            "bcrypt": "$2a$10$5I5nUzqNEs8jKhi7BFS55uFYRf5TE4ErSUH8HymMNAbpMAvsOcl2C"
         }
      },
      "username": "uniqueusername",
      "emails": [
         {
            "address": "newemail@user.tld",
            "verified": false
         }
      ],
      "type": "user",
      "status": "offline",
      "active": true,
      "roles": [
         "user"
      ],
      "_updatedAt": "2016-09-13T14:57:56.175Z",
      "name": "new name",
      "customFields": {
         "twitter": "userstwitter"
      }
   },
   "success": true
}

Channels

AddAll

Adds all of the users of the Rocket.Chat server to the channel.

this.rocketChatClient.channels.addAll(roomId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/addall)

{
   "channel": {
      "_id": "ByehQjC44FwMeiLbX",
      "name": "channelname",
      "t": "c",
      "usernames": [
         "example",
         "rocket.cat"
      ],
      "msgs": 0,
      "u": {
         "_id": "aobEdbYhXfu5hkeqG",
         "username": "example"
      },
      "ts": "2016-05-30T13:42:25.304Z"
   },
   "success": true
}

addModerator

Gives the role of moderator for a user in the current channel.

this.rocketChatClient.channels.addModerator(roomId, userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/addmoderator)

{
   "success": true
}

addOwner

Gives the role of owner for a user in the current channel.

this.rocketChatClient.channels.addOwner(roomId, userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/addowner)

{
   "success": true
}
  • archive

archive

Archives a channel.

this.rocketChatClient.channels.archive(roomId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/archive)

{
   "success": true
}
  • cleanHistory

cleanHistory

Cleans up a channel, removing messages from the provided time range.

this.rocketChatClient.channels.cleanHistory(roomId, roomId, latest, oldest, function (err, body) {});
// inclusive default value is false, if you want to change that pass the parameter
this.rocketChatClient.channels.cleanHistory(roomId, roomId, latest, oldest, inclusive, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/cleanhistory)

{
   "success"
}
  • close

close

Removes the channel from the user’s list of channels.

this.rocketChatClient.channels.close(roomId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/close)

{
   "success"
}

create

Creates a new public channel.

this.rocketChatClient.channels.create(roomName, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/create)

{
   "channel": {
      "_id": "ByehQjC44FwMeiLbX",
      "name": "channelname",
      "t": "c",
      "usernames": [
         "example"
      ],
      "msgs": 0,
      "u": {
         "_id": "aobEdbYhXfu5hkeqG",
         "username": "example"
      },
      "ts": "2016-05-30T13:42:25.304Z"
   },
   "success": true
}

getIntegrations

Retrieves the integrations which the channel has, requires the permission manage-integrations. And supports the Offset and Count Query Parameters.

this.rocketChatClient.channels.getIntegrations(roomId, {/** query options */},function (err, body) {});
this.rocketChatClient.channels.getIntegrations(roomId, {0, 5}, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/getintegrations)

{
    "integrations": [{
        "_id": "WMQDChpnYTRmFre9h",
        "enabled": true,
        "username": "rocket.cat",
        "alias": "Guggy",
        "avatar": "http://res.guggy.com/logo_128.png",
        "name": "Guggy",
        "triggerWords": [
            "!guggy",
            "guggy",
            "gif+"
        ],
        "urls": [
            "http://text2gif.guggy.com/guggify"
        ],
        "token": "8DFS89DMKLWEN",
        "script": "/* Some script */",
        "scriptEnabled": true,
        "impersonateUser": false,
        "scriptCompiled": "/* lot of script */",
        "scriptError": null,
        "type": "webhook-outgoing",
        "userId": "rocket.cat",
        "channel": [],
        "_createdAt": "2017-01-05T17:06:05.660Z",
        "_createdBy": {
            "username": "graywolf336",
            "_id": "R4jgcQaQhvvK6K3iY"
        },
        "_updatedAt": "2017-01-05T17:06:05.660Z"
    }],
    "success": true
}

history

Retrieves the messages from a channel. And supports the Offset and Count Query Parameters.

this.rocketChatClient.channels.history(roomId, {/** query option here*/}, function (err, body) {});
this.rocketChatClient.channels.history(roomId, {0, 5}, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/history)

{
  "messages": [
    {
      "_id": "AkzpHAvZpdnuchw2a",
      "rid": "ByehQjC44FwMeiLbX",
      "msg": "hi",
      "ts": "2016-12-09T12:50:51.555Z",
      "u": {
        "_id": "y65tAmHs93aDChMWu",
        "username": "testing"
      },
      "_updatedAt": "2016-12-09T12:50:51.562Z"
    },
    {
      "_id": "vkLMxcctR4MuTxreF",
      "t": "uj",
      "rid": "ByehQjC44FwMeiLbX",
      "ts": "2016-12-08T15:41:37.730Z",
      "msg": "testing2",
      "u": {
        "_id": "bRtgdhzM6PD9F8pSx",
        "username": "testing2"
      },
      "groupable": false,
      "_updatedAt": "2016-12-08T16:03:25.235Z"
    },
    {
      "_id": "bfRW658nEyEBg75rc",
      "t": "uj",
      "rid": "ByehQjC44FwMeiLbX",
      "ts": "2016-12-07T15:47:49.099Z",
      "msg": "testing",
      "u": {
        "_id": "nSYqWzZ4GsKTX4dyK",
        "username": "testing1"
      },
      "groupable": false,
      "_updatedAt": "2016-12-07T15:47:49.099Z"
    },
    {
      "_id": "pbuFiGadhRZTKouhB",
      "t": "uj",
      "rid": "ByehQjC44FwMeiLbX",
      "ts": "2016-12-06T17:57:38.635Z",
      "msg": "testing",
      "u": {
        "_id": "y65tAmHs93aDChMWu",
        "username": "testing"
      },
      "groupable": false,
      "_updatedAt": "2016-12-06T17:57:38.635Z"
    }
  ],
  "success": true
}

info

Retrieves the information about the channel.

this.rocketChatClient.channels.info(roomId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/info)

{
  "channel": {
    "_id": "ByehQjC44FwMeiLbX",
    "ts": "2016-11-30T21:23:04.737Z",
    "t": "c",
    "name": "testing",
    "usernames": [
      "testing",
      "testing1",
      "testing2"
    ],
    "msgs": 1,
    "default": true,
    "_updatedAt": "2016-12-09T12:50:51.575Z",
    "lm": "2016-12-09T12:50:51.555Z"
  },
  "success": true
}

invite

Adds a user to the channel.

this.rocketChatClient.channels.invite(roomId, userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/invite)

{
  "channel": {
    "_id": "ByehQjC44FwMeiLbX",
    "ts": "2016-11-30T21:23:04.737Z",
    "t": "c",
    "name": "testing",
    "usernames": [
      "testing",
      "testing1"
    ],
    "msgs": 1,
    "_updatedAt": "2016-12-09T12:50:51.575Z",
    "lm": "2016-12-09T12:50:51.555Z"
  },
  "success": true
}

kick

Kicks a user from the channel.

this.rocketChatClient.channels.kick(roomId, userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/kick)

{
  "channel": {
    "_id": "ByehQjC44FwMeiLbX",
    "name": "invite-me",
    "t": "c",
    "usernames": [
      "testing1"
    ],
    "msgs": 0,
    "u": {
      "_id": "aobEdbYhXfu5hkeqG",
      "username": "testing1"
    },
    "ts": "2016-12-09T15:08:58.042Z",
    "ro": false,
    "sysMes": true,
    "_updatedAt": "2016-12-09T15:22:40.656Z"
  },
  "success": true
}

leave

Causes the callee to be removed from the channel.

this.rocketChatClient.channels.leave(roomId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/leave)

{
  "channel": {
    "_id": "ByehQjC44FwMeiLbX",
    "name": "invite-me",
    "t": "c",
    "usernames": [
      "testing2"
    ],
    "msgs": 0,
    "u": {
      "_id": "aobEdbYhXfu5hkeqG",
      "username": "testing1"
    },
    "ts": "2016-12-09T15:08:58.042Z",
    "ro": false,
    "sysMes": true,
    "_updatedAt": "2016-12-09T15:22:40.656Z"
  },
  "success": true
}

list.joined

Lists all of the channels the calling user has joined.

// pass a query object to limit the results
this.rocketChatClient.channels.listJoined({}, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/list-joined)

{
    "channels": [
        {
            "_id": "ByehQjC44FwMeiLbX",
            "name": "invite-me",
            "t": "c",
            "usernames": [
                "testing1"
            ],
            "msgs": 0,
            "u": {
                "_id": "aobEdbYhXfu5hkeqG",
                "username": "testing1"
            },
            "ts": "2016-12-09T15:08:58.042Z",
            "ro": false,
            "sysMes": true,
            "_updatedAt": "2016-12-09T15:22:40.656Z"
        }
    ],
    "success": true
}

list

Lists all of the channels on the server, this method supports the Offset and Count Query Parameters.

// get the first items
this.rocketChatClient.channels.list({}, function (err, body) {});
// get by offset and count
// first 5 items
this.rocketChatClient.channels.list({0, 5}, function (err, body) {});
// third page
this.rocketChatClient.channels.list({10, 5}, function (err, body) {});
// find an item using mongo query syntax
this.rocketChatClient.channels.list({ query : { "name": { "$regex": "thisreallydoesnotexist" } } }, function (err, body) {});
// sort using mongo sort syntax
this.rocketChatClient.channels.list({ sort : { "_updatedAt": 1 } }, function (err, body) {});
// fielding using mongo field syntax
this.rocketChatClient.channels.list({ fields : { "name": 1 } }, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/list)

{
    "channels": [
        {
            "_id": "ByehQjC44FwMeiLbX",
            "name": "test-test",
            "t": "c",
            "usernames": [
                "testing1"
            ],
            "msgs": 0,
            "u": {
                "_id": "aobEdbYhXfu5hkeqG",
                "username": "testing1"
            },
            "ts": "2016-12-09T15:08:58.042Z",
            "ro": false,
            "sysMes": true,
            "_updatedAt": "2016-12-09T15:22:40.656Z"
        },
        {
            "_id": "t7qapfhZjANMRAi5w",
            "name": "testing",
            "t": "c",
            "usernames": [
                "testing2"
            ],
            "msgs": 0,
            "u": {
                "_id": "y65tAmHs93aDChMWu",
                "username": "testing2"
            },
            "ts": "2016-12-01T15:08:58.042Z",
            "ro": false,
            "sysMes": true,
            "_updatedAt": "2016-12-09T15:22:40.656Z"
        }
    ],
    "success": true
}

open

Adds the channel back to the user’s list of channels.

this.rocketChatClient.channels.open(roomId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/open)

{
  "success": true
}

removeModerator

Removes the role of moderator from a user in the currrent channel.

this.rocketChatClient.channels.removeModerator(roomId, userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/removemoderator)

{
  "success": true
}

removeOwner

Removes the role of owner from a user in the currrent channel.

this.rocketChatClient.channels.removeOwner(roomId, userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/removeowner)

{
  "success": true
}

rename

Changes the name of the channel.

this.rocketChatClient.channels.rename(roomId, newName, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/rename)

{
  "channel": {
    "_id": "ByehQjC44FwMeiLbX",
    "name": "new-name",
    "t": "c",
    "usernames": [
      "testing1"
    ],
    "msgs": 4,
    "u": {
      "_id": "aobEdbYhXfu5hkeqG",
      "username": "testing1"
    },
    "ts": "2016-12-09T15:08:58.042Z",
    "ro": false,
    "sysMes": true,
    "_updatedAt": "2016-12-09T15:57:44.686Z"
  },
  "success": true
}

setDescription

Sets the description for the channel.

this.rocketChatClient.channels.setDescription(roomId, description, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/setdescription)

{
  "description": "Testing out everything.",
  "success": true
}

setJoinCode

Sets the code required to join the channel.

this.rocketChatClient.channels.setJoinCode(roomId, joinCode, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/setjoincode)

{
    "channel": {
        "_id": "ByehQjC44FwMeiLbX",
        "name": "testing0",
        "t": "c",
        "msgs": 0,
        "u": {
            "_id": "aiPqNoGkjpNDiRx6d",
            "username": "goose160"
        },
        "ts": "2017-01-05T18:02:50.754Z",
        "ro": false,
        "sysMes": true,
        "_updatedAt": "2017-01-05T18:41:48.840Z",
        "usernames": [
            "goose160",
            "graywolf336"
        ],
        "joinCodeRequired": true
    },
    "success": true
}

setPurpose

Sets the purpose/description for the channel.

this.rocketChatClient.channels.setPurpose(roomId, purpose, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/setpurpose)

{
  "purpose": "Testing out everything.",
  "success": true
}

setReadOnly

Sets whether the channel is read only or not.

this.rocketChatClient.channels.setReadOnly(roomId, readonly, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/setreadonly)

{
    "channel": {
        "_id": "ByehQjC44FwMeiLbX",
        "name": "testing0",
        "t": "c",
        "msgs": 0,
        "u": {
            "_id": "aiPqNoGkjpNDiRx6d",
            "username": "goose160"
        },
        "ts": "2017-01-05T18:02:50.754Z",
        "ro": true,
        "sysMes": true,
        "_updatedAt": "2017-01-05T19:02:24.429Z",
        "usernames": [
            "goose160",
            "graywolf336"
        ],
        "joinCodeRequired": true,
        "muted": []
    },
    "success": true
}

setTopic

Sets the topic for the channel.

this.rocketChatClient.channels.setTopic(roomId, topic, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/settopic)

{
  "topic": "Testing out everything.",
  "success": true
}

unarchive

Unarchives a channel.

this.rocketChatClient.channels.unarchive(roomId, topic, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/channels/unarchive)

{
  "success": true
}

Groups

AddAll

Adds all of the users of the Rocket.Chat server to the group.

this.rocketChatClient.groups.addAll(roomId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/addall)

{
   "group": {
      "_id": "ByehQjC44FwMeiLbX",
      "name": "groupname",
      "t": "c",
      "usernames": [
         "example",
         "rocket.cat"
      ],
      "msgs": 0,
      "u": {
         "_id": "aobEdbYhXfu5hkeqG",
         "username": "example"
      },
      "ts": "2016-05-30T13:42:25.304Z"
   },
   "success": true
}

addModerator

Gives the role of moderator for a user in the current group.

this.rocketChatClient.groups.addModerator(roomId, userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/addmoderator)

{
   "success": true
}

addOwner

Gives the role of owner for a user in the current group.

this.rocketChatClient.groups.addOwner(roomId, userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/addowner)

{
   "success": true
}
  • archive

archive

Archives a private group, only if you’re part of the group.

this.rocketChatClient.groups.archive(roomId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/archive)

{
   "success": true
}
  • close

close

Removes the group from the user’s list of groups.

this.rocketChatClient.groups.close(roomId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/close)

{
   "success" : true
}

create

Creates a new private group, optionally including specified users. The group creator is always included.

this.rocketChatClient.groups.create(roomName, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/create)

{
   "group": {
      "_id": "ByehQjC44FwMeiLbX",
      "name": "groupname",
      "t": "c",
      "usernames": [
         "example"
      ],
      "msgs": 0,
      "u": {
         "_id": "aobEdbYhXfu5hkeqG",
         "username": "example"
      },
      "ts": "2016-05-30T13:42:25.304Z"
   },
   "success": true
}

getIntegrations

Retrieves the integrations which the group has, requires the permission manage-integrations. And supports the Offset and Count Query Parameters.

this.rocketChatClient.groups.getIntegrations(roomId, {/** query options */},function (err, body) {});
this.rocketChatClient.groups.getIntegrations(roomId, {0, 5}, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/getintegrations)

{
    "integrations": [{
        "_id": "WMQDChpnYTRmFre9h",
        "enabled": true,
        "username": "rocket.cat",
        "alias": "Guggy",
        "avatar": "http://res.guggy.com/logo_128.png",
        "name": "Guggy",
        "triggerWords": [
            "!guggy",
            "guggy",
            "gif+"
        ],
        "urls": [
            "http://text2gif.guggy.com/guggify"
        ],
        "token": "8DFS89DMKLWEN",
        "script": "/* Some script */",
        "scriptEnabled": true,
        "impersonateUser": false,
        "scriptCompiled": "/* lot of script */",
        "scriptError": null,
        "type": "webhook-outgoing",
        "userId": "rocket.cat",
        "group": [],
        "_createdAt": "2017-01-05T17:06:05.660Z",
        "_createdBy": {
            "username": "graywolf336",
            "_id": "R4jgcQaQhvvK6K3iY"
        },
        "_updatedAt": "2017-01-05T17:06:05.660Z"
    }],
    "success": true
}

history

Retrieves the messages from a private group, only if you’re part of the group. And supports the Offset and Count Query Parameters.

this.rocketChatClient.groups.history(roomId, {/** query option here*/}, function (err, body) {});
this.rocketChatClient.groups.history(roomId, {0, 5}, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/history)

{
  "messages": [
    {
      "_id": "AkzpHAvZpdnuchw2a",
      "rid": "ByehQjC44FwMeiLbX",
      "msg": "hi",
      "ts": "2016-12-09T12:50:51.555Z",
      "u": {
        "_id": "y65tAmHs93aDChMWu",
        "username": "testing"
      },
      "_updatedAt": "2016-12-09T12:50:51.562Z"
    },
    {
      "_id": "vkLMxcctR4MuTxreF",
      "t": "uj",
      "rid": "ByehQjC44FwMeiLbX",
      "ts": "2016-12-08T15:41:37.730Z",
      "msg": "testing2",
      "u": {
        "_id": "bRtgdhzM6PD9F8pSx",
        "username": "testing2"
      },
      "groupable": false,
      "_updatedAt": "2016-12-08T16:03:25.235Z"
    },
    {
      "_id": "bfRW658nEyEBg75rc",
      "t": "uj",
      "rid": "ByehQjC44FwMeiLbX",
      "ts": "2016-12-07T15:47:49.099Z",
      "msg": "testing",
      "u": {
        "_id": "nSYqWzZ4GsKTX4dyK",
        "username": "testing1"
      },
      "groupable": false,
      "_updatedAt": "2016-12-07T15:47:49.099Z"
    },
    {
      "_id": "pbuFiGadhRZTKouhB",
      "t": "uj",
      "rid": "ByehQjC44FwMeiLbX",
      "ts": "2016-12-06T17:57:38.635Z",
      "msg": "testing",
      "u": {
        "_id": "y65tAmHs93aDChMWu",
        "username": "testing"
      },
      "groupable": false,
      "_updatedAt": "2016-12-06T17:57:38.635Z"
    }
  ],
  "success": true
}

info

Retrieves the information about the private group, only if you’re part of the group.

this.rocketChatClient.groups.info(roomId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/info)

{
  "group": {
    "_id": "ByehQjC44FwMeiLbX",
    "ts": "2016-11-30T21:23:04.737Z",
    "t": "c",
    "name": "testing",
    "usernames": [
      "testing",
      "testing1",
      "testing2"
    ],
    "msgs": 1,
    "default": true,
    "_updatedAt": "2016-12-09T12:50:51.575Z",
    "lm": "2016-12-09T12:50:51.555Z"
  },
  "success": true
}

invite

Adds a user to the private group.

this.rocketChatClient.groups.invite(roomId, userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/invite)

{
  "group": {
    "_id": "ByehQjC44FwMeiLbX",
    "ts": "2016-11-30T21:23:04.737Z",
    "t": "c",
    "name": "testing",
    "usernames": [
      "testing",
      "testing1"
    ],
    "msgs": 1,
    "_updatedAt": "2016-12-09T12:50:51.575Z",
    "lm": "2016-12-09T12:50:51.555Z"
  },
  "success": true
}

kick

Removes a user from the private group.

this.rocketChatClient.groups.kick(roomId, userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/kick)

{
  "group": {
    "_id": "ByehQjC44FwMeiLbX",
    "name": "invite-me",
    "t": "c",
    "usernames": [
      "testing1"
    ],
    "msgs": 0,
    "u": {
      "_id": "aobEdbYhXfu5hkeqG",
      "username": "testing1"
    },
    "ts": "2016-12-09T15:08:58.042Z",
    "ro": false,
    "sysMes": true,
    "_updatedAt": "2016-12-09T15:22:40.656Z"
  },
  "success": true
}

leave

Causes the callee to be removed from the private group, if they’re part of it and are not the last owner.

this.rocketChatClient.groups.leave(roomId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/leave)

{
  "group": {
    "_id": "ByehQjC44FwMeiLbX",
    "name": "invite-me",
    "t": "c",
    "usernames": [
      "testing2"
    ],
    "msgs": 0,
    "u": {
      "_id": "aobEdbYhXfu5hkeqG",
      "username": "testing1"
    },
    "ts": "2016-12-09T15:08:58.042Z",
    "ro": false,
    "sysMes": true,
    "_updatedAt": "2016-12-09T15:22:40.656Z"
  },
  "success": true
}

list

Lists all of the private groups the calling user has joined, this method supports the Offset and Count Query Parameters.

// get the first items
this.rocketChatClient.groups.list({}, function (err, body) {});
// get by offset and count
// first 5 items
this.rocketChatClient.groups.list({0, 5}, function (err, body) {});
// third page
this.rocketChatClient.groups.list({10, 5}, function (err, body) {});
// find an item using mongo query syntax
this.rocketChatClient.groups.list({ query : { "name": { "$regex": "thisreallydoesnotexist" } } }, function (err, body) {});
// sort using mongo sort syntax
this.rocketChatClient.groups.list({ sort : { "_updatedAt": 1 } }, function (err, body) {});
// fielding using mongo field syntax
this.rocketChatClient.groups.list({ fields : { "name": 1 } }, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/list)

{
    "groups": [
        {
            "_id": "ByehQjC44FwMeiLbX",
            "name": "test-test",
            "t": "c",
            "usernames": [
                "testing1"
            ],
            "msgs": 0,
            "u": {
                "_id": "aobEdbYhXfu5hkeqG",
                "username": "testing1"
            },
            "ts": "2016-12-09T15:08:58.042Z",
            "ro": false,
            "sysMes": true,
            "_updatedAt": "2016-12-09T15:22:40.656Z"
        },
        {
            "_id": "t7qapfhZjANMRAi5w",
            "name": "testing",
            "t": "c",
            "usernames": [
                "testing2"
            ],
            "msgs": 0,
            "u": {
                "_id": "y65tAmHs93aDChMWu",
                "username": "testing2"
            },
            "ts": "2016-12-01T15:08:58.042Z",
            "ro": false,
            "sysMes": true,
            "_updatedAt": "2016-12-09T15:22:40.656Z"
        }
    ],
    "success": true
}

open

Adds the private group back to the user’s list of private groups.

this.rocketChatClient.groups.open(roomId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/open)

{
  "success": true
}

removeModerator

Removes the role of moderator from a user in the currrent group.

this.rocketChatClient.groups.removeModerator(roomId, userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/removemoderator)

{
  "success": true
}

removeOwner

Removes the role of owner from a user in the current group.

this.rocketChatClient.groups.removeOwner(roomId, userId, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/removeowner)

{
  "success": true
}

rename

Changes the name of the private group.

this.rocketChatClient.groups.rename(roomId, newName, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/rename)

{
  "group": {
    "_id": "ByehQjC44FwMeiLbX",
    "name": "new-name",
    "t": "c",
    "usernames": [
      "testing1"
    ],
    "msgs": 4,
    "u": {
      "_id": "aobEdbYhXfu5hkeqG",
      "username": "testing1"
    },
    "ts": "2016-12-09T15:08:58.042Z",
    "ro": false,
    "sysMes": true,
    "_updatedAt": "2016-12-09T15:57:44.686Z"
  },
  "success": true
}

setDescription

Sets the description for the private group.

this.rocketChatClient.groups.setDescription(roomId, description, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/setdescription)

{
  "description": "Testing out everything.",
  "success": true
}

setPurpose

Sets the purpose/description for the private group.

this.rocketChatClient.groups.setPurpose(roomId, purpose, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/setpurpose)

{
  "purpose": "Testing out everything.",
  "success": true
}

setReadOnly

Sets whether the group is read only or not.

this.rocketChatClient.groups.setReadOnly(roomId, readonly, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/setreadonly)

{
    "group": {
        "_id": "ByehQjC44FwMeiLbX",
        "name": "testing0",
        "t": "c",
        "msgs": 0,
        "u": {
            "_id": "aiPqNoGkjpNDiRx6d",
            "username": "goose160"
        },
        "ts": "2017-01-05T18:02:50.754Z",
        "ro": true,
        "sysMes": true,
        "_updatedAt": "2017-01-05T19:02:24.429Z",
        "usernames": [
            "goose160",
            "graywolf336"
        ],
        "joinCodeRequired": true,
        "muted": []
    },
    "success": true
}

setTopic

Sets the topic for the private group.

this.rocketChatClient.groups.setTopic(roomId, topic, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/settopic)

{
  "topic": "Testing out everything.",
  "success": true
}

unarchive

Unarchives a private group.

this.rocketChatClient.groups.unarchive(roomId, topic, function (err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/groups/unarchive)

{
  "success": true
}

Im

close

Removes the direct message from the user’s list of direct messages.

this.rocketChatClient.im.close(roomId, function(err, body) {});

Result (https://rocket.chat/docs/developer-guides/rest-api/im/close)

{
   "success": true
}

history

Retrieves the messages from a direct message.

this.rocketchatClient.im.history(historyOpts, callback);

Result(https://rocket.chat/docs/developer-guides/rest-api/im/history)

{
  "messages": [
    {
      "_id": "AkzpHAvZpdnuchw2a",
      "rid": "ByehQjC44FwMeiLbX",
      "msg": "hi",
      "ts": "2016-12-09T12:50:51.555Z",
      "u": {
        "_id": "y65tAmHs93aDChMWu",
        "username": "testing"
      },
      "_updatedAt": "2016-12-09T12:50:51.562Z"
    },
    {
      "_id": "vkLMxcctR4MuTxreF",
      "t": "uj",
      "rid": "ByehQjC44FwMeiLbX",
      "ts": "2016-12-08T15:41:37.730Z",
      "msg": "testing2",
      "u": {
        "_id": "bRtgdhzM6PD9F8pSx",
        "username": "testing2"
      },
      "groupable": false,
      "_updatedAt": "2016-12-08T16:03:25.235Z"
    },
    {
      "_id": "bfRW658nEyEBg75rc",
      "t": "uj",
      "rid": "ByehQjC44FwMeiLbX",
      "ts": "2016-12-07T15:47:49.099Z",
      "msg": "testing",
      "u": {
        "_id": "nSYqWzZ4GsKTX4dyK",
        "username": "testing1"
      },
      "groupable": false,
      "_updatedAt": "2016-12-07T15:47:49.099Z"
    },
    {
      "_id": "pbuFiGadhRZTKouhB",
      "t": "uj",
      "rid": "ByehQjC44FwMeiLbX",
      "ts": "2016-12-06T17:57:38.635Z",
      "msg": "testing",
      "u": {
        "_id": "y65tAmHs93aDChMWu",
        "username": "testing"
      },
      "groupable": false,
      "_updatedAt": "2016-12-06T17:57:38.635Z"
    }
  ],
  "success": true
}

messages.others

Retrieves the messages from any direct message in the server, this method supports the Offset and Count Query Parameters.

this.rocketChatClient.im.messagesOthers(roomId, callback);

Result(https://rocket.chat/docs/developer-guides/rest-api/im/messages-others)

{
  "messages": [
    {
      "_id": "AkzpHAvZpdnuchw2a",
      "rid": "ByehQjC44FwMeiLbX",
      "msg": "hi",
      "ts": "2016-12-09T12:50:51.555Z",
      "u": {
        "_id": "y65tAmHs93aDChMWu",
        "username": "testing"
      },
      "_updatedAt": "2016-12-09T12:50:51.562Z"
    },
    {
      "_id": "vkLMxcctR4MuTxreF",
      "t": "uj",
      "rid": "ByehQjC44FwMeiLbX",
      "ts": "2016-12-08T15:41:37.730Z",
      "msg": "testing2",
      "u": {
        "_id": "bRtgdhzM6PD9F8pSx",
        "username": "testing2"
      },
      "groupable": false,
      "_updatedAt": "2016-12-08T16:03:25.235Z"
    },
    {
      "_id": "bfRW658nEyEBg75rc",
      "t": "uj",
      "rid": "ByehQjC44FwMeiLbX",
      "ts": "2016-12-07T15:47:49.099Z",
      "msg": "testing",
      "u": {
        "_id": "nSYqWzZ4GsKTX4dyK",
        "username": "testing1"
      },
      "groupable": false,
      "_updatedAt": "2016-12-07T15:47:49.099Z"
    },
    {
      "_id": "pbuFiGadhRZTKouhB",
      "t": "uj",
      "rid": "ByehQjC44FwMeiLbX",
      "ts": "2016-12-06T17:57:38.635Z",
      "msg": "testing",
      "u": {
        "_id": "y65tAmHs93aDChMWu",
        "username": "testing"
      },
      "groupable": false,
      "_updatedAt": "2016-12-06T17:57:38.635Z"
    }
  ],
  "success": true
}

listEveryone

Lists all of the direct messages in the server, requires the permission view-room-administration permission and this method supports the Offset and Count Query Parameters.

this.rocketChatClient.im.listEveryone({ offset = 0, count = 0, sort = undefined, fields = undefined, query = undefined}, callback);

Result(https://rocket.chat/docs/developer-guides/rest-api/im/list-everyone)

{
    "ims": [
        {
            "_id": "ByehQjC44FwMeiLbX",
            "name": "test-test",
            "t": "p",
            "usernames": [
                "testing1"
            ],
            "msgs": 0,
            "u": {
                "_id": "aobEdbYhXfu5hkeqG",
                "username": "testing1"
            },
            "ts": "2016-12-09T15:08:58.042Z",
            "ro": false,
            "sysMes": true,
            "_updatedAt": "2016-12-09T15:22:40.656Z"
        },
        {
            "_id": "t7qapfhZjANMRAi5w",
            "name": "testing",
            "t": "p",
            "usernames": [
                "testing2"
            ],
            "msgs": 0,
            "u": {
                "_id": "y65tAmHs93aDChMWu",
                "username": "testing2"
            },
            "ts": "2016-12-01T15:08:58.042Z",
            "ro": false,
            "sysMes": true,
            "_updatedAt": "2016-12-09T15:22:40.656Z"
        }
    ],
    "success": true
}

<a id=>"Im.list" list

Lists all of the direct messages the calling user has joined, this method supports the Offset and Count Query Parameters.

this.rocketChatClient.im.list({ offset = 0, count = 0, sort = undefined, fields = undefined, query = undefined}, callback);

Result(https://rocket.chat/docs/developer-guides/rest-api/im/list)

{
    "ims": [
        {
            "_id": "ByehQjC44FwMeiLbX",
            "name": "test-test",
            "t": "p",
            "usernames": [
                "testing1"
            ],
            "msgs": 0,
            "u": {
                "_id": "aobEdbYhXfu5hkeqG",
                "username": "testing1"
            },
            "ts": "2016-12-09T15:08:58.042Z",
            "ro": false,
            "sysMes": true,
            "_updatedAt": "2016-12-09T15:22:40.656Z"
        },
        {
            "_id": "t7qapfhZjANMRAi5w",
            "name": "testing",
            "t": "p",
            "usernames": [
                "testing2"
            ],
            "msgs": 0,
            "u": {
                "_id": "y65tAmHs93aDChMWu",
                "username": "testing2"
            },
            "ts": "2016-12-01T15:08:58.042Z",
            "ro": false,
            "sysMes": true,
            "_updatedAt": "2016-12-09T15:22:40.656Z"
        }
    ],
    "success": true
}

open

Adds the direct message back to the user’s list of direct messages.

this.rocketChatClient.im.open(roomId, callback);

Result(https://rocket.chat/docs/developer-guides/rest-api/im/open)

{
   "success": true
}

setTopic

Sets the topic for the direct message.

this.rocketChatClient.im.setTopic(roomId, newTopic, callback);

Result(https://rocket.chat/docs/developer-guides/rest-api/im/settopic)

{
  "topic": "Testing out everything.",
  "success": true
}

Chat

delete

this.rocketChatClient.chat.delete({ roomId, msgId }, callback);

Result (https://rocket.chat/docs/developer-guides/rest-api/chat/delete)

{
  "_id": "7aDSXtjMA3KPLxLjt",
  "ts": 1481741940895,
  "success": true
}

postMessage

Post a chat message

this.rocketChatClient.chat.postMessage({ roomId : roomId, text : message }, callback);

The passed object is equivalent to the payload from the documentation.

Result (https://rocket.chat/docs/developer-guides/rest-api/chat/postmessage)

{
  "ts": 1481748965123,
  "channel": "general",
  "message": {
    "alias": "",
    "msg": "This is a test!",
    "parseUrls": true,
    "groupable": false,
    "ts": "2016-12-14T20:56:05.117Z",
    "u": {
      "_id": "y65tAmHs93aDChMWu",
      "username": "graywolf336"
    },
    "rid": "GENERAL",
    "_updatedAt": "2016-12-14T20:56:05.119Z",
    "_id": "jC9chsFddTvsbFQG7"
  },
  "success": true
}

update

this.rocketChatClient.chat.update({ roomId, msgId, text: updatedText }, callback);

Result (https://rocket.chat/docs/developer-guides/rest-api/chat/update)

{
    "message": {
        "_id": "qGdhTGDnhMLJPQYY8",
        "rid": "GENERAL",
        "msg": "gif+ testing update",
        "ts": "2017-01-05T17:06:14.403Z",
        "u": {
            "_id": "R4jgcQaQhvvK6K3iY",
            "username": "graywolf336"
        },
        "_updatedAt": "2017-01-05T19:42:20.433Z",
        "editedAt": "2017-01-05T19:42:20.431Z",
        "editedBy": {
            "_id": "R4jgcQaQhvvK6K3iY",
            "username": "graywolf336"
        }
    },
    "success": true
}

Settings

get

Gets the setting for the provided _id.

this.rocketChatClient.settings.get(_id, callback);

Result(https://rocket.chat/docs/developer-guides/rest-api/settings/get)

{
  "_id": "Livechat_enabled",
  "value": false,
  "success": true
}

update

Updates the setting for the provided _id.

this.rocketChatClient.settings.update(id, value, callback);

Result(https://rocket.chat/docs/developer-guides/rest-api/settings/update)

{
  "success": true
}
'''

### Integration<a id="Integration"></a>

#### <a id="Integration.create"></a>create

Creates an integration, if the callee has the permission.

- event: [see here](https://github.com/RocketChat/Rocket.Chat/blob/develop/packages/rocketchat-integrations/lib/rocketchat.js)
- channel: The channel, group, or @username. Can also be all_public_channels, all_private_groups, or all_direct_messages. Comma separated for more than one.

```js
this.rocketChatClient.integration.create({
            "type": "webhook-outgoing",
            "name": "Testing via REST API",
            "enabled": false,
            "username": "username",
            "urls": ["http://some-url.example.com"],
            "scriptEnabled": false,
            "channel" : "all_public_channels",
            "event" :  "sendMessage"
        }, callback);

Result (https://rocket.chat/docs/developer-guides/rest-api/integration/create)

{
    "integration": {
        "type": "webhook-outgoing",
        "name": "Testing via REST API",
        "enabled": false,
        "username": "rocket.cat",
        "urls": [
            "http://text2gif.guggy.com/guggify"
        ],
        "scriptEnabled": false,
        "userId": "rocket.cat",
        "channel": [],
        "_createdAt": "2017-01-06T13:23:46.018Z",
        "_createdBy": {
            "username": "graywolf336",
            "_id": "aobEdbYhXfu5hkeqG"
        },
        "_updatedAt": "2017-01-06T13:23:46.018Z",
        "_id": "3aazpZ2WzoBP8msi9"
    },
    "success": true
}

list

Lists all of the integrations on the server, this method supports the Offset and Count Query Parameters.

this.rocketChatClient.integration.list({}, callback);

Result (https://rocket.chat/docs/developer-guides/rest-api/integration/list)

{
    "integrations": [
        {
            "_id": "WMQDChpnYTRmFre9h",
            "enabled": true,
            "username": "rocket.cat",
            "alias": "Guggy",
            "avatar": "https://image.crisp.im/avatar/website/17651a90-e082-43f6-b308-957cea6e323c/128",
            "name": "Guggy",
            "triggerWords": [
                "!guggy",
                "guggy",
                "gif+"
            ],
            "urls": [
                "http://text2gif.guggy.com/guggify"
            ],
            "token": "aobEdbYhXfu5hkeqG",
            "script": ...,
            "scriptEnabled": true,
            "impersonateUser": false,
            "scriptCompiled": ...,
            "scriptError": null,
            "type": "webhook-outgoing",
            "userId": "rocket.cat",
            "channel": [],
            "_createdAt": "2017-01-05T17:06:05.660Z",
            "_createdBy": {
                "username": "graywolf336",
                "_id": "R4jgcQaQhvvK6K3iY"
            },
            "_updatedAt": "2017-01-05T17:06:05.660Z"
        },
        {
            "_id": "3aazpZ2WzoBP8msi9",
            "type": "webhook-outgoing",
            "name": "Testing via REST API",
            "enabled": false,
            "username": "rocket.cat",
            "urls": [
                "http://text2gif.guggy.com/guggify"
            ],
            "scriptEnabled": false,
            "userId": "rocket.cat",
            "channel": [],
            "_createdAt": "2017-01-06T13:23:46.018Z",
            "_createdBy": {
                "username": "graywolf336",
                "_id": "R4jgcQaQhvvK6K3iY"
            },
            "_updatedAt": "2017-01-06T13:23:46.018Z"
        }
    ],
    "offset": 0,
    "items": 2,
    "total": 2,
    "success": true
}

remove

Removes an integration from the server.

this.rocketChatClient.integration.remove({
  type,
  integrationId
}, callback);

Result (https://rocket.chat/docs/developer-guides/rest-api/integration/remove)

{
    "integration": {
        "_id": "oNLthAt9RwMw39N2B",
        "type": "webhook-outgoing",
        "name": "Testing via REST API",
        "enabled": false,
        "username": "rocket.cat",
        "urls": [
            "http://text2gif.guggy.com/guggify"
        ],
        "scriptEnabled": false,
        "userId": "rocket.cat",
        "channel": [],
        "_createdAt": "2017-01-06T13:42:14.143Z",
        "_createdBy": {
            "username": "graywolf336",
            "_id": "R4jgcQaQhvvK6K3iY"
        },
        "_updatedAt": "2017-01-06T13:42:14.144Z"
    },
    "success": true
}

Realtime

IMPORTANT! These implementations are based on an unreleased version of the API. Use this at the risk that it may stop working anytime.

The realtime API is composed of two elements: Method Calls and Subscriptions.

Methods allow you to invoke methods (i.e. send message) while subscriptions allow you to subscribe to methods. Not all methods of the realtime api are implemented, so combining those two apis - classic and realtime - should give you all the tools you need to create an interactive application.

Realtime API

Subscriptions

stream-notify-user
notification

Subscribe to notification. A notification seems to be a mention in a channel. The result is only a part of the full message, to get attachments one will have to query for the message afterwards.

this.rocketChatClient.notify.user.onNotification(userId, callback);

Result:

{
    "msg":"changed",
    "collection":"stream-notify-user",
    "id":"id",
    "fields":{
        "eventName":"${userId}/message",
        "args":[
            {
                "title":"@username-sender",
                "text":"message text",
                "payload":{
                    "_id":"id of the payload. might be use to ensure delivered only once?",
                    "rid":"some id, probably userId + smth unique?",
                    "sender":{
                        "_id":"userid of the sender",
                        "username":"username of sender"
                    },
                    "type":"d"
                }
            }
        ]
    }
}
stream-room-messages

Subscribe to new messages in a room.

this.rocketChatClient.notify.room.onChanged(roomId, callback);

Result

{
    "msg":"changed",
    "collection":"stream-room-messages",
    "id":"id",
    "fields":{
        "eventName":"${roomId}"
    }
}

Options

RocketChatApi Options:

  • protocol<string>: Typically 'http:' or 'https:'
  • host<string>: The hostname for your jira server
  • port<int>: The port your jira server is listening on (probably 80 or 443)
  • username<string>: The username to log in with
  • password<string>: Keep it secret, keep it safe

Implemented APIs

  • Authentication
  • HTTP
  • OAuth(comming soon)
  • Room
  • get public rooms
  • join a room
  • leave a room
  • Messages
  • get unread messages from a room
  • send messages to a room
  • Set Topic for Room

TODO

  • achieved OAuth authentication mode
  • Add SSL security mode