Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bbot isn't working anymore #19566

Closed
HoffErik-JohnerInst opened this issue Nov 17, 2020 · 5 comments · Fixed by #20801
Closed

Bbot isn't working anymore #19566

HoffErik-JohnerInst opened this issue Nov 17, 2020 · 5 comments · Fixed by #20801

Comments

@HoffErik-JohnerInst
Copy link

Description:

My Bbot boilerplate-bot isn't working anymore since 3.8. Even the example-commands aren't working anymore. The bot tries to retrieve the roomID and the messageID, both are now "undefined" as well as the userID.

Steps to reproduce:

  1. Start the bot "npm start" for ex.
  2. Send a valid command through Rocket, "hi" for ex.

Expected behavior:

The bot should answer with "hello" to my "hi" command.

Actual behavior:

The bot script throws an error in the console and doesn't send a "hello" back.

info:   [received] Message in room undefined
(node:15740) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '_id' of undefined
    at Object.<anonymous> (C:\Users\name\Documents\rocket-folder-bot\node_modules\@rocket.chat\sdk\dist\lib\driver.js:357:23)
    at Generator.next (<anonymous>)
    at C:\Users\name\Documents\rocket-folder-bot\node_modules\@rocket.chat\sdk\dist\lib\driver.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (C:\Users\name\Documents\rocket-folder-bot\node_modules\@rocket.chat\sdk\dist\lib\driver.js:3:12)
    at C:\Users\name\Documents\rocket-folder-bot\node_modules\@rocket.chat\sdk\dist\lib\driver.js:351:45
    at ReactiveQuery.<anonymous> (C:\Users\name\Documents\rocket-folder-bot\node_modules\@rocket.chat\sdk\dist\lib\driver.js:314:17)
    at C:\Users\name\Documents\rocket-folder-bot\node_modules\asteroid\dist\asteroid.node.js:170:12
    at Array.forEach (<anonymous>)
    at ReactiveQuery._emit (C:\Users\name\Documents\rocket-folder-bot\node_modules\asteroid\dist\asteroid.node.js:169:22)
(node:15740) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15740) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Server Setup Information:

  • Version of Rocket.Chat Server: 3.8
  • Operating System: linux/amd64
  • Deployment Method: docker
  • Number of Running Instances: 1
  • NodeJS Version: 8.0.0

Client Setup Information

  • Desktop App or Browser Version: 1.19.0
  • Operating System: win10

Additional context

The "bleep bloop" in the logs means that the connection and the login to rocket were successfull and he receives the message as you can see. I think, he is just not able to retrieve the message or any information about the message.
Any help here?

Relevant logs:

{"message":"[subscribe] Preparing subscription: stream-room-messages: __my_messages__","level":"info","timestamp":"2020-11-17T07:57:37.314Z"}
{"message":"[subscribe] Stream ready: 2","level":"info","timestamp":"2020-11-17T07:57:37.355Z"}
{"message":"[reactive] Listening for change events in collection stream-room-messages","level":"info","timestamp":"2020-11-17T07:57:37.357Z"}
{"message":"[rocketchat] connected via DDP","level":"debug","timestamp":"2020-11-17T07:57:37.361Z"}
{"message":"[core] brocket started  . . . . . ~(O_O)~ bleep bloop","level":"info","timestamp":"2020-11-17T07:57:37.385Z"}
{"message":"[received] Message in room undefined","level":"info","timestamp":"2020-11-17T07:57:41.403Z"}
@jadanah
Copy link

jadanah commented Nov 17, 2020

Same issue with Hubot #19433 looks like 3.8.0 has broken all bot integrations

@ataraxus
Copy link

jep... quick and dirty fix and analysis here: #19567

@felipetomm
Copy link

Hello, another point is in driver.js, line 306, function reactToMessages. My SDK version i 0.2.9-2. The SDK log an undefined room id:

2020-11-17T14:11:04: PM2 log: Launching in no daemon mode
2020-11-17T14:11:04: PM2 log: App [index:0] starting in -fork mode-
2020-11-17T14:11:04: PM2 log: App [index:0] online
[connect] Connecting {
  username: 'bot_user',
  password: '****,
  ldap: true,
  host: '****',
  useSsl: true,
  timeout: 20000,
  rooms: [],
  allPublic: false,
  dm: true,
  livechat: true,
  edited: false,
  integrationId: 'js.SDK',
  roomCacheMaxSize: 10,
  roomCacheMaxAge: 300000,
  dmCacheMaxSize: 10,
  dmCacheMaxAge: 100000
}
[connect] Connected
[login] Logging in bot_user
[subscribe] Preparing subscription: stream-room-messages: __my_messages__
[subscribe] Stream ready: 2
[reactive] Listening for change events in collection stream-room-messages
[[{"_id":"84YMDeXmEA6WE4hyc","rid":"RQg5HEbuAeQcK34y7upapMwRTXwpLvntWJ","msg":"a","ts":{"$date":1605633080313},"u":{"_id":"RQg5HEbuAeQcK34y7","username":"felipe.tomm","name":"Felipe Tomm"},"unread":true,"_updatedAt":{"$date":1605633080431},"mentions":[],"channels":[]}],{"roomParticipant":true,"roomType":"d"}]
[received] Message in room undefined

This is solved add an second call to 0 pos in args, like this:

function reactToMessages(callback) {
    log_1.logger.info(`[reactive] Listening for change events in collection ${exports.messages.name}`);
    exports.messages.reactiveQuery({}).on('change', (_id) => {
        const changedMessageQuery = exports.messages.reactiveQuery({ _id });        
        if (changedMessageQuery.result && changedMessageQuery.result.length > 0) {
            const changedMessage = changedMessageQuery.result[0];
            if (Array.isArray(changedMessage.args)) {
                log_1.logger.info(`[received] Message in room ${changedMessage.args[0][0].rid}`); /* Here */
                callback(null, changedMessage.args[0][0] /* And here */, changedMessage.args[1]);
            }
            else {
                log_1.logger.debug('[received] Update without message args');
            }
        }
        else {
            log_1.logger.debug('[received] Reactive query at ID ${ _id } without results');
        }
    });
}

But i think this is not the correctly solution.
Note: this undefined message not breaks the app, but, in the same time, it's not an ideal behavior

@HoffErik-JohnerInst
Copy link
Author

I managed to fix it with message = message[0]; in my driver.js.

Best solution for now but Rocket should replace the array with the old object again.

@felipetomm
Copy link

In my case, i need to work with 3.7.1 and 3.8.0 RC Servers. For this, i make that change:

message = Array.isArray(message) ? message[0] : message;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants