{"id":78,"date":"2025-07-24T01:45:35","date_gmt":"2025-07-24T01:45:35","guid":{"rendered":"https:\/\/aiautomation.help\/?page_id=78"},"modified":"2025-07-24T01:45:35","modified_gmt":"2025-07-24T01:45:35","slug":"rag-chatbot","status":"publish","type":"page","link":"https:\/\/aiautomation.help\/?page_id=78","title":{"rendered":"Rag Chatbot"},"content":{"rendered":"    <div id=\"rag-chatbot1-wrapper\">\n        <h3>Chef Frankenstein<\/h3>\n        <div id=\"rag-chatbot1-history\" style=\"border:1px solid #ccc; padding:10px; height:300px; overflow:auto;\"><\/div>\n        <input type=\"text\" id=\"rag-chatbot1-input\" placeholder=\"Type your message\u2026\" style=\"width:80%;\">\n        <button id=\"rag-chatbot1-send\">Send<\/button>\n    <\/div>\n    <script>\n    document.addEventListener('DOMContentLoaded', function() {\n        const sendBtn = document.getElementById('rag-chatbot1-send');\n        const input = document.getElementById('rag-chatbot1-input');\n        const historyDiv = document.getElementById('rag-chatbot1-history');\n        const ajaxURL = 'https:\/\/aiautomation.help\/wp-admin\/admin-ajax.php?action=rag_chatbot1_send';\n        const userLabel = 'Chef Frankenstein';\n        const botLabel = 'Bot';\n\n        function escapeHTML(str) {\n            const div = document.createElement('div');\n            div.textContent = str;\n            return div.innerHTML;\n        }\n\n        function appendMessage(author, text) {\n            const p = document.createElement('p');\n            p.innerHTML = `<strong>${escapeHTML(author)}:<\/strong> ${escapeHTML(text)}`;\n            historyDiv.appendChild(p);\n            historyDiv.scrollTop = historyDiv.scrollHeight;\n        }\n\n        function sendMessage() {\n            const message = input.value.trim();\n            if (!message) return;\n            appendMessage(userLabel, message);\n            input.value = '';\n            appendMessage(botLabel, '\u2026thinking\u2026');\n\n            fetch(ajaxURL, {\n                method: 'POST',\n                headers: { 'Content-Type': 'application\/x-www-form-urlencoded' },\n                body: 'chatInput=' + encodeURIComponent(message)\n            })\n            .then(res => res.json())\n            .then(json => {\n                historyDiv.lastChild.remove();\n                appendMessage(botLabel, json.response);\n            });\n        }\n\n        sendBtn.addEventListener('click', sendMessage);\n        input.addEventListener('keydown', function(e) {\n            if (e.key === 'Enter') {\n                e.preventDefault();\n                sendMessage();\n            }\n        });\n    });\n    <\/script>\n    \n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-78","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/aiautomation.help\/index.php?rest_route=\/wp\/v2\/pages\/78","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiautomation.help\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/aiautomation.help\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/aiautomation.help\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aiautomation.help\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=78"}],"version-history":[{"count":0,"href":"https:\/\/aiautomation.help\/index.php?rest_route=\/wp\/v2\/pages\/78\/revisions"}],"wp:attachment":[{"href":"https:\/\/aiautomation.help\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}