I am using custom UI webchat.js -->directline API--> Microsoft copilot studio.
I want to implement a reset function, which will reset the chat bot and remove the previous messages from the chat box.
in backend, the conversation is getting reset, but in the UI, the old chat messages are still there.
is there a way to clear that ?
Tried the below and still not clearing it chat bot in the UI
store.dispatch({ type: 'WEB_CHAT/CLEAR_MESSAGES' });
Any help highly appreciated.
Similar context- Is it possible to populate the input bar in webchat with an onclick method
I am using custom UI webchat.js -->directline API--> Microsoft copilot studio.
I want to implement a reset function, which will reset the chat bot and remove the previous messages from the chat box.
in backend, the conversation is getting reset, but in the UI, the old chat messages are still there.
is there a way to clear that ?
Tried the below and still not clearing it chat bot in the UI
store.dispatch({ type: 'WEB_CHAT/CLEAR_MESSAGES' });
Any help highly appreciated.
Similar context- Is it possible to populate the input bar in webchat with an onclick method
Share asked Mar 5 at 17:56 AnilalAnilal 335 bronze badges 1- Accepting / upvoting an answer serves the greater Stack Overflow community and anyone with a similar question. If you feel my answer was sufficient, please "accept" and upvote it. If not, let me know how else I can help! – Steven Kanberg Commented Mar 6 at 0:49
1 Answer
Reset to default 1Activities passed thru Web Chat's store
are stored in an array. You can clear the store by assigning the activities property an empty array. Obviously, how or at what point you want to do this is up to you. Below is a simple example demonstrating one possible way.
const store = window.WebChat.createStore( {}, ( { dispatch } ) => next => async action => {
if ( action.type === 'DIRECT_LINE/INCOMING_ACTIVITY' ) {
const activity = action.payload?.activity;
if (activity.type === 'message' && activity.text === 'clear') {
store.getState().activities = []
}
next( action );
} );
When 'clear' is typed into the send box the transcript window is cleared of any messages displayed up to that point.