howdyai / botkit

Botkit is an open source developer tool for building chat bots, apps and custom integrations for major messaging platforms.
MIT License
11.46k stars 2.28k forks source link

Botkit boilerplate does not pass initial handshake for Slack's event subscription #2194

Closed samcodrington-xero closed 2 years ago

samcodrington-xero commented 2 years ago

Are you sure this is an issue with the Botkit core module?

It could be resolved by slack or botkit however it may be able to be more easily resolved in botkit.

What are you trying to achieve or the steps to reproduce?

I am trying to subscribe a botkit bot to events from slack

  1. Install barebones botkit repo using npm install -g yo generator-botkit && yo botkit
  2. run the bootstrapped server using npm start
  3. Create botkit in slack then configure .env with BOT_TOKEN, SIGNING_SECRET and VERIFICATION_TOKEN
  4. Use ngrok to expose localhost:3000 to the internet using npx ngrok http 3000
  5. Attempt to enable events using https://api.slack.com/apps/your-app-id-here/event-subscriptions? (can be found under Features -> Event Subscriptions in the sidebar once you have your app selected on api.slack.com)

What was the result you received?

Unable to pass the handshake with the following response on the UI: Screen Shot 2022-02-01 at 4 12 06 PM

Upon further inspection it appears that the server is responding with the wrong Content-Type: text/html rather than the text/plain, application/x-www-form-urlencoded or application/json which are the three response types suggested by the slack documentation . I initially thought that ngrok was perhaps suspect, modifying the response somehow: Screen Shot 2022-02-01 at 4 09 12 PM

But a curl request shows that this is an issue even when the request is sent locally:

curl http://localhost:3000/api/messages -H 'Content-Type: application/json' -H 'Accept: application/json' --data '{"token":"foobar","challenge":"hi its me","type":"url_verification"}' -v
*   Trying ::1:3000...
* Connected to localhost (::1) port 3000 (#0)
> POST /api/messages HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.77.0
> Accept: */*
> Content-type: application/json
> Content-Length: 68
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Content-Type: text/html; charset=utf-8           < ---- this should be text/plain
< Content-Length: 9
< ETag: W/"9-6860Vqr68AiYT0YZ1EVysp65QG4"
< Date: Tue, 01 Feb 2022 21:10:20 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< 
* Connection #0 to host localhost left intact
hi its me

I believe that this issue can be resolved by responding to this specific request in the proper format.

What did you expect?

To be able to pass the url_verification handshake for events subscription

Screenshots and animated GIFs

Context:

benbrown commented 2 years ago

Thank you for this bug report. I just published 4.15.0 of this adapter which should resolve this issue. Please let me know if you have continued problems.

stathischaritos commented 2 years ago

https://github.com/howdyai/botkit/blob/main/packages/botbuilder-adapter-slack/src/slack_adapter.ts#L520 Should it be:


res.header('Content-Type',  'text/plain');