collabcentral/html/auth.js
Joseph B. McQueen e604c7e9c9 Initial commit: multi-bot CollabCentral
Extends the single-Novi codebase into a multi-bot mass-messenger where
each bot has its own token, avatar, label, and per-user authorization.

- Secrets moved out of config.json: per-bot tokens in gitignored
  config/botTokens.json (with enabled flag), service-account OAuth in
  gitignored config/token.json (rewritten by refresh cron), integration
  and Google keys in .env.
- Single Webex integration handles OAuth for all bots via a per-app
  redirect URI derived from OAUTH_CALLBACK_URL_TEMPLATE.
- New requireBot middleware and getBotConfig helper reject requests for
  unknown or disabled bots at the /CollabCentral/:app boundary.
- New /info endpoint plus dynamic frontend loading (sendMessage,
  monitorJobs) so pages self-describe per bot, including bot avatar
  fetched from Webex /people/me at startup.
- Job draft state keyed by cookieId + appName so each bot has its own
  building queue; job list/detail endpoints filter by appName so users
  only see jobs from bots they are authorized on.
- New jobDetail page for a readable per-job view; completed jobs are
  retained for 30 days by the cleanup cron.
- Completion adaptive cards use per-bot avatar and label.
- Miscellaneous fixes: off-by-two in the send loop, removed three dead
  send/process variants, added defensive init for jobs.* on load,
  dropped the deprecated crypto npm shim, and cleaned up stray logger
  labels and typos.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-01 17:53:07 -04:00

57 lines
No EOL
1.7 KiB
JavaScript

//console.log(window.location.pathname);
var pathArray = window.location.pathname.split('/');
//console.log(pathArray);
//console.log(pathArray);
var appName = pathArray[2];
//console.log("appName=" + appName);
/*
if (appName == "novi") {
setCookie("appLabel", "Novi Communicator");
} else if (appName == "techupdates") {
setCookie("appLabel", "Technology Updates");
} else {
setCookie("appLabel", "Unknown");
}
setCookie("appName",appName,1);
*/
if (getCookie("id")) {
console.log("Found ID Cookie: " + getCookie("id"));
window.location.href = "/CollabCentral/" + appName + "/sendMessage.html";
} else {
console.log("No ID Cookie found.");
var randomNumber = Math.random().toString();
randomNumber = randomNumber.substring(2, randomNumber.length);
fetch('/CollabCentral/' + appName + '/authUrl')
.then(res => res.text())
.then((res) => {
window.location.href = res + randomNumber;
});
}
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function setCookie(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}