slack-irc icon indicating copy to clipboard operation
slack-irc copied to clipboard

IRC -> Slack direction no longer works

Open tetlowgm opened this issue 4 years ago • 7 comments

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.

tetlowgm avatar Aug 19 '21 14:08 tetlowgm

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

adamhorden avatar Aug 19 '21 18:08 adamhorden

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)

Byproduct avatar Aug 22 '21 18:08 Byproduct

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?

drislands avatar Aug 24 '21 16:08 drislands

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);
+      });
     }
   }
 }

gkelle avatar Aug 28 '21 06:08 gkelle

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

bovine avatar Sep 03 '21 18:09 bovine

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

gkelle avatar Sep 05 '21 15:09 gkelle

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

tetlowgm avatar Sep 14 '21 18:09 tetlowgm