Isolate MAX chat commands from outbox sends

This commit is contained in:
sevenhill
2026-07-05 22:48:05 +03:00
parent dcc74252c6
commit 0106130744
3 changed files with 143 additions and 11 deletions
+18 -8
View File
@@ -347,7 +347,7 @@ app.post("/chat/resolve-url", async (req, res) => {
}
const result = await withPageLock(async () => {
const p = await ensurePage("incoming");
const p = await ensurePage("commands");
const currentStatus = await status(null, p);
if (!currentStatus.isAuthorized) {
return { success: false, chatUrl: null, error: "MAX is not authorized." };
@@ -359,7 +359,7 @@ app.post("/chat/resolve-url", async (req, res) => {
chatUrl: chatUrl || null,
error: chatUrl ? null : "MAX chat URL was not found."
};
}, "incoming");
}, "commands");
res.json(result);
} catch (error) {
@@ -376,9 +376,9 @@ app.post("/chat/clear-history", async (req, res) => {
}
const result = await withPageLock(async () => {
const p = await ensurePage("incoming");
const p = await ensurePage("commands");
return await clearChatHistoryInMax(p, externalChatId, chatUrl);
}, "incoming");
}, "commands");
res.json(result);
} catch (error) {
res.json({ success: false, error: String(error?.message || error) });
@@ -394,9 +394,9 @@ app.post("/chat/delete", async (req, res) => {
}
const result = await withPageLock(async () => {
const p = await ensurePage("incoming");
const p = await ensurePage("commands");
return await deleteChatInMax(p, externalChatId, chatUrl);
}, "incoming");
}, "commands");
res.json(result);
} catch (error) {
res.json({ success: false, error: String(error?.message || error) });
@@ -416,7 +416,7 @@ app.post("/chat/menu-probe", async (req, res) => {
}
const result = await withPageLock(async () => {
const p = await ensurePage("incoming");
const p = await ensurePage("commands");
const menuOpened = await openSidebarChatMenu(p, externalChatId, chatUrl, labels);
const actionClicked = menuOpened && probeAction
? await clickActionByTextWithRetry(p, labels, 1500)
@@ -434,7 +434,7 @@ app.post("/chat/menu-probe", async (req, res) => {
actionClicked,
visibleActions
};
}, "incoming");
}, "commands");
res.json(result);
} catch (error) {
res.json({ success: false, error: String(error?.message || error), chatUrl: null });
@@ -759,6 +759,7 @@ async function status(overrideStatus = null, statusPage = null) {
url,
title,
lastError,
pageRoles: getOpenPageRoles(),
updatedAt: new Date().toISOString()
};
} catch (error) {
@@ -776,6 +777,7 @@ function errorStatus(error) {
url: fallbackPage?.url?.() || null,
title: null,
lastError,
pageRoles: getOpenPageRoles(),
updatedAt: new Date().toISOString()
};
}
@@ -785,9 +787,17 @@ function firstKnownPage() {
pagesByRole.get("default") ||
pagesByRole.get("incoming") ||
pagesByRole.get("outgoing") ||
pagesByRole.get("commands") ||
null;
}
function getOpenPageRoles() {
return Array.from(pagesByRole.entries())
.filter(([, rolePage]) => rolePage && !rolePage.isClosed())
.map(([roleName]) => roleName)
.sort();
}
function isAllowedMediaUrl(value) {
const raw = String(value || "").trim();
if (!raw) return false;