Rakesh
Rakesh

Reputation: 594

How to discover what is wrong with my bot

I've been going through a bot framework tutorial and made the below code.

var builder = require('botbuilder');
var restify = require('restify');
//Create Connector
var connector = new builder.ChatConnector(
    {
        appId: process.env.MICROSOFT_APP_ID,
        appPassword: process.env.MICROSOFT_APP_PASSWORD
    }
);

//Create bot with Connector
var bot = new builder.UniversalBot(connector);



//Restify
//Create a server

var server = restify.createServer();

//listen to server
server.listen(process.env.port || process.env.PORT || 33333, function () {
    console.log('%s listening to URL %s', server.name, server.url);
});

server.post('/api/messages', connector.listen());

bot.dialog('/', [function (session) {
    session.beginDialog('/ensureProfile', session.userData.profile);
}, function (session, result) {
    session.userData.profile = result.response;
    console.log(result.response);
    session.send("I'm %(name) and my org is %(company)", session.userData.profile);
}]);


bot.dialog('/ensureProfile', [function (session, args, next) {
    session.dialogData.profile = args || {};
    if (!session.dialogData.profile.name) {
        builder.Prompts.text(session, "enter you name");
    }
    else {
        next();
    }
}, function (session, result, next) {
    if (result.response) {
        session.dialogData.profile.name = result.response;
        console.log(result.response + " is user name");
    }
    if (!session.dialogData.profile.company) {
        builder.Prompts.text(session, "Enter your company");
    }
    else {
        next();
    }
},
function (session, result) {
    if (result.response) {
        session.dialogData.profile.company = result.response;
        console.log(result.response + " is user name");
    }
    session.endDialogWithResult({ response: session.dialogData.profile });
}
]);

When I run this, the bot, as expected is asking for my name and company. And I enter the details, but at the end it is giving me the below error.

session.sendBatch() sending 1 messages
SyntaxError: [sprintf] unexpected placeholder
    at Function.sprintf.parse (C:\Users\user\Desktop\Node Tutorial\node_modules\sprintf-js\src\sprintf.js:164
:23)
    at sprintf (C:\Users\user\Desktop\Node Tutorial\node_modules\sprintf-js\src\sprintf.js:19:34)
    at Object.vsprintf (C:\Users\user\Desktop\Node Tutorial\node_modules\sprintf-js\src\sprintf.js:174:24)
    at fmtText (C:\Users\user\Desktop\Node Tutorial\node_modules\botbuilder\lib\Message.js:261:46)
    at Message.text (C:\Users\user\Desktop\Node Tutorial\node_modules\botbuilder\lib\Message.js:49:33)
    at Session.createMessage (C:\Users\user\Desktop\Node Tutorial\node_modules\botbuilder\lib\Session.js:401:
36)
    at Session.send (C:\Users\user\Desktop\Node Tutorial\node_modules\botbuilder\lib\Session.js:144:26)
    at Array.<anonymous> (C:\Users\user\Desktop\Node Tutorial\sample.js:33:13)
    at SimpleDialog.waterfallAction [as fn] (C:\Users\user\Desktop\Node Tutorial\node_modules\botbuilder\lib\
dialogs\DialogAction.js:117:32)
    at SimpleDialog.dialogResumed (C:\Users\user\Desktop\Node Tutorial\node_modules\botbuilder\lib\dialogs\Si
mpleDialog.js:21:14)

I tried to print the json using console.log and the response is correct giving me a reply like

name : userName
company : userCompany

Where am I going wrong and how can I fix this?

Upvotes: 2

Views: 760

Answers (1)

idmitme
idmitme

Reputation: 929

According to examples in sprintf docs, seems you have to use type specifier, i.e. instead of %(key) should be %(key)s:

session.send("I'm %(name)s and my org is %(company)s", session.userData.profile)

Upvotes: 5

Related Questions