Rdeirection BDE

This commit is contained in:
2026-05-04 11:16:20 +02:00
parent 99300db2ca
commit f3af1428af
14 changed files with 605 additions and 83 deletions

55
Test_SMS.py Normal file
View File

@@ -0,0 +1,55 @@
import os, time
from dotenv import load_dotenv
import ovh
load_dotenv()
client = ovh.Client(
endpoint=os.getenv("OVH_ENDPOINT", "ovh-eu"),
application_key=os.getenv("OVH_APPLICATION_KEY"),
application_secret=os.getenv("OVH_APPLICATION_SECRET"),
consumer_key=os.getenv("OVH_CONSUMER_KEY"),
)
service = os.getenv("OVH_SMS_SERVICE")
sender = os.getenv("OVH_SMS_SENDER")
to = os.getenv("TEST_RECEIVER")
message = "ALERTE TEST DOMO91 (transactionnel)."
# Envoi immédiat (pas de differedDelivery)
payload = {
"sender": sender,
"receivers": [to],
"message": message,
"priority": "high",
"coding": "7bit",
"class": "phoneDisplay",
"noStopClause": True, # => H24 si autorisé par OVH
"senderForResponse": False, # True si vous utilisez un numéro et attendez des réponses
"validityPeriod": 2880, # minutes où le SMS reste valable (2 jours)
"tag": "test-ovh",
}
print("Envoi en cours…")
resp = client.post(f"/sms/{service}/jobs", **payload)
# La réponse contient des taskIds pour suivre l'état
print("Réponse OVH:", resp)
task_ids = resp.get("ids", [])
if task_ids:
task_id = task_ids[0]
# Boucle de suivi simple (optionnelle)
while True:
task = client.get(f"/sms/{service}/jobs/{task_id}")
print("Etat tâche:", task.get("status"))
if task.get("status") in ("done", "error", "cancelled"):
break
time.sleep(2)
# On peut aussi lister les SMS sortants pour voir le statut final
outgoing_ids = client.get(f"/sms/{service}/outgoing")
if outgoing_ids:
last_id = outgoing_ids[-1]
last = client.get(f"/sms/{service}/outgoing/{last_id}")
print("Dernier SMS:", {k: last[k] for k in ("creationDatetime","receiver","status","messageId")})