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.
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.
record_id into a single row per participant holding their dates, the completion flag on each instrument, and their contact details.›[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.›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 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.
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.
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.
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 point | What TEMPO needs from it |
|---|---|
| Survey platform | A record export, date fields, per-form completion flags, and a per-participant survey link |
| SMS provider | A send endpoint. Optionally a message-history endpoint, used to arbitrate against duplicates |
| SMTP credentials, or any HTTP send API | |
| Scheduler | Anything that can invoke a URL on a schedule — cron, a platform cron trigger, or a CI timer |
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]",
}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:00await 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),
});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 });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 layer | How it works |
|---|---|
Append-only ledgerpid|alert|time|channel|recipient | Every run checks it before transmitting. |
| Slot claim | A run claims each slot before transmission; only its holder sends. |
| Provider history | Before 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.
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.
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),
});
}// 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 });
}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.
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.
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.