设置 Watson Dialog 配置文件变量时遇到问题

Trouble setting Watson Dialog profile variables

我正在尝试通过 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":[{"name":"CPE_Name","value":"Tracey Moon"},{"name":"CPE_Name","value":"Kellogg"},{ "name":"CPE_StateTerritory","value":"California"}]}

这是 watson-developer-cloud 库中的错误吗?enter code here

在这里大摇大摆的文档:
https://watson-api-explorer.mybluemix.net/swagger.html?url=/listings/dialog-v1.json#/

我会达到以下终点:
https://gateway.watsonplatform.net/dialog/api/v1/dialogs/7eb167d5-f581-40d3-b91a-ad9c142282ad/profile

正文中包含以下内容:
{ "client_id": 155351, "name_values": [ { "name": "Name", "value": "Mitch" } ] }

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

上面的代码对我有用。希望对您有所帮助!

这个问题显然是早期版本的 watson-developer-cloud 包中的错误。 运行 npm install watson-developer-cloud@latestthis post 中所述似乎已解决问题。