Bryan Grohman

All Writing

HipChat Room History Exporter

2019-01-28

We've used HipChat for instant messaging, group chat, and various automated notifications at work for years now. On February 15th, HipChat is shutting down as part of a partnership with Slack.

HipChat does provide an export feature, but it's limited to group administrators and does not let you choose which rooms to export. I have a few rooms with history I want to preserve, so I wrote a small Node.js script to export the message history (just the messages, no attachments) for a single room at a time. The script uses a personal access token, so you can export any room your user has access to.

Setup

You'll need a personal access token and the room ID to use the script:

  1. Create a personal access token by navigating to your HipChat site at /account/api (e.g. https://hipchat.com/account/api). Your token must have the "View Messages" scope.
  2. Find the room ID for the room you want to export by navigating to your HipChat site at /rooms, searching for the room by name, and clicking on the room name. The "API ID" field listed in the "Room Details" section is the room ID.
  3. Create a HIPCHAT_AUTH_TOKEN environment variable with your personal access token.
  4. Create a HIPCHAT_ROOM_ID environment variable with your room ID. Alternatively, you can pass the room ID to the script as the first argument.

Usage

Make sure you have Node.js installed, and run the script with the following command:

node export.js [hipchat_room_id]

The script retrieves messages in groups of 1000 and logs the current iteration and message count to the console as it executes. When all of the message history has been retrieved, it will be written to the history.json file in the current directory.

If you prefer plain text instead of JSON, you can use the convertToPlainText.js script to convert the JSON history file into plain text:

node convertToPlainText.js <json-history-file-path> <output-text-file-path>

You can find the source code hosted on GitHub.