noblox/noblox.js

[BUG] onMessage() and onNotification() returns an Error

Closed this issue · 6 comments

Before posting a bug, be sure that someone else has not posted it already and it is an actual bug with noblox.js and not other frameworks like discord.js

Describe the bug
When I use the onMessage() or onNotification() event it returns the following error:
Something went wrong: Negotiate Unknown

To Reproduce
Steps to reproduce the behavior:

  1. Add this code:
    const notification = noblox.onNotification()
    notification.on("data", function(data) {
    console.log("New notification! ", data)
    })
    notification.on("error", function(err) {
    console.error("Something went wrong: ", err)
    // Handle error as needed
    })
    or add this:
    const notification = rbxbot.onNotification()
    notification.on("data", function(data) {
    console.log("New notification! ", data)
    })
    notification.on("error", function(err) {
    console.error("Something went wrong: ", err)
    // Handle error as needed
    })
  2. Now run the bot.
  3. See error
  4. Try sending a PM to the bot.
  5. Nothing happens.

Expected behavior
It is supposed to log the data received from a notification or message to the console.

Screenshots
image
image

Could you identify if Roblox has updated their notification protocol?

Idk if they did or not?
The realtime.roblox.com API returns 503

However, they do have a notifications.roblox.com API Idk if that will work with PM messages.

realtime.roblox.com has been deprecated and now removed. The package should be switched to use realtime-signalr.roblox.com/userhub with the @microsoft/signalr package.

realtime.roblox.com has been deprecated and now removed. The package should be switched to use realtime-signalr.roblox.com/userhub with the @microsoft/signalr package.

How would I edit the file to make it work?

Issue has been fixed. I updated the onNotification file:
`// Dependencies
const signalR = require('@microsoft/signalr')
const events = require('events')

// Includes
const getSession = require('../util/getSession.js').func
const settings = require('../../settings.json')

// Args
exports.optional = ['jar']

// Docs
/**

  • 🔐 An event for when you get a notification.
  • @category Client
  • @alias onNotification
  • @returns An EventEmitter that emits when you get a notification.
  • @example const noblox = require("noblox.js")
  • // Login using your cookie
  • const notification = noblox.onNotification()
  • notification.on("data", function(data) {
  • console.log("New notification! ", data)
  • })
  • notification.on("error", function(err) {
  • console.error("Something went wrong: ", err)
  • // Handle error as needed
  • })
    **/

// Define
exports.func = function (args) {
const max = settings.event.maxRetries
const notifications = new events.EventEmitter()
function connect (retries) {
if (typeof args.jar === 'string') {
args.jar = { session: args.jar }
}
const session = getSession({ jar: args.jar })
let userNotificationConnection = null;

userNotificationConnection = new signalR.HubConnectionBuilder()
  .withUrl('https://realtime-signalr.roblox.com/userhub', {
    transport: signalR.HttpTransportType.WebSockets,
    skipNegotiation: true,
    headers: {
      Cookie: '.ROBLOSECURITY=' + session + ';'
    }
  })
  .build();

  userNotificationConnection.on('notification', function(name, message) {
    notifications.emit('data', name, JSON.parse(message))
  })

  notifications.on('close', userNotificationConnection.stop)

  userNotificationConnection.disconnected = function (err) {
    notifications.emit('error', new Error('Connection failed: ' + err.message))
    if (retries !== -1) {
      if (retries > max) {
        notifications.emit('close', new Error('Max retries reached'))
      } else {
        setTimeout(connect, 5000, retries + 1)
      }
    }
  }

  userNotificationConnection.error = function (err) {
    notifications.emit('error', err)
  }

  userNotificationConnection.connected = function(connection) {
    notifications.emit('connect', connection)
  }

  userNotificationConnection.reconnecting = function () {
    setTimeout(connect, 5000, 0)
  notifications.emit('error', new Error('Lost connection, reconnecting'))
  return true // Abort reconnection
  }

  userNotificationConnection.start()

}
connect(-1)
return notifications
}
`