system-prompts-and-models-o.../dealix/auto_client_acquisition/service_tower/service_wizard.py
Dealix Builder e106a9a0d2 feat(targeting+service+excellence): Saudi Targeting OS + Service Tower + Service Excellence — 38 modules + 62 endpoints + 105 tests
Targeting & Acquisition OS (16 modules) — نظام الاستهداف الذكي
- account_finder: account-first targeting; 12 buying signals; deterministic 10-25 accounts per (sector, city)
- buyer_role_mapper: 14 buyer roles + sector-specific buying-committee maps + role-based Arabic angles
- contact_source_policy: 12 sources (crm_customer→opt_out) with risk_score, channels-allowed, retention guidance, lawful_basis
- contactability_matrix: 5 action modes (suggest_only/draft_only/approval_required/approved_execute/blocked); opt-out always blocked
- linkedin_strategy: Lead Forms + Ads + manual ONLY; linkedin_do_not_do() locks scrape/auto-DM/auto-connect/extensions
- email_strategy: drafts + unsubscribe footer + domain-pacing (fresh/warmed/trusted/damaged) + spam-trigger risk
- whatsapp_strategy: opt-in only; rejects cold + risky phrases; opt-in template requires explicit purpose+company+unsubscribe
- social_strategy: official APIs only; listening + drafts; no auto-publish
- outreach_scheduler: day-by-day plans + daily limits + opt-out enforcement
- reputation_guard: bounce/complaint/opt-out thresholds → healthy/watch/pause + recovery actions per channel
- daily_autopilot: Arabic brief + 7 today actions + EOD report
- acquisition_scorecard: pipeline + meetings + risks + productivity_score
- self_growth_mode: 5 ICP focuses for Dealix; daily brief + monthly targets
- free_diagnostic: Free Growth Diagnostic (3 ops + msg + risk + plan) → paid pilot recommendation
- contract_drafts: Pilot/DPA/Referral/Agency/SOW outlines (legal_review_required, PDPL-aware)
- service_offers: 7 targeting-tier offers + recommend by customer-type

Service Tower (8 modules) — برج الخدمات الذاتية (12 productized services)
- service_catalog: 12 services with target_customer/outcome/inputs/workflow/deliverables/pricing/risk/proof/upgrade
- service_wizard: deterministic recommend (agency→partner; list→list_intelligence; founder→self_growth; CEO→exec_brief; budget≥2999→growth_os; default→first_10)
- mission_templates: workflow steps with approval gates + linked growth missions
- pricing_engine: SAR quotes scaled by company_size×urgency×channels_count + setup_fee + monthly_offer
- deliverables: client report outline + proof pack template + operator checklist (no live actions)
- service_scorecard: 0..100 score from drafts/replies/meetings/pipeline/CSAT
- whatsapp_ceo_control: daily brief, approval cards (≤3 buttons), risk alerts, EOD reports
- upgrade_paths: deterministic next-service recommendation + Arabic upsell messages

Service Excellence OS (8 modules) — مصنع الخدمات الممتازة
- feature_matrix: 12 must-have features per service + advanced/premium/future tiers
- service_scoring: 10-dimension excellence score (clarity, speed_to_value, automation, compliance, proof, upsell, uniqueness, scalability, ops_daily, proof_data) → launch_ready/beta_only/needs_work
- quality_review: 4 gates (proof / approval / pricing / channels) + status verdict; review_service_before_launch and review/all
- competitor_gap: 7 competitor categories (CRM, WhatsApp tools, email assistants, LinkedIn tools, agencies, revenue intelligence, generic AI) + Dealix advantages + do-not-copy
- proof_metrics: required metrics + ROI estimate (pipeline_x + closed_won_x) + Arabic summary
- research_lab: monthly brief + feature hypotheses + top-3 experiments + monthly review
- service_improvement_backlog: feedback→backlog conversion + impact/effort prioritization + weekly improvements
- launch_package: landing outline + sales script + 12-min demo script + 5-day onboarding checklist

Routers (3 new) — 62 endpoints
- /api/v1/targeting/* — 20 endpoints (accounts, buying-committee, contacts, uploaded-list, outreach, daily-autopilot, self-growth, reputation, linkedin, drafts, free-diagnostic, services, contracts)
- /api/v1/services/* — 20 endpoints (catalog, recommend, intake, start, workflow, deliverables, proof-pack, quote, setup-fee, monthly-offer, scorecard, upgrade-path, ceo daily-brief/approval-card/risk-alert/EOD)
- /api/v1/service-excellence/* — 22 endpoints (feature-matrix, score, quality-review, review/all, proof-metrics, roi-estimate, gap-analysis, research-brief, hypotheses, experiments, monthly-review, backlog, weekly-improvements, launch-package, landing/sales/demo/onboarding)

Tests (3 new files, 105 tests)
- test_targeting_os: 47 tests (Arabic accounts, buying committees, opt-out blocked, cold WA blocked, LinkedIn no-scraping, email unsubscribe, WA risk, outreach plan, reputation guard, self-growth, contracts, scorecard)
- test_service_tower: 38 tests (12+ services, all have pricing/proof/deliverables/approval, wizard recommendations, workflow includes approval, quote scales, CEO cards ≤3 buttons, no live send)
- test_service_excellence: 33 tests (feature matrix, score returns status, ALL services pass quality gates, ROI x-multiples, 7 competitor categories, hypotheses+experiments, backlog conversion, launch package complete, demo=12min)

Docs (3 new + 1 updated)
- TARGETING_ACQUISITION_OS.md (Arabic)
- SERVICE_TOWER_STRATEGY.md (Arabic)
- SERVICE_EXCELLENCE_OS.md (Arabic)
- DEALIX_100_PERCENT_LAUNCH_PLAN.md — added §36 Targeting OS + §37 Service Tower + §38 Service Excellence + §39 Landing Pages

Landing pages (4 new, RTL Arabic)
- services.html — 3 doors + 12 productized services
- free-diagnostic.html — free growth diagnostic
- first-10-opportunities.html — kill feature
- agency-partner.html — agency partner program

Test results
- 105/105 new tests pass
- Full suite: 768 passed, 2 skipped
- 0 existing tests broken

Safety + integration with previous layers
- Targeting OS uses contactability_matrix → ALL contacts gated before any send
- Service Tower's workflow includes approval gate; ALL services live_send_allowed=False
- Service Excellence quality_review BLOCKS launch on missing proof/approval/pricing/unsafe channels
- linkedin_do_not_do() encodes 8 explicit prohibitions (scraping/auto-DM/auto-connect/extensions)
- whatsapp_do_not_do() blocks cold sends + group scraping
- Contracts always: legal_review_required=True, not_legal_advice=True, PDPL sections present
- Self-Growth Mode lets Dealix target its OWN ICP using the same approval-first pipeline

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 17:11:00 +03:00

138 lines
5.5 KiB
Python

"""Service wizard — يوصي بالخدمة المناسبة من إجابات بسيطة."""
from __future__ import annotations
from typing import Any
from .service_catalog import ALL_SERVICES, get_service
def recommend_service(
*,
company_type: str = "",
goal: str = "fill_pipeline",
has_contact_list: bool = False,
channels: list[str] | None = None,
budget_sar: int = 1000,
) -> dict[str, Any]:
"""
Recommend the best-fit service based on inputs. Deterministic.
"""
channels = channels or []
company_type_lc = (company_type or "").lower()
chosen_id: str
reason: str
# Highest priority first.
if "agency" in company_type_lc or "وكالة" in company_type:
chosen_id = "agency_partner_program" if budget_sar >= 10_000 else "partner_sprint"
reason = "وكالة → برنامج شريك أو سبرنت شراكات."
elif has_contact_list:
chosen_id = "list_intelligence"
reason = "العميل لديه قائمة → ابدأ بـ List Intelligence."
elif "founder" in company_type_lc or "مؤسس" in company_type:
chosen_id = "self_growth_operator"
reason = "مؤسس بدون فريق نمو → Self-Growth Operator."
elif "executive" in company_type_lc or "ceo" in company_type_lc:
chosen_id = "executive_growth_brief"
reason = "CEO/تنفيذي → موجز نمو يومي."
elif "whatsapp" in company_type_lc or "واتساب" in company_type:
chosen_id = "whatsapp_compliance_setup"
reason = "حالة واتساب عشوائية → امتثال أولاً."
elif goal == "rescue_lost_revenue":
chosen_id = "email_revenue_rescue"
reason = "الهدف استعادة إيراد ضائع → Email Revenue Rescue."
elif goal == "book_meetings":
chosen_id = "meeting_booking_sprint"
reason = "الهدف اجتماعات → Meeting Booking Sprint."
elif goal == "expand_partners":
chosen_id = "partner_sprint"
reason = "الهدف شراكات → Partner Sprint."
elif budget_sar >= 2999:
chosen_id = "growth_os_monthly"
reason = "الميزانية شهرية → Growth OS."
else:
chosen_id = "first_10_opportunities_sprint"
reason = "الافتراضي: ابدأ بـ 10 فرص في 10 دقائق."
service = get_service(chosen_id)
return {
"recommended_service_id": chosen_id,
"service": service.to_dict() if service else None,
"reason_ar": reason,
"next_step_ar": (
"املأ نموذج الـ intake، وسنبدأ خلال 24 ساعة عمل."
),
}
def build_intake_questions(service_id: str) -> dict[str, Any]:
"""Return intake questions for a service. Empty if service unknown."""
s = get_service(service_id)
if s is None:
return {"error": f"unknown service: {service_id}", "questions": []}
base_q = [
{"key": "company_name", "label_ar": "اسم الشركة", "required": True},
{"key": "sector", "label_ar": "القطاع", "required": True},
{"key": "city", "label_ar": "المدينة", "required": True},
{"key": "decision_maker_name", "label_ar": "اسم صانع القرار", "required": True},
{"key": "decision_maker_role", "label_ar": "المسمى الوظيفي", "required": True},
]
extra = []
if "uploaded_csv" in s.inputs_required:
extra.append({"key": "uploaded_csv", "label_ar": "ملف CSV", "required": True})
if "offer" in s.inputs_required:
extra.append({"key": "offer", "label_ar": "وصف العرض", "required": True})
if "goal" in s.inputs_required:
extra.append({"key": "goal", "label_ar": "الهدف الأساسي", "required": True})
if "channels_available" in s.inputs_required:
extra.append({"key": "channels", "label_ar": "القنوات المتاحة", "required": False})
return {
"service_id": service_id,
"service_name_ar": s.name_ar,
"questions": base_q + extra,
"approval_required": True,
}
def validate_service_inputs(
service_id: str, payload: dict[str, Any],
) -> dict[str, Any]:
"""Validate intake payload against service requirements."""
s = get_service(service_id)
if s is None:
return {"valid": False, "errors_ar": [f"خدمة غير معروفة: {service_id}"]}
errors: list[str] = []
for required in s.inputs_required:
if required in ("uploaded_csv", "offer", "goal", "channels_available",
"ICP", "calendar_link", "company_profile",
"current_practice", "ad_budget", "client_count",
"partner_goal", "team_size", "channels", "agency_profile",
"prospect_list", "gmail_label", "contact_list",
"goals", "sector", "city"):
if not payload.get(required):
errors.append(f"الحقل ناقص: {required}")
return {
"valid": not errors,
"errors_ar": errors,
"service_id": service_id,
}
def summarize_recommendation_ar(result: dict[str, Any]) -> str:
"""Build a one-paragraph Arabic recommendation summary."""
sid = result.get("recommended_service_id", "?")
reason = result.get("reason_ar", "")
svc = result.get("service") or {}
name = svc.get("name_ar", sid)
outcome = svc.get("outcome_ar", "")
return (
f"الخدمة المقترحة: {name}. السبب: {reason} "
f"المخرجات: {outcome}"
)