document.addEventListener('DOMContentLoaded', function() {
const chatbotToggle = document.getElementById('chatbot-toggle');
if (!chatbotToggle) return; // Exit if element not found
const chatbotContainer = document.createElement('div');
chatbotContainer.id = 'chatbot-container';
chatbotContainer.style.cssText = 'display: none; position: fixed; bottom: 70px; right: 20px; width: 300px; background: #fff; border: 1px solid #ddd; box-shadow: 0 0 10px rgba(0,0,0,0.1); z-index: 1001; border-radius: 10px;';
document.body.appendChild(chatbotContainer);
const chatbotClose = document.createElement('span');
chatbotClose.id = 'chatbot-close';
chatbotClose.style.cssText = 'position: absolute; top: 5px; right: 10px; cursor: pointer; font-size: 18px; color: #000;';
chatbotClose.textContent = '×';
chatbotContainer.appendChild(chatbotClose);
const chatbotBody = document.createElement('div');
chatbotBody.id = 'chatbot-body';
chatbotBody.style.cssText = 'max-height: 300px; overflow-y: auto; padding: 1rem; font-family: Arial, sans-serif;';
chatbotContainer.appendChild(chatbotBody);
chatbotToggle.addEventListener('click', function(e) {
e.preventDefault(); // Prevent default action
chatbotContainer.classList.toggle('active');
if (chatbotContainer.classList.contains('active') && chatbotBody.innerHTML === '') {
const greeting = document.createElement('p');
greeting.classList.add('bot-message');
greeting.textContent = 'Hello! Welcome to Vertex Road Safety. I’m here to help with your road safety needs. What would you like to know?';
chatbotBody.appendChild(greeting);
}
});
chatbotClose.addEventListener('click', function() {
chatbotContainer.classList.remove('active');
});
const chatOptions = [
'What are Rubber Speed Breakers?',
'How much do Plastic Speed Breakers cost?',
'What is the use of Convex Mirrors?',
'Do you install Road Studs?',
'What are Delineators used for?',
'Can I get custom Safety Signage?',
'How long is the delivery time?',
'Are Traffic Cones available in different sizes?',
'What materials are used in your products?',
'Do you offer installation services?'
];
const chatbotResponses = {
'What are Rubber Speed Breakers?': 'Rubber Speed Breakers are durable, flexible devices made from high-quality rubber to slow down vehicles and enhance safety.',
'How much do Plastic Speed Breakers cost?': 'Plastic Speed Breakers cost between ₹500 and ₹1,500 depending on size. Contact us at +91 7387301083 for a quote.',
'What is the use of Convex Mirrors?': 'Convex Mirrors offer a wide-angle view to eliminate blind spots, perfect for intersections and parking lots.',
'Do you install Road Studs?': 'Yes, we provide professional Road Stud installation. Call +91 7387301083 to arrange.',
'What are Delineators used for?': 'Delineators guide traffic and mark lanes, especially in construction zones and highways.',
'Can I get custom Safety Signage?': 'Yes, we offer custom Safety Signage. Reach out at +91 7387301083 for details.',
'How long is the delivery time?': 'Delivery takes 3-7 business days. Contact +91 7387301083 for specifics.',
'Are Traffic Cones available in different sizes?': 'Yes, Traffic Cones are available in 30cm, 50cm, and 75cm heights. Check with +91 7387301083.',
'What materials are used in your products?': 'We use rubber, plastic, reflective sheeting, and UV-resistant materials for durability.',
'Do you offer installation services?': 'Yes, we offer installation for all products. Book at +91 7387301083.'
};
chatOptions.forEach(option => {
const optionElement = document.createElement('p');
optionElement.classList.add('chat-option');
optionElement.textContent = option;
optionElement.style.cssText = 'cursor: pointer; padding: 5px; margin: 5px 0;';
chatbotContainer.appendChild(optionElement);
optionElement.addEventListener('click', function() {
const userMessage = document.createElement('p');
userMessage.classList.add('user-message');
userMessage.textContent = this.textContent;
chatbotBody.appendChild(userMessage);
const botReply = document.createElement('p');
botReply.classList.add('bot-message');
botReply.textContent = chatbotResponses[this.textContent] || 'I’m sorry, I don’t have an answer for that. Please click the WhatsApp or Call button for further assistance.';
chatbotBody.appendChild(botReply);
chatbotBody.scrollTop = chatbotBody.scrollHeight;
});
});
const styleSheet = document.createElement('style');
styleSheet.textContent = `
.user-message { background-color: #e0e0e0; padding: 8px; border-radius: 5px; margin: 5px 0; text-align: right; }
.bot-message { background-color: #f0f0f0; padding: 8px; border-radius: 5px; margin: 5px 0; }
#chatbot-container.active { display: block; }
`;
document.head.appendChild(styleSheet);
});