abi*_*964 6 javascript css chatbot reactjs botpress
我正在尝试将时间戳添加到botpress聊天的每个对话框中。到目前为止,我已经可以在bot的对话框中添加此时间戳,但是我需要一些指针来将其添加到用户的对话框和选择技巧中。
export class InfaText extends React.Component {
message = 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() {
return (<div className="infaTextMain">
<p className="infaTextMessage">{this.message}</p>
<small className="infaTextTimestamp">{this.getTimestamp()}</small>
</div>)
}
}
Run Code Online (Sandbox Code Playgroud)
注意:Botpress v11.9.5
另外,是否有一种通用方法可以向所有对话框添加时间戳? 更新资料
我完全按照@eff_it的说法
我复制MessageWrapper&MySuperOverride功能modules\infa-module\src\views\lite\index.jsx

然后在modules\channel-web\src\views\full\index.tsx文件覆盖下的代码段下方添加
{
module: 'infa-module',
component: 'MySuperOverride'
}
Run Code Online (Sandbox Code Playgroud)
仍然没有效果,@ eff_it请看一看并建议这里缺少什么?
你试过BP 12吗?定制组件现在更容易实现。
您可以使用 botpressWebchat 存储来包装每条消息setMessageWrapper,但要做到这一点,您需要在使用另一个自定义组件初始化 Webchat 时使用 overrides 属性(该组件不会呈现任何内容,但会使用 Webchat 存储)。这是一个示例views/lite/index.jsx
export const MessageWrapper = props => (
<div>
<p style={{ color: 'blue' }}>sent on: {new Date(props.sentOn).toDateString()}</p>
<div style={{ background: 'black', color: 'white' }}>{props.children}</div>
</div>
)
export const MySuperOverride = props => {
props.store.setMessageWrapper({ module: 'yourModule', component: 'MessageWrapper' })
return null
}
Run Code Online (Sandbox Code Playgroud)
然后,当您初始化 botpressWebchat 时,您可以简单地使用覆盖 api,如下所示
window.botpressWebChat.init({
overrides: {
before_container: {
module: 'yourModule',
component: 'MySuperOverride'
}
}
})
Run Code Online (Sandbox Code Playgroud)
请参阅文档,有有关自定义组件和自定义模块的更多信息。这是最终的渲染结果:
| 归档时间: |
|
| 查看次数: |
248 次 |
| 最近记录: |