sendTemplate($tplName, $lang, $to, [$prenomNom, $dateHeureDDMMYYYY_HHMM]); } function notify_rdv_en_attente(string $to, string $prenomNom, string $dateHeureDDMMYYYY_HHMM, int $rdvId): array { // Config & templates $cfg = is_file(__DIR__.'/config.php') ? require __DIR__.'/config.php' : [ 'phone_number_id' => getenv('WHATSAPP_PHONE_NUMBER_ID') ?: '', 'access_token' => getenv('WHATSAPP_TOKEN') ?: '', 'default_lang' => 'ru', 'timeout' => 20, ]; if (($cfg['phone_number_id'] ?? '') === '' || ($cfg['access_token'] ?? '') === '') { throw new \RuntimeException("Config WhatsApp manquante: crée /sms/config.php ou définis les variables d'environnement."); } $templates = require __DIR__ . '/templates.php'; $tplName = 'en_attente_confirmation'; $tpl = $templates[$tplName] ?? null; if (!$tpl) { throw new \RuntimeException("Template {$tplName} non déclaré dans /sms/templates.php"); } // Valide date/heure "01/01/2025 12:00" if (!preg_match('/^\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}$/', $dateHeureDDMMYYYY_HHMM)) { throw new \InvalidArgumentException('Format date/heure invalide. Attendu: "01/01/2025 12:00"'); } // Vérifie compte de variables attendu $expectedBody = (int)($tpl['components']['body_params'] ?? 0); if ($expectedBody !== 2) { throw new \RuntimeException("Le template {$tplName} attend {$expectedBody} paramètres BODY, 2 fournis."); } // Bouton URL index "0" avec 1 paramètre ({{1}}) $btnCfg = $tpl['components']['button_url_params']['0'] ?? 0; if ((int)$btnCfg !== 1) { throw new \RuntimeException("Le bouton URL index 0 du template {$tplName} doit attendre 1 paramètre."); } $lang = $tpl['language'] ?: ($cfg['default_lang'] ?? 'ru'); $client = new WaClient($cfg); // BODY: {{1}} prénomNom, {{2}} dateHeure ; BUTTON index "0": {{1}} = rdvId return $client->sendTemplate( $tplName, $lang, $to, [$prenomNom, $dateHeureDDMMYYYY_HHMM], ['0' => [(string)$rdvId]] ); }