【发布时间】:2020-05-30 02:13:39
【问题描述】:
我正在尝试使用 react js 在我的机器人框架网络聊天 (v-4) 中添加自动建议/自动完成功能。我想从天蓝色表中获取输入数据。听说不建议在 React js 中使用 j-query。寻找解决方案来添加这个。
我正在寻找如下图所示的解决方案,即 PFA。 我用于 React 的代码附在下面,
React.js file
import React from 'react';
import { DirectLine, ConnectionStatus } from 'botframework-directlinejs';
import ReactWebChat from 'botframework-webchat';
import './ChatComponent.css';
export default class extends React.Component {
constructor(props) {
super(props);
this.state = {
token: '',
conversationId:'',
directLine: {},
view: false,
feedBack: null,
value: '',
popupContent: '',
storeValue:''
};
this.handleTokenGeneration = this.handleTokenGeneration.bind(this);
this.handleChange = this.handleChange.bind(this);
}
handleTokenGeneration = async () => {
console.log("handleTokenGeneration");
const response = await fetch(`api/TokenGenerationService/GetToken`);
const data = await response.json();
this.setState({ token: data.categoryObject.token, conversationId: data.categoryObject.conversationId });
console.log("conversationId");
};
async componentDidMount() {
try {
await this.handleTokenGeneration();
} catch (error) {
console.log("error in fetchung token");
console.log(error);
}
this.state.directLine = new DirectLine({ token: this.state.token });
this.setState({ view: true });
}
handleChange = (event) => {
this.setState({ value: event.target.value });
}
render() {
if (!this.state.view) {
return <div />
} else {
return (
<div className="react-container webchat" >
<ReactWebChat directLine={this.state.directLine} webSocket={true} userID='2656' username='res' store={this.state.storeValue} />
<footer className="chat-footer" >
<div className="foot-footer">
Was I helpful ?
<span className="feedback" >Yes</span><span>|</span><span className="feedback" >No</span>
</div>
</footer>
</div>
);
}
}
}
【问题讨论】:
-
您可能有兴趣阅读this thread。它在 Web Chat v4 发布之前就开始了,但它仍然具有相关性。听起来您对正常建议的操作有太多数据,而且您也不想依赖移动操作系统的内置自动完成功能。您是否正在寻找一个专门用于从 Azure 表中提取建议的解决方案,或者您是否想要更通用的解决方案,例如可以通过从 QnA Maker 中提取问题来工作,例如线程描述的?
-
@KyleDelaney 您好,感谢您的回复。我已经阅读了关于自动建议的那篇文章,但它没有帮助。我正在使用 bot framework v.4 使用 react js 构建一个聊天应用程序,我现在想要的只是在聊天输入区域中完成按键操作时从 azure 获取数据。我在我的项目的先前版本中使用 J-query 做到了这一点,但是由于我现在使用的是 react js,所以我想在 react 中编写它。
-
我的回答可以接受吗?
-
@KyleDelaney 这对我的问题没有帮助,但它以另一种方式有所帮助,我正在努力解决这个问题。完成后一定会通知您。
-
您能解释一下为什么我的回答对您的问题没有帮助吗?如果除了您在此处提出的问题之外,您还有其他问题,您是否会考虑接受我的回答并提出一个新问题,其中包含有关您需要什么的具体细节?
标签: reactjs .net-core autocomplete botframework