tempo
open-source research software

tracking · engagement · messaging · participant outreach

TEMPO (Tracking, Engagement, Messaging & Participant Outreach) is a server that automates participant communication and completion tracking for research studies lasting months or years.

It sends SMS and email reminders, invitations and follow-ups according to each participant's dates and completed forms. It tracks completed instruments, answered or missed slots, and progress across study phases. REDCap or Qualtrics remains the survey platform and source of truth.

TEMPO is for studies where participants follow individual schedules and communication needs to be a two-way conversation. Texts use the study's own phone number, with automated messages and participant replies in one thread that a coordinator can read and answer.

A schedule is declared as a list of rules, each referencing study fields for its condition and anchor date, such as sending a reminder fourteen days after baseline, repeating weekly up to three times while the form remains incomplete.

tempo — scheduler --:--:--
tempo› try: queue · ledger · send
01
How it works

From a date field to a sent message

A run is one pass through the study's current data and scheduling rules. TEMPO pulls participant records, expands the rules into dated occurrences, selects what is due, sends those messages and records them in the ledger.

Architecture: a REDCap or Qualtrics export is keyed on record ID and expanded into a grid of dated messages; a window filter selects what is due, the senders transmit by SMS and email, and every send is appended to a ledger the filter consults on the next run. survey platform REDCap · Qualtrics date fields completion flags survey links API export, per event, keyed on record_id the grid rules × roster one dated row per participant, per occurrence due now in window still incomplete not opted out not in ledger send SMS email claim, then send ledger pid | alert | timestamp | channel | recipient checked before every send cron invokes the run on a clock
01 pullExport the study out of REDCap or Qualtrics over the API, one call per event, and stitch it together on record_id into a single row per participant holding their dates, the completion flag on each instrument, and their contact details.›
02 expandTEMPO evaluates every rule against each participant's row, substitutes that participant's values into [event][field] references, fetches the required survey URLs, and performs the date arithmetic to produce one dated line per participant for each time a message is owed.›
03 selectA row qualifies for sending when its timestamp falls within the run's window and daily sending window, its condition still holds, the participant's opt-out status permits contact, its survey link resolves, and its ledger key is unused.›
04 sendClaim the line so nothing else can take it, render the body with that person's details and survey URL in it, and POST it to the messaging provider or hand it to SMTP.›
05 recordWrite pid | alert | timestamp | channel | recipient to the ledger. That line is what every later run checks against, which is how the same message never goes out twice.›
the grid

The study declares each message once as a rule. Each run evaluates those rules using participant data and builds a grid with one dated row per participant per occurrence, including its destination and rendered message. This grid is the complete schedule. TEMPO discards and rebuilds it every run; the ledger persists. Correcting a visit date in REDCap corrects every message anchored to it on the next run.

TEMPO selects rows within the run's window whose conditions still hold against current completion flags. It excludes opted-out participants, messages in quiet hours, messages with unresolved survey links and messages already recorded in the ledger.

what counts as a trigger

Every rule has a condition that decides whether a message is owed and an anchor date from which its timing is measured. Both reference fields in the study database using `[event][field]`. The condition checks a field for incomplete status; the anchor references a date field. The code has no message-type enumeration or special cases for EMA prompts or visit reminders.

Schedules chain through those fields. Recording a visit brings dependent questionnaires due. Completing the questionnaires stops their reminders, and the visit date anchors the next phase. A three-year protocol that branches on participant behaviour can still be expressed as a flat list of rules.

the clock

TEMPO sends messages at their scheduled times, including prompts due at a specific minute, without a continuously running process. Cron invokes the pipeline often enough to cover every slot. For precise prompts, runs cover overlapping windows, and the sender claims the slot early and waits in process until the scheduled second.

Measured production delivery is 2–4 seconds past the scheduled second, with latency recorded for every message in the ledger. Extra runs are harmless because each rebuilds the grid from a fresh export and checks the ledger before transmitting. A redundant invocation finds nothing to send. The timing requirement determines how often cron runs.

what it plugs into

The build here uses REDCap, OpenPhone and Gmail SMTP. Swapping any of them means reimplementing a few calls; Qualtrics, Twilio and SES offer the same operations.

Integration pointWhat TEMPO needs from it
Survey platformA record export, date fields, per-form completion flags, and a per-participant survey link
SMS providerA send endpoint. Optionally a message-history endpoint, used to arbitrate against duplicates
EmailSMTP credentials, or any HTTP send API
SchedulerAnything that can invoke a URL on a schedule — cron, a platform cron trigger, or a CI timer
02
Sample code

Declaring and sending a message

The field names below are placeholders for the study's event and instrument names.

{
  instrument: "Follow-up reminder",

  // Owed only while the form is still incomplete.
  condition: "[followup_arm_1][followup_1_complete]<>2",

  // 14 days after the baseline date, then every 7 days, at most 3 times.
  sendDateSpec: "14 days after [baseline_arm_1][baseline_date] " +
                "repeat every 7 days up to 3 times",

  // A phone field implies SMS, an email field implies email.
  destinationSpec: "[baseline_arm_1][participant_phone]\t[baseline_arm_1][participant_email]",

  // [event][field] fills per participant; [survey-link:form] becomes
  // that participant's own URL, resolved at send time.
  message: "Hi [baseline_arm_1][first_name], your follow-up is open: " +
           "[followup_arm_1][survey-link:followup_1]",
}
Declaring a message. A single entry sets the condition under which the message is owed, the send time, the destination fields and the body.
const anchor = participant.fields["baseline_date"];   // "2026-03-04"
const { offsetDays, everyDays, maxTimes } = parseSpec(alert.sendDateSpec);

const sends = [];
for (let n = 0; n < maxTimes; n++) {
  if (isComplete(participant, alert.condition)) break;   // responded, stop
  sends.push(atStudyTime(addDays(anchor, offsetDays + n * everyDays), "17:00"));
}
// → 2026-03-18T17:00, 2026-03-25T17:00, 2026-04-01T17:00
Computing the send time. The send time resolves per participant against their own dates, and repeats stop once the completion flag flips, so responders are not chased.
await fetch("https://api.openphone.com/v1/messages", {
  method: "POST",
  headers: { "Content-Type": "application/json", Authorization: API_KEY },
  body: JSON.stringify({ content: body, from: FROM_NUMBER, to: [e164] }),
  signal: AbortSignal.timeout(30_000),
});
Sending a text. The send is one POST to the provider's messages endpoint, so any provider that exposes one fits here.
const mailer = nodemailer.createTransport({
  host: "smtp.gmail.com", port: 587, secure: false,
  pool: true, auth: { user: SMTP_USER, pass: SMTP_PASS },
});

await mailer.sendMail({ from, to: recipient, subject, text: body });
Sending an email. SMTP is pooled, so a batch of messages reuses one connection.
once-only delivery

TEMPO delivers each message once and records it in the ledger. The design provides this guarantee through three independent layers, described in the table below.

Design layerHow it works
Append-only ledger
pid|alert|time|channel|recipient
Every run checks it before transmitting.
Slot claimA run claims each slot before transmission; only its holder sends.
Provider historyBefore late or recovered sends, the sender checks the provider's message history.

Study operators can set a daily sending window and a per-run send cap. TEMPO honours the opt- out list when building the queue and again at send time, and holds messages whose survey links have not resolved. Dry-run is the default, and an operator can return the system to dry-run with a switch, without a redeploy.

03
Momentary assessment

Prompts on the minute

TEMPO delivers each participant's momentary-assessment sampling grid at exact clock times throughout a sampling period and tracks which slots they answer. In the reference deployment, each cycle contains 25 prompts across roughly ten days, with fixed weekday and clock-time slots anchored to that participant's start date.

sampling grid — 25 slots / 7 days
sent 0 queued 25 last —
scheduled sent quiet hours — no prompt scheduled now

The grid is a list of weekday and clock-time slots: Monday 8:10am, Monday 1:45pm, and so on. Every participant gets the same set of slots anchored to their own start date. Expanding it gives one row per prompt with that person's phone number and survey link attached. In the picture above, stem height is the time of day, and the shaded columns are the hours when nobody gets texted.

// A sampling grid: slots repeat across the period, anchored per participant.
const GRID = [
  { day: "Mon", at: "08:10" }, { day: "Mon", at: "13:45" }, { day: "Mon", at: "19:20" },
  // … 25 slots across the sampling period
];

for (const slot of GRID) {
  schedule.push({
    pid: participant.id,
    sendAt: atStudyTime(nextWeekday(startDay, slot.day), slot.at),
    phone: participant.fields["prompt_phone"],
    surveyLink: await resolveLink(participant, slot.form),
  });
}
Expanding the grid. The same weekday-and-clock-time slots for everyone, hung off whatever date that particular participant started on.
// Wait out the remainder in-process, then claim and fire.
const waitMs = slot.sendAt - Date.now();
if (waitMs > 0) await sleep(waitMs);

if (await claim(slot.key)) {            // lost the race? another run has it
  await sendSMS(slot.phone, render(slot));
  await ledger.append({ ...slot, status: "sent", latencySec: 2 });
}
Waiting out the remainder. On cron's coarse schedule, the sender collects messages due soon and waits until the exact scheduled second, such as 8:10:00, to send each one.

TEMPO sends prompts at the scheduled second; measured delivery in production is 2 to 4 seconds later, recorded per message. Cron starts runs with overlapping windows, and the sender claims each slot early and waits in process until its scheduled second. A prompt past its window is recorded as skipped.

04
The server

The dashboard

The password-gated dashboard shows instrument completion and completion by wave or phase across the roster. Each participant's view shows their position in the sequence, with slots answered, missed or still due. It reads the same files the senders write. Contact details are masked in the data routes before they reach the browser, so a screen carries enough to tell participants apart without the identifiers themselves. The screens shown use synthetic records.

tempo.local/dashboard/overview
Overview screen: participant totals, a histogram of prompts delivered per participant, and completion by study phase Momentary assessment tracker with one participant expanded, showing each of their 25 scheduled prompts marked answered or missed Participant roster with each participant's position in their own sequence Outgoing queue grouped by day, listing scheduled messages per participant Sent log listing each delivered message with channel, recipient and status

Access is a shared password behind a signed cookie, checked in middleware on every route. A daily job reconciles what was scheduled against what the ledger recorded and flags anything missing.