From 7eb7d90f8b5de12e504981aa435860a94223f86d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Fri, 16 Oct 2026 17:49:50 -0300 Subject: [PATCH] refactor: remove the WhatsApp integration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The system will not send WhatsApp messages: the client's n8n already does, from Tiny's status changes. Paid orders and stage changes now queue only the Tiny delivery; the fake WhatsApp adapter, its setting and secret, the Integrações row and the send log's Destino column are gone, and the old WhatsApp log rows are removed. The customer's WhatsApp number, the "Avisar no WhatsApp" link for corrections and the contact links stay. Co-Authored-By: Claude Opus 5.5 --- .env.example | 1 - app/adapters.py | 12 ++---------- app/api/operator.py | 7 +++---- app/core/secrets.py | 1 - app/payments.py | 7 +++---- app/schema.sql | 3 +++ app/worker.py | 4 ++-- compose.local.yaml | 1 - deploy/PRODUCTION_CHECKLIST.md | 2 +- deploy/portainer.env.example | 2 -- deploy/production_preflight.py | 8 ++++---- deploy/test_production_preflight.py | 3 +-- docker-compose.yml | 1 - docs/CONTEXT.md | 6 ++++-- tests/payment_test.py | 7 +++---- tests/smoke_test.py | 9 ++++----- web/kanban.html | 4 ++-- web/kanban.js | 13 +++++-------- 18 files changed, 37 insertions(+), 54 deletions(-) diff --git a/.env.example b/.env.example index b366e49..3d9bb84 100644 --- a/.env.example +++ b/.env.example @@ -42,7 +42,6 @@ TINY_ADAPTER=fake # JADLOG_CNPJ=... # the "Usuário" Jadlog issued, the CNPJ that contracts freight # JADLOG_CONTA=... # conta corrente # JADLOG_CONTRATO= # only if Jadlog issued a contract number -WHATSAPP_ADAPTER=fake # E-mail stays in the database and the worker log (MAIL_ADAPTER=log). To send # through a real server: MAIL_ADAPTER=smtp with the settings below. # MAIL_FROM=DTF Dropstar diff --git a/app/adapters.py b/app/adapters.py index e8a3305..95c23c0 100644 --- a/app/adapters.py +++ b/app/adapters.py @@ -12,13 +12,10 @@ from botocore.exceptions import ClientError def require_runtime(): """Validate the supported local and R2-backed deployment modes. - Real payment, freight, ERP, and WhatsApp providers are deliberately not - enabled yet. A non-local deployment keeps those adapters fake and disables - checkout until their audited implementations are added. + Each provider is fake until its settings are complete; a real one refuses + to start without them. """ environment = os.environ.get('APP_ENV', 'local') - if os.environ.get('WHATSAPP_ADAPTER') != 'fake': - raise RuntimeError('WHATSAPP must use the currently supported fake adapter') freight = os.environ.get('FREIGHT_ADAPTER') if freight == 'jadlog': from .jadlog import required_settings as jadlog_settings @@ -197,11 +194,6 @@ class FakeTiny: return {'provider': 'fake-tiny', 'reference': f"LOCAL-{payload['number']}", 'event_key': event_key, 'status': 'recorded-locally'} -class FakeWhatsApp: - def deliver(self, event_key: str, payload: dict) -> dict: - return {'provider': 'fake-whatsapp', 'event_key': event_key, - 'event': payload['event'], 'status': 'recorded-locally'} - class ObjectStorage(Protocol): def begin(self, key: str) -> str: ... def parts(self, key: str, upload_id: str) -> list: ... diff --git a/app/api/operator.py b/app/api/operator.py index c3b5052..80dc459 100644 --- a/app/api/operator.py +++ b/app/api/operator.py @@ -267,7 +267,7 @@ def payment_events(state: Literal['open','resolved','all'] = 'open', @router.get('/api/operator/events') -def events(provider: Literal['tiny','whatsapp'] | None = None, +def events(provider: Literal['tiny'] | None = None, status: Literal['delivered','queued','failing'] | None = None, event: Literal['payment_approved','production_started','correction_needed','ready'] | None = None, order: int | None = Query(default=None, ge=1), offset: int = Query(default=0, ge=0), @@ -631,9 +631,8 @@ def move(uid: UUID, body: Move, user=Depends(can('produce'))): sale = c.execute("SELECT receipt FROM dtf_local.outbox WHERE event_key=%s AND delivered_at IS NOT NULL", (f'{uid}:paid:tiny',)).fetchone() tiny = {**event, 'order': row['snapshot'], 'tiny_id': ((sale or {}).get('receipt') or {}).get('tiny_id')} - for provider, payload in (('tiny', tiny), ('whatsapp', event)): - key = f'{uid}:{events[body.state]}:{provider}' if once else f'{uid}:{changed["version"]}:{provider}' - enqueue(c, key, provider, payload) + key = f'{uid}:{events[body.state]}:tiny' if once else f'{uid}:{changed["version"]}:tiny' + enqueue(c, key, 'tiny', tiny) return changed @router.post('/api/operator/orders/{uid}/print-files') diff --git a/app/core/secrets.py b/app/core/secrets.py index 982e921..38b6019 100644 --- a/app/core/secrets.py +++ b/app/core/secrets.py @@ -27,7 +27,6 @@ SECRET_FILE_SETTINGS = ( 'PAYMENT_TOKEN', 'PAYMENT_WEBHOOK_SECRET', 'TINY_TOKEN', - 'WHATSAPP_TOKEN', 'SMTP_PASSWORD', 'CORREIOS_CODIGO_ACESSO', ) diff --git a/app/payments.py b/app/payments.py index 986eb09..5f3b3b3 100644 --- a/app/payments.py +++ b/app/payments.py @@ -99,10 +99,9 @@ def create_order(c, quote, payment): queue_print_files(c, order['id'], len(approved['items'])) if is_test(order): return order, True - for provider in ('tiny', 'whatsapp'): - enqueue(c, f"{order['id']}:paid:{provider}", provider, - {'order_id': str(order['id']), 'number': order['number'], - 'event': 'payment_approved', 'order': approved}) + enqueue(c, f"{order['id']}:paid:tiny", 'tiny', + {'order_id': str(order['id']), 'number': order['number'], + 'event': 'payment_approved', 'order': approved}) mail.alert(c, f"Pedido #{order['number']} pago · {mail.money(approved['total_cents'])}", ['Um pedido novo foi pago e está em Arte recebida.', '', *mail.summary(approved)], '/') return order, True diff --git a/app/schema.sql b/app/schema.sql index 92a03a4..bee0c05 100644 --- a/app/schema.sql +++ b/app/schema.sql @@ -173,6 +173,9 @@ CREATE INDEX IF NOT EXISTS order_files_upload ON dtf_local.order_files(upload_id -- index stays the size of the backlog rather than of all history. CREATE INDEX IF NOT EXISTS outbox_pending ON dtf_local.outbox(available_at, id) WHERE delivered_at IS NULL; +-- The system sends no WhatsApp messages (the client's own n8n does, from Tiny): +-- its old log rows would wait for an adapter that no longer exists. +DELETE FROM dtf_local.outbox WHERE provider='whatsapp'; -- The scanner and the retention sweep both walk live uploads in arrival order. -- now() cannot appear in a partial index predicate, so the time comparisons stay diff --git a/app/worker.py b/app/worker.py index c8cda42..e626946 100644 --- a/app/worker.py +++ b/app/worker.py @@ -7,7 +7,7 @@ import time from http.server import BaseHTTPRequestHandler, HTTPServer from psycopg.types.json import Jsonb from . import mail -from .adapters import FakeTiny, FakeWhatsApp, LocalS3Storage, require_runtime +from .adapters import FakeTiny, LocalS3Storage, require_runtime from .core.secrets import load as load_secret_files from .core.db import connect from .printjobs import render_loop @@ -15,7 +15,7 @@ from .scanning import ClamAV, scan_loop load_secret_files() require_runtime() -adapters = {'tiny': FakeTiny(), 'whatsapp': FakeWhatsApp()} +adapters = {'tiny': FakeTiny()} # Not yet confirmed against the client's account; see app/tiny.py. if os.environ.get('TINY_ADAPTER') == 'tiny': from .tiny import TinyOrders diff --git a/compose.local.yaml b/compose.local.yaml index 06399cc..65a718e 100644 --- a/compose.local.yaml +++ b/compose.local.yaml @@ -79,7 +79,6 @@ x-app: &app TINY_SKU_METRO_UV_FOLHA: ${TINY_SKU_METRO_UV_FOLHA:-} TINY_SKU_METRO_UV_AVULSA: ${TINY_SKU_METRO_UV_AVULSA:-} TINY_ECOMMERCE_ID: ${TINY_ECOMMERCE_ID:-} - WHATSAPP_ADAPTER: fake # log keeps each e-mail in the database and the worker's log, with the # recovery link readable there; smtp with the SMTP_* settings in .env. MAIL_ADAPTER: ${MAIL_ADAPTER:-log} diff --git a/deploy/PRODUCTION_CHECKLIST.md b/deploy/PRODUCTION_CHECKLIST.md index 969820e..763ece3 100644 --- a/deploy/PRODUCTION_CHECKLIST.md +++ b/deploy/PRODUCTION_CHECKLIST.md @@ -6,7 +6,7 @@ substitute for `production_preflight.py`, CI, staging acceptance, or change appr ## Application and external contracts - [ ] `docs/PRODUCTION_INPUTS.md` has owners, decisions, and evidence for every item. -- [ ] Production R2, freight, Mercado Pago, Tiny/Olist, and WhatsApp adapters have +- [ ] Production R2, freight, Mercado Pago, and Tiny/Olist adapters have sandbox contract tests and least-privilege credentials. - [ ] Payment webhook authenticity, replay handling, and idempotency are tested. - [ ] Docker secret `*_FILE` loading is implemented and tested without logging values. diff --git a/deploy/portainer.env.example b/deploy/portainer.env.example index f5e3bcd..1457715 100644 --- a/deploy/portainer.env.example +++ b/deploy/portainer.env.example @@ -44,7 +44,6 @@ TINY_PRODUCT_UV_AVULSA=TBD TINY_FORMA_ENVIO_RETIRADA=TBD # true only at go-live, after the n8n DTFIMP designer branch is removed. TINY_STATUS_UPDATES=false -WHATSAPP_ADAPTER=TBD # E-mail (password recovery and team alerts). off until the SMTP account exists. MAIL_ADAPTER=off MAIL_FROM=DTF Dropstar @@ -79,4 +78,3 @@ OPERATOR_PASSWORD_SECRET=TBD PAYMENT_TOKEN_SECRET=TBD PAYMENT_WEBHOOK_SECRET=TBD TINY_TOKEN_SECRET=TBD -WHATSAPP_TOKEN_SECRET=TBD diff --git a/deploy/production_preflight.py b/deploy/production_preflight.py index b486416..6a38f58 100644 --- a/deploy/production_preflight.py +++ b/deploy/production_preflight.py @@ -20,12 +20,12 @@ REQUIRED = ( 'POSTGRES_DB', 'POSTGRES_USER', 'APP_DB_USER', 'POSTGRES_VOLUME', 'OPERATOR_EMAIL', 'STORAGE_QUOTA_BYTES', 'OWNER_UPLOAD_QUOTA_BYTES', 'MAX_UPLOAD_BYTES', 'UPLOAD_PART_BYTES', 'MAX_PENDING_UPLOADS', 'SCAN_MAX_BYTES', - 'PAYMENT_ADAPTER', 'FREIGHT_ADAPTER', 'TINY_ADAPTER', 'WHATSAPP_ADAPTER', + 'PAYMENT_ADAPTER', 'FREIGHT_ADAPTER', 'TINY_ADAPTER', 'DATABASE_URL_SECRET', 'DATABASE_ADMIN_URL_SECRET', 'DB_ADMIN_PASSWORD_SECRET', 'APP_DB_PASSWORD_SECRET', 'R2_ACCESS_KEY_ID_SECRET', 'R2_SECRET_ACCESS_KEY_SECRET', 'OPERATOR_PASSWORD_SECRET', 'PAYMENT_TOKEN_SECRET', - 'PAYMENT_WEBHOOK_SECRET', 'TINY_TOKEN_SECRET', 'WHATSAPP_TOKEN_SECRET', + 'PAYMENT_WEBHOOK_SECRET', 'TINY_TOKEN_SECRET', ) IMMUTABLE_IMAGE = re.compile(r'^[a-z0-9][a-z0-9._:/-]*@sha256:([0-9a-f]{64})$') IMAGE_REPOSITORY = re.compile( @@ -42,7 +42,7 @@ SOURCE_BLOCKERS = { 'payment = FakePayment()', ), 'app/worker.py': ( - "adapters = {'tiny': FakeTiny(), 'whatsapp': FakeWhatsApp()}", + "adapters = {'tiny': FakeTiny()}", ), } @@ -148,7 +148,7 @@ def config_errors(values): bucket = values.get('R2_BUCKET', '') if bucket and not re.fullmatch(r'[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]', bucket): errors.append('R2_BUCKET must be a valid S3 bucket name') - for name in ('PAYMENT_ADAPTER', 'FREIGHT_ADAPTER', 'TINY_ADAPTER', 'WHATSAPP_ADAPTER'): + for name in ('PAYMENT_ADAPTER', 'FREIGHT_ADAPTER', 'TINY_ADAPTER'): if values.get(name, '').lower() in {'', 'fake', 'mock', 'local'}: errors.append(f'{name} must select an approved non-fake implementation') for name in REQUIRED: diff --git a/deploy/test_production_preflight.py b/deploy/test_production_preflight.py index cbb0e62..2af2e4a 100644 --- a/deploy/test_production_preflight.py +++ b/deploy/test_production_preflight.py @@ -59,14 +59,13 @@ def valid_config(): 'PAYMENT_ADAPTER': 'mercado-pago', 'FREIGHT_ADAPTER': 'approved-freight', 'TINY_ADAPTER': 'tiny-olist', - 'WHATSAPP_ADAPTER': 'approved-whatsapp', } for name in ( 'DATABASE_URL_SECRET', 'DATABASE_ADMIN_URL_SECRET', 'DB_ADMIN_PASSWORD_SECRET', 'APP_DB_PASSWORD_SECRET', 'R2_ACCESS_KEY_ID_SECRET', 'R2_SECRET_ACCESS_KEY_SECRET', 'OPERATOR_PASSWORD_SECRET', 'PAYMENT_TOKEN_SECRET', - 'PAYMENT_WEBHOOK_SECRET', 'TINY_TOKEN_SECRET', 'WHATSAPP_TOKEN_SECRET', + 'PAYMENT_WEBHOOK_SECRET', 'TINY_TOKEN_SECRET', ): values[name] = 'dtf_prod_' + name.lower() return values diff --git a/docker-compose.yml b/docker-compose.yml index 9b3a746..d3c1b44 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -111,7 +111,6 @@ x-app-environment: &app-environment # only together with TINY_ADAPTER=tiny and after n8n stops sending the # designer message for DTFIMP products. TINY_STATUS_UPDATES: ${TINY_STATUS_UPDATES:-false} - WHATSAPP_ADAPTER: fake # E-mail: customers' password recovery and the team's alerts (app/mail.py). # off until the client's SMTP account exists; then smtp with the settings # below, or the API and worker refuse to start. SMTP_SECURITY is starttls diff --git a/docs/CONTEXT.md b/docs/CONTEXT.md index 9633978..0569778 100644 --- a/docs/CONTEXT.md +++ b/docs/CONTEXT.md @@ -38,7 +38,9 @@ online system, not factory-machine automation. - Freight quotation and charging at checkout. - Idempotent Tiny/Olist order integration and order traceability. - Online Kanban for production status and secure file download. -- WhatsApp status notifications. +- Customer status notices: not sent by this system. The client's own n8n sends + WhatsApp messages from Tiny's status changes (decided 2026-10-16); the Kanban + only offers a one-click WhatsApp link for a correction. - Private object storage, 30-day file retention, backups, and basic security. - Operator guidance for the factory team. @@ -316,7 +318,7 @@ as references and are not imported or started by Compose. jobs provision restricted runtime identities, for nine Compose services total. - MinIO implements the S3 storage boundary with direct multipart browser uploads, resumable parts, private objects, and short-lived signed operator downloads. -- Payment, freight, Tiny/Olist, and WhatsApp use fake adapters only. No production +- Payment, freight, and Tiny/Olist use fake adapters only. No production credentials or integrations are configured. The API and worker have no external network route; only local web/storage gateways publish loopback ports. - The original Site commercial calculation and appearance remain the source of diff --git a/tests/payment_test.py b/tests/payment_test.py index 26c35be..c1b0b18 100644 --- a/tests/payment_test.py +++ b/tests/payment_test.py @@ -134,9 +134,8 @@ def run(): events = board.call('/operator/events?order=' + str(order['number']), operator=True)['events'] paid = [e for e in events if e['payload'].get('order_id') == order['id'] and e['payload'].get('event') == 'payment_approved'] - assert len(paid) == 2, f'expected one tiny and one whatsapp event, got {len(paid)}' - assert {e['provider'] for e in paid} == {'tiny', 'whatsapp'}, paid - print('PASS: exactly one notification per provider for the order') + assert [e['provider'] for e in paid] == ['tiny'], paid + print('PASS: exactly one Tiny notification for the order') # A payment that was never reviewed, and one for something that is not a quote. deliver({'event_id': 'nonsense-' + uuid4().hex, 'reference': 'not-a-uuid', @@ -160,7 +159,7 @@ def run(): queued = c.execute("SELECT count(*) AS n FROM dtf_local.outbox WHERE event_key LIKE %s", (order['id'] + ':%',)).fetchone()['n'] jobs = c.execute('SELECT count(*) AS n FROM dtf_local.print_files WHERE order_id=%s', (order['id'],)).fetchone()['n'] assert queued == 0 and jobs == 1, (queued, jobs) - print('PASS: an operator test order reaches the board and the print queue, never Tiny or WhatsApp') + print('PASS: an operator test order reaches the board and the print queue, never Tiny') # Files are uploaded before payment. An unpaid cart keeps them briefly; a # paid order keeps them for its 30 days; a payment never starts for files diff --git a/tests/smoke_test.py b/tests/smoke_test.py index 125127c..36d4a74 100644 --- a/tests/smoke_test.py +++ b/tests/smoke_test.py @@ -240,7 +240,7 @@ def run(): assert len(client.call('/operator/orders/'+oid+'/history',operator=True))==6 # A mistaken move can be undone one stage at a time, with an internal # reason. The customer is not told again: going back and forward once more - # adds no messages (the outbox count below stays 8). + # adds no messages (the outbox count below stays 4). client.call('/operator/orders/'+oid+'/move',{'state':'imp','version':version},operator=True,expected=422) client.call('/operator/orders/'+oid+'/move',{'state':'tra','version':version},operator=True,expected=409) back=client.call('/operator/orders/'+oid+'/move',{'state':'imp','version':version,'reason':'Movido por engano'},operator=True) @@ -258,16 +258,15 @@ def run(): deadline=time.monotonic()+30 while time.monotonic()