feat: probe 30s, no [] wrapper, show webhook reply in chat + auto-open panel
This commit is contained in:
+38
-7
@@ -2025,6 +2025,17 @@
|
|||||||
return wrap;
|
return wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── public API for probe script ────────────────────────── */
|
||||||
|
window._mbs = {
|
||||||
|
appendMsg: appendMsg,
|
||||||
|
openSilent: function () {
|
||||||
|
greeted = true; /* suppress default welcome message */
|
||||||
|
panel.classList.add("open");
|
||||||
|
panel.setAttribute("aria-hidden", "false");
|
||||||
|
scrollLog();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
/* ── send ────────────────────────────────────────────────── */
|
/* ── send ────────────────────────────────────────────────── */
|
||||||
function send(text) {
|
function send(text) {
|
||||||
text = (text || "").trim();
|
text = (text || "").trim();
|
||||||
@@ -2331,17 +2342,37 @@
|
|||||||
fetch(CHAT_URL, {
|
fetch(CHAT_URL, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify([
|
body: JSON.stringify({
|
||||||
{
|
|
||||||
action: "sendMessage",
|
action: "sendMessage",
|
||||||
chatid: chatId,
|
chatid: chatId,
|
||||||
chatInput: buildMsg(geo),
|
chatInput: buildMsg(geo),
|
||||||
},
|
}),
|
||||||
]),
|
})
|
||||||
}).catch(function () {}); /* silently ignore errors */
|
.then(function (res) {
|
||||||
|
var ct = res.headers.get("content-type") || "";
|
||||||
|
if (ct.indexOf("json") !== -1) return res.json();
|
||||||
|
return res.text().then(function (t) {
|
||||||
|
return { output: t };
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(function (d) {
|
||||||
|
var item = Array.isArray(d) ? d[0] : d;
|
||||||
|
var reply =
|
||||||
|
(item &&
|
||||||
|
(item.output ||
|
||||||
|
item.text ||
|
||||||
|
item.message ||
|
||||||
|
item.reply)) ||
|
||||||
|
(typeof d === "string" ? d : null);
|
||||||
|
if (reply && window._mbs) {
|
||||||
|
window._mbs.appendMsg("agent", reply);
|
||||||
|
window._mbs.openSilent();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function () {}); /* silently ignore errors */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Schedule: 60 seconds after page load ────────────────── */
|
/* ── Schedule: 30 seconds after page load ────────────────── */
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
fetch(GEO_URL)
|
fetch(GEO_URL)
|
||||||
.then(function (res) {
|
.then(function (res) {
|
||||||
@@ -2353,7 +2384,7 @@
|
|||||||
.catch(function () {
|
.catch(function () {
|
||||||
fire(null);
|
fire(null);
|
||||||
});
|
});
|
||||||
}, 60000);
|
}, 30000);
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user