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
Activities 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.