Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 4481e35

Browse files
committedApr 27, 2018
send callback on startRTM websocket error
1 parent 3e008d7 commit 4481e35

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed
 

‎lib/Slackbot_worker.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,22 @@ module.exports = function(botkit, config) {
128128
botkit.shutdown();
129129
};
130130

131-
bot.startRTM = function(cb) {
131+
bot.startRTM = function(userCb) {
132+
var userCbCalled = false;
133+
var cb = function() {
134+
if (!userCbCalled) {
135+
userCbCalled = true;
136+
userCb && userCb.apply(this, arguments);
137+
}
138+
};
132139
var lastPong = 0;
133140
bot.api.rtm.connect({}, function(err, res) {
134141
if (err) {
135-
return cb && cb(err);
142+
return cb(err);
136143
}
137144

138145
if (!res) {
139-
return cb && cb('Invalid response from rtm.start');
146+
return cb('Invalid response from rtm.start');
140147
}
141148

142149
bot.identity = res.self;
@@ -206,14 +213,16 @@ module.exports = function(botkit, config) {
206213

207214
botkit.startTicking();
208215

209-
cb && cb(null, bot, res);
216+
cb(null, bot, res);
210217
});
211218

212219
bot.rtm.on('error', function(err) {
213220
botkit.log.error('RTM websocket error!', err);
214221
if (pingTimeoutId) {
215222
clearTimeout(pingTimeoutId);
216223
}
224+
225+
cb(err);
217226
botkit.trigger('rtm_close', [bot, err]);
218227
});
219228

@@ -222,6 +231,8 @@ module.exports = function(botkit, config) {
222231
if (pingTimeoutId) {
223232
clearTimeout(pingTimeoutId);
224233
}
234+
235+
cb(message);
225236
botkit.trigger('rtm_close', [bot]);
226237

227238
/**

0 commit comments

Comments
 (0)
This repository has been archived.