Reputation: 41
I developed my chatbot using c# and bot framework sdk v4. I connected it to my webpage using react js by passing directline token. But now when i Minimize the chat and then maximize it the chat stops the flow and gets restarted. But the old messages are still there. I doesn't need to restart the flow when minimized. My reactjs implementation code is given below.
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
}));
}
inside render
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"}
/>
Please help me in resolving the issue. Thanks in advance.
Upvotes: 0
Views: 298
Reputation: 6383
Check out this solution 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 for visual reference.
Upvotes: 1