Tobias Vasquez
Tobias Vasquez
TTypebot
Created by Tobias Vasquez on 7/23/2024 in #help-and-questions
Cant mount the chatbot (initBubble) after unmounting
As the title says, i cant mount the chatbot as an initBubble from a custom script after the bot has been unmounted. The code basically listens to a button click, and if the user has a localStorage key, it should close the current bot, unmount it, and open another different chatbot, i'll leave the code so you can see what im talking about

let chatBotUserName;
let chatBotUserMail;
document.querySelector('.triggerBot').addEventListener('click', (e) => {


if(document.querySelectorAll('typebot-bubble')[0].shadowRoot.querySelector('.typebot-chat-chunk')){
if(localStorage.getItem('typebot-clpxar0hl0005p826y90ijz8l-input-2')){
chatBotUserName = JSON.parse(localStorage.getItem('typebot-clpxar0hl0005p826y90ijz8l-input-2')).text;
}
if(localStorage.getItem('typebot-clpxar0hl0005p826y90ijz8l-input-4')){
chatBotUserMail = JSON.parse(localStorage.getItem('typebot-clpxar0hl0005p826y90ijz8l-input-4')).text;
}

// Typebot.unmount();
localStorage.clear();
localStorage.setItem("triggerMode", "button");

// Typebot.initBubble({
// typebot: "***",
// apiHost: "***",
// previewMessage: {
// message: "I have a question for you!",
// autoShowDelay: 7000,
// avatarUrl:
// "***",
// },
// theme: {
// button: { backgroundColor: "#03ebdd", iconColor: "#09145f", size: "large" },
// previewMessage: { backgroundColor: "#1a1a1a",textColor: "#FFFFFF" },
// },
// });
}else{
localStorage.setItem("triggerMode", "button");
Typebot.open()
}
})

let chatBotUserName;
let chatBotUserMail;
document.querySelector('.triggerBot').addEventListener('click', (e) => {


if(document.querySelectorAll('typebot-bubble')[0].shadowRoot.querySelector('.typebot-chat-chunk')){
if(localStorage.getItem('typebot-clpxar0hl0005p826y90ijz8l-input-2')){
chatBotUserName = JSON.parse(localStorage.getItem('typebot-clpxar0hl0005p826y90ijz8l-input-2')).text;
}
if(localStorage.getItem('typebot-clpxar0hl0005p826y90ijz8l-input-4')){
chatBotUserMail = JSON.parse(localStorage.getItem('typebot-clpxar0hl0005p826y90ijz8l-input-4')).text;
}

// Typebot.unmount();
localStorage.clear();
localStorage.setItem("triggerMode", "button");

// Typebot.initBubble({
// typebot: "***",
// apiHost: "***",
// previewMessage: {
// message: "I have a question for you!",
// autoShowDelay: 7000,
// avatarUrl:
// "***",
// },
// theme: {
// button: { backgroundColor: "#03ebdd", iconColor: "#09145f", size: "large" },
// previewMessage: { backgroundColor: "#1a1a1a",textColor: "#FFFFFF" },
// },
// });
}else{
localStorage.setItem("triggerMode", "button");
Typebot.open()
}
})
17 replies