Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ exact tag (`ghcr.io/calnode/calnode:0.1.0`) if you need stability between upgrad
is still pending is refused until the reconciler has removed it. A past meeting's event stays on
the host's calendar, because removing it through the provider would email the guest; the
dialog says so. Database backups keep the data until their own retention ends.
- **Intake answers in the host's booking email.** A per-event-type option (Notifications
tab, `answers_in_host_email`, off by default) lists the attendee's answers to the intake
questions in each host's new-booking email, and in the new host's email when a booking is
reassigned, so the context is at hand before the call. Only hosts get them. The
attendee's emails and the calendar event do not, because on Google, Microsoft and CalDAV
the attendee sees the event description in their own invite. Migration `00076` adds the
column.
- **German without du or Sie (`de-x-neutral`).** An opt-in wording variant of the German
booker catalogue that addresses nobody: "Tag auswählen" rather than "Wählen Sie einen
Tag". It is for operators whose own site is informal, where the formal widget stands out
Expand Down
8 changes: 8 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,14 @@ as the desired state:
- **Per-event-type customisation:** custom note bodies (`msg_*`) and custom subject
lines (`subj_*`, migration 00026) for the four attendee emails; a blank subject
falls back to the built-in default (`BookingData.SubjectOverride` / `subjectOr`).
- **Intake answers in the host's email** (`event_types.answers_in_host_email`, migration
00076, **default off**, #264): each host's new-booking email (on create, and to the new
host on reassignment) lists the attendee's answers, unanswered ones left out
(`Handler.hostEmailAnswers`). They travel in `BookingData.HostAnswers`, which only the
host templates read and which is set only on each host's copy (`notifyHosts`), never on
the data the attendee's email and `.ics` are built from. The calendar event description
is deliberately **not** used: on Google, Microsoft and CalDAV the attendee is an invitee
and sees it in their own invite, so it is not a host-only channel.
- **Branding (`branding_settings.go`, migrations 00029/00050):** instance-wide
`business_name` + `logo_url` + `banner_url` on the singleton row. Business name is the
wordmark fallback (defaults to "Calnode") + public-page header; the logo is the email
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export type EventType = {
* them. Off by default: the slots endpoint is public, so this makes the host's
* booked hours visible to anyone with the link. */
show_taken_slots: boolean;
/** List the attendee's intake answers in each host's new-booking email. Off by
* default; never added to the attendee's emails or the calendar event. */
answers_in_host_email: boolean;
/** Show the next free time above the booking page's time list, as a button that
* opens that day. Off by default. */
show_next_available: boolean;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,8 @@
"notifications": {
"reminders": "Reminders",
"remindersHint": "Send attendees a reminder email before the meeting. Defaults to 24 hours before if none are set.",
"answersInHostEmail": "List intake answers in the host's booking email",
"answersInHostEmailHint": "The new-booking email to each host includes the attendee's answers to the intake questions, so they are at hand before the meeting. Only hosts receive them: the attendee's emails and the calendar event never include them. Off by default, because answers can contain personal details.",
"addReminder": "+ Add reminder",
"customMessages": "Custom messages",
"customMessagesHint": "Add an optional note appended to each email type.",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,8 @@
"notifications": {
"reminders": "Rappels",
"remindersHint": "Envoyer aux participants un e-mail de rappel avant la réunion. Par défaut 24 heures avant si aucun n'est défini.",
"answersInHostEmail": "Inclure les réponses au questionnaire dans l'e-mail à l'hôte",
"answersInHostEmailHint": "L'e-mail de nouvelle réservation envoyé à chaque hôte contient les réponses du participant aux questions du formulaire, pour les avoir sous la main avant la réunion. Seuls les hôtes les reçoivent : les e-mails du participant et l'événement du calendrier ne les contiennent jamais. Désactivé par défaut, car les réponses peuvent contenir des données personnelles.",
"addReminder": "+ Ajouter un rappel",
"customMessages": "Messages personnalisés",
"customMessagesHint": "Ajoutez une note facultative à la fin de chaque type d'e-mail.",
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/routes/event-types/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
{ value: 168, label: $t('eventTypeEditor.reminders.option.168h') },
]);
let reminders = $state<number[]>([]);
let answersInHostEmail = $state(false);
let msg_confirmation = $state('');
let msg_cancellation = $state('');
let msg_reschedule = $state('');
Expand Down Expand Up @@ -350,6 +351,7 @@
};
priceMajor = ((et.price_cents ?? 0) / 100).toFixed(2);
reminders = et.reminders ?? [];
answersInHostEmail = et.answers_in_host_email ?? false;
if (et.routing_mode === 'round_robin') { hostScope = 'people'; staffing = 'rotate'; }
else if (et.routing_mode === 'collective') { hostScope = 'people'; staffing = 'together'; }
else { hostScope = 'me'; }
Expand Down Expand Up @@ -414,6 +416,7 @@
routing_mode: routingMode,
rr_strategy: rrStrategy,
reminders,
answers_in_host_email: answersInHostEmail,
// Not `|| null`: this form always saves the whole page state, so a blanked
// field must send '' to actually clear it. The API treats null as "leave
// unchanged" (for partial-PATCH callers), which would silently keep the old
Expand Down Expand Up @@ -1129,6 +1132,15 @@
</div>
</div>

<!-- Intake answers in the host's email -->
<div class="border-t pt-5 space-y-1.5">
<div class="flex items-center gap-2">
<Checkbox id="answers-in-host-email" bind:checked={answersInHostEmail} />
<Label for="answers-in-host-email" class="cursor-pointer font-normal">{$t('eventTypeEditor.notifications.answersInHostEmail')}</Label>
</div>
<p class="text-xs text-muted-foreground">{$t('eventTypeEditor.notifications.answersInHostEmailHint')}</p>
</div>

<!-- Custom messages -->
<div class="border-t pt-5">
<p class="mb-1 text-sm font-medium">{$t('eventTypeEditor.notifications.customMessages')}</p>
Expand Down
15 changes: 15 additions & 0 deletions internal/db/migrations/00076_event_type_answers_in_host_email.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- +goose Up
-- Whether the host's new-booking email lists the attendee's intake answers, so the
-- context they gave (company, topic, phone number...) is where the host looks right
-- before the call instead of only in the admin UI. Requested in discussion #264.
--
-- Default 0: intake answers are often the sensitive part of a booking (a phone number,
-- free text about a person or a condition), and an email is a copy that leaves Calnode,
-- so it has to be chosen per event type and never inherited by surprise. Only the host's
-- own notification carries them. The attendee's emails and the calendar event do not:
-- the event description is visible to the attendee in their invite on Google, Microsoft
-- and CalDAV alike, which is why that half of #264 was not taken.
ALTER TABLE event_types ADD COLUMN answers_in_host_email INTEGER NOT NULL DEFAULT 0;

-- +goose Down
ALTER TABLE event_types DROP COLUMN answers_in_host_email;
63 changes: 60 additions & 3 deletions internal/handler/booking_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1346,10 +1346,65 @@ func (h *Handler) createHostEvents(ctx context.Context, b *booking.Booking, in b
wg.Wait()
}

// hostEmailAnswers returns the booking's intake answers for the host's new-booking
// email, or nil when the event type has not opted in (answers_in_host_email, #264).
// Unanswered optional questions are left out. Errors are logged and yield nil: a
// missing answers block must not hold up the confirmation itself.
func (h *Handler) hostEmailAnswers(ctx context.Context, eventTypeID, bookingID string) []mailer.Answer {
var optedIn bool
if err := h.db.QueryRowContext(ctx,
`SELECT answers_in_host_email FROM event_types WHERE id = ?`, eventTypeID).Scan(&optedIn); err != nil {
if !errors.Is(err, sql.ErrNoRows) {
h.logger.Error("host email answers: load opt-in", "error", err, "booking_id", bookingID)
}
return nil
}
if !optedIn {
return nil
}
rows, err := h.db.QueryContext(ctx, `
SELECT q.label, q.type, a.value
FROM booking_answers a
JOIN event_type_questions q ON q.id = a.question_id
WHERE a.booking_id = ? AND a.value != ''
ORDER BY q.position, q.id`, bookingID)
Comment thread
pullfrog[bot] marked this conversation as resolved.
Resolved
if err != nil {
h.logger.Error("host email answers: query", "error", err, "booking_id", bookingID)
return nil
}
defer rows.Close()
var answers []mailer.Answer
for rows.Next() {
var a mailer.Answer
var typ string
if err := rows.Scan(&a.Question, &typ, &a.Value); err != nil {
h.logger.Error("host email answers: scan", "error", err, "booking_id", bookingID)
return nil
}
// A checkbox reads as Yes/No, as in the admin booking view: older rows hold
// whatever the surface sent ("Yes", "1", "on"), and a consent box must never read
// as the opposite of what the guest ticked.
if typ == "checkbox" {
if checkboxTicked(a.Value) {
a.Value = "Yes"
} else {
a.Value = "No"
}
}
answers = append(answers, a)
}
if err := rows.Err(); err != nil {
h.logger.Error("host email answers: rows", "error", err, "booking_id", bookingID)
return nil
}
return answers
}

// notifyHosts emails each host that has host-booking notifications on. Returns the
// primary host's notification prefs, for the caller's single attendee-confirmation send,
// and whether any host email failed.
func (h *Handler) notifyHosts(ctx context.Context, b *booking.Booking, bData mailer.BookingData, hosts []assignedHost, livekitHostURL string) (hostPrefs, bool) {
// and whether any host email failed. answers (see hostEmailAnswers) go on each host's
// copy only, never on bData, which the caller goes on to send to the attendee.
func (h *Handler) notifyHosts(ctx context.Context, b *booking.Booking, bData mailer.BookingData, hosts []assignedHost, livekitHostURL string, answers []mailer.Answer) (hostPrefs, bool) {
primaryPrefs := allOnPrefs
confirmFailed := false
for _, host := range hosts {
Expand All @@ -1359,6 +1414,7 @@ func (h *Handler) notifyHosts(ctx context.Context, b *booking.Booking, bData mai
}
if prefs.NotifyHostBooking {
hd := h.hostBookingData(ctx, bData, host, b.InviteDelivery, b.UpdatedAt)
hd.HostAnswers = answers
if livekitHostURL != "" {
hd.LocationValue = livekitHostURL // host email gets the controls-enabled link
}
Expand Down Expand Up @@ -1483,7 +1539,8 @@ func (h *Handler) dispatchBookingConfirmation(b *booking.Booking, in bookingConf

mailCtx, cancelMail := context.WithTimeout(context.Background(), dispatchMailBudget)
defer cancelMail()
primaryPrefs, confirmFailed := h.notifyHosts(mailCtx, b, bData, hosts, livekitHostURL)
answers := h.hostEmailAnswers(mailCtx, b.EventTypeID, b.ID)
primaryPrefs, confirmFailed := h.notifyHosts(mailCtx, b, bData, hosts, livekitHostURL, answers)

// Attendee confirmation, once. "With:" names the primary host; gated on the
// primary host's notification preference (matches prior behaviour).
Expand Down
27 changes: 22 additions & 5 deletions internal/handler/event_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ type eventTypeJSON struct {
// instead of omitting them. Off by default: the slots endpoint is public, so this
// makes the host's booked hours legible to anyone with the link (#19).
ShowTakenSlots bool `json:"show_taken_slots"`
// AnswersInHostEmail lists the attendee's intake answers in the host's new-booking
// email. Off by default: answers are often the sensitive part of a booking, and only
// the host's own email carries them, never the attendee's or the calendar event (#264).
AnswersInHostEmail bool `json:"answers_in_host_email"`
// ShowNextAvailable shows the next free time above the booking page's time list, as a
// button that opens that day. Off by default (#254).
ShowNextAvailable bool `json:"show_next_available"`
Expand Down Expand Up @@ -109,7 +113,7 @@ func scanEventTypeRow(s rowScanner, trailing ...any) (*eventTypeJSON, error) {
var et eventTypeJSON
var desc, locVal, msgConf, msgCancel, msgResched, msgRemind, msgGreeting sql.NullString
var subjConf, subjCancel, subjResched, subjRemind sql.NullString
var isActive, isPublic, showTaken, showNext int
var isActive, isPublic, showTaken, showNext, answersInHostEmail int

dests := []any{
&et.ID, &et.Slug, &et.Name, &desc,
Expand All @@ -122,6 +126,7 @@ func scanEventTypeRow(s rowScanner, trailing ...any) (*eventTypeJSON, error) {
&msgConf, &msgCancel, &msgResched, &msgRemind, &msgGreeting,
&subjConf, &subjCancel, &subjResched, &subjRemind,
&et.PriceCents, &et.Currency, &et.InviteDelivery, &et.DisplayOrder,
&answersInHostEmail,
}
dests = append(dests, trailing...)
err := s.Scan(dests...)
Expand All @@ -140,6 +145,7 @@ func scanEventTypeRow(s rowScanner, trailing ...any) (*eventTypeJSON, error) {
et.IsActive = isActive != 0
et.IsPublic = isPublic != 0
et.ShowTakenSlots = showTaken != 0
et.AnswersInHostEmail = answersInHostEmail != 0
et.ShowNextAvailable = showNext != 0
if msgConf.Valid {
et.MsgConfirmation = &msgConf.String
Expand Down Expand Up @@ -181,7 +187,8 @@ const etColumns = `id, slug, name, description,
is_active, is_public, show_taken_slots, show_next_available, created_at,
msg_confirmation, msg_cancellation, msg_reschedule, msg_reminder, msg_greeting,
subj_confirmation, subj_cancellation, subj_reschedule, subj_reminder,
price_cents, currency, invite_delivery, display_order`
price_cents, currency, invite_delivery, display_order,
answers_in_host_email`

// selectETCols fetches a single event type without the caller-relative columns.
const selectETCols = "SELECT " + etColumns + " FROM event_types"
Expand Down Expand Up @@ -286,6 +293,7 @@ func (h *Handler) CreateEventType(w http.ResponseWriter, r *http.Request) {
MaxActiveBookings *int `json:"max_active_bookings"`
AllowPhoneCall *bool `json:"allow_phone_call"`
ShowTakenSlots *bool `json:"show_taken_slots"`
AnswersInHostEmail *bool `json:"answers_in_host_email"`
ShowNextAvailable *bool `json:"show_next_available"`
InviteDelivery *string `json:"invite_delivery"`
}
Expand Down Expand Up @@ -362,6 +370,9 @@ func (h *Handler) CreateEventType(w http.ResponseWriter, r *http.Request) {
if req.ShowTakenSlots != nil && *req.ShowTakenSlots {
showTaken = 1
}
// Off unless asked for, for the same reason: intake answers leave Calnode in an
// email, so that is chosen per event type (#264).
answersInHostEmail := req.AnswersInHostEmail != nil && *req.AnswersInHostEmail
showNext := 0
if req.ShowNextAvailable != nil && *req.ShowNextAvailable {
showNext = 1
Expand Down Expand Up @@ -395,12 +406,14 @@ func (h *Handler) CreateEventType(w http.ResponseWriter, r *http.Request) {
slot_interval_minutes, location_type, location_value, allow_phone_call,
routing_mode, buffer_before_minutes, buffer_after_minutes,
min_notice_minutes, max_future_days, max_active_bookings, show_taken_slots, show_next_available, invite_delivery,
msg_confirmation, msg_cancellation, msg_reschedule, msg_reminder, display_order)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
msg_confirmation, msg_cancellation, msg_reschedule, msg_reminder, display_order,
answers_in_host_email)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
id, user.ID, req.Slug, req.Name, req.Description,
req.DurationMinutes, slotInterval, locType, req.LocationValue, req.AllowPhoneCall != nil && *req.AllowPhoneCall,
routingMode, bufBefore, bufAfter, minNotice, maxFuture, maxActive, showTaken, showNext, inviteDelivery,
defaultMsgConfirmation, defaultMsgCancellation, defaultMsgReschedule, defaultMsgReminder, req.DisplayOrder)
defaultMsgConfirmation, defaultMsgCancellation, defaultMsgReschedule, defaultMsgReminder, req.DisplayOrder,
answersInHostEmail)
if err != nil {
if db.IsUniqueViolation(err) {
h.writeError(w, http.StatusConflict, "slug already in use")
Expand Down Expand Up @@ -529,6 +542,7 @@ func (h *Handler) PatchEventType(w http.ResponseWriter, r *http.Request) {
IsPublic *bool `json:"is_public"`
AllowPhoneCall *bool `json:"allow_phone_call"`
ShowTakenSlots *bool `json:"show_taken_slots"`
AnswersInHostEmail *bool `json:"answers_in_host_email"`
ShowNextAvailable *bool `json:"show_next_available"`
InviteDelivery *string `json:"invite_delivery"`
Archived *bool `json:"archived"`
Expand Down Expand Up @@ -688,6 +702,9 @@ func (h *Handler) PatchEventType(w http.ResponseWriter, r *http.Request) {
}
set("show_taken_slots", v)
}
if req.AnswersInHostEmail != nil {
set("answers_in_host_email", *req.AnswersInHostEmail)
}
if req.ShowNextAvailable != nil {
v := 0
if *req.ShowNextAvailable {
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/event_type_duplicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (h *Handler) DuplicateEventType(w http.ResponseWriter, r *http.Request) {
is_active, is_public, show_taken_slots, show_next_available, archived_at,
msg_confirmation, msg_cancellation, msg_reschedule, msg_reminder, msg_greeting,
subj_confirmation, subj_cancellation, subj_reschedule, subj_reminder,
price_cents, currency, invite_delivery, display_order)
price_cents, currency, invite_delivery, display_order, answers_in_host_email)
SELECT
?, user_id, team_id, ?, name, description,
duration_minutes, slot_interval_minutes,
Expand All @@ -154,7 +154,7 @@ func (h *Handler) DuplicateEventType(w http.ResponseWriter, r *http.Request) {
0, is_public, show_taken_slots, show_next_available, NULL,
msg_confirmation, msg_cancellation, msg_reschedule, msg_reminder, msg_greeting,
subj_confirmation, subj_cancellation, subj_reschedule, subj_reminder,
price_cents, currency, invite_delivery, display_order
price_cents, currency, invite_delivery, display_order, answers_in_host_email
FROM event_types WHERE id = ?`, newID, newSlug, srcID); err != nil {
h.logger.ErrorContext(r.Context(), "duplicate event type: copy row", "error", err)
h.writeError(w, http.StatusInternalServerError, "internal error")
Expand Down
Loading
Loading