This repository was archived by the owner on Sep 20, 2024. It is now read-only.
File tree 1 file changed +15
-4
lines changed
1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -128,15 +128,22 @@ module.exports = function(botkit, config) {
128
128
botkit . shutdown ( ) ;
129
129
} ;
130
130
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
+ } ;
132
139
var lastPong = 0 ;
133
140
bot . api . rtm . connect ( { } , function ( err , res ) {
134
141
if ( err ) {
135
- return cb && cb ( err ) ;
142
+ return cb ( err ) ;
136
143
}
137
144
138
145
if ( ! res ) {
139
- return cb && cb ( 'Invalid response from rtm.start' ) ;
146
+ return cb ( 'Invalid response from rtm.start' ) ;
140
147
}
141
148
142
149
bot . identity = res . self ;
@@ -206,14 +213,16 @@ module.exports = function(botkit, config) {
206
213
207
214
botkit . startTicking ( ) ;
208
215
209
- cb && cb ( null , bot , res ) ;
216
+ cb ( null , bot , res ) ;
210
217
} ) ;
211
218
212
219
bot . rtm . on ( 'error' , function ( err ) {
213
220
botkit . log . error ( 'RTM websocket error!' , err ) ;
214
221
if ( pingTimeoutId ) {
215
222
clearTimeout ( pingTimeoutId ) ;
216
223
}
224
+
225
+ cb ( err ) ;
217
226
botkit . trigger ( 'rtm_close' , [ bot , err ] ) ;
218
227
} ) ;
219
228
@@ -222,6 +231,8 @@ module.exports = function(botkit, config) {
222
231
if ( pingTimeoutId ) {
223
232
clearTimeout ( pingTimeoutId ) ;
224
233
}
234
+
235
+ cb ( message ) ;
225
236
botkit . trigger ( 'rtm_close' , [ bot ] ) ;
226
237
227
238
/**
You can’t perform that action at this time.
0 commit comments