ekmartin / slack-irc

Connects Slack and IRC channels by sending messages back and forth.
MIT License
588 stars 158 forks source link

IRC -> Slack direction no longer works #269

Open tetlowgm opened 2 years ago

tetlowgm commented 2 years ago

I get the following error when someone writes something in IRC on a bridged channel. It doesn't end up in Slack:

error: Received error event from IRC TypeError: Cannot read property 'map' of undefined at Bot.sendToSlack (/usr/home/ec2-user/git/slack-irc/dist/bot.js:297:60) at Client.emit (node:events:378:20) at Client. (/usr/home/ec2-user/git/slack-irc/node_modules/irc-upd/lib/irc.js:581:22) at Client.emit (node:events:378:20) at /usr/home/ec2-user/git/slack-irc/node_modules/irc-upd/lib/irc.js:896:26 at Array.forEach () at Socket.handleData (/usr/home/ec2-user/git/slack-irc/node_modules/irc-upd/lib/irc.js:890:15) at Socket.emit (node:events:378:20) at addChunk (node:internal/streams/readable:313:12) at readableAddChunk (node:internal/streams/readable:284:11) at Socket.Readable.push (node:internal/streams/readable:227:10) at TCP.onStreamRead (node:internal/stream_base_commons:190:23)

For reference, Slack -> IRC still works, just not the other direction.

adamhorden commented 2 years ago

We are having the same issue. I have spent a couple of hours debugging to try and find out why this has just randomly stopped working. So far not found anything. Will keep looking.

Adam Horden

Byproduct commented 2 years ago

My bot has stopped working too. It manages to join IRC, then soon dies with this message:

/usr/lib/node_modules/slack-irc/node_modules/irc/lib/irc.js:849
                        throw err;
                        ^

TypeError: Cannot read property 'map' of undefined
    at Bot.sendToSlack (/usr/lib/node_modules/slack-irc/dist/bot.js:295:60)
    at emitMany (events.js:147:13)
    at Client.emit (events.js:224:7)
    at Client.<anonymous> (/usr/lib/node_modules/slack-irc/node_modules/irc/lib/irc.js:557:22)
    at emitOne (events.js:116:13)
    at Client.emit (events.js:211:7)
    at iterator (/usr/lib/node_modules/slack-irc/node_modules/irc/lib/irc.js:846:26)
    at Array.forEach (<anonymous>)
    at Socket.handleData (/usr/lib/node_modules/slack-irc/node_modules/irc/lib/irc.js:841:15)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:246:13)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:601:20)
drislands commented 2 years ago

Unless I'm mistaken, this is the line that is failing:

var currentChannelUsernames = slackChannel.members.map(function (member) {

Whatever part of the code that gets the members list is not working, for some reason. Perhaps an API change on Slack's end?

gkelle commented 2 years ago

Here's a patch @drislands and I cooked up for a quick fix. Took some inspiration from https://github.com/slackapi/node-slack-sdk/wiki/DataStore-v3.x-Migration-Guide


--- a/lib/bot.js    2021-08-27 23:34:32.622846730 -0700
+++ b/lib/bot.js    2021-08-27 23:34:28.351824023 -0700
@@ -254,27 +254,29 @@
         return;
       }

-      const currentChannelUsernames = slackChannel.members.map(member =>
-        dataStore.getUserById(member).name
-      );
+      this.slack.web.conversations.members(slackChannel.id).then( resp => {
+        const currentChannelUsernames = resp.members.map(member =>
+          dataStore.getUserById(member).name
+        );

-      const mappedText = currentChannelUsernames.reduce((current, username) =>
-        highlightUsername(username, current)
-      , text);
+        const mappedText = currentChannelUsernames.reduce((current, username) =>
+          highlightUsername(username, current)
+        , text);

-      let iconUrl;
-      if (author !== this.nickname && this.avatarUrl) {
-        iconUrl = this.avatarUrl.replace(/\$username/g, author);
-      }
+        let iconUrl;
+        if (author !== this.nickname && this.avatarUrl) {
+          iconUrl = this.avatarUrl.replace(/\$username/g, author);
+        }

-      const options = {
-        username: this.slackUsernameFormat.replace(/\$username/g, author),
-        parse: 'full',
-        icon_url: iconUrl
-      };
+        const options = {
+          username: this.slackUsernameFormat.replace(/\$username/g, author),
+          parse: 'full',
+          icon_url: iconUrl
+        };

-      logger.debug('Sending message to Slack', mappedText, channel, '->', slackChannelName);
-      this.slack.web.chat.postMessage(slackChannel.id, mappedText, options);
+        logger.debug('Sending message to Slack', mappedText, channel, '->', slackChannelName);
+        this.slack.web.chat.postMessage(slackChannel.id, mappedText, options);
+      });
     }
   }
 }
bovine commented 2 years ago

@gkelle Perhaps you could submit that change as a new pull request and reference this issue?

gkelle commented 2 years ago

@bovine I've just submitted a pull request for the change

tetlowgm commented 2 years ago

I can confirm this is working for me. Would be nice for @ekmartin to accept the PR.