(function () { document.head.insertAdjacentHTML('beforeend', ''); const style = document.createElement('style'); style.innerHTML = ` .hidden { display: none; } #chat-widget-container { position: fixed; bottom: 32px; right: 32px; flex-direction: column; z-index: 99; } .chatbot__arrow--left { border-top: 6px solid transparent; border-bottom: 6px solid transparent; border-right: 6px solid #f0f0f0; } .chatbot__arrow { width: 0; height: 0; margin-top: 18px; } .chatbot__arrow--right { border-top: 6px solid transparent; border-bottom: 6px solid transparent; border-left: 6px solid #1a181e; } #chat-popup { height: 70vh; max-height: 70vh; transition: all 0.3s; overflow: hidden; position:relative; z-index: 99; } .content-loader { display: none; padding: 12px 20px; position: absolute; right: 25px; bottom: 100px; z-index: 99; } .typing-loader::after { content: "Thinking ..."; animation: typing 1s steps(1) infinite, blink .75s step-end infinite; font-size:10px; } @keyframes typing { from,to { width: 0; } 50% { width: 15px; } } @keyframes blink { 50% { color: transparent; } } @media (max-width: 768px) { #chat-popup { position: fixed; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%; max-height: 100%; border-radius: 0; } } .icon { width: 70px; height: 70px; background-image: url('https://www.yourai.uk/chatbot/chatbot1.png'); } `; document.head.appendChild(style); // Create container for chat widget const chatWidgetContainer = document.createElement('div'); chatWidgetContainer.id = 'chat-widget-container'; document.body.appendChild(chatWidgetContainer); chatWidgetContainer.innerHTML = `
`; // Add event listeners const chatInput = document.getElementById('chat-input'); const chatSubmit = document.getElementById('chat-submit'); const chatBubble = document.getElementById('chat-bubble'); const chatPopup = document.getElementById('chat-popup'); const chatMessages = document.getElementById('chat-messages'); const loader = document.querySelector('.content-loader'); const closePopup = document.getElementById('close-popup'); chatSubmit.addEventListener('click', function () { const message = chatInput.value.trim(); if (!message) return; chatMessages.scrollTop = chatMessages.scrollHeight; chatInput.value = ''; onUserRequest(message); }); chatInput.addEventListener('keyup', function (event) { if (event.key === 'Enter') { chatSubmit.click(); } }); chatBubble.addEventListener('click', function () { togglePopup(); }); closePopup.addEventListener('click', function () { togglePopup(); }); function togglePopup() { const chatPopup = document.getElementById('chat-popup'); chatPopup.classList.toggle('hidden'); if (!chatPopup.classList.contains('hidden')) { document.getElementById('chat-input').focus(); } } function highlightContactDetails(text) { // Email regex const emailRegex = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z|a-z]{2,}\b/g; // Phone number regex const phoneRegex = /(\b\+?1\s)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g; // Simples URL regex const urlRegex = /\b((http|https):\/\/)?[a-z0-9\.-]+\.[a-z]{2,}[^\s]*\b/g; // Replace and add mark tag for highlighting return text; } function onUserRequest(message) { // Display user message const messageElement = document.createElement('div'); messageElement.className = 'flex justify-end mb-3'; messageElement.innerHTML = `
${message}
`; chatMessages.appendChild(messageElement); chatMessages.scrollTop = chatMessages.scrollHeight; chatInput.value = ''; // Reply to the user let url = "https://api.openai.com/v1/chat/completions"; let OPENAI_API_KEY = "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"; let headers = { "Content-Type": "application/json", "Authorization": `Bearer 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` }; let body = { "model": "gpt-3.5-turbo-16k", "messages": [ { "role": "system", "content": "You are a friendly chatbot that responds only to the questions and answers given in this prompt. If you are asked any questions not given in this prompt, apologize and say you can't answer. Format your response using HTML so that links will be active in a javascript environment. Use a friendly tone, use Pound Sterling as the currency, and use british english spelling. Questions and answers: Call: +44 (0) 784 050 2509\nWhatsApp: 447840502509\nEmail address: david@peppercorn.biz\nRegister :peppercorn.biz\n\nHow do I get access? How do I get started? How do I sign up? How do I join? How do I book a meeting? \nSignup at https://peppercorn.biz/peppercorn-subscription-plan/ you will need to enter your payment details but you will not be charged for 30 days. You can cancel at any time and you will not be charged. When that is done you can book any events at https://peppercorn.biz/networking-events/ and access previous AI The Cool Stuff records via https://peppercorn.biz/networking-events/\n\nI have forgotten my password. How do I change my password? I cannot login\nYou can reset via https://peppercorn.biz/peppercorn-member-lost-password/ or by following the Members - Lost Password link in the menu.\nYou will be emailed a reset link. If that fails email David@peppercorn.biz and we will manually reset and sent you a one-time access link. You can then change your password via the membership page. \n\nWhen is the next meeting? What time is the next meeting? What are the dates of the next meeting? When is the next event?\nPeppercorn Speed Networking is run each Thursday 2pm-3pm and AI:The cool stuff is on Friday 10am-11am. The booking links are on this page: https://peppercorn.biz/networking-events/ - you will need to be a member, which is free for 30 days then £10 a month with no ongoing commitment. \n\nWhere can I find details of my subscription? Where can I find my invoices? How do I cancel my subscription? Cancel my subscription\nNavigate to Members - Membership Account in the menu or go to https://peppercorn.biz/peppercorn-member-account/ From here you can view your subscription, change your password, change your avatar, and download your invoices. Invoices are listed by pressing the 'orders' button\n\nWhy are you called Peppercorn?\nDavid Harris says \'When the Covid lockdown started and face to face networking died I was already using Zoom for client meetings and recognised it's possibilities with breakout rooms for Speed Networking. Given the circumstances it needed to be great value and the term 'peppercorn rent' came to mind. I set the membership at only £10 a month. Amazingly peppercorn.biz was available and 7 days later in May 2020 we ran our first meeting as Peppercorn Speed Networking. " }, { "role": "user", "content": message } ], "temperature": 1, "max_tokens": 13906, "top_p": 1, "frequency_penalty": 0, "presence_penalty": 0 }; loader.style.display = 'inline-block'; fetch(url, { method: 'POST', headers: headers, body: JSON.stringify(body) }) .then(response => response.json()) .then(data => { loader.style.display = 'none'; reply(data['choices'][0]['message']['content'].replace('Answer:', '')) }) // Logs the response data from the API to the console .catch(error => console.error('Error:', error)); } function reply(message) { const chatMessages = document.getElementById('chat-messages'); const replyElement = document.createElement('div'); replyElement.className = 'flex mb-3'; replyElement.innerHTML = `
${highlightContactDetails(message)}
`; chatMessages.appendChild(replyElement); chatMessages.scrollTop = chatMessages.scrollHeight; } })();