Chatbot 重新启动关于最小化的对话
Chatbot restarts conversation on minimizing
我使用 c# 和机器人框架 sdk v4 开发了我的聊天机器人。我通过传递直线令牌使用 react js 将它连接到我的网页。但是现在当我最小化聊天然后最大化它时,聊天会停止并重新启动。但旧消息仍然存在。最小化时我不需要重新启动流程。下面给出我的reactjs实现代码
const store = createStore({}, () => next => action => {
if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
if (action.payload.activity.from.role === 'bot') {
this.setState(() => ({ newMessage: true }));
}
}
return next(action);
});
this.state = {
minimized: true,
newMessage: false,
side: 'right',
store,
styleSet: createStyleSet({
backgroundColor: 'Transparent'
}),
token: null
};
}
async handleFetchToken() {
if (!this.state.token) {
const res = <ReactWebChat directLine={ this.directLine } />
console.log(res)
// const { token } = await res.json();
// this.setState(() => ({ token }));
}
}
handleMaximizeButtonClick() {
this.setState(() => ({
minimized: false,
newMessage: false,
}));
}
handleMinimizeButtonClick() {
this.setState(() => ({
minimized: true,
newMessage: false
}));
}
内部渲染
render() {
const {
state: { minimized, newMessage, side, store, styleSet, token }
} = this;
<WebChat
className="react-web-chat"
// onFetchToken={this.handleFetchToken}
store={store}
styleSet={styleSet}
token={"my_token_here"}
/>
请帮我解决这个问题。提前致谢。
查看 I posted explaining how to make a basic local token server. Enabling CORS here only applies if you are running purely local. If you are tunneling via ngrok to Azure Bot Service, then you will need to make changes either on your bot's DirectLine Channel or on the App Service. View this image post 以供视觉参考。
我使用 c# 和机器人框架 sdk v4 开发了我的聊天机器人。我通过传递直线令牌使用 react js 将它连接到我的网页。但是现在当我最小化聊天然后最大化它时,聊天会停止并重新启动。但旧消息仍然存在。最小化时我不需要重新启动流程。下面给出我的reactjs实现代码
const store = createStore({}, () => next => action => {
if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
if (action.payload.activity.from.role === 'bot') {
this.setState(() => ({ newMessage: true }));
}
}
return next(action);
});
this.state = {
minimized: true,
newMessage: false,
side: 'right',
store,
styleSet: createStyleSet({
backgroundColor: 'Transparent'
}),
token: null
};
}
async handleFetchToken() {
if (!this.state.token) {
const res = <ReactWebChat directLine={ this.directLine } />
console.log(res)
// const { token } = await res.json();
// this.setState(() => ({ token }));
}
}
handleMaximizeButtonClick() {
this.setState(() => ({
minimized: false,
newMessage: false,
}));
}
handleMinimizeButtonClick() {
this.setState(() => ({
minimized: true,
newMessage: false
}));
}
内部渲染
render() {
const {
state: { minimized, newMessage, side, store, styleSet, token }
} = this;
<WebChat
className="react-web-chat"
// onFetchToken={this.handleFetchToken}
store={store}
styleSet={styleSet}
token={"my_token_here"}
/>
请帮我解决这个问题。提前致谢。
查看