我正在按照這裏的教程https://slackapi.github.io/node-slack-sdk/bots#posting-a-message和我flummoxed爲什麼我不能讓這部分的教程代碼工作。我複製並從這一節,低於使用Slack RTM api發佈消息
var RtmClient = require('@slack/client').RtmClient;
var RTM_CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS.RTM;
var bot_token = process.env.SLACK_BOT_TOKEN || ''; //I know the problem is not here.
var rtm = new RtmClient(bot_token);
rtm.start();
var channel = "#general"; //could also be a channel, group, DM, or user ID (C1234), or a username (@don)
// you need to wait for the client to fully connect before you can send messages
rtm.on(RTM_CLIENT_EVENTS.RTM_CONNECTION_OPENED, function() {
rtm.sendMessage("Hello!", channel);
});
由於教程代碼的第一部分工作,這個問題肯定是從過去的3行代碼來粘貼代碼。據推測這是該事件的一個問題。我的錯誤訊息是
Unhandled rejection Error
at RTMClient.handleMessageAck [as _handleMessageAck] (/Users/mg/projects/slack_projects/games/s
lack_connect_four/node_modules/@slack/client/lib/clients/rtm/client.js:496:40)
at RTMClient._handleWsMessageViaEventHandler (/Users/mg/projects/slack_projects/games/slack_con
nect_four/node_modules/@slack/client/lib/clients/rtm/client.js:459:12)
at RTMClient.handleWsMessage (/Users/mg/projects/slack_projects/games/slack_connect_four/node_m
odules/@slack/client/lib/clients/rtm/client.js:419:10)
at WebSocket.wrapper (/Users/mg/projects/slack_projects/games/slack_connect_four/node_modules/l
odash/lodash.js:4968:19)
at emitTwo (events.js:106:13)
at WebSocket.emit (events.js:191:7)
at Receiver.ontext (/Users/mg/projects/slack_projects/games/slack_connect_four/node_modules/ws/
lib/WebSocket.js:841:10)
at /Users/mg/projects/slack_projects/games/slack_connect_four/node_modules/ws/lib/Receiver.js:5
36:18
at Receiver.applyExtensions (/Users/mg/projects/slack_projects/games/slack_connect_four/node_mo
dules/ws/lib/Receiver.js:371:5)
at /Users/mg/projects/slack_projects/games/slack_connect_four/node_modules/ws/lib/Receiver.js:5
08:14
at Receiver.flush (/Users/mg/projects/slack_projects/games/slack_connect_four/node_modules/ws/l
ib/Receiver.js:347:3) at Receiver.finish (/Users/mg/projects/slack_projects/games/slack_connect_four/node_modules/ws/
lib/Receiver.js:541:12)
at Receiver.expectHandler (/Users/mg/projects/slack_projects/games/slack_connect_four/node_modu
les/ws/lib/Receiver.js:499:31)
at Receiver.add (/Users/mg/projects/slack_projects/games/slack_connect_four/node_modules/ws/lib
/Receiver.js:103:24)
at TLSSocket.realHandler (/Users/mg/projects/slack_projects/games/slack_connect_four/node_modul
es/ws/lib/WebSocket.js:825:20)
at emitOne (events.js:96:13)
我真的很感激任何幫助。
意識到我面臨的問題在這些鏈接中提出https://github.com/slackapi/node-slack-sdk/issues/251 https://github.com/slackapi/node-slack-sdk/問題/ 300#issuecomment-266804306 – MattGoldwater