Skip to content

Commit

Permalink
Apply the rest of the emails to the new template.
Browse files Browse the repository at this point in the history
  • Loading branch information
MelissaAutumn committed Aug 15, 2024
1 parent 7a77fe4 commit 815203d
Show file tree
Hide file tree
Showing 16 changed files with 371 additions and 169 deletions.
55 changes: 32 additions & 23 deletions backend/src/appointment/controller/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,27 @@ def __init__(self, name, email, date, duration, *args, **kwargs):
self.email = email
self.date = date
self.duration = duration

# Pass to super now!
super().__init__(*args, **kwargs)

# Localize date and time range format
self.time_format = l10n('time-format')
self.date_format = l10n('date-format')

# If value is key then there's no localization available, set a default.
if self.time_format == 'time-format':
self.time_format = '%I:%M%p'
if self.date_format == 'date-format':
self.date_format = '%A, %B %d %Y'

date_end = self.date + datetime.timedelta(minutes=self.duration)

self.time_range = ' - '.join([date.strftime('%I:%M%p'), date_end.strftime('%I:%M%p')])
self.time_range = ' - '.join([date.strftime(self.time_format), date_end.strftime(self.time_format)])
self.timezone = ''
if self.date.tzinfo:
self.timezone += f'({date.strftime("%Z")})'
self.day = date.strftime('%A, %B %d %Y')
self.day = date.strftime(self.date_format)

def _attachments(self):
"""We need these little icons for the message body"""
Expand Down Expand Up @@ -226,20 +238,12 @@ def text(self):
class ConfirmationMail(BaseBookingMail):
def __init__(self, confirm_url, deny_url, name, email, date, duration, schedule_name, *args, **kwargs):
"""init Mailer with confirmation specific defaults"""
print("Init!")
self.confirmUrl = confirm_url
self.denyUrl = deny_url
self.schedule_name = schedule_name
default_kwargs = {'subject': l10n('confirm-mail-subject', {'name': name})}
super().__init__(name=name, email=email, date=date, duration=duration, *args, **default_kwargs, **kwargs)

date_end = self.date + datetime.timedelta(minutes=self.duration)

self.time_range = ' - '.join([date.strftime('%I:%M%p'), date_end.strftime('%I:%M%p')])
self.timezone = ''
if self.date.tzinfo:
self.timezone += f'({date.strftime("%Z")})'
self.day = date.strftime('%A, %B %d %Y')

def text(self):
return l10n(
Expand Down Expand Up @@ -303,30 +307,35 @@ def html(self):
return get_template('pending.jinja2').render(owner_name=self.owner_name, date=self.date)


class NewBookingMail(Mailer):
def __init__(self, attendee_name, attendee_email, date, *args, **kwargs):
class NewBookingMail(BaseBookingMail):
def __init__(self, name, email, date, duration, schedule_name, *args, **kwargs):
"""init Mailer with confirmation specific defaults"""
self.attendee_name = attendee_name
self.attendee_email = attendee_email
self.date = date
default_kwargs = {'subject': l10n('new-booking-subject', {'attendee_name': self.attendee_name})}
super(NewBookingMail, self).__init__(*args, **default_kwargs, **kwargs)
self.schedule_name = schedule_name
default_kwargs = {'subject': l10n('new-booking-subject', {'name': name})}
super().__init__(name=name, email=email, date=date, duration=duration, *args, **default_kwargs, **kwargs)

def text(self):
return l10n(
'new-booking-plain',
{
'attendee_name': self.attendee_name,
'attendee_email': self.attendee_email,
'name': self.name,
'email': self.email,
'date': self.date,
},
)

def html(self):
return get_template('new_booking.jinja2').render(
attendee_name=self.attendee_name,
attendee_email=self.attendee_email,
date=self.date,
name=self.name,
email=self.email,
time_range=self.time_range,
timezone=self.timezone,
day=self.day,
duration=self.duration,
schedule_name=self.schedule_name,
# Icon cids
calendar_icon_cid=self._attachments()[0].filename,
clock_icon_cid=self._attachments()[1].filename,
)


Expand All @@ -338,7 +347,7 @@ def __init__(self, requestee_name, requestee_email, topic, details, *args, **kwa
self.topic = topic
self.details = details
default_kwargs = {'subject': l10n('support-mail-subject', {'topic': topic})}
super(SupportRequestMail, self).__init__(os.getenv('SUPPORT_EMAIL'), *args, **default_kwargs, **kwargs)
super(SupportRequestMail, self).__init__(os.getenv('SUPPORT_EMAIL', '[email protected]'), *args, **default_kwargs, **kwargs)

def text(self):
return l10n(
Expand Down
59 changes: 40 additions & 19 deletions backend/src/appointment/l10n/de/email.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,50 @@ mail-brand-footer = {-brand-footer}

invite-mail-subject = Einladung gesendet von {-brand-name}
invite-mail-plain = {-brand-footer}
invite-mail-html = {-brand-footer}
## New Booking

# Variables
# $attendee_name (String) - Name of the person who requested the appointment
new-booking-subject = Du hast eine neue bestätigte Terminbuchung mit { $attendee_name }
# $name (String) - Name of the person who requested the appointment
new-booking-subject = Du hast eine neue bestätigte Terminbuchung mit { $name }
# Variables:
# $attendee_name (String) - Name of the person who requested the appointment
# $appointment_email (String) - Email of the person who requested the appointment
# $name (String) - Name of the person who requested the appointment
# $email (String) - Email of the person who requested the appointment
# $date (String) - Date of the Appointment
new-booking-plain = { $attendee_name } ({ $attendee_email }) hat soeben { $date } gebucht
new-booking-plain = { $name } ({ $email }) hat soeben { $date } gebucht
{-brand-footer}
# Variables:
# $attendee_name (String) - Name of the person who requested the appointment
# $appointment_email (String) - Email of the person who requested the appointment
# $name (String) - Name of the person who requested the appointment
# $email (String) - Email of the person who requested the appointment
# $date (String) - Date of the requested appointment
new-booking-html-heading = { $attendee_name } ({ $attendee_email }) hat soeben { $date } gebucht
# $schedule_name (String) - The name of the schedule used to book the appointment
# $duration (String) - Length of minutes the appointment will be
new-booking-html-heading-name = { $name }
new-booking-html-heading-email = ({ $email })
# FIXME: Google Translate Patch !
new-booking-html-heading-text = hat gerade Zeit im { $schedule_name } gebucht
new-booking-html-time = { $duration } mins
## Confirm Appointment

confirm-mail-subject = Buchungsanfrage von {-brand-name} bestätigen
# Variables:
# $attendee_name (String) - Name of the person who requested the appointment
# $appointment_email (String) - Email of the person who requested the appointment
# $date (String) - Date of the Appointment
# $name (String) - Name of the person who requested the appointment
# $email (String) - Email of the person who requested the appointment
# $duration (String) - Length of meeting in minutes
# $day (String) - Formatted date string
# $time_range (String) - Formatted time string
# $timezone (String) - Timezone (e.g. UTC, PST, etc...)
# $schedule_name - Name of the schedule the appointment was booked on
# $confirm_url (String) - URL that when clicked will confirm the appointment
# $deny_url (String) - URL that when clicked will deny the appointment
confirm-mail-plain = { $attendee_name } ({ $attendee_email }) hat soeben dieses Zeitfenster aus deinem Kalender angefordert: { $date }
confirm-mail-plain = { $name } ({ $email }) hat soeben dieses Zeitfenster aus deinem Kalender angefordert:
{ $duration } mins
{ $time_range } ({ $timezone })
{ $day }
Dieser Link führt zur Bestätigung der Buchungsanfrage:
{ $confirm_url }
Expand All @@ -51,10 +64,17 @@ confirm-mail-plain = { $attendee_name } ({ $attendee_email }) hat soeben dieses
{-brand-footer}
# Variables:
# $attendee_name (String) - Name of the person who requested the appointment
# $appointment_email (String) - Email of the person who requested the appointment
# $name (String) - Name of the person who requested the appointment
# $email (String) - Email of the person who requested the appointment
# $date (String) - Date of the requested appointment
confirm-mail-html-heading = { $attendee_name } ({ $attendee_email }) hat soeben dieses Zeitfenster aus deinem Kalender angefordert: { $date }.
# $schedule_name (String) - The name of the schedule used to book the appointment
# $duration (String) - Length of minutes the appointment will be
# FIXME: Google Translation patch !
confirm-mail-html-heading-name = { $name }
confirm-mail-html-heading-email = ({ $email })
confirm-mail-html-heading-text = fordert die Buchung eines Zeitfensters in { $schedule_name } an
confirm-mail-html-time = { $duration } mins
confirm-mail-html-confirm-text = Dieser Link führt zur Bestätigung der Buchungsanfrage:
confirm-mail-html-confirm-action = Buchung bestätigen
confirm-mail-html-deny-text = Dieser Link führt zur Ablehnung der Buchungsanfrage:
Expand Down Expand Up @@ -126,7 +146,8 @@ support-mail-plain = { $requestee_name } ({ $requestee_email }) hat folgende Sup
## New/Invited Account Email
new-account-mail-subject = Du wurdest zu Thunderbird Appointment eingeladen
new-account-mail-action = Weiter zu Thunderbird Appointment
new-account-mail-html-heading = Du wurdest zu Thunderbird Appointment eingeladen. Logge dich mit dieser E-Mail-Adresse ein um fortzufahren.
new-account-mail-html-heading = Du wurdest zu Thunderbird Appointment eingeladen.
new-account-mail-html-body = Logge dich mit dieser E-Mail-Adresse ein um fortzufahren.
# Variables:
# $homepage_url (String) - URL to Thunderbird Appointment
new-account-mail-plain = Du wurdest zu Thunderbird Appointment eingeladen.
Expand All @@ -138,8 +159,8 @@ new-account-mail-plain = Du wurdest zu Thunderbird Appointment eingeladen.
confirm-email-mail-subject = Bestätige deine E-Mail-Adresse um der Warteliste beizutreten!
confirm-email-mail-confirm-action = Bestätige deine E-Mail-Adresse
confirm-email-mail-decline-action = Entferne deine E-Mail-Adresse
confirm-email-mail-html-body = Danke für Dein Interesse an Thunderbird Appointment.
Bevor wir Dich auf unsere Warteliste setzen, musst Du Deine E-Mail-Adresse unten bestätigen.
confirm-email-mail-html-heading = Danke für Dein Interesse an Thunderbird Appointment.
confirm-email-mail-html-body = Bevor wir Dich auf unsere Warteliste setzen, musst Du Deine E-Mail-Adresse unten bestätigen.
confirm-email-mail-html-body-2 = Hast Du diese E-Mail irrtümlich erhalten, oder bist nicht mehr interessiert?
# Variables:
# $confirm_email_url (String) - URL to confirm your email
Expand Down
7 changes: 7 additions & 0 deletions backend/src/appointment/l10n/de/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
# Locale code
locale = de
# Format Strings

# Time Format: 20:23
time-format = %H:%M
# Date Format: Sunday, 04. April 2024
date-format = %A, %d. %B %Y
## Health Check

# Should indicate application wellness.
Expand Down
33 changes: 20 additions & 13 deletions backend/src/appointment/l10n/en/email.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ mail-brand-footer = This message was sent from:

invite-mail-subject = Invitation sent from {-brand-name}
invite-mail-plain = {-brand-footer}
invite-mail-html = {-brand-footer}
invite-mail-html-heading-name = { $name }
invite-mail-html-heading-email = ({ $email })
Expand All @@ -31,20 +30,25 @@ invite-mail-html-download = Download

# Variables
# $attendee_name (String) - Name of the person who requested the appointment
new-booking-subject = You have a new confirmed booking with { $attendee_name }
new-booking-subject = You have a new confirmed booking with { $name }
# Variables:
# $attendee_name (String) - Name of the person who requested the appointment
# $appointment_email (String) - Email of the person who requested the appointment
# $name (String) - Name of the person who requested the appointment
# $email (String) - Email of the person who requested the appointment
# $date (String) - Date of the Appointment
new-booking-plain = { $attendee_name } ({ $attendee_email }) has just booked { $date }
new-booking-plain = { $name } ({ $email }) has just booked { $date }
{-brand-footer}
# Variables:
# $attendee_name (String) - Name of the person who requested the appointment
# $appointment_email (String) - Email of the person who requested the appointment
# $name (String) - Name of the person who requested the appointment
# $email (String) - Email of the person who requested the appointment
# $date (String) - Date of the requested appointment
new-booking-html-heading = { $attendee_name } ({ $attendee_email }) has just booked { $date }
# $schedule_name (String) - The name of the schedule used to book the appointment
# $duration (String) - Length of minutes the appointment will be
new-booking-html-heading-name = { $name }
new-booking-html-heading-email = ({ $email })
new-booking-html-heading-text = has just booked time in { $schedule_name }:
new-booking-html-time = { $duration } mins
## Confirm Appointment

Expand Down Expand Up @@ -75,9 +79,11 @@ confirm-mail-plain = { $name } ({ $email }) is requesting to book a time slot in
{-brand-footer}
# Variables:
# $attendee_name (String) - Name of the person who requested the appointment
# $appointment_email (String) - Email of the person who requested the appointment
# $name (String) - Name of the person who requested the appointment
# $email (String) - Email of the person who requested the appointment
# $date (String) - Date of the requested appointment
# $schedule_name (String) - The name of the schedule used to book the appointment
# $duration (String) - Length of minutes the appointment will be
confirm-mail-html-heading-name = { $name }
confirm-mail-html-heading-email = ({ $email })
confirm-mail-html-heading-text = is requesting to book a time slot in { $schedule_name }:
Expand Down Expand Up @@ -154,7 +160,8 @@ support-mail-plain = { $requestee_name } ({ $requestee_email }) sent the followi
## New/Invited Account Email
new-account-mail-subject = You've been invited to Thunderbird Appointment
new-account-mail-action = Continue to Thunderbird Appointment
new-account-mail-html-heading = You've been invited to Thunderbird Appointment. Login with this email address to continue.
new-account-mail-html-heading = You've been invited to Thunderbird Appointment.
new-account-mail-html-body = Login with this email address to continue.
# Variables:
# $homepage_url (String) - URL to Thunderbird Appointment
new-account-mail-plain = You've been invited to Thunderbird Appointment.
Expand All @@ -166,8 +173,8 @@ new-account-mail-plain = You've been invited to Thunderbird Appointment.
confirm-email-mail-subject = Confirm your email to join the waiting list!
confirm-email-mail-confirm-action = Confirm your email
confirm-email-mail-decline-action = Remove your email
confirm-email-mail-html-body = Thank you for your interest in Thunderbird Appointment.
Before we add you to our waiting list we need you to confirm your email address below.
confirm-email-mail-html-heading = Thank you for your interest in Thunderbird Appointment.
confirm-email-mail-html-body = Before we add you to our waiting list we need you to confirm your email address below.
confirm-email-mail-html-body-2 = Did you receive this email in error, or are you no longer interested?
# Variables:
# $confirm_email_url (String) - URL to confirm your email
Expand Down
7 changes: 7 additions & 0 deletions backend/src/appointment/l10n/en/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
# Locale code
locale = en
# Format Strings

# Time Format: 8:23pm
time-format = %I:%M%p
# Date Format: Sunday, April 04 2024
date-format = %A, %B %d %Y
## Health Check

# Should indicate application wellness.
Expand Down
10 changes: 9 additions & 1 deletion backend/src/appointment/routes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ..exceptions import validation
from ..exceptions.validation import RemoteCalendarConnectionError, APIException
from ..l10n import l10n
from ..tasks.emails import send_support_email, send_confirmation_email, send_invite_email
from ..tasks.emails import send_support_email

router = APIRouter()

Expand Down Expand Up @@ -520,6 +520,14 @@ def send_feedback(
):
"""Send a subscriber's support request to the configured support email address"""
if not os.getenv('SUPPORT_EMAIL'):
# Ensure sentry at least captures it!
if os.getenv('SENTRY_DSN'):
sentry_sdk.capture_message("No SUPPORT_EMAIL is set, support messages are being ignored!")
sentry_sdk.capture_message(f"""
Support Email Alert!
FROM: {subscriber.name} <{subscriber.preferred_email}>
SUBJECT: {form_data.topic}
MESSAGE: {form_data.details}""")
raise APIException()

background_tasks.add_task(
Expand Down
6 changes: 4 additions & 2 deletions backend/src/appointment/routes/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,11 @@ def request_schedule_availability_slot(
# Notify the subscriber that they have a new confirmed booking
background_tasks.add_task(
send_new_booking_email,
attendee_name=attendee.name,
attendee_email=attendee.email,
name=attendee.name,
email=attendee.email,
date=date,
duration=slot.duration,
schedule_name=schedule.name,
to=subscriber.preferred_email
)

Expand Down
Loading

0 comments on commit 815203d

Please sign in to comment.