Note: This library is still in development! Some features may be missing/not in a working state. While this library is functional, use with caution.
What is ChatExchangeJS?
ChatExchangeJS is a Node.js wrapper library for the Stack Exchange chats. It allows you to interact with the chat from your code, allowing the creation of bots and the like.
Features:
- Message API: Easily send, receive, edit and delete chat messages.
- Event API: React to any event type; From stars to notifications.
- Actions API: Do anything a user can do. Star messages, register for events, and much more.
- Browser: Send requests to the Stack Exchange site as a logged in user.
Don't want to use Node.js? There are ChatExchange libraries for Python and .NET 4.5.
Installation
Installing ChatExchangeJS, like most Node.js modules, couldn't be easier:
npm install chatexchangejs
Or yarn
, if you're hip:
yarn add chatexchangejs
You can also download the zip, or clone it from github.
Using ChatExchangeJS
ChatExchangeJS is built to be simple to use. Because Node.js requests are async, there is extensive usage of Promises.
var Client = require("chatexchangejs");
//Enter the bot users creds here
var user = {email:"myemail", password: "mypassword", roomID:133210};
function Room(room) {
room.on("message", msg => {
console.log("New Message!", msg.content);
});
}
//Create new client for site
var me = new Client("stackoverflow.com");
//Login to site with username and password
me.login(user.email, user.password).then(session => session.join(user.roomID).then(Room));
Further examples, as well as documentation, will be available in the future, as the beta progresses.