Init Git Prod Mars 2026
This commit is contained in:
commit
d81efe93b1
362 files changed
+86627
No files matched your search
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
// /sms/notify_rdv.php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sms;
|
||||
|
||||
require_once __DIR__ . '/wa_client.php';
|
||||
|
||||
function notify_rdv(string $to, string $prenomNom, string $dateHeureDDMMYYYY_HHMM): array
|
||||
{
|
||||
// Charge config & templates
|
||||
$cfg = require __DIR__ . '/config.php';
|
||||
$templates = require __DIR__ . '/templates.php';
|
||||
|
||||
$tplName = 'notification_rdv';
|
||||
$tpl = $templates[$tplName] ?? null;
|
||||
if (!$tpl) {
|
||||
throw new \RuntimeException("Template {$tplName} non déclaré dans /sms/templates.php");
|
||||
}
|
||||
|
||||
// Valide le format date/heure attendu "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 le compte de variables attendu dans le BODY
|
||||
$expected = (int)($tpl['components']['body_params'] ?? 0);
|
||||
$actual = 2;
|
||||
if ($expected !== $actual) {
|
||||
throw new \RuntimeException("Le template {$tplName} attend {$expected} paramètres BODY, {$actual} fournis.");
|
||||
}
|
||||
|
||||
$lang = $tpl['language'] ?: ($cfg['default_lang'] ?? 'ru');
|
||||
|
||||
$client = new WaClient($cfg);
|
||||
// {{1}} = prénom nom ; {{2}} = date-heure
|
||||
return $client->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]]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user