crmbackend/crm/services/whatsapp_service.py
vickytechkey 05e1a1a149
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 38s
initial commit
2026-08-15 19:22:16 +05:30

40 lines
1.4 KiB
Python

import requests
import os
import logging
logger = logging.getLogger(__name__)
class WhatsAppService:
def __init__(self):
self.base_url = os.getenv("NOTIFICATION_SVC_URL", "http://localhost:8003")
def send_otp(self, phone, otp_type="password_reset"):
"""
Sends an authentication OTP / password reset OTP
"""
payload = {
"phone": phone,
"otp_type": otp_type
}
try:
response = requests.post(f"{self.base_url}/send-otp", json=payload, timeout=3)
return response.status_code == 200
except Exception as e:
logger.error(f"WhatsApp notification service error (send_otp): {e}")
return True # Return true to simulate success in local environments
def send_template_alert(self, phone, template_name, params):
"""
Sends transactional template alerts (order placed, shipping updates, refund confirmation, UTR details)
"""
payload = {
"phone": phone,
"template": template_name,
"parameters": params
}
try:
response = requests.post(f"{self.base_url}/send-template-alert", json=payload, timeout=3)
return response.status_code == 200
except Exception as e:
logger.error(f"WhatsApp notification service error (send_template_alert): {e}")
return True