我正在尝试通过watson-developer-cloud库更新一些Dialog配置文件变量。 client_id变量似乎被忽略,并被设置为随机数。因此,未设置配置文件变量。这是我的API中应该进行更新的端点:
app.put('/update', function(req, res)
{
setHeaders(req,res); //set up headers for CORS
var parms=req.body;
parms.dialog_id=dialogId;
console.log("Processing PUT /update...");
console.log("Setting: ",parms);
dialog.updateProfile(parms,function(err, results)
{
if (err)
{
console.log(err);
res.status(500);
res.send(err);
}
else
{
console.log('Update returning: ',results);
res.send(results);
}
});
});
这是parms的示例值(在JSON.stringify(parms)之后显示:
{ “CLIENT_ID”:12345 “dialog_id”: “4a6e3699-10ab-4703-86bb-0b74384aaf94”, “conversation_id”:245895 “name_values”:[{ “名称”: “CPE_Name”, “值”: “Tracey Moon”},{“name”:“CPE_Name”,“value”:“Kellogg”},{“name”:“CPE_StateTerritory”,“value”:“California”}}}
这是watson-developer-cloud库中的错误吗?enter code here
答案 0 :(得分:1)
在这里摆脱招摇文件:
https://watson-api-explorer.mybluemix.net/swagger.html?url=/listings/dialog-v1.json#/
身体中有以下内容:
{
" client_id":155351,
" name_values":[
{
" name":" Name",
"价值":" Mitch"
}
]
}
答案 1 :(得分:1)
Here's a code snippet which does the getConversation to get a client id and then an updateProfile to set a profile var:
var watson = require('watson-developer-cloud');
var dialogid = <dialog_id>;
var clientid = '';
var dialog = watson.dialog({
username: <username>,
password: <password>,
version: 'v1'
});
dialog.conversation({dialog_id: dialogid}, function (err, dialogs) {
if (err)
console.log('error:', err);
else{
console.log('Started conversation with dialog id ' + dialogid + '.');
console.log(JSON.stringify(dialogs, null, 2));
clientid = dialogs.client_id;
}
});
dialog.updateProfile({ client_id: clientid, dialog_id: dialogid, name_values: [{"name":"Topic","value":"Education"}]}, function (err, dialogs) {
if (err)
console.log('error:', err);
else{
console.log('Set profile variable "Topic" to "Education".');
console.log(JSON.stringify(dialogs, null, 2));
}
});
以上代码适合我。希望它有所帮助!
答案 2 :(得分:0)
问题显然是早期版本的watson-developer-cloud软件包中的一个错误。运行
this post中描述的npm install watson-developer-cloud@latest
似乎解决了这个问题。