简体   繁体   中英

Chatbot restarts conversation on minimizing

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM