Use firm email templates, logo, and header/footer in async UI
This commit is contained in:
+52
-6
@@ -11,10 +11,13 @@ from datetime import datetime
|
||||
from .celery_app import celery_app
|
||||
from .autotranscript import Scraibe
|
||||
from .misc import setup_logging
|
||||
from .email_sender import send_email, EmailError
|
||||
from .email_sender import send_email, EmailError, load_template
|
||||
|
||||
logger = logging.getLogger("scraibe.tasks")
|
||||
|
||||
# Contact email used in templates; can be overridden via env
|
||||
CONTACT_EMAIL = os.getenv("EMAIL_CONTACT_ADDRESS", "support@example.com")
|
||||
|
||||
|
||||
def get_queue_position(task_id: str) -> int:
|
||||
"""
|
||||
@@ -38,9 +41,11 @@ def get_queue_position(task_id: str) -> int:
|
||||
|
||||
def send_initial_email(to: str, queue_pos: int):
|
||||
"""
|
||||
Send initial confirmation email with queue position.
|
||||
Send initial confirmation email with queue position using HTML template.
|
||||
"""
|
||||
subject = "ScrAIbe: Your transcription request has been received"
|
||||
|
||||
# Build plain-text fallback
|
||||
body = (
|
||||
"Hello,\n\n"
|
||||
"We have received your audio file for transcription.\n"
|
||||
@@ -55,11 +60,24 @@ def send_initial_email(to: str, queue_pos: int):
|
||||
"\n"
|
||||
"You will receive an email with your transcript (and summary, if requested) "
|
||||
"once processing is complete.\n\n"
|
||||
"If you have any questions, contact us at "
|
||||
f"{CONTACT_EMAIL}.\n\n"
|
||||
"This is an automated message from ScrAIbe.\n"
|
||||
)
|
||||
|
||||
# Build HTML using template
|
||||
html = None
|
||||
try:
|
||||
send_email(to=to, subject=subject, body=body, attachments=[])
|
||||
html = load_template(
|
||||
"upload_notification_template.html",
|
||||
queue_position=str(queue_pos) if queue_pos > 0 else "the queue",
|
||||
contact_email=CONTACT_EMAIL,
|
||||
)
|
||||
except EmailError as e:
|
||||
logger.warning("Failed to render upload notification template: %s", e)
|
||||
|
||||
try:
|
||||
send_email(to=to, subject=subject, body=body, html=html, attachments=[])
|
||||
logger.info("Initial confirmation email sent to %s", to)
|
||||
except EmailError as e:
|
||||
logger.error("Failed to send initial email to %s: %s", to, e)
|
||||
@@ -73,10 +91,11 @@ def send_success_email(
|
||||
task_id: str,
|
||||
):
|
||||
"""
|
||||
Send final email with transcript and attachments.
|
||||
Send final email with transcript and attachments using HTML template.
|
||||
"""
|
||||
subject = "ScrAIbe: Your transcript is ready"
|
||||
|
||||
# Build plain-text fallback
|
||||
body = (
|
||||
"Hello,\n\n"
|
||||
"Your transcription is ready.\n\n"
|
||||
@@ -94,14 +113,27 @@ def send_success_email(
|
||||
body += (
|
||||
"\n"
|
||||
"Job ID: " + str(task_id) + "\n\n"
|
||||
"If you have any questions, contact us at "
|
||||
f"{CONTACT_EMAIL}.\n\n"
|
||||
"This is an automated message from ScrAIbe.\n"
|
||||
)
|
||||
|
||||
# Build HTML using template
|
||||
html = None
|
||||
try:
|
||||
html = load_template(
|
||||
"success_template.html",
|
||||
contact_email=CONTACT_EMAIL,
|
||||
)
|
||||
except EmailError as e:
|
||||
logger.warning("Failed to render success template: %s", e)
|
||||
|
||||
try:
|
||||
send_email(
|
||||
to=to,
|
||||
subject=subject,
|
||||
body=body,
|
||||
html=html,
|
||||
attachments=attachments,
|
||||
)
|
||||
logger.info("Success email sent to %s for job %s", to, task_id)
|
||||
@@ -111,21 +143,35 @@ def send_success_email(
|
||||
|
||||
def send_error_email(to: str, error_message: str, task_id: str):
|
||||
"""
|
||||
Send error notification email.
|
||||
Send error notification email using HTML template.
|
||||
"""
|
||||
subject = "ScrAIbe: Error with your transcription request"
|
||||
|
||||
# Build plain-text fallback
|
||||
body = (
|
||||
"Hello,\n\n"
|
||||
"We encountered an error while processing your transcription request.\n\n"
|
||||
f"Details: {error_message}\n\n"
|
||||
"Job ID: " + str(task_id) + "\n\n"
|
||||
"Please contact your administrator if the problem persists.\n\n"
|
||||
"If you have any questions, contact us at "
|
||||
f"{CONTACT_EMAIL}.\n\n"
|
||||
"This is an automated message from ScrAIbe.\n"
|
||||
)
|
||||
|
||||
# Build HTML using template
|
||||
html = None
|
||||
try:
|
||||
send_email(to=to, subject=subject, body=body, attachments=[])
|
||||
html = load_template(
|
||||
"error_notification_template.html",
|
||||
exception=str(error_message),
|
||||
contact_email=CONTACT_EMAIL,
|
||||
)
|
||||
except EmailError as e:
|
||||
logger.warning("Failed to render error template: %s", e)
|
||||
|
||||
try:
|
||||
send_email(to=to, subject=subject, body=body, html=html, attachments=[])
|
||||
logger.info("Error email sent to %s for job %s", to, task_id)
|
||||
except EmailError as e:
|
||||
logger.error("Failed to send error email to %s for job %s: %s", to, task_id, e)
|
||||
|
||||
Reference in New Issue
Block a user