{"id":5108,"date":"2026-01-08T14:05:49","date_gmt":"2026-01-08T07:05:49","guid":{"rendered":"https:\/\/satrc.apt.int\/?page_id=5108"},"modified":"2026-01-13T14:48:43","modified_gmt":"2026-01-13T07:48:43","slug":"your-personal-ai-assistant","status":"publish","type":"page","link":"https:\/\/satrc.apt.int\/index.php\/your-personal-ai-assistant\/","title":{"rendered":"Your Personal AI Assistant"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"5108\" class=\"elementor elementor-5108\" data-elementor-settings=\"{&quot;ha_cmc_init_switcher&quot;:&quot;no&quot;}\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-66bbaad elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"66bbaad\" data-element_type=\"section\" data-e-type=\"section\" data-settings=\"{&quot;_ha_eqh_enable&quot;:false}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-e779a03\" data-id=\"e779a03\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-3d9f5d5 elementor-widget elementor-widget-html\" data-id=\"3d9f5d5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<style>\r\n  .duke-chat-wrap{max-width:920px;margin:40px auto;font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif}\r\n  .duke-chat-title{font-size:44px;line-height:1.1;margin:0 0 24px;color:#2b2b2b}\r\n  .duke-chat-card{border:1px solid #e8e8e8;border-radius:16px;background:#fff;box-shadow:0 10px 30px rgba(0,0,0,.06);overflow:hidden}\r\n  .duke-chat-head{padding:18px 20px;border-bottom:1px solid #eee}\r\n  .duke-chat-head h2{margin:0;font-size:22px}\r\n  .duke-chat-head p{margin:6px 0 0;color:#666}\r\n  .duke-chat-log{height:min(62vh,560px);padding:18px;overflow:auto;background:#fafafa}\r\n  .msg{display:flex;margin:10px 0}\r\n  .msg.user{justify-content:flex-end}\r\n  .bubble{max-width:78%;padding:12px 14px;border-radius:14px;white-space:pre-wrap;word-break:break-word}\r\n  .msg.user .bubble{background:#2b6cff;color:#fff;border-bottom-right-radius:4px}\r\n  .msg.bot .bubble{background:#fff;border:1px solid #e7e7e7;color:#222;border-bottom-left-radius:4px}\r\n  .duke-chat-input{display:flex;gap:10px;padding:14px;border-top:1px solid #eee;background:#fff}\r\n  .duke-chat-input textarea{flex:1;resize:none;height:52px;max-height:140px;padding:12px 12px;border:1px solid #ddd;border-radius:12px;font-size:16px;outline:none}\r\n  .duke-chat-input textarea:focus{border-color:#2b6cff}\r\n  .duke-chat-input button{width:110px;border:0;border-radius:12px;background:#111;color:#fff;font-size:16px;cursor:pointer}\r\n  .duke-chat-input button:disabled{opacity:.6;cursor:not-allowed}\r\n  .duke-chat-foot{padding:10px 14px;color:#888;font-size:12px;background:#fff}\r\n<\/style>\r\n\r\n<div class=\"duke-chat-wrap\">\r\n  <h1 class=\"duke-chat-title\">Your Personal AI Assistant<\/h1>\r\n\r\n  <div class=\"duke-chat-card\">\r\n    <div class=\"duke-chat-head\">\r\n      <h2>Chat<\/h2>\r\n      <p>Ask anything<\/p>\r\n    <\/div>\r\n\r\n    <div id=\"dukeChatLog\" class=\"duke-chat-log\"><\/div>\r\n\r\n    <div class=\"duke-chat-input\">\r\n      <textarea id=\"dukeChatText\" placeholder=\"Type a message...\"><\/textarea>\r\n      <button id=\"dukeChatSend\">Send<\/button>\r\n    <\/div>\r\n\r\n    <div class=\"duke-chat-foot\" id=\"dukeChatStatus\"><\/div>\r\n  <\/div>\r\n<\/div>\r\n\r\n<script>\r\n  \/\/ \u2705 IMPORTANT: paste your n8n PRODUCTION webhook URL here\r\n  const WEBHOOK_URL = \"https:\/\/nidup.app.n8n.cloud\/webhook\/feb88306-2609-45e0-a07e-3f573b95196e\/chat\";\r\n\r\n  const logEl = document.getElementById(\"dukeChatLog\");\r\n  const textEl = document.getElementById(\"dukeChatText\");\r\n  const sendBtn = document.getElementById(\"dukeChatSend\");\r\n  const statusEl = document.getElementById(\"dukeChatStatus\");\r\n\r\n  function uuid() {\r\n    return (crypto.randomUUID ? crypto.randomUUID() : \"sess_\" + Math.random().toString(16).slice(2) + Date.now());\r\n  }\r\n\r\n  \/\/ Keep conversation memory stable across refreshes\r\n  const sessionIdKey = \"duke_n8n_sessionId\";\r\n  let sessionId = localStorage.getItem(sessionIdKey) || uuid();\r\n  localStorage.setItem(sessionIdKey, sessionId);\r\n\r\n  function addMsg(role, text) {\r\n    const row = document.createElement(\"div\");\r\n    row.className = \"msg \" + role;\r\n    const bubble = document.createElement(\"div\");\r\n    bubble.className = \"bubble\";\r\n    bubble.textContent = text;\r\n    row.appendChild(bubble);\r\n    logEl.appendChild(row);\r\n    logEl.scrollTop = logEl.scrollHeight;\r\n  }\r\n\r\n  function setStatus(t) { statusEl.textContent = t || \"\"; }\r\n\r\n  async function sendMessage() {\r\n    const msg = (textEl.value || \"\").trim();\r\n    if (!msg) return;\r\n\r\n    addMsg(\"user\", msg);\r\n    textEl.value = \"\";\r\n    textEl.focus();\r\n\r\n    sendBtn.disabled = true;\r\n    setStatus(\"Thinking...\");\r\n\r\n    try {\r\n      \/\/ Chat Trigger generally uses chatInput + sessionId :contentReference[oaicite:2]{index=2}\r\n      const payload = { chatInput: msg, sessionId };\r\n\r\n      const res = await fetch(WEBHOOK_URL, {\r\n        method: \"POST\",\r\n        headers: { \"Content-Type\": \"application\/json\" },\r\n        body: JSON.stringify(payload),\r\n      });\r\n\r\n      const raw = await res.text();\r\n\r\n      \/\/ Try to interpret JSON responses (some workflows return {output:\"...\"} or {text:\"...\"})\r\n      let reply = raw;\r\n      try {\r\n        const j = JSON.parse(raw);\r\n        reply =\r\n          j.output ?? j.text ?? j.message ??\r\n          (typeof j === \"string\" ? j : JSON.stringify(j, null, 2));\r\n      } catch (_) {}\r\n\r\n      if (!res.ok) {\r\n        addMsg(\"bot\", \"Error from n8n (\" + res.status + \"):\\n\" + reply);\r\n      } else {\r\n        addMsg(\"bot\", reply);\r\n      }\r\n      setStatus(\"\");\r\n    } catch (e) {\r\n      addMsg(\"bot\", \"Network\/CORS error:\\n\" + (e && e.message ? e.message : String(e)));\r\n      setStatus(\"If this says CORS, set Allowed Origin (CORS) in your Chat Trigger to your WordPress domain (or *).\");\r\n    } finally {\r\n      sendBtn.disabled = false;\r\n    }\r\n  }\r\n\r\n  \/\/ Enter = send, Shift+Enter = new line\r\n  textEl.addEventListener(\"keydown\", (e) => {\r\n    if (e.key === \"Enter\" && !e.shiftKey) {\r\n      e.preventDefault();\r\n      sendMessage();\r\n    }\r\n  });\r\n\r\n  sendBtn.addEventListener(\"click\", sendMessage);\r\n\r\n  \/\/ Show something immediately so you can confirm JS is running\r\n  addMsg(\"bot\", \"Hi! I\u2019m connected. Ask me something.\");\r\n<\/script>\r\n\r\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Your Personal AI Assistant Chat Ask anything Send<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"class_list":["post-5108","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/satrc.apt.int\/index.php\/wp-json\/wp\/v2\/pages\/5108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/satrc.apt.int\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/satrc.apt.int\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/satrc.apt.int\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/satrc.apt.int\/index.php\/wp-json\/wp\/v2\/comments?post=5108"}],"version-history":[{"count":14,"href":"https:\/\/satrc.apt.int\/index.php\/wp-json\/wp\/v2\/pages\/5108\/revisions"}],"predecessor-version":[{"id":5123,"href":"https:\/\/satrc.apt.int\/index.php\/wp-json\/wp\/v2\/pages\/5108\/revisions\/5123"}],"wp:attachment":[{"href":"https:\/\/satrc.apt.int\/index.php\/wp-json\/wp\/v2\/media?parent=5108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}