- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我从 botpress 调用一个 api,它返回我需要在我的自定义组件中显示的对象列表,但我总是将它作为字符串 InfaLinkPreview.jsx: "[object Object]"
如果我使用 console.log(JSON.parse(this.contentArray))
我得到下面的异常
Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at eval (eval at render (VM449 lite.bundle.js:10992), <anonymous>:1:18)
at InfaLinkPreview.render (VM449 lite.bundle.js:10992)
at finishClassComponent (react-dom.development.js:14741)
at updateClassComponent (react-dom.development.js:14696)
at beginWork (react-dom.development.js:15644)
at performUnitOfWork (react-dom.development.js:19312)
at workLoop (react-dom.development.js:19352)
at renderRoot (react-dom.development.js:19435)
at performWorkOnRoot (react-dom.development.js:20342)
at performWork (react-dom.development.js:20254)
at performSyncWork (react-dom.development.js:20228)
at requestWork (react-dom.development.js:20097)
at scheduleWork (react-dom.development.js:19911)
at Object.enqueueSetState (react-dom.development.js:11169)
at Web.push../node_modules/react/cjs/react.development.js.Component.setState (react.development.js:335)
看来我在自定义组件中遗漏了一些东西。
显示 session.response 的服务器调用 api Node 和 Infa 链接预览 Node 屏幕截图
botpress 模拟器屏幕截图显示了 session.response 的值 modules\custom-component\src\content-types\infa-link-preview.js
const base = require('./_base');
function render(data) {
const events = [];
return [{
type: 'custom',
module: 'custom-component',
component: 'InfaLinkPreview',
text: data.text
}]
}
function renderElement(data, channel) {
if (channel === 'web' || channel === 'api') {
return render(data);
}
return []; // TODO
}
module.exports = {
id: 'custom_linkpreview',
group: 'Custom Component',
title: 'Infa Link Preview',
jsonSchema: {
description: 'Displays content of an array of KB/Docs/Video links',
type: 'object',
required: ['text'],
properties: {
text: {
type: 'string',
title: 'Message'
},
variations: {
type: 'array',
title: 'Alternates (optional)',
items: {
type: 'string',
default: ''
}
},
...base.typingIndicators
}
},
uiSchema: {
text: {
'ui:field': 'i18n_field',
$subtype: 'textarea'
},
variations: {
'ui:options': {
orderable: false
}
}
},
computePreviewText: formData => 'Infa Link Preview: ' + formData.text,
renderElement: renderElement
}
modules\custom-component\src\views\lite\components\InfaLinkPreview.jsx
export class InfaLinkPreview extends React.Component {
noAnswer = "Sorry no answer found."
contentArray = this.props.text
getTimestamp = () => {
let date = new Date();
let options = {
month: "short",
day: "numeric", hour: "2-digit", minute: "2-digit"
};
return date.toLocaleTimeString("en-us", options);
}
render() {
console.log("InfaLinkPreview.jsx: " + JSON.stringify(this.contentArray));
if (this.contentArray[0].query_status == "answer_available") {
return (
<div className="linkPreviewMain">
<p className="linkPreviewTitle"><b>{this.contentArray[0].answer[1].title}</b></p>
<p className="linkPreviewDesc">{this.contentArray[0].answer[1].content}</p>
<small className="linkPreviewTimestamp">{this.getTimestamp()}</small>
</div>
)
} else {
return (
<div className="infaTextMain">
<p className="infaTextMessage">{this.noAnswer}</p>
<small className="infaTextTimestamp">{this.getTimestamp()}</small>
</div>
)
}
}
}
注意:使用botpress v11.9.5
更新 网络响应.. 在这个 JSON 中 session.response 是正确的,但是 responses.text 作为 [object Object ]
。因此,在向 InfaLinkPreview 组件提供 session.response 时,不知何故,这是错误的。
请帮我弄清楚 infa-link-preview.js
或 InfaLinkPreview.jsx
文件出了什么问题。
{
"responses": [{
"type": "custom",
"module": "custom-component",
"component": "InfaLinkPreview",
"text": "[object Object]"
}
],
"nlu": {
"entities": [],
"language": "en",
"slots": {},
"intent": {
"name": "none",
"confidence": 1,
"context": "global"
},
"intents": [{
"name": "none",
"confidence": 1,
"context": "global"
}
],
"errored": false,
"includedContexts": ["global"],
"ms": 738
},
"suggestions": [],
"state": {
"user": {},
"context": {},
"session": {
"lastMessages": [{
"eventId": "156183685440297440",
"incomingPreview": "hii",
"replyConfidence": 1,
"replySource": "dialogManager",
"replyDate": "2019-06-29T19:34:17.244Z",
"replyPreview": "#!custom_infatext--mgyiK"
}, {
"eventId": "156183685440297440",
"incomingPreview": "hii",
"replyConfidence": 1,
"replySource": "dialogManager",
"replyDate": "2019-06-29T19:34:17.260Z",
"replyPreview": "#!builtin_single-choice-FxG4EN"
}, {
"eventId": "156183686163322750",
"incomingPreview": "No",
"replyConfidence": 1,
"replySource": "dialogManager",
"replyDate": "2019-06-29T19:34:24.103Z",
"replyPreview": "#!custom_infatext-ZSUgWA"
}, {
"eventId": "156183686163322750",
"incomingPreview": "No",
"replyConfidence": 1,
"replySource": "dialogManager",
"replyDate": "2019-06-29T19:34:24.106Z",
"replyPreview": "#!custom_infatext-bO33uu"
}, {
"eventId": "156183688271887300",
"incomingPreview": "How to install secure agent on linux?",
"replyConfidence": 1,
"replySource": "dialogManager",
"replyDate": "2019-06-29T19:34:47.378Z",
"replyPreview": "#!custom_linkpreview-Zple6W"
}
],
"extractedSlots": {},
"response": [{
"answer": {
"1": {
"content": "this article provides details on how the nnn secure\nagent can be installed on linux the steps are as follows 1 log on to your\nnnn org and download the linux secure agent installer agent64_install bin 2 log on to linux server as non root user and create a directory the secure agent will be\ninstalled in this directory for example in our environment we logged on\nto linux machine as a non root user admin\nand created a directory mylinuxagent 3 copy the downloaded agent installer file to the linux server\nand run agent64_install bin as shown in the following screenshots 4 once the installation is complete navigate to mylinuxagent apps agentcore directory and start the secure agent using the command infaagent\nstartup 5 now run the command consoleagentmanager sh\n getstatus to get information on the status of the secure agent 6 the above screenshot indicates that the secure agent needs to be registered with your\nnnn org run consoleagentmanager sh configure and enter your nnn org username and password admin aaaa agentcore consoleagentmanager sh configure test nnn com test123\njava_home data admin mylinuxagent apps agentcore jre\nlogin succeeds admin aaaa agentcore consoleagentmanager sh isconfigured\njava_home data admin mylinuxagent apps agentcore jre\ntrue 7 using the commands shown in step 6 above the secure agent should get registered with your nnn org check the status of the secure agent a couple of times\nusing consoleagentmanager sh getstatus after some time the status should get changed to ready which indicates that\nthe secure agent has been installed successfully and is fully up and running 8 login to your nnn org configure runtime environments and click on the linux secure agent the process server\nand the data integration server should be up and running one thing to note is that in the above screenshot the\nprocess server component of the secure agent will be available only if your nnn org is licensed for\nnnn cloud realtime icrt",
"source": "KB",
"title": "Install nnn Secure Agent on Linux",
"url": "https://kb.nnn.com/howto/6/Pages/20/513826.aspx"
},
"2": {
"content": "silent install to specified target location can be done by using the following command agent64_install bin i silent duser_install_dir target directory ",
"source": "KB",
"title": "Install a Linux secure agent in a specified location using Silent install",
"url": "https://ncom/howto/6/Pages/19/5094.aspx"
},
"3": {
"actual_title": "Install and register the Secure Agent on Linux",
"content": "",
"name": {
"NERAction": ["install", "register"],
"NERComponent": ["secure_agent"],
"NEROS": ["linux"]
},
"source": "DOC",
"title": "Install and register the Secure Agent on Linux",
"url": "https://n/install-and-register-the-secure-agent-on-linux.html"
}
},
"query_status": "answer_available"
}
]
},
"temp": {}
},
"decision": {
"decision": {
"reason": "no suggestion matched",
"status": "elected"
},
"confidence": 1,
"payloads": [],
"source": "decisionEngine",
"sourceDetails": "execute default flow"
}
}
最佳答案
尝试以下 2 个更改,它应该可以工作
{
type: 'custom',
module: 'custom-component',
component: 'InfaLinkPreview',
text: data.text,
response: {
data
}
}
和
contentArray = JSON.parse(this.props.response.data.session.response)
关于javascript - 如何在 botpress 自定义组件中获取 json 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56819726/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!