Last active
June 10, 2024 13:07
-
-
Save airburst/caee4262ffa9c71c9d61d997624f2966 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add unique partial urls to this list and the Chatbot will automatically open on them | |
const pagesWithChatbotOpen = [ | |
"Instant-help-with-our-chatbot", | |
// "Give-us-a-call", | |
]; | |
const delay = 2500; // 500ms = 0.5s | |
const urlIsInList = pagesWithChatbotOpen.filter(page => location.pathname.includes(page)).length > -1; | |
document.addEventListener("DOMContentLoaded", () => { | |
if (urlIsInList) { | |
setTimeout(async () => { | |
// Find out whether drawer is already open | |
const { isChatOpen } = await window.adaEmbed.getInfo(); | |
if (!isChatOpen) { | |
window.adaEmbed.toggle(); | |
} | |
}, delay); | |
} | |
}); | |
// Add a click handler to any chatbot links | |
const chatbotLink = document.getElementById("chatbot-link"); | |
if (chatbotLink) { | |
chatbotLink.addEventListener("click", async (e) => { | |
e.preventDefault(); | |
const { isChatOpen } = await window.adaEmbed.getInfo(); | |
if (!isChatOpen) { | |
window.adaEmbed.toggle(); | |
} | |
}); | |
} | |
// Add the link below to any page where you want the chatbot to open. | |
// NOTE: The link must have the id "chatbot-link", and can only be added once per page. | |
/* | |
<a id="chatbot-link" title="Click this link to open the Simply Business chat bot" href="#"> | |
<span class="wysiwyg-underline" style="color: #1155cc;">try our chat bot</span> | |
</a> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment