在 watson 助手上使用第三方 api
using third party api on watson assistant
我在终端上部署之前使用 open weather map api in order to get information on the current weather and then integrate it with watson assistant (i used this as a reference 作为 watson 助手代码)。这是我的代码:
var city = "Seattle";
weather.setCity(city);
function processResponse(err, response){
if(err){
console.log(err);
return;
}
var endConversation = false;
if(response.intents[0]){
if(response.intents[0].intent=="CurrentWeather"){
weather.getDescription(function(err, desc){
weather.getTemperature(function(err, temp){
console.log("It is " + desc + " today with a temperature of " + temp + " degrees Celsius.");
)};
)};
}
else if(response.intents[0].intent=="end_conversation"){
console.log(response.output.text);
endConversation = true;
}
}
if(!endConversation){
var newMessageFromUser = prompt(">> ");
service.message({
workspace_id: workspace_id,
input: {
text: newMessageFromUser
},
context: response.context
},processResponse);
}
}
有效,但响应如下所示:
>> what is the weather today in seattle
>>
It is few clouds today with a temperature of 29 degrees Celsius.
>> bye
['See ya!']
每当我使用任何第三方 api 时,终端不会在我输入触发器关键字后立即响应,而是要求我输入另一个条目(在上面的场景中,我什么也没输入)然后再响应。但是,当我尝试输入与意图相关的关键字时,其响应会立即从 watson 助手中检索到(与 end_conversation 一样),终端会立即响应。
有没有办法强制终端只询问一次?
有多种方法可以避免在实际响应之前输入内容。
看看client-based dialog actions. The key is to use the skip_user_input
flag and check it within your application. Basically, it would indicate to your application that you need to process some data. The app would it send back to Watson Assistant to respond. There is also the server-based dialog action. In that case Watson Assistant is invoking an IBM Cloud Functions action. A tutorial using that approach is here, interfacing with a Db2 database。
另一种技术就是我所说的replaced markers。您会让 Watson Assistant returns 得到一个带占位符的答案。您的应用将替换这些标记。
第三,您正在使用 JavaScript 进行异步处理。似乎在您获取天气数据时处理了您的空提示。天气的 IF 独立于空提示。尝试解决这个问题。
关注 , I tried implementing the third party API in cloud function and it worked. simply created a php function using the php implementation of the openweather map api and followed the steps on how to create an action in php through this tutorial. for the implementation, i followed this tutorial 如何在 watson 助手中执行操作。即使直接从 watson 助手旁边的聊天机器人调用,它现在也能正常工作。
它 returns 的响应示例是:
{"weather":"It is raining today in Seattle with a temperature of 15 degrees Celsius"}
我在终端上部署之前使用 open weather map api in order to get information on the current weather and then integrate it with watson assistant (i used this as a reference 作为 watson 助手代码)。这是我的代码:
var city = "Seattle";
weather.setCity(city);
function processResponse(err, response){
if(err){
console.log(err);
return;
}
var endConversation = false;
if(response.intents[0]){
if(response.intents[0].intent=="CurrentWeather"){
weather.getDescription(function(err, desc){
weather.getTemperature(function(err, temp){
console.log("It is " + desc + " today with a temperature of " + temp + " degrees Celsius.");
)};
)};
}
else if(response.intents[0].intent=="end_conversation"){
console.log(response.output.text);
endConversation = true;
}
}
if(!endConversation){
var newMessageFromUser = prompt(">> ");
service.message({
workspace_id: workspace_id,
input: {
text: newMessageFromUser
},
context: response.context
},processResponse);
}
}
有效,但响应如下所示:
>> what is the weather today in seattle
>>
It is few clouds today with a temperature of 29 degrees Celsius.
>> bye
['See ya!']
每当我使用任何第三方 api 时,终端不会在我输入触发器关键字后立即响应,而是要求我输入另一个条目(在上面的场景中,我什么也没输入)然后再响应。但是,当我尝试输入与意图相关的关键字时,其响应会立即从 watson 助手中检索到(与 end_conversation 一样),终端会立即响应。
有没有办法强制终端只询问一次?
有多种方法可以避免在实际响应之前输入内容。
看看client-based dialog actions. The key is to use the skip_user_input
flag and check it within your application. Basically, it would indicate to your application that you need to process some data. The app would it send back to Watson Assistant to respond. There is also the server-based dialog action. In that case Watson Assistant is invoking an IBM Cloud Functions action. A tutorial using that approach is here, interfacing with a Db2 database。
另一种技术就是我所说的replaced markers。您会让 Watson Assistant returns 得到一个带占位符的答案。您的应用将替换这些标记。
第三,您正在使用 JavaScript 进行异步处理。似乎在您获取天气数据时处理了您的空提示。天气的 IF 独立于空提示。尝试解决这个问题。
关注
它 returns 的响应示例是:
{"weather":"It is raining today in Seattle with a temperature of 15 degrees Celsius"}