Remise en état des fichiers
This commit is contained in:
34
app/utils_sms.py
Normal file
34
app/utils_sms.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
import ovh
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
def envoyer_sms(message: str, lieu: str = ""):
|
||||
try:
|
||||
client = ovh.Client(
|
||||
endpoint=os.getenv("OVH_ENDPOINT"),
|
||||
application_key=os.getenv("OVH_APP_KEY"),
|
||||
application_secret=os.getenv("OVH_APP_SECRET"),
|
||||
consumer_key=os.getenv("OVH_CONSUMER_KEY"),
|
||||
)
|
||||
|
||||
services = client.get('/sms/')
|
||||
if not services:
|
||||
print("❌ Aucun service SMS OVH trouvé", flush=True)
|
||||
return
|
||||
|
||||
service_name = services[0]
|
||||
numero_dest = os.getenv("NUMERO_DESTINATAIRE")
|
||||
|
||||
result = client.post(f'/sms/{service_name}/jobs',
|
||||
sender='Monitor',
|
||||
message=message,
|
||||
receivers=[numero_dest],
|
||||
noStopClause=True
|
||||
)
|
||||
print(f"📱 SMS envoyé à {numero_dest} pour {lieu}. Job ID : {result['ids']}", flush=True)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Erreur envoi SMS : {e}", flush=True)
|
||||
|
||||
Reference in New Issue
Block a user