RocketChat / Rocket.Chat.js.SDK

Utility for apps and bots to interact with Rocket.Chat via DDP and/or API
MIT License
136 stars 94 forks source link

new structure of rocketchat api #130

Closed yuriyo closed 2 years ago

yuriyo commented 3 years ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch @rocket.chat/sdk@0.1.0 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@rocket.chat/sdk/dist/lib/driver.js b/node_modules/@rocket.chat/sdk/dist/lib/driver.js
index 1f3dd8f..e607bb8 100644
--- a/node_modules/@rocket.chat/sdk/dist/lib/driver.js
+++ b/node_modules/@rocket.chat/sdk/dist/lib/driver.js
@@ -340,7 +340,7 @@ function reactToMessages(callback) {
         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].rid}`);
+                log_1.logger.info(`[received] Message in room ${changedMessage.args[0][0].rid}`);
                 callback(null, changedMessage.args[0], changedMessage.args[1]);
             }
             else {
@@ -370,6 +370,7 @@ function respondToMessages(callback, options = {}) {
             log_1.logger.error(`Unable to receive messages ${JSON.stringify(err)}`);
             callback(err); // bubble errors back to adapter
         }
+        message = Array.isArray(message) ? message[0] : message;
         // Ignore bot's own messages
         if (message.u._id === exports.userId)
             return;

This issue body was partially generated by patch-package.

felipetomm commented 3 years ago

@yuriyo , please verify this issue with RocketChat version 3.12.0 or above. In this release, that structure has rollbacked :)

Here our solution is in production with oficial SDK (without changes).