6
votes

I'm trying to use MS botframework V3 to create a basic bot using the nodejs tutorial code, but I keep getting 401 Unauthorized using the emulator. Please help?

AppId / Secret are set in env variables and definitely correct in emulator.

Code below

var restify = require('restify');
var builder = require('botbuilder');

//=========================================================
// Bot Setup
//=========================================================

// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
   console.log('%s listening to %s', server.name, server.url); 
});

// Create chat bot
var connector = new builder.ChatConnector({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());

//=========================================================
// Bots Dialogs
//=========================================================

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

3 Answers

7
votes

try changing the appId and appSecret to MicrosoftAppId and MicrosoftAppPassword respectively

As stated on botframework website

In V1, the authentication properties were stored with these keys:

  • AppId
  • AppSecret

In V3, to reflect changes to the underlying auth model, these keys have been changed to:

  • MicrosoftAppId
  • MicrosoftAppPassword

Edit: So, from a post on github by Steven the actual values are

  • appId

  • appPassword

    These values won't work with the emulator due to an issue with node sdk however they should work when deployed.

Link: https://github.com/Microsoft/BotBuilder/issues/625

2
votes

While using the emulator for the first time, i was giving an appid and password on my own. I learnt that no app id and no password also works fine in local.

:Removing the appid and password in the web.config in the bot application and in the emulator resolved my error. Hope it helps. Cheers!

0
votes

I am having the same the issue, but I can get the above solution to work. It appears to suggest, you can put in any values for id and pw. If they are not found, then authorization is turned off? Is this correct? I tried this

var connector = new builder.ChatConnector({appId:'999', appPassword: 'xxxx'});

And I still get a 401.