addAuthenticatedHandler

addAuthenticatedHandler

我刚刚开始为Slack开发服务,我只是创建了与Slack bot的连接,但是我遇到了一个问题


  无法读取未定义的属性“ RTM”


这是我的代码

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;


我不知道确切的问题是什么人可以告诉我为什么会这样。

最佳答案

RTM_EVENTS词典不是必需的,您只需要直接将事件名称预订为字符串即可。

兑换:

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



  由于常量是V3.x,因此已从V4.x中删除


至:

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



  使用简单的字符串作为事件名称是V4.x


migration guide

09-27 06:51