Hey {{FirstName}},

It's {RepName}, I am with Shiney Solar. Hope you're well.

Had my calendar ping me, but didn't want to disturb you without texting first.
{{Special/Offer/Update}}

If you prefer not to receive my texts, please respond with "delete".

Should I send over the details for you to take a look?

function typeWriterEffect(element, text, delay = 10) { let i = 0; function typeItOut() { if (i < text.length) { element.textContent += text.charAt(i); i++; setTimeout(typeItOut, delay); } } typeItOut(); } function handleBotResponse(response) { const botMessageDiv = document.createElement('div'); botMessageDiv.innerHTML = `

`; const messageParagraph = botMessageDiv.querySelector('p'); chatContainer.appendChild(botMessageDiv); typeWriterEffect(messageParagraph, response); // Apply the typewriter effect to the bot's message scrollToBottom(); // Check if the response includes the trigger phrase if (response.includes("Alright, I have added it to our calendar.")) { setTimeout(() => { sendAutomatedFollowUp(); }, 3000); // Adjust timing as needed } } function sendAutomatedFollowUp() { // First message to be sent const firstMessage = "Congratulations! The AI would have booked the appointment in your team's calendar. What do you think would happen if we let the AI reach out to your aged data? - you would get more appointments than your team can handle."; displayAIMessage(firstMessage); // Display the first message setTimeout(() => { const secondMessageText = "Our partners usually see their cost per contract go down with 50%, and we only work on performance based pay. Click below to discuss how this would work with your business."; const secondMessageButtonHTML = `

Schedule Meeting

`; displayAIMessageWithButton(secondMessageText, secondMessageButtonHTML); // Display the second message with the button after a delay }, 6000); // Adjust the delay as needed (6000 milliseconds = 6 seconds) } function displayAIMessage(message) { const aiMessageDiv = document.createElement('div'); aiMessageDiv.innerHTML = `

${message}

`; chatContainer.appendChild(aiMessageDiv); scrollToBottom(); } // This is the corrected function that also handles the button HTML function displayAIMessageWithButton(messageText, messageButtonHTML) { const aiMessageDiv = document.createElement('div'); aiMessageDiv.innerHTML = `

${messageText}

${messageButtonHTML}
`; chatContainer.appendChild(aiMessageDiv); scrollToBottom(); } // Function to create a new thread and store the thread ID in localStorage function createThread() { fetch('https://router.shiney.ai/solardemo1/create_thread', { method: 'POST', headers: { 'Content-Type': 'application/json' } }) .then(response => response.json()) .then(data => { currentThreadId = data.thread_id; localStorage.setItem('thread_id', currentThreadId); // Store thread ID in localStorage console.log('Thread created with ID:', currentThreadId); }) .catch(error => { console.error('Error creating thread:', error); }); } // Check if a thread ID exists in localStorage when the page loads window.onload = function() { currentThreadId = localStorage.getItem('thread_id'); if (!currentThreadId) { createThread(); // Create a new thread if no thread ID is found } else { console.log('Using existing thread ID:', currentThreadId); } }; function typeWriterEffect(element, text, delay = 10) { let i = 0; function typeItOut() { if (i < text.length) { element.textContent += text.charAt(i); i++; setTimeout(typeItOut, delay); } } typeItOut(); } function handleBotResponse(response) { const botMessageDiv = document.createElement('div'); botMessageDiv.innerHTML = `

`; const messageParagraph = botMessageDiv.querySelector('p'); chatContainer.appendChild(botMessageDiv); typeWriterEffect(messageParagraph, response); // Apply the typewriter effect to the bot's message scrollToBottom(); // Check if the response includes the trigger phrase if (response.includes("Alright, I have added it to our calendar.")) { setTimeout(() => { sendAutomatedFollowUp(); }, 3000); // Adjust timing as needed } } function sendAutomatedFollowUp() { // First message to be sent const firstMessage = "Congratulations! The AI would have booked the appointment in your team's calendar. What do you think would happen if we let the AI reach out to your aged data? - you would get more appointments than your team can handle."; displayAIMessage(firstMessage); // Display the first message setTimeout(() => { const secondMessageText = "Our partners usually see their cost per contract go down with 50%, and we only work on performance based pay. Click below to discuss how this would work with your business."; const secondMessageButtonHTML = `

Schedule Meeting

`; displayAIMessageWithButton(secondMessageText, secondMessageButtonHTML); // Display the second message with the button after a delay }, 6000); // Adjust the delay as needed (6000 milliseconds = 6 seconds) } function displayAIMessage(message) { const aiMessageDiv = document.createElement('div'); aiMessageDiv.innerHTML = `

${message}

`; chatContainer.appendChild(aiMessageDiv); scrollToBottom(); } // This is the corrected function that also handles the button HTML function displayAIMessageWithButton(messageText, messageButtonHTML) { const aiMessageDiv = document.createElement('div'); aiMessageDiv.innerHTML = `

${messageText}

${messageButtonHTML}
`; chatContainer.appendChild(aiMessageDiv); scrollToBottom(); } // Function to create a new thread and store the thread ID in localStorage function createThread() { fetch('https://router.shiney.ai/solardemo1/create_thread', { method: 'POST', headers: { 'Content-Type': 'application/json' } }) .then(response => response.json()) .then(data => { currentThreadId = data.thread_id; localStorage.setItem('thread_id', currentThreadId); // Store thread ID in localStorage console.log('Thread created with ID:', currentThreadId); }) .catch(error => { console.error('Error creating thread:', error); }); }