---
title: "Surveys"
description: "The post-stay survey, when it is sent, what it stores and how a guest answers."
url: https://docs-staging-lehoetel.findmalek.engineer/docs/surveys
markdown: https://docs-staging-lehoetel.findmalek.engineer/docs/surveys.md
---

# Surveys

One short survey per guest after the stay: six questions at most, one minute on a phone.

## Questions

- NPS, 0 to 10: "How likely are you to recommend the hotel to a friend?"
- Three optional ratings from 1 to 5: your room, cleanliness, staff and food
- One optional free comment (1000 characters)

## When it is sent

The `survey-invites` job runs every hour (pg-boss, jobs module). A guest is due 24 hours after check-out (counted from noon hotel time). With no check-out date it is 24 hours after the guest was captured. Only guests due in the last 14 days are picked up, so a new deploy never surveys old guests.

- Sent through `sendToGuest` on the channels the guest agreed to: the `survey` email and the `guest_survey` WhatsApp template (see `whatsapp-templates`).
- Never in quiet hours, 21:00 to 08:00 hotel time. The next hourly run sends it.
- Once per guest: `survey_invites` has one row per guest and `automation_sends` one claim per channel. A crash between the invite and the send is picked up by the next run.

## Data

- `survey_invites`: `hotel_id`, `guest_id`, `sent_at`, `expires_at` (14 days). Deleted with the guest.
- `survey_responses`: `hotel_id`, `guest_id` (set to null when the guest is deleted, so the answer stays as anonymous feedback), `invite_id` (unique, one response per invite), `nps`, three ratings, `comment`, `language`, `submitted_at`, `review_link_clicked_at`.

Every query is scoped by hotel id.

## The page

`/s/<token>` in `apps/web`, branded with the hotel's logo and colors like the capture page, in the guest's language (en, fr, ar RTL). The token is signed (HMAC), so it cannot be guessed. It is a server component with a plain form and no client JavaScript. The NPS row wraps in two rows on a 390px phone. After sending, and on a second visit, the page shows the thank you state. After 14 days it says the survey has closed. The page is `noindex` and sends no referrer.

Seed data: about one guest in five of the four demo hotels has an invite, 70% of them answered, with scores from 3 to 10 and comments in fr, ar and en.

## Low score alert

A response with `nps` at or below the hotel's `hotel_settings.low_score_threshold` (default 6, `hotel.update` takes `lowScoreThreshold` 0 to 10) does two things:

- opens a `feedback_cases` row for the response with status `new` (then `contacted`, `resolved`), `notes` and `handled_by`, so it shows in the feedback inbox
- calls `notifyManager(hotelId, text)`: Telegram first, email when there is no chat. The text has the guest's first name, the score, a comment excerpt (140 characters) and a link to `/feedback/<case id>` in the dashboard. Never a phone number or email.

A failed alert never fails the guest's answer. One case per response.

## Share on Google

After the survey, whatever the score (never gated by score), the thank you state shows a secondary button "Share on Google" with a short line, in en, fr and ar. It only shows when the hotel has a `hotel_settings.google_review_url`.

The button points to `/r/<token>` in `apps/web`, a signed redirect (a `review` token, which cannot open the survey and the other way round). It stamps `survey_responses.review_link_clicked_at` on the first click and redirects to the hotel's page. A hotel without a link, or a bad token, gets a 404. Nothing else is sent after the survey, so the thank you page is the thank you message.
