Closed L0wry closed 7 years ago
Hey @Lowry99 :) Thanks for giving slack-mock a try :)
Underneath the hood, Botkit calls the Web API rtm.start
method before starting the RTM connection. You'll need to mock the response to that endpoint. Take a look at this example test where I do something similar: https://github.com/Skellington-Closet/slack-mock/blob/master/examples/test/slack-app.spec.js#L25
Hey man,
Thanks for the help. Managed to make a fair bit of progress. Unfortunately this is a side project so I don't very often get the time to spend on it that I would like.
Botkit seems to now use rtm.connect
which is cool. I've mocked the response out, but
the part that has now got me is in the response for rtm.connect
you need to provide a websocket url
for your app to connect to. Not totally sure what to put here. I've tried various things and added a responses for it, but no luck
Does Slack-Mock support the rtm.connect websocket or should I go ahead and mock it out myself? You can find the debug below
Cheers!
slack-mock DEBUG intercepted web request: https://slack.com/api/rtm.connect
slack-mock DEBUG responding to web with override
{
"statusCode": 200,
"body": {
"ok": true,
"url": "????",
"team": {
"id": "T654321",
"name": "team",
"domain": "libsocos"
},
"self": {
"id": "mockBotId",
"name": "mockBot"
}
},
"headers": {}
}
debug: Got response null {"ok":true,"url":"????","team":{"id":"T654321","name":"team","domain":"libsocos"},"self":{"id":"mockBotId","name":"mockBot"}}
notice: ** BOT ID: mockBot ...attempting to connect to RTM!
error: RTM websocket error! { Error: socket hang up
at createHangUpError (_http_client.js:343:15)
at Socket.socketOnEnd (_http_client.js:435:23)
at emitNone (events.js:110:20)
at Socket.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1045:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9) code: 'ECONNRESET' }
notice: RTM close event: 1006 :
error: Abnormal websocket close event, attempting to reconnect
just spent some time looking at slack-mock
I think the problem might possibly come from here
const body = response[1]
if (/rtm\.start/.test(url) && body.ok) {
const rtmUrl = rtm._.addToken(params.token)
body.url = rtmUrl
}
I don't think we call rtm._addToken
if rtm.connect
is used
No problem about the lag :) I think you're right, this is a bug in slack-mock. Are you interested in submitting a PR? Otherwise I can take a look some time this week.
Thanks again for reporting!
Hey guys,
Having some trouble mocking out the slack api and would really appreciate some help! I've pretty much copied your example test for a slack app.
My problem is that when the bot gets spawned and i call
startRTM()
(using botkit npm package) I get this exceptionslack-mock ERROR uncaughtException: Cannot read property 'name' of undefined
I can see that if i log out the bot that there is an identity object set to
id:null
andname:''
and have tried to hack my way around it with no luck.Am I missing something here? You can see how I spawn the bot below
Thank you!!