reactjs - 如何在 ReactJS 中使用 react-simple-chatbot 制作聊天机器人组件
问题描述
我正在尝试使用react-simple-chatbot库在动态 ReactJS 中制作 React-Simple-Chatbot 组件。
我想要做的是在步骤数组中动态设置消息属性。
任何有关如何最好地做到这一点的建议将不胜感激。
这是代码片段:
import React from "react";
import ChatBot from "react-simple-chatbot";
function CustomChatbot(props) {
const steps = [{
id: "Greet",
message: props.data,
trigger: "Ask Name"
},
{
id: "Ask Name",
message: "Please type your name?",
trigger: "Waiting user input for name"
},
{
id: "Waiting user input for name",
user: true,
//trigger: "Asking options to eat"
trigger: (input) => {
props.eventHandler(input.value);
return "Asking options to eat"
}
},
{
id: "Asking options to eat",
message: "Hi {previousValue}, Please click on what you want to buy...?",
trigger: "Displaying options to eat"
},
{
id: "Displaying options to eat",
options: [{
value: "pizza",
label: "Jeans",
trigger: "Asking for Tomatoes in Pizza"
},
{
value: "burger",
label: "Jacket",
trigger: "Burger Not available"
}
]
},
{
id: "Burger Not available",
message: "Sorry, We don't have burger available at the moment. Would you like to try our pizza?",
trigger: "Asking for pizza after burger"
},
{
id: "Asking for pizza after burger",
options: [{
value: true,
label: "Yes",
trigger: "Asking for Tomatoes in Pizza"
},
{
value: "false",
label: "No",
trigger: "Done"
}
]
}
]
return (<ChatBot steps={steps} {...config} />);
}
export default CustomChatbot;
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
解决方案
推荐阅读
- twilio-api - 如何获取加入 Twilio 的 whatsapp 沙箱的参与者列表
- c++ - 析构函数c ++后的分段错误
- python - 在 Windows 10 上的 Pycharm 中安装 Openpyxl 包时出现 TLS/SSL 错误
- swift - 如何根据 UI 对象确定结构的返回值
- haskell - 我的 Haskell 代码中的缩进/布局错误在哪里?
- ios - 如果单击特定的 CollectionViewCell 做某事
- r - 在R中使用正则表达式删除字符串中的特定子字符串
- python - python中字符串的比较(从文件中读取)不起作用
- java - SQL Developer V19 - 从连接 XML 中解密密码
- java - Java使用最低有效位从int数组返回字符串