help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
slack-bot-assistant
/
static
/
js
RSK World
slack-bot-assistant
Slack Bot Assistant - Python + Slack API + SQLite + PHP Dashboard + Bot Commands + Automation
js
  • admin.js1.4 KB
  • chat.js2.5 KB
run.pychat.js
static/js/chat.js
Raw Download
Find: Go to:
/*
Project: E-commerce Chatbot
Developed by: Molla Samser
Team: Rima Khatun (Designer & Tester)
Website: https://rskworld.in
Email: support@rskworld.in
Year: 2026
"Empowering E-commerce with AI"
*/

const chatTrigger = document.getElementById('chat-trigger');
const closeChat = document.getElementById('close-chat');
const chatContainer = document.getElementById('chat-container');
const sendBtn = document.getElementById('send-btn');
const voiceBtn = document.getElementById('voice-btn');
const userInput = document.getElementById('user-input');
const chatMessages = document.getElementById('chat-messages');

let chatHistory = [];

chatTrigger.onclick = () => {
    chatContainer.style.display = 'flex';
    chatTrigger.style.display = 'none';
};

closeChat.onclick = () => {
    chatContainer.style.display = 'none';
    chatTrigger.style.display = 'block';
};

sendBtn.onclick = async () => {
    const message = userInput.value.trim();
    if (!message) return;

    // Add user message to UI
    appendMessage(message, 'user');
    userInput.value = '';

    try {
        const response = await fetch('/api/chat', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ message, history: chatHistory })
        });
        const data = await response.json();

        // Add bot message to UI
        appendMessage(data.response, 'bot');

        // Update history
        chatHistory.push({ role: 'user', content: message });
        chatHistory.push({ role: 'assistant', content: data.response });

        // Auto scroll
        chatMessages.scrollTop = chatMessages.scrollHeight;
    } catch (error) {
        console.error('Error:', error);
        appendMessage("Sorry, I'm having trouble connecting to the AI brain.", 'bot');
    }
};

userInput.onkeypress = (e) => {
    if (e.key === 'Enter') sendBtn.click();
};

voiceBtn.onclick = () => {
    voiceBtn.style.color = 'red';
    appendMessage("Listening... (Voice simulation active for 2026)", 'bot');
    setTimeout(() => {
        voiceBtn.style.color = 'var(--text-muted)';
        userInput.value = "Show my loyalty points";
        sendBtn.click();
    }, 2000);
};

function appendMessage(text, sender) {
    const msgDiv = document.createElement('div');
    msgDiv.className = `message ${sender}`;
    msgDiv.innerText = text;
    chatMessages.appendChild(msgDiv);
    chatMessages.scrollTop = chatMessages.scrollHeight;
}
83 lines•2.5 KB
javascript
🚀 Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ❤️

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer