Botframework-sdk: BotBuilder doesn't work with Microsoft Teams for newly-created bots

Created on 3 Jan 2017  路  15Comments  路  Source: microsoft/botframework-sdk

The following code just listens for incoming messages and replies with _Hello_ to them. It fails when a message is received from Microsoft Teams when handled by a recently created bot, but works perfectly if I do the same with bots, that were created a month ago.

const fs = require('fs');
const restify = require('restify');
const builder = require('botbuilder');

const server = restify.createServer({
  key: fs.readFileSync('../privkey.pem'),
  certificate: fs.readFileSync('../cert.pem')
});
server.listen(8889, function () {
  console.log('%s listening to %s', server.name, server.url);
});

const connector = new builder.ChatConnector({
  appId: '... Bot ID ...',
  appPassword: '... Bot Password ...'
});
const bot = new builder.UniversalBot(connector);
server.post('/incoming', connector.listen());

bot.dialog('/', function (session) {
    session.send('Hello');
});

For the recently created bots it stops on the following error:

Error: Request to 'https://smba.trafficmanager.net/v3/conversations/19%3A7bccb3fd-ec20-4d39-934d-14be2002c27e_423f5dfe-6118-4a00-ba23-4fafc4b6fc19%40unq.gbl.spaces/activities/1483459651513' failed: [404] Not Found
    at Request._callback (/raid/www/sapho.drud.cz/bot/node_modules/botbuilder/lib/bots/ChatConnector.js:415:46)
    at Request.self.callback (/raid/www/sapho.drud.cz/bot/node_modules/request/request.js:186:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/raid/www/sapho.drud.cz/bot/node_modules/request/request.js:1081:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at IncomingMessage.<anonymous> (/raid/www/sapho.drud.cz/bot/node_modules/request/request.js:1001:12)
    at IncomingMessage.g (events.js:292:16)
    at emitNone (events.js:91:20)

See the detailed log here: https://gist.github.com/drudv/24f82af359f6d8d9313033cfe9c6f947
Also here is a log for the "old" bots, for which it works as expected: https://gist.github.com/drudv/aaf838e1ed2c47d568a0858f748a7b30

I have 5 different bots (2 were registered today, others were created a month ago) and can confirm that it's reproducible only with these two recently created bots. All of them have correct Messaging endpoint on https://dev.botframework.com/bots page (test connection returns Accepted) and Microsoft Teams channel is enabled for them.

A few more observations:

  1. Old and new bots are handled by different servers. It's evident from the User-Agent header of incoming requests, which is
    BF-Skype (Microsoft-BotFramework/3.1 +https://botframework.com/ua) for the old bots and Microsoft-SkypeBotApi (Microsoft-BotFramework/3.0) for the recently created bots.

  2. If a message is sent from the test chat window on https://dev.botframework.com/bots then this code works for all bots. So the issue relates only to Microsoft Teams channel.

Most helpful comment

Thank you, we have confirmed the issue you described. I will follow up when the fix to the Node.js SDK is published.

All 15 comments

I can't recreate this - I successfully created a new bot using the SendAttachment sample. Perhaps you can try the same sample to eliminate any subtle differences in your code?

I found where the problem came from. BotBuilder Node.js SDK produces wrong URL for outgoing messages. When serviceUrl is https://smba.trafficmanager.net/amer-client-ss.msg, it uses the following URL to send a response message:

https://smba.trafficmanager.net/v3/conversations/19%3A7bccb3fd-ec20-4d39-934d-14be2002c27e_423f5dfe-6118-4a00-ba23-4fafc4b6fc19%40unq.gbl.spaces/activities/1484144325260

which is wrong. It should be:

https://smba.trafficmanager.net/amer-client-ss.msg/v3/conversations/19%3A7bccb3fd-ec20-4d39-934d-14be2002c27e_423f5dfe-6118-4a00-ba23-4fafc4b6fc19%40unq.gbl.spaces/activities/1484144325260

Thank you, we have confirmed the issue you described. I will follow up when the fix to the Node.js SDK is published.

@RichMoeMSFT Any update on the above? I set aside some time this weekend for an eager first dive into Teams bots and I think I have come up against the same issue as @drudv.

+1 @RichMoeMSFT I have a very similar issue here :( My bot works great with the web chat but fails with Skype and Teams channels with the following error:
Error: Request to 'https://smba.trafficmanager.net/v3/conversations/29%3A1f3Mogz8_KQCtQcri6YnI_PyqiSzUUoLqc2IrwGsF-wgtdRGtPhlX9wuX2JbOpqGJ/activities' failed: [400] Bad Request at Request._callback (D:\home\site\wwwroot\node_modules\botbuilder\lib\bots\ChatConnector.js:435:46) at Request.self.callback (D:\home\site\wwwroot\node_modules\botbuilder\node_modules\request\request.js:186:22) at emitTwo (events.js:106:13) at Request.emit (events.js:191:7) at Request.<anonymous> (D:\home\site\wwwroot\node_modules\botbuilder\node_modules\request\request.js:1081:10) at emitOne (events.js:96:13) at Request.emit (events.js:188:7) at IncomingMessage.<anonymous> (D:\home\site\wwwroot\node_modules\botbuilder\node_modules\request\request.js:1001:12) at IncomingMessage.g (events.js:291:16) at emitNone (events.js:91:20)

Version 3.5.4 was just published and it appears to work in my sample code. Please update (npm install botbuilder) and see if it works for you as well.

@RichMoeMSFT Seems to work now in Teams and Skype channels. However, I have an other issue in Teams: I'm not able to click on the link in a Sign-In card. Maybe it's just related to the Teams channel and not the Bot Builder itself I suppose (work with web and Skype channels). Thanks!

Thanks @RichMoeMSFT it works for me too!

Experienced the same issue. After updating the botbuilder package from 3.5.3 to 3.5.4, the bot now works in Microsoft Teams. Thanks!

@FranckyC I'm getting the same problem with sign-in card on Node.js only. C# works fine. I'll let the team now.

@FranckyC, regarding the sign-in card, we're looking into it. The bug tracking this is here.

I'll close this specific issue since it was fixed in 3.5.4. Thanks!

Hi, I'm facing same issue with skype channel and same is working fine in emulator. Using latest versions
"dependencies": {
"bluebird": "^3.4.7",
"botbuilder": "^3.7.0",
"dotenv-extended": "^1.0.4",
"restify": "^4.3.0",
"update": "^0.7.4"
}

2017-05-28T07:07:26.907222+00:00 app[web.1]: Error: Request to 'https://smba.trafficmanager.net/apis/v3/conversations/29%3A1-KtonFC1l_9Sba1nwWEpyCP4gY1qMUgSsCbW2j8o6No/activities' failed: [400] Bad Request
2017-05-28T07:07:26.907241+00:00 app[web.1]: at Request._callback (/app/node_modules/botbuilder/lib/bots/ChatConnector.js:512:46)
2017-05-28T07:07:26.907243+00:00 app[web.1]: at Request.self.callback (/app/node_modules/request/request.js:188:22)
2017-05-28T07:07:26.907244+00:00 app[web.1]: at emitTwo (events.js:106:13)
2017-05-28T07:07:26.907245+00:00 app[web.1]: at Request.emit (events.js:191:7)
2017-05-28T07:07:26.907245+00:00 app[web.1]: at Request. (/app/node_modules/request/request.js:1171:10)
2017-05-28T07:07:26.907246+00:00 app[web.1]: at emitOne (events.js:96:13)
2017-05-28T07:07:26.907247+00:00 app[web.1]: at Request.emit (events.js:188:7)
2017-05-28T07:07:26.907248+00:00 app[web.1]: at IncomingMessage. (/app/node_modules/request/request.js:1091:12)
2017-05-28T07:07:26.907248+00:00 app[web.1]: at IncomingMessage.g (events.js:292:16)
2017-05-28T07:07:26.907249+00:00 app[web.1]: at emitNone (events.js:91:20)

The same here @RichMoeMSFT everything works with Bot Framework Emulator but not with MS Teams:

"dependencies": {
"adal-node": "^0.1.27",
"axios": "^0.17.1",
"botbuilder": "^3.13.1",
"botbuilder-azure": "^3.0.4",
"es6-promise": "^4.2.2",
"lodash": "^4.17.4",
"restify": "^5.2.1"
},

Error: POST to 'https://smba.trafficmanager.net/emea-client-ss.msg/v3/conversations/a%3A1Xnq4KhIrUJkVEd3yT67GYcPPJklI3BrH-gR4X3lemfZqxMBkqrRY4DmH2Eu0f1NQKgBZEIT-H2Xp7gpf4sZYvqxTgRSN3goFgqQyFCPq5K8ekxVDlr61bT0jM6Zynyny/activities/1516745027476' failed: [400] Bad Request
at Request._callback (D:\home\site\wwwroot\node_modules\botbuilder\lib\bots\ChatConnector.js:545:46)
at Request.self.callback (D:\home\site\wwwroot\node_modules\request\request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request. (D:\home\site\wwwroot\node_modules\request\request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage. (D:\home\site\wwwroot\node_modules\request\request.js:1091:12)
at IncomingMessage.g (events.js:291:16)
at emitNone (events.js:91:20)

Error in Bot service with message * POST to 'https://smba.trafficmanager.net/amer/v3/conversations/a%3A1taZNBMcuPHBqvkmOy9FgPv4Q1vO_3SuKdONKI90861H421bCoVhHGNBegQiH4mufNoljJ5FNWyIArZSCygghZE-ZPjnF5ElIqrUIsBAZDClAi4_nYyYKwlp5wUdAR7_9/activities/1567951571075' failed: [400] Bad Request* stackTrace * Error: POST to 'https://smba.trafficmanager.net/amer/v3/conversations/a%3A1taZNBMcuPHBqvkmOy9FgPv4Q1vO_3SuKdONKI90861H421bCoVhHGNBegQiH4mufNoljJ5FNWyIArZSCygghZE-ZPjnF5ElIqrUIsBAZDClAi4_nYyYKwlp5wUdAR7_9/activities/1567951571075' failed: [400] Bad Request

We started to see this message starting friday, it was working fine till friday morning. please help, we are seeing this issue in all our dev and prod bots. Please help us.

Hi @laxmanj8666 - I'd suggest you first file a new issue with your problem. That way, it will be triaged promptly and looked into.

In your issue, please include more information than in this message. SDK language? SDK version you are using? How exactly do you reproduce the issue? What channel? If we can reproduce the issue ourselves itwill be much easier to help you.

Also, did you deploy something on Friday or make changes to your bot, or did this happen without changes on your side?

Please include all of this in a new issue. When you create one, there will be a template that will ask this kind of information. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jschristophe picture jschristophe  路  3Comments

akakoychenko picture akakoychenko  路  3Comments

mattlanham picture mattlanham  路  3Comments

daveta picture daveta  路  3Comments

Vigneshramkumar picture Vigneshramkumar  路  3Comments