[Node.js] rbxwebhook.js - simple node and Roblox event communication

About

rbxwebhook.js is a fork and maintained version of @Reselim and her roblox-long-polling npm module. It allows you to communicate using events similar to BindableEvents. You are able to send events to your server and receive events. You also have the capabilities to send out events to all servers similar to MessagingService

How does it work?

This uses a long-polling (better explained by @Seranok in his blog post). It basically sends a request to your server and waits for a response instead of sending back a response immediately. It will send a request and wait 60 seconds for a response, if it does not get one within that time-frame it will abort the request and send another request right after it and do the exact same thing.

What are the Pros and Cons?

Pros
  • Client and Server communication
  • Simplistic
  • Built into express to easily import to an already existing project.
Cons
  • High in HTTP request budget
  • Not great error handling

What is planned?

We have a few things planned in the future to ensure security and speed.

  • Allow for @grilme99’s rocheck to be built right into the connection. (read more about it here)
  • Better error handling.

Drawbacks for rocheck

  • You need to create an maintain the account cookie to check
  • There will not be any cookie refreshing (you will need to do that yourself, more about it here)
  • Your place needs to be multiplayer (meaning more than 1 player able to join).

Example

View Example

Server

Main Script
// MainScript
var express = require("express")

var app = express();

app.use('/rbxwebhook', require(../PATH/TO/ROUTER/FILE))

app.get('/', (req, res) => {
  res.send("Howdy")
});


app.listen(3000);
Router File
var longPolling = require("rbxwebhook.js");
var server = new longPolling();

server.on("connection", (conn) => {
	console.log(`New connection (id: ${conn.id})`);

	conn.on("ping", (message) => {
		console.log(`echo: ${message}`);
		conn.send("pong", message);
	});

	conn.on("broadcast", (message) => {
		console.log(`broadcast: ${message}`);
		server.broadcast("broadcast", message);
	});

	conn.on("disconnect", () => {
		console.log(`${conn.id} disconnected`);
	});
});

module.exports = server.router;

Client

local Connection = require(script.Connection)
local client = Connection.new()

client:connect("127.0.0.1:8080")

client:on("pong", function(message)
	print("echoed from server: ", message)
end)

client:send("ping", "Hello world!")

game:BindToClose(function()
	client:disconnect()
end)

I want to use it!

Great! Thanks for thinking about using rbxwebhook.js. Below is the link to the npm package.

To install it just run this in your terminal!

$ npm i -save rbxwebhook.js
23 Likes

This is an awesome project! I really hope to see RoCheck and an API key system implemented in the near future. I’ll definitely consider using this.

2 Likes

Thanks a lot! I’ll implement the API key system later today.

1 Like

Version 0.8.0

I’ve released version 0.8.0 of the npm module. There are a few changes that you need to understand with this update.

NOTICE

Version 0.8.0 has changed the client.lua file meaning that you will need to change the module that you’re using for connecting to the API.

What’s new?

  • Added API keys for added protection.
  • Changed the module to fit the new API needed.

How does the protection work?

When you connect using the :connect() function in the module it will send an api request including your API key in the header. If it is correct it will successfully authenticate the request a return a unique uuid key that the module will use to authenticate requests without the apiKey.

How do I use it?

It’s very simple to add your apiKey to your project

Example

Server

Change this

const rbxwebhook = require("rbxwebhook.js");
const server = new rbxwebhook();

to this

const rbxwebhook = require("rbxwebhook.js");
const server = new rbxwebhook({apiKey: "YOURKEYHERE"});

Client

Change this

local rbxwebhook = require(game:GetService("ServerScriptService"):WaitForChild("rbxwebhook"));
local client = rbxwebhook.new();

to this

local rbxwebhook = require(game:GetService("ServerScriptService"):WaitForChild("rbxwebhook"));
local client = rbxwebhook.new( { apiKey = "YOURKEYHERE" } );

Conclusion

If you have any questions DM me on here or reply.

2 Likes

Notice

I have noticed that there are debugging console.logs still in the server.js code. I will be fixing that up in version 0.8.1 which should come out very soon. Sorry for that problem.

Update

  1. A fix has been made and is currently being tested for stability for publishing, we don’t suggest using the current version until 0.8.1 is released.
  2. Stability testing has concluded and version 0.8.1 is being pushed.
  3. Update has been pushed read more about it here
1 Like

Version 0.8.1

What’s new?

  • Removed debugging console.log’s from server.js
  • Removed repr debugging from client.lua
  • Added some error handling.

What should I update?

You don’t need to update to 0.8.1 if you don’t want to as nothing besides the console.log was removed but you should update your client.lua code for more stability in error handling.

2 Likes

Do you have a github repo? As, I might PR rocheck support.

3 Likes
1 Like

This is quite interesting and amazing. I’ve been looking at an easier way to make actions from Discord to ROBLOX and I’ve struggled, one of the things I wanted to do is be able to kick people and ban from Discord, thanks so much for this.

1 Like

Where would all the different scripts be placed, or does it not matter?

What do you mean by scripts? Are you taking about the npm module itself or the client module?

I am taking about the module itself.

There are two separate modules, there’s the npm module which is used for your Node.JS server and then the client module Which is what you place in a module script. There is no exact place where you need to put that module because it’s all up to how you want to develop but, considering it uses HTTPService and the Client doesn’t have access to that service I would suggest putting it in ServerScriptService.

Okay thank you very much for answering my question.

1 Like