chore: import maquina-comercial-pessoal history via subtree
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> git-subtree-dir: maquina-comercial-pessoal git-subtree-mainline:f5af038e19git-subtree-split:a9ef4d776d
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
export function hasCampaignsPausedByRestart(db) {
|
||||
return Boolean(db.prepare(
|
||||
"SELECT 1 FROM outreach_campaigns WHERE status = 'paused' AND pause_reason = 'server_restart' LIMIT 1"
|
||||
).get());
|
||||
}
|
||||
|
||||
async function safeAlert({ alerter, key, text, log = () => {} }) {
|
||||
try {
|
||||
await alerter.alert(key, text);
|
||||
} catch {
|
||||
log(`telegram: alerta ${key} falhou`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function notifyStartupState({ alerter, whatsappStatus, campaignsPausedByRestart, log }) {
|
||||
if (campaignsPausedByRestart) {
|
||||
await safeAlert({
|
||||
alerter,
|
||||
key: 'campaigns-paused-restart',
|
||||
text: 'Campanhas pausadas apos restart. Acesse o painel, revise a fila e reinicie manualmente.',
|
||||
log
|
||||
});
|
||||
}
|
||||
if (whatsappStatus === 'QR_REQUIRED') {
|
||||
await safeAlert({
|
||||
alerter,
|
||||
key: 'whatsapp-qr',
|
||||
text: 'WhatsApp requer leitura de QR. Acesse o painel da Maquina Comercial Pessoal.',
|
||||
log
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function notifyWhatsAppTransition({ alerter, previousState, nextState }) {
|
||||
if (previousState === nextState) return;
|
||||
if (previousState === 'READY' && nextState !== 'READY') {
|
||||
await alerter.alert('whatsapp-left-ready', `WhatsApp saiu de READY e agora esta ${nextState}.`);
|
||||
}
|
||||
if (nextState === 'QR_REQUIRED') {
|
||||
await alerter.alert('whatsapp-qr', 'WhatsApp requer leitura de QR. Acesse o painel.');
|
||||
}
|
||||
}
|
||||
|
||||
export async function notifyInitialReconnectFailure({ alerter, error, log }) {
|
||||
log(`whatsapp: reconexao inicial falhou: ${error.message}`);
|
||||
await safeAlert({
|
||||
alerter,
|
||||
key: 'whatsapp-initial-reconnect-failed',
|
||||
text: 'WhatsApp nao reconectou no startup. Acesse o painel e verifique o QR.',
|
||||
log
|
||||
});
|
||||
}
|
||||
|
||||
export async function startInitialWhatsAppReconnect({ hasSession, whatsapp, alerter, log }) {
|
||||
if (!(await hasSession())) return false;
|
||||
|
||||
whatsapp.connect().catch((error) => notifyInitialReconnectFailure({ alerter, error, log }));
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user