为什么CLIENT_EVENTS不工作RTM在我的松弛机器人不确定?

问题描述 投票:1回答:1

我只是开始开发松弛服务,我刚刚创建的松弛机器人的连接,但我已经面临着一个问题,即

无法读取的未定义的属性“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;

我不知道什么是确切的问题是,谁能告诉我,为什么发生这种情况。

node.js express slack slack-api
1个回答
1
投票

该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

© www.soinside.com 2019 - 2024. All rights reserved.