Spaces:
Sleeping
Sleeping
# SMS TONES MODULE FOR JAY'S MOBILE WASH | |
# Simplified version for compatibility | |
import os | |
import json | |
import logging | |
from pathlib import Path | |
# Configure logging | |
logging.basicConfig( | |
level=logging.INFO, | |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' | |
) | |
logger = logging.getLogger('sms_tones') | |
# Import utility functions with fallbacks | |
try: | |
from modules.utils import handle_errors, ErrorManager, generate_id | |
except ImportError: | |
# Fallback definitions if imports fail | |
def handle_errors(func): | |
return func | |
class ErrorManager: | |
def add_error(*args, **kwargs): | |
logger.error(f"Error: {kwargs.get('error_message', 'Unknown error')}") | |
def generate_id(prefix='id_'): | |
import random, time | |
timestamp = int(time.time() * 1000) | |
random_part = random.randint(1000, 9999) | |
return f"{prefix}{timestamp}{random_part}" | |
# Paths with fallbacks | |
try: | |
from modules.utils import CONFIG_DIR, STATIC_DIR | |
TONES_DIR = os.path.join(STATIC_DIR, "tones") | |
except ImportError: | |
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
CONFIG_DIR = os.path.join(BASE_DIR, "config") | |
STATIC_DIR = os.path.join(BASE_DIR, "static") | |
TONES_DIR = os.path.join(STATIC_DIR, "tones") | |
# Ensure directories exist | |
Path(TONES_DIR).mkdir(parents=True, exist_ok=True) | |
Path(CONFIG_DIR).mkdir(parents=True, exist_ok=True) | |
class ToneManager: | |
"""Simplified SMS tone manager""" | |
def __init__(self): | |
"""Initialize tone manager with default examples only""" | |
self.examples = self._create_default_examples() | |
logger.info("Initialized simplified tone manager") | |
def _create_default_examples(self): | |
"""Create default tone examples""" | |
return { | |
"Professional": { | |
"text": "Thank you for scheduling with Jay's Mobile Wash. Your appointment is confirmed for {date} at {time}.", | |
"audio": "professional.mp3" | |
}, | |
"Friendly": { | |
"text": "Hey there! Thanks for booking with us! We've got you down for {date} at {time}. Can't wait to get your car looking awesome! π", | |
"audio": "friendly.mp3" | |
}, | |
"Casual": { | |
"text": "Your wash is booked for {date} at {time}. See you then!", | |
"audio": "casual.mp3" | |
}, | |
"Urgent": { | |
"text": "IMPORTANT: Your appointment in 1 HOUR. Please ensure your vehicle is accessible.", | |
"audio": "urgent.mp3" | |
}, | |
"Reminder": { | |
"text": "Just a friendly reminder about your car wash tomorrow at {time}. Text back if you need to reschedule.", | |
"audio": "reminder.mp3" | |
} | |
} | |
def get_examples(self): | |
"""Get all tone examples""" | |
return self.examples | |
def get_example(self, tone_name): | |
"""Get a specific tone example""" | |
return self.examples.get(tone_name, None) | |
def format_message(self, tone_name, **kwargs): | |
"""Format a message using the specified tone and parameters""" | |
if tone_name not in self.examples: | |
tone_name = "Professional" # Default to Professional if not found | |
template = self.examples[tone_name]["text"] | |
try: | |
return template.format(**kwargs) | |
except KeyError: | |
return template # Return unformatted template if formatting fails | |
# Global instance | |
tone_manager = ToneManager() |