botbuilder-js: Error: BotFrameworkAdapter.processActivity(): 401 ERROR

Versions

botbuilder: 4.9.2 (Latest) node: 12.18.2 (Latest) OS: Ubuntu (Docker-Container)

Describe the bug

One of a sudden adapter.processActivity fails with these two error messages when sending a chat-message to the bot:

1. Error Message: JwtTokenExtractor.getIdentity:err! ReferenceError: XMLHttpRequest is not defined dev_server | at /var/huforce/node_modules/whatwg-fetch/dist/fetch.umd.js:484:17 ... dev_server | at /var/huforce/node_modules/botframework-connector/lib/auth/openIdMetadata.js:14:71 dev_server | at new Promise (<anonymous>) dev_server | at __awaiter (/var/huforce/node_modules/botframework-connector/lib/auth/openIdMetadata.js:10:12) dev_server | at OpenIdMetadata.getKey (/var/huforce/node_modules/botframework-connector/lib/auth/openIdMetadata.js:30:16) dev_server | at JwtTokenExtractor.<anonymous> (/var/huforce/node_modules/botframework-connector/lib/auth/jwtTokenExtractor.js:86:56)

2. Error Message: (node:18) UnhandledPromiseRejectionWarning: Error: BotFrameworkAdapter.processActivity(): 401 ERROR dev_server | ReferenceError: XMLHttpRequest is not defined dev_server | at /var/huforce/node_modules/whatwg-fetch/dist/fetch.umd.js:484:17 dev_server | at new Promise (<anonymous>) dev_server | at fetch (/var/huforce/node_modules/whatwg-fetch/dist/fetch.umd.js:477:12) dev_server | at OpenIdMetadata.<anonymous> (/var/huforce/node_modules/botframework-connector/lib/auth/openIdMetadata.js:54:31) dev_server | at Generator.next (<anonymous>) dev_server | at /var/huforce/node_modules/botframework-connector/lib/auth/openIdMetadata.js:14:71 dev_server | at new Promise (<anonymous>) dev_server | at __awaiter (/var/huforce/node_modules/botframework-connector/lib/auth/openIdMetadata.js:10:12) dev_server | at OpenIdMetadata.refreshCache (/var/huforce/node_modules/botframework-connector/lib/auth/openIdMetadata.js:53:16) dev_server | at OpenIdMetadata.<anonymous> (/var/huforce/node_modules/botframework-connector/lib/auth/openIdMetadata.js:34:32) dev_server | at Generator.next (<anonymous>) dev_server | at /var/huforce/node_modules/botframework-connector/lib/auth/openIdMetadata.js:14:71 dev_server | at new Promise (<anonymous>) dev_server | at __awaiter (/var/huforce/node_modules/botframework-connector/lib/auth/openIdMetadata.js:10:12) dev_server | at OpenIdMetadata.getKey (/var/huforce/node_modules/botframework-connector/lib/auth/openIdMetadata.js:30:16) dev_server | at JwtTokenExtractor.<anonymous> (/var/huforce/node_modules/botframework-connector/lib/auth/jwtTokenExtractor.js:86:56) dev_server | at BotFrameworkAdapter.<anonymous> (/var/huforce/node_modules/botbuilder/lib/botFrameworkAdapter.js:674:27) dev_server | at Generator.throw (<anonymous>) dev_server | at rejected (/var/huforce/node_modules/botbuilder/lib/botFrameworkAdapter.js:12:65) dev_server | at processTicksAndRejections (internal/process/task_queues.js:97:5)

Details

I created my bot via the App-Studio. I don’t have an azure subscription. I neither use the emulator. The bot runs locally. I am using ngrok to tunnel the requests to my PC.

What I have tried

  • I tried various versions of your (awesome) package
  • I checked the client-id & the client-secret
  • I created a new client-secret
  • I verified my client-id & my client-secret
  • I checked my messaging endpoint
  • I verified the system time
  • I created a new bot via the App Studio and the https://dev.botframework.com
  • Installing xmlhttprequest manually

Code:

` … const bot = new Bot(); export const adapter = new BotFrameworkAdapter({ appId: msteams.CLIENT_ID, appPassword: msteams.CLIENT_SECRET }); MicrosoftAppCredentials.trustServiceUrl( “https://smba.trafficmanager.net/emea/” ); … expressApp.post(“/bot”, secure((req, res) => { adapter.processActivity(req, res, async context => { // <-- error await bot.run(context); }); }));

`

I am desperate, because we need to deliver a new version of our bot. But, I just can’t fix this issue. I really appreciate any help.

[bug]

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 18 (4 by maintainers)

Most upvoted comments

Ok, I now know how to fix the error. But it is extremely strange.

Error: … const expressApp = express();

import botbuilder from “botbuilder”; const { BotFrameworkAdapter } = botbuilder; …

No Error: … import botbuilder from “botbuilder”; const { BotFrameworkAdapter } = botbuilder;

const expressApp = express(); …

Why on earth do I have to import the botbuilder before initializing express? Can someone please explain this to me.

@geckgecko @janandreschweiger, thanks for the above info. I will update the thread soon with my findings.