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

IRC -> Slack direction no longer works #269

Open
tetlowgm opened this issue Aug 19, 2021 · 7 comments
Open

IRC -> Slack direction no longer works #269

tetlowgm opened this issue Aug 19, 2021 · 7 comments

Comments

@tetlowgm
Copy link

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 tetlowgm changed the title Slack -> IRC direction no longer works IRC -> Slack direction no longer works Aug 19, 2021
@adamhorden
Copy link

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
Copy link

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
Copy link

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
Copy link

gkelle commented Aug 28, 2021

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
Copy link

bovine commented Sep 3, 2021

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

gkelle added a commit to gkelle/slack-irc that referenced this issue Sep 5, 2021
@gkelle
Copy link

gkelle commented Sep 5, 2021

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

@tetlowgm
Copy link
Author

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

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

No branches or pull requests

6 participants