Add WABA outreach automation (Z-PRO integration)

Per-product message templates, official/não-oficial channel selection,
manual per-number sending, and a 20-minute internal scheduler for the
existing automatic outreach batch — all pre-existing local work being
committed as-is.
This commit is contained in:
Gustavo
2026-08-03 13:14:09 -03:00
parent 0894ab68b3
commit eaaf7af659
32 changed files with 3522 additions and 342 deletions
+17 -1
View File
@@ -1,6 +1,6 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { openDb, createLeadInserter, transaction, getSetting, setSetting, seedSegments, seedMunicipios, seedGeoCache, seedSettings } from '../src/db.mjs';
import { openDb, createLeadInserter, transaction, getSetting, setSetting, seedSegments, seedMunicipios, seedGeoCache, seedSettings, seedMessageTemplates, updateMessageTemplate } from '../src/db.mjs';
function sampleLead(overrides = {}) {
return {
@@ -90,6 +90,22 @@ test('settings: get/set e seed com defaults Z-PRO', () => {
db.close();
});
test('message_templates salva variaveis WABA automaticas por produto', () => {
const db = openDb(':memory:');
seedMessageTemplates(db, ['ERP']);
const updated = updateMessageTemplate(db, 'ERP', {
canal: 'oficial',
templateWabaNome: 'gti_inicio_atendimento_solicitado',
templateWabaIdioma: 'pt_BR',
templateWabaVariaveis: ['{empresa}', 'Assunto: {produto}', '']
});
assert.equal(updated.template_waba_nome, 'gti_inicio_atendimento_solicitado');
assert.deepEqual(JSON.parse(updated.template_waba_variaveis_json), ['{empresa}', 'Assunto: {produto}']);
db.close();
});
test('seeds de segments, municipios e geo_cache', () => {
const db = openDb(':memory:');