microsoft / BotFramework-WebChat

A highly-customizable web-based client for Azure Bot Services.
https://www.botframework.com/
MIT License
1.58k stars 1.53k forks source link

Handler function missing third parameter in both `javascript/bot` and `javascript/web` of sample k.direct-line-token #4871

Open InfinytRam opened 11 months ago

InfinytRam commented 11 months ago

Is it an issue related to Adaptive Cards?

No

Is this an accessibility issue?

No

What version of Web Chat are you using?

Latest production

Which distribution are you using Web Chat from?

Unrelated

Which hosting environment does this issue primarily affect?

Web apps

Which browsers and platforms do the issue happened?

Browser: Edge (latest)

Which area does this issue affect?

Protocol or service

What is the public URL for the website?

No response

Please describe the bug

In sample k.direct-line-token, the javascript web and bot project server routes and handlers were not functioning as expected, causing issues with server startup and request handling.

Environment:

Do you see any errors in console log?

# npm start

> web@1.0.0 start
> node-dev --no-notify --respawn .

AssertionError [ERR_ASSERTION]: Handler [handler-1 on POST /api/messages] is missing a third argument (the "next" callback) but is not an async function. Middleware handlers can be either as
ync/await or callback-based.Callback-based (non-async) handlers should accept three arguments: (req, res, next). Async handler functions should accept maximum of 2 arguments: (req, res).
    at Chain.add (/Users/ram/Documents/bot/BotFramework-WebChat/samples/01.getting-started/k.direct-line-token/javascript/web/node_modules/restify/lib/chain.js:79:16)
    at forEach (/Users/ram/Documents/bot/BotFramework-WebChat/samples/01.getting-started/k.direct-line-token/javascript/web/node_modules/restify/lib/router.js:211:15)
    at Array.forEach (<anonymous>)
    at Router.mount (/Users/ram/Documents/bot/BotFramework-WebChat/samples/01.getting-started/k.direct-line-token/javascript/web/node_modules/restify/lib/router.js:203:14)
    at Server.serverMethod [as post] (/Users/ram/Documents/bot/BotFramework-WebChat/samples/01.getting-started/k.direct-line-token/javascript/web/node_modules/restify/lib/server.js:1779:33)
    at Object.<anonymous> (/Users/ram/Documents/bot/BotFramework-WebChat/samples/01.getting-started/k.direct-line-token/javascript/web/src/index.js:27:8)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Object.nodeDevHook [as .js] (/Users/ram/Documents/bot/BotFramework-WebChat/samples/01.getting-started/k.direct-line-token/javascript/web/node_modules/node-dev/lib/hook.js:54:7)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
(node:68169) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
[ERROR] 00:02:19 AssertionError: Handler [handler-1 on POST /api/messages] is missing a third argument (the "next" callback) but is not an async function. Middleware handlers can be either a
sync/await or callback-based.Callback-based (non-async) handlers should accept three arguments: (req, res, next). Async handler functions should accept maximum of 2 arguments: (req, res).

How to reproduce the issue?

This issue reproduces in both javascript/web and javascript/bot in sample sample k.direct-line-token:

javascript/web

  1. Navigate to the root javascript/web project directory.
  2. Run npm i then npm start to start the server.
  3. Send a request to the /api/messages route.
  4. Observe the error related to the missing third parameter in the handler function.

javascript/bot

  1. Navigate to the root javascript/bot project directory.
  2. Run npm i then npm start to start the server.
  3. Send a request to the /api/messages route.
  4. Observe the error related to the missing third parameter in the handler function.

What do you expect?

Requests to the /api/messages route should be handled without errors.

What actually happened?

Received an error indicating the missing third parameter (next callback) in the handler function for the following files:

  1. javascript/bot: createBot.js.
  2. javascript/web: botMessages.js.

Do you have any screenshots or recordings to repro the issue?

No response

Adaptive Card JSON

No response

Additional context

This issue pertains to how Restify expects handler functions to be structured. The function should either be an async function with (req, res) or a callback-based function with (req, res, next).

InfinytRam commented 11 months ago

🔗 Related Issues: #4871, #4872, #4873

I've identified these issues are all related to the k.direct-line-token sample. I'm currently working on a fix to address all three issues together.