我刚刚开始为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;
我不知道确切的问题是谁能告诉我为什么会这样。
答案 0 :(得分: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