Skip to content

Instantly share code, notes, and snippets.

@airburst
Last active June 10, 2024 13:07
Show Gist options
  • Save airburst/caee4262ffa9c71c9d61d997624f2966 to your computer and use it in GitHub Desktop.
Save airburst/caee4262ffa9c71c9d61d997624f2966 to your computer and use it in GitHub Desktop.
// 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