javascript - 根据 Watson Assistant 上下文自动加载网页
问题描述
我正在尝试让应用程序根据 Watson Assistant 对话中的上下文来编排特定的网页。
我使用的文件是对 github ( https://github.com/watson-developer-cloud/assistant-intermediate ) 上的 Watson Assistant(中间)示例文件的编辑。
这是我为使其工作而编辑的代码片段(在 api.js 中):
var http = new XMLHttpRequest();
http.open('POST', messageEndpoint, true);
http.setRequestHeader('Content-type', 'application/json');
http.onreadystatechange = function() {
if (http.readyState === 4 && http.status === 200 && http.responseText) {
Api.setResponsePayload(http.responseText);
var json = JSON.parse(http.responseText);
context = json.context;
if(json.context.action === 'SocialMedia') {
document.getElementById("payload-column").setAttribute("style", "background-color: #ffffff;") //renders background white as without this line the webpage comes back with black hidden text for some reason
document.getElementById("payload-column").setAttribute("src", "https://www.csc2.ncsu.edu/faculty/healey/tweet_viz/tweet_app/?q=" + json.context.AnalysisSearchItem);
}
Watson Assistant 工作区中的相应配置是:
{
"context": {
"action": "SocialMedia"
},
"output": {
"text": {
"values": [
"Loading sentiment analysis from the Computer Science department of North Carolina State University..."
],
"selection_policy": "sequential"
}
}
}
当正常的聊天机器人对话正常工作时,我已连接到 Watson Assistant 工作区,并且
document.getElementById("payload-column").setAttribute("src", "https://www.csc2.ncsu.edu/faculty/healey/tweet_viz/tweet_app/?q=" + json.context.AnalysisSearchItem);
行本身确实将 iframe 更改为我想要的网站(我在 index.html 文件中定义了一个 iframe),它只是 IF 条件
if(json.context.action === 'SocialMedia')
当上下文属于 SocialMedia 时,不会成功执行。
如果有人能帮助解决这个问题,将不胜感激......!
解决方案
推荐阅读
- sql - 我应该如何创建关系模式才能在 oracle 数据库中“加入”?我需要将哪些列与哪个键关联?
- javascript - React JS,道具验证
- python - SQL 一对多关系 - 以 JSON 格式检索数据的查询
- r - 根据条件复杂的另一行调整数据框行
- node.js - 我对 react.js 中的 state.map 有问题,没有显示数据
- android - 在颤振飞镖中,我必须为包和应用程序 ID 添加相同的名称
- mysql - 查询根据条件返回值
- mysql - JSON_Extract 错误:函数 json_extract 的参数 1 中的 JSON 文本无效:“缺少对象成员的名称。”
- javascript - 为什么我的滚动顶部功能会根据我的位置滚动到页面的不同部分,仅在移动设备上?
- spring-boot - 在客户端通过 STOMP 发送大消息失败