Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate Resetting Store for Restart Conversation #1846

Closed
kunal7898 opened this issue Mar 26, 2019 · 9 comments
Closed

Investigate Resetting Store for Restart Conversation #1846

kunal7898 opened this issue Mar 26, 2019 · 9 comments
Assignees
Labels
blocked currently prevented from making progress bug Indicates an unexpected problem or an unintended behavior. external-others front-burner p0 Must Fix. Release-blocker

Comments

@kunal7898
Copy link

Hi,

How to add support for restart conversation in webchat(React).

I have requirment where user can click on clear button then all the conversation should delete and
new conversatoin will start.

@corinagum corinagum reopened this Mar 26, 2019
@corinagum
Copy link
Contributor

@kunal7898 - reopening this issue, sorry for the confusion!

We are concerned there may be a bug on resetting the store in Web Chat, which would prevent users from implementing their own restart button. I am reopening this bug and changing the criteria to track investigation of the store issue.

Thanks for filing!

@corinagum corinagum changed the title Restart Conversation Webchat Investigate Resetting Store for Restart Conversation Webchat Mar 26, 2019
@corinagum corinagum added 4.0 needs-repro Waiting for repro or investigation and removed 4.0 labels Mar 26, 2019
@corinagum corinagum changed the title Investigate Resetting Store for Restart Conversation Webchat Investigate Resetting Store for Restart Conversation Mar 26, 2019
@corinagum corinagum added bug Indicates an unexpected problem or an unintended behavior. Pending labels Mar 26, 2019
@corinagum corinagum added 4.5 and removed Pending labels Apr 1, 2019
@compulim
Copy link
Contributor

compulim commented Apr 1, 2019

We are using an old way of passing in the store using store props, instead of Provider. This is required for multiple store setup, but it looks like it is buggy.

We should move to the new way of react-redux to pass in a store via ReactReduxContext, and it should fix this issue.

Repro steps

  1. Create a Web Chat Redux store
  2. Create a <ReactWebChat> with the reference of the store
  3. Talk to the bot for a few turns
  4. Create a new Web Chat Redux store
  5. Assign the new store to the existing <ReactWebChat> component

Expected

The transcript should be cleared because the newer store is empty. Also, verify:

  • The older DirectLineJS (contained in previous store) should be disconnected (all observables are unsubscribed)
  • Web Chat will talk to the newer DirectLineJS and offline UI will work with it

Actual

The transcript is not empty.

@compulim compulim removed the Triage-E label Apr 1, 2019
@corinagum corinagum added backlog Out of scope for the current iteration but it will be evaluated in a future release. and removed 4.5 labels Apr 2, 2019
@cwhitten cwhitten added p1 Painful if we don't fix, won't block releasing 4.5 labels May 13, 2019
@corinagum corinagum added Approved front-burner and removed 4.5 backlog Out of scope for the current iteration but it will be evaluated in a future release. labels May 13, 2019
@compulim
Copy link
Contributor

Bumped to react-redux@6.0.1, it fixed an issue about switching store, a.k.a. transcripts not clear after switching store. But there is another bug on react-redux preventing our work, submitted at reduxjs/react-redux#1339.

The react-redux bug is causing action to dispatch to wrong store after switching store. This will prevent us from switching store because apparently all actions are still dispatching to the old store.

Their bug does not repro on react-redux@^7. But moving to that version would require us to bump to react@^16.8 (with React hooks), which we planned for 4.6 and is a big risk while doing it in 4.5.

I am postponing this bug to 4.6.

@corinagum corinagum removed the needs-repro Waiting for repro or investigation label Jun 23, 2019
@corinagum
Copy link
Contributor

corinagum commented Jul 8, 2019

Taking a look at the issue you filed above, the team no longer supports version 6. This should be fixed by WC at the same time as #1818

@corinagum corinagum added blocked currently prevented from making progress p0 Must Fix. Release-blocker and removed p1 Painful if we don't fix, won't block releasing labels Jul 8, 2019
@corinagum corinagum assigned corinagum and unassigned compulim Jul 10, 2019
@compulim
Copy link
Contributor

When working on this PR, also do the followings:

  • Bump react-redux to >= 7.1.0
  • Bump redux-saga to latest (1.0.5)

@Kaiqb Kaiqb added the Customer label Jul 23, 2019
@sgellock sgellock removed the Customer label Aug 8, 2019
@corinagum corinagum assigned tdurnford and unassigned corinagum Aug 16, 2019
@tdurnford
Copy link
Contributor

This is resolved in the latest build from the master branch. I put together a quick sample that resets the store after the user is inactive for five seconds. Note, when the store is replaced, Web Chat dispatches a DIRECT_LINE/DISCONNECT action so you need to create a new Direct Line connection as well.

Bot Framework Web Chat (master)

function App() {

  const [directLine, setDirectLine] = useState(createDirectLine({}));
  const [store, setStore] = useState();
  const [timer, setTimer] = useState();

  const initConversation = useCallback(() => {
    setStore(createStore(
      {},
      () =>  next => action => {
        if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
          const { payload: { activity: { from: { role }}}} = action;
          role === 'user' && setTimer(5000);
        }
        return next(action);
      }));

    (async function() { 
      const res = await fetch('https://webchat-mockbot.azurewebsites.net/directline/token', { method: 'POST' });
      const { token } = await res.json();
  
      setDirectLine(createDirectLine({ token }));
    })().catch(error => console.log(error));

  }, [setStore, setDirectLine, setTimer]);

  useEffect(() => {
    initConversation();
  }, []);

  return directLine && (
    <div className="App">
      <Timer ms={timer} onComplete={initConversation} />
      <ReactWebChat className='chat' directLine={directLine} store={store} />
    </div>
  )
}

Screen capture
restart

@alokraj68
Copy link

This is resolved in the latest build from the master branch. I put together a quick sample that resets the store after the user is inactive for five seconds. Note, when the store is replaced, Web Chat dispatches a DIRECT_LINE/DISCONNECT action so you need to create a new Direct Line connection as well.

Bot Framework Web Chat (master)

function App() {

  const [directLine, setDirectLine] = useState(createDirectLine({}));
  const [store, setStore] = useState();
  const [timer, setTimer] = useState();

  const initConversation = useCallback(() => {
    setStore(createStore(
      {},
      () =>  next => action => {
        if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
          const { payload: { activity: { from: { role }}}} = action;
          role === 'user' && setTimer(5000);
        }
        return next(action);
      }));

    (async function() { 
      const res = await fetch('https://webchat-mockbot.azurewebsites.net/directline/token', { method: 'POST' });
      const { token } = await res.json();
  
      setDirectLine(createDirectLine({ token }));
    })().catch(error => console.log(error));

  }, [setStore, setDirectLine, setTimer]);

  useEffect(() => {
    initConversation();
  }, []);

  return directLine && (
    <div className="App">
      <Timer ms={timer} onComplete={initConversation} />
      <ReactWebChat className='chat' directLine={directLine} store={store} />
    </div>
  )
}

Screen capture
restart

how to achieve the same on webchat without using react?

@tdurnford
Copy link
Contributor

@alokraj68 This how to question is better suited for StackOverflow. Please post your question there with the Web Chat and BotFramework tags so the BotFramework Support Team and the community at large can help you work through your issue.

@narik1989
Copy link

Hi,

Can this sample be implemented in a normal HTML web chat, in the below sample?

https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/01.getting-started/a.full-bundle

If we could can anyone please share the code.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked currently prevented from making progress bug Indicates an unexpected problem or an unintended behavior. external-others front-burner p0 Must Fix. Release-blocker
Projects
None yet
Development

No branches or pull requests

9 participants