Vetspire.Reminders.Autoconfirm.Request (vetspire v3.0.0)

View Source

One row per outbound appointment-confirmation text. An inbound reply resolves the row it targets by matching on phone and the pending status.

data holds the render snapshot (see Vetspire.Reminders.Autoconfirm) so a reply can build its response without re-fetching the appointment.

phone is a lookup key: the client's number reduced to its last ten digits. Twilio always sends From in E.164, while phone_numbers.value holds whatever a member of staff typed, so both sides go through Vetspire.Accounts.PhoneNumber.sanitise_phone_number/1 before they are compared. Every outbound text resolves its own destination, so the original formatting stays in phone_numbers.

Every row needs a location_id. The column mirrors the location of the first appointment in the group. The location carries the timezone and the clinic name the message needs, so the query that selects appointments for a run leaves out any appointment without one.

status starts at pending and moves to exactly one of confirmed, cancelled, reschedule_requested, unrecognized_reply, expired, send_failed, or apply_failed. A new request for the same (phone, org_id) marks any still-pending row superseded, since only the newest request stays live for that phone.

unrecognized_reply is a status no new row gets: a free-text reply now leaves the request pending. It stays in the enum so that rows written before that change still load. The retention sweep deletes those rows after 30 days, and then the value can go.

send_failed means the initial text never went out, so nothing can reply to this row and it must not lapse.

apply_failed means the client replied but the appointment write raised. The row is terminal: Twilio does not redeliver a webhook that got a 5xx, so nothing retries it, and it must not lapse either. The Sentry event and this row are the record for support.

Summary

Types

status()

@type status() ::
  :pending
  | :confirmed
  | :cancelled
  | :reschedule_requested
  | :unrecognized_reply
  | :expired
  | :superseded
  | :send_failed
  | :apply_failed

t()

@type t() :: %Vetspire.Reminders.Autoconfirm.Request{
  __meta__: term(),
  appt_ids: term(),
  client: term(),
  client_id: term(),
  data: term(),
  expires_at: term(),
  id: term(),
  inserted_at: term(),
  location: term(),
  location_id: term(),
  org: term(),
  org_id: term(),
  phone: term(),
  status: term(),
  updated_at: term()
}

Functions

changeset(request, attrs \\ %{})