crm-sync

Syncs PalFish CRM sales data into Supabase via hybrid autonomous and extension-delivered token flows.

1|Updated May 23, 2026
One-click install
npx skills add https://github.com/palfish-t-i-u/palfish-t-i-u-h-th-ng-ver-2 --skill crm-sync-palfish-t-i-u
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: crm-sync
Source: https://github.com/palfish-t-i-u/palfish-t-i-u-h-th-ng-ver-2/tree/main/.claude/skills/crm-sync
Command: npx skills add https://github.com/palfish-t-i-u/palfish-t-i-u-h-th-ng-ver-2 --skill crm-sync-palfish-t-i-u

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires cryptography, xlsx.

What problem does it solve? CRM sync failures (HTTP 503s), missing sales dates, and stale team hierarchies break GMV dashboards because CRM env vars are absent from render.yaml and the hierarchy JSON is baked into the Docker image. This Skill documents the exact configuration, backfill, and deployment procedures to keep the crm_sales_data pipeline running. ## Core Features & Use Cases - Token & encryption setup: Generate a Fernet CRM_ENCRYPT_KEY, create the crm_tokens table, and configure the extension ingest token on Render. - Incremental sync and backfill: Run single-day syncs, backfill date ranges (concurrency capped at 3), and auto-detect missing dates past the PostgREST 1000-row cap. - Team hierarchy updates: Convert the Metabase xlsx export to team_hierarchy.json, rebuild the Docker image, and reseed the nhan_su_sale table. - Use Case: After a fresh Render deploy returns 503 on all CRM endpoints, follow the deployment-trap checklist to set CRM_ENCRYPT_KEY and CRM_EXTENSION_INGEST_TOKEN manually in the Render dashboard. ## Quick Start Ask the assistant to diagnose why the CRM sync endpoint returns HTTP 503 and walk through the Render environment variable checklist.

Frequently Asked Questions about crm-sync

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does CRM sync return HTTP 503 after a Render deploy?

CRM sync returns 503 when CRM_ENCRYPT_KEY or CRM_EXTENSION_INGEST_TOKEN is missing. Both are absent from render.yaml and backend/.env.example, so they must be set manually in the Render dashboard for prod and sandbox services.

How do I backfill missing CRM sales data for a date range?

POST to /crm/sync/backfill with start_date, end_date, and concurrency (max 3). To find gaps first, call GET /crm/sync/missing-dates?lookback_days=60, or POST /crm/sync/missing to detect and backfill automatically.

How do I generate a valid CRM_ENCRYPT_KEY for Fernet encryption?

Run python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())" once and paste the URL-safe base64 32-byte key into the Render environment variables. Never commit the value to the repo.

Does the Sync Metabase now button pull live data from Metabase?

No. The button only re-reads docs/team_hierarchy.json from the running container's filesystem. Updating the hierarchy requires exporting the Metabase xlsx, running extract_hierarchy.cjs, committing the JSON, redeploying, and reseeding nhan_su_sale.

Why is CRM data double-counted in dashboard KPIs?

CRM data is month-to-date cumulative, not daily deltas, so multiple rows per sale and date cause double-counting. The latest_snapshot_rows() function in crm_metrics.py keeps only the newest row per sale and period for KPI calculations.

When should I not use the CRM sync workflow?

Do not use it for revenue ledger imports, Zalo or DingTalk notification issues, or mPOS/Payoo reconciliation, which are separate subsystems with their own extension ingest token. It covers only the CRM sales-funnel sync into crm_sales_data.