Site Builder
Editing:
tools-writing-cs-omni.php
writable 0666
<?php /********************************************************************** * Promptinator — Omni‑Issue CS Reply Studio · v1.1 (Aug 2025) * ------------------------------------------------------------------- * Uses shared toolbar + helper (no local cookie code needed) *********************************************************************/ require_once $_SERVER['DOCUMENT_ROOT'].'/openai/init.php'; ai_handle_key_post(); /* ---------- AJAX end‑point --------------------------------------- */ if ($_SERVER['REQUEST_METHOD']==='POST' && ($_GET['ajax']??'')==='1') { header('Content-Type: application/json;charset=utf-8'); $msg = trim($_POST['cust'] ?? ''); $issue = $_POST['issue'] ?? ''; $prod = trim($_POST['prod'] ?? ''); $order = trim($_POST['order'] ?? ''); $tone = $_POST['tone'] ?? 'Professional'; $extra = trim($_POST['extra1'] ?? ''); $policy = trim($_POST['policy'] ?? ''); $model = $_POST['model'] ?? 'gpt-3.5-turbo'; if (!ai_has_key()) { echo json_encode(['error'=>'No API key']); exit; } if ($msg === '') { echo json_encode(['error'=>'Customer message required']); exit; } /* build prompt -------------------------------------------------- */ $prompt = "You are an e‑commerce customer‑service agent.\n". "ISSUE TYPE: {$issue}\nTONE: {$tone}\n". ($prod ? "PRODUCT: {$prod}\n" : ''). ($order ? "ORDER #: {$order}\n": ''). ($extra ? "ADDITIONAL CONTEXT: {$extra}\n" : ''). ($policy? "COMPANY POLICY: {$policy}\n" : ''). "TASKS:\n". "• Draft a helpful reply e‑mail solving the issue.\n". "• Offer clear next steps.\n". "• Use brand‑appropriate empathy.\n". "• After the e‑mail add an <h3>Internal Note</h3> summarising action items (≤40 words).\n\n". "CUSTOMER MESSAGE:\n{$msg}"; $reply = ai_chat($prompt, ['model'=>$model, 'temperature'=>0.6, 'max_tokens'=>800]); echo $reply ? json_encode(['html'=>$reply]) : json_encode(['error'=>'Empty response']); exit; } /* ---------- view -------------------------------------------------- */ $logged = ai_has_key(); $models = ['gpt-3.5-turbo','gpt-4o-mini','gpt-4']; // shown in selector ?> <!doctype html> <html lang="en"><head> <meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> <title>Omni‑Issue CS Reply • Promptinator</title> <style> :root{--bg:#f1f4fb;--card:#fff;--brand:#004cff;--brand-d:#0841c4; --shadow:0 6px 30px rgba(0,0,0,.08);--radius:26px; font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif} body{margin:0;min-height:100vh;background:var(--bg);display:flex;flex-direction:column} .breadcrumb{background:#ececec;padding:.7rem 1.2rem;font-weight:600} .breadcrumb a{color:var(--brand);text-decoration:none} main{max-width:960px;width:100%;margin:2.4rem auto;padding:0 1.2rem;flex:1} .tool-card{background:var(--card);border-radius:var(--radius);box-shadow:var(--shadow);padding:2rem} label{font-weight:600;font-size:.95rem;display:flex;flex-direction:column;gap:.4rem;margin-top:1.1rem} input,select,textarea{width:100%;padding:.7rem 1rem;border:1px solid #ccd4e8;border-radius:10px;font-size:1rem} input:focus,select:focus,textarea:focus{outline:2px solid var(--brand);border-color:var(--brand)} textarea{min-height:120px;resize:vertical;font-family:ui-monospace,monospace} .form-grid{display:grid;gap:1.4rem;margin-top:1.8rem} @media(min-width:700px){.form-grid{grid-template-columns:repeat(auto-fit,minmax(260px,1fr))}} .btn{background:var(--brand);color:#fff;border:none;border-radius:10px;padding:.75rem 1.55rem;font-size:1rem;font-weight:600;cursor:pointer} .btn:hover{background:var(--brand-d)} .copyBtn{margin-top:.7rem} #spin{display:none;gap:.6ch;align-items:center;margin-top:.8rem} #spin.show{display:flex}@keyframes rot{to{transform:rotate(360deg)}} #spin svg{width:20px;height:20px;animation:rot 1s linear infinite} .preview{background:#fff;border:1px solid #dfe3ef;border-radius:12px;padding:1.2rem;max-height:65vh;overflow:auto} </style> </head><body> <nav class="breadcrumb"> <a href="/members/dashboard.php">Dashboard</a> » <a href="/ai-tools/tools.php">AI Toolbox</a> » Omni‑Issue CS Reply <a href="/<?= htmlspecialchars($_SESSION['slug']??'') ?>/" style="float:right">View Site</a> </nav> <?php ai_render_key_bar(); ?> <?php require_once $_SERVER['DOCUMENT_ROOT'].'/ai-tools/share.php'; ?> <main> <?php if(!$logged): ?> <div class="tool-card" style="text-align:center"> <h2>Connect your OpenAI key</h2> <p>Use the black bar above.</p> </div> <?php else: ?> <div class="tool-card"> <h2 style="margin-top:0">Generate a customer‑service reply</h2> <form id="gen" class="form-grid"> <input type="hidden" name="model" id="modelHidden" value="gpt-3.5-turbo"> <label class="full" style="grid-column:1/-1">Customer message <small>(omit personal data)</small> <textarea id="cust" name="cust" required></textarea> </label> <label>Issue type <select id="issue" name="issue"> <option>Order status update</option> <option>Shipping delay apology</option> <option>Out‑of‑stock / substitution</option> <option>Warranty / return request</option> <option>Received wrong item</option> <option>Price‑match / discount request</option> </select> </label> <label>Product <input id="prod" name="prod" placeholder="e.g. XL Red Hoodie"></label> <label>Order # <input id="order" name="order"></label> <label>Extra context <input id="extra1" name="extra1" placeholder="ETA date, warranty state, etc."> </label> <label>Tone <select id="tone" name="tone"><?php foreach(['Professional','Friendly','Apologetic','Cheerful','Concise'] as $t) echo "<option>$t</option>"; ?></select> </label> <label class="full" style="grid-column:1/-1">Policy snippet (optional) <textarea id="policy" name="policy" placeholder="e.g. 30‑day returns, buyer pays shipping after 30 days…"></textarea> </label> <button class="btn" id="go" style="grid-column:1/-1">Generate reply</button> <div id="spin"><svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" fill="none"/></svg><span id="s">0</span> s</div> </form> <section id="out" style="display:none;margin-top:2rem"> <h3>HTML source</h3><textarea id="raw" readonly style="min-height:180px"></textarea> <button class="btn copyBtn" id="copyRaw">Copy HTML</button> <h3 style="margin-top:2rem">Rendered preview</h3> <div id="rend" class="preview"></div> <button class="btn copyBtn" id="copyR">Copy Rendered HTML</button> </section> </div> <?php endif;?> </main> <script> (()=>{ const $ = id=>document.getElementById(id); /* sync toolbar model selector */ if($('modelHidden') && $('modelSel')) $('modelSel').addEventListener('change',e=>$('modelHidden').value=e.target.value); /* AJAX submit */ if($('gen')){ $('gen').addEventListener('submit',e=>{ e.preventDefault(); if(!$('cust').value.trim()) { alert('Paste the customer message first'); return; } $('go').disabled=true; $('spin').classList.add('show'); let s=0; $('s').textContent=0; const t=setInterval(()=>$('s').textContent=++s,1000); fetch('?ajax=1',{method:'POST',body:new FormData($('gen'))}) .then(r=>r.json()).then(j=>{ clearInterval(t); $('spin').classList.remove('show'); $('go').disabled=false; if(j.error){ alert(j.error); return; } $('raw').value=j.html; $('rend').innerHTML=j.html; $('out').style.display=''; $('copyRaw').onclick=()=>copyTxt($('raw'),'copyRaw'); $('copyR').onclick =()=>copyTxtInner($('rend'),'copyR'); $('rend').scrollIntoView({behavior:'smooth'}); }).catch(err=>{ clearInterval(t); $('spin').classList.remove('show'); $('go').disabled=false; alert(err); }); }); } /* helpers --------------------------------------------------- */ function copyTxt(el,btnId){ navigator.clipboard.writeText(el.value) .then(()=>flash($(btnId))); } function copyTxtInner(el,btnId){ navigator.clipboard.writeText(el.innerHTML) .then(()=>flash($(btnId))); } function flash(btn){const t=btn.textContent; btn.textContent='✔ Copied'; setTimeout(()=>btn.textContent=t,1200); } })(); </script> </body></html>
Save changes
Create folder
writable 0777
Create
Cancel