conscious-sapphire
conscious-sapphire2y ago

Start a new chat from JS

Hello, I would like to restart a chat via JS/React whenever I want. So far, I have to do it manually. Is there any way to do it via JS? Thanks!
2 Replies
Tico | Voiceflow Assistant
To restart a chat from JavaScript/React in the Voiceflow Web Chat, you can use the window.voiceflow.chat.reset() function provided by the Voiceflow Web Chat API. This function will reset the conversation state and start a new chat session. Here's an example of how you can call this function in a React component:
import React from 'react';

const ResetChatButton = () => {
const handleResetChat = () => {
window.voiceflow.chat.reset();
};

return <button onClick={handleResetChat}>Reset Chat</button>;
};

export default ResetChatButton;
import React from 'react';

const ResetChatButton = () => {
const handleResetChat = () => {
window.voiceflow.chat.reset();
};

return <button onClick={handleResetChat}>Reset Chat</button>;
};

export default ResetChatButton;
In this example, when the "Reset Chat" button is clicked, the handleResetChat function is called, which in turn calls window.voiceflow.chat.reset() to reset the chat session. You can also call the reset function directly from JavaScript without React, like this:
window.voiceflow.chat.reset();
window.voiceflow.chat.reset();
This will reset the chat session and start a new conversation. Please note that the window.voiceflow.chat object is only available after the Voiceflow Web Chat has been loaded and initialized. Make sure to call the reset function after the chat has been loaded successfully. https://developer.voiceflow.com/docs/chat-widget#reset
conscious-sapphire
conscious-sapphireOP2y ago
Seems that reset is no longer available Solved by setting "Forget" in the widget memory option

Did you find this page helpful?