1

i am just started to develop service for slack and i just creating a connection to the slack bot but i have facing a problem that

Cannot read property 'RTM' of undefined

this is my code

const { RTMClient, CLIENT_EVENTS, RTM_EVENTS, RTM_MESSAGE_SUBTYPES } = require('@slack/client');

function handleOnAuthenticated(rtmStartData) {
    console.log(`logged in as ${rtmStartData.self.name} of team ${rtmStartData.self.team.name} but not et connected to channel`);
}

function addAuthenticatedHandler(rtm, handler) {
    rtm.on(CLIENT_EVENTS.RTM.AUTHENTICATED, handler);
}

module.exports.init = function slackClient(bot_token, logLevel) {
    rtm = new RTMClient(bot_token);
    addAuthenticatedHandler(rtm, handleOnAuthenticated);
    return rtm;
}

module.exports.addAuthenticatedHandler = addAuthenticatedHandler;

i dont know what is the exact problem is can anyone tell me that why this is happening.

1 Answers1

1

The RTM_EVENTS dictionary isn't necessary, you just need to directly subscribe to the event name as a string.

Convert:

function addAuthenticatedHandler(rtm, handler) {
rtm.on(CLIENT_EVENTS.RTM.AUTHENTICATED, handler);
}

As Constants is V3.x ,which have been removed from V4.x

To:

function addAuthenticatedHandler(rtm, handler) {
rtm.on('authenticated', handler);
}

Using simple strings for event names is V4.x

migration guide

Abdel-Raouf
  • 700
  • 1
  • 8
  • 20