npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chatexchangejs

v1.0.0

Published

A Node.js wrapper for the Stack Exchange chat system

Downloads

5

Readme

ChatExchangeJS

This project is still in the beta stage, and may be unstable. Use with caution.

A Node.js wrapper for the Stack Exchange chat system, allowing the ability to interact with the chat.

This library is still missing some major features, especially when it comes to error reporting. You may run into situations where the library simply doesn't work, and the errors outputted aren't that useful. These should be fixed in the upcoming weeks.

###Features:

  • Message API, allowing to send and receive messages
  • Chat event listener, so you can listen for any event from the chat room

###Installation Install from NPM:

npm install chatexchangejs

###Usage:

var Client = require("chatexchangejs");

//Enter the bot users creds here
var user = {email:"myemail", password: "mypassword"};

//Function called when joining a room
function Room(room) {

	console.log("Joined room " + room.id + "!")

	//Add event listener to this room
	room.on("message", msg => {

		//NOTE: The objects that an even listener returns _will_ change in the future, use with caution!

		console.log("Received message:", msg.content);

		var command = msg.content.split(" ");

		console.log(command)

		switch(command.shift()){
			case "!edit":
				room.editMessage(command.shift(), command.join(" "));
				break;
			case "!delete":
				room.deleteMessage(command.join(" "));
				break;

			case "!help":

				//Send message to room
				room.sendMessage("I'm a happy little chatbot :D");
				break;
			case "!ping":

				//Send message to room and ping user that sent the `!ping` message
				room.sendMessage("@" + msg.user_name.replace(" ", "") + " ping!");
				break;
			case "!reply":

				msg.reply("here's a reply!")
				break;
		}
	});

	//Send welcome message when user enters room
	room.on("userEntered", data => {
		room.sendMessage("@" + data.user_name.replace(" ", "") + " welcome to my chatroom!");
	});

	//Send goodbye message when user leaves
	room.on("userLeft", data => {
		room.sendMessage(data.user_name.replace(" ", "") + " left :'(");
	});
}

//This is the user session. All actions that require the user to be logged in should be done in here.
function Session(me) {

	console.log("Logged in to " + me.host + " as " + me.user + "(ID #" + me.id + ")!")

	//Join room, then run room function
	me.join(133210).then(Room);
}

//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);

A demo can be seen in demo.js.

To run the demo, create a user.json file in the project dir, and add the bot username and password to it.

Then, just run node demo.

Your chat bot is now running in the ChatExchangeJS Beta room on stackoverflow.

Don't leave the demo file running! It's for demo purposes only, and gives anyone the ability to edit or delete your bot's messages!