gpt4 book ai didi

node.js - 如何发现我的机器人出了什么问题

转载 作者:太空宇宙 更新时间:2023-11-03 23:03:51 26 4
gpt4 key购买 nike

我一直在学习机器人框架教程并编写了以下代码。

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 });
}
]);

当我运行此程序时,机器人正如预期的那样询问我的姓名和公司。我输入了详细信息,但最后它给出了以下错误。

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)

我尝试使用 console.log 打印 json,响应是正确的,给了我这样的回复

name : userName
company : userCompany

我哪里出了问题,如何解决这个问题?

最佳答案

根据 sprintf docs 中的示例,似乎你必须使用类型说明符,即 %(key) 应该是 %(key)s:

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

关于node.js - 如何发现我的机器人出了什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41034342/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com