Spaces:
Sleeping
Sleeping
File size: 3,641 Bytes
f9cd25c 9eaa27a f9cd25c 9eaa27a f9cd25c 9eaa27a f9cd25c 9eaa27a f9cd25c 9eaa27a f9cd25c 9eaa27a f9cd25c 9eaa27a f9cd25c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# 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:
@staticmethod
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"
}
}
@handle_errors
def get_examples(self):
"""Get all tone examples"""
return self.examples
@handle_errors
def get_example(self, tone_name):
"""Get a specific tone example"""
return self.examples.get(tone_name, None)
@handle_errors
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() |