Voice AI

Build a Durable Order-Status Agent That Answers "Where's My Order?" Over SMS

"Where is my order?" is, by most counts, the most common question in e-commerce support — and the one stores answer worst. The standard reply is a tracking link: homework the customer has to do themselves, on a carrier page that may or may not have updated. The customer didn't want a link. They wanted an answer.

This sample builds the thing they actually want: a store's own phone line that answers "where's my order?" in one plain sentence, remembers the conversation across days, and — before the customer ever asks — texts them when the carrier reports a delay. It runs on the Telnyx edge runtime as a single durable actor per customer, with no external database, no queue, no cron, and no API keys in the code.

In this walkthrough we'll look at what the app does, how the durable actor model makes it work, and how to run it yourself.

What the App Does

The full flow has six beats:

  1. A storefront links an order. POST /rpc/linkOrder?customer=<E.164> routes to the customer's actor via env.CUSTOMERS.idFromName(customerE164). The actor is born, creates its orders table, and inserts the order as pending.
  2. A carrier webhook fires. POST /webhook/carrier → onCarrier(event) upserts the order row. For shipped/delivered, the actor texts immediately ("Your order is on the way — out for delivery Tue."). For delayed, it schedules a wake.
  3. The customer texts. "where's my order?" arrives on the Telnyx message.received callback → /webhook/inbound → onInboundMessage(msg). The actor reads its SQL rows, produces a one-line plain-language answer, and replies by SMS.
  4. The customer follows up. "will it make it by Friday?" hits the same actor, same thread — answered from durable state and MessageLog history, with no re-identification step.
  5. A delay lands on day 3. notifyDelay() fires on the scheduled wake, checks its lastNotified guard, and sends the proactive SMS before the customer asks.
  6. The worker dies mid-flow. SQL state is intact. The next inbound re-wakes the actor with full state — and no double notification.

That last beat is the one worth pausing on. Everything above it depends on state that survives restarts, and that's exactly what the actor model buys you.

How It Works

One durable actor per customer

Every interaction — storefront call, carrier webhook, inbound SMS — routes to the same place:

// The customer's E.164 number IS the actor's identity.
const stub = env.CUSTOMERS.idFromName(customerE164);

There's no lookup service mapping phone numbers to sessions, no session store to expire. The platform routes, wakes, and persists the actor. When the customer texts on day 3, it's the same actor that received the carrier webhook on day 1.

Per-actor SQL

The actor owns its state:

this.ctx.storage.sql.exec(`
  CREATE TABLE IF NOT EXISTS orders (
    order_id TEXT PRIMARY KEY,
    customer TEXT,
    status   TEXT,
    eta      TEXT,
    ts       INTEGER
  )
`);

Carrier events upsert into it; inbound questions read from it. There's no connection pool to manage, no cross-tenant query to worry about, no migration coordination across services. The actor's table lives with the actor.

The thread is state, not a log

this.messages (MessageLog) is the durable SMS thread. This is what makes the follow-up work: when the customer asks "will it make it by Friday?", the actor already knows which order is in play, because the conversation is part of its durable state. No "please reply with your order number."

Carrier events: react now or schedule later

async onCarrier(event: CarrierEvent) {
  this.ctx.storage.sql.exec(
    `INSERT INTO orders (order_id, customer, status, eta, ts)
     VALUES (?, ?, ?, ?, ?)
     ON CONFLICT(order_id) DO UPDATE
       SET status = excluded.status, eta = excluded.eta, ts = excluded.ts`,
    event.orderId, this.customer, event.status, event.eta, Date.now()
  );

  if (event.status === "shipped" || event.status === "delivered") {
    await this.notify(event.status);           // SMS now
  } else if (event.status === "delayed") {
    this.schedule(0, "notifyDelay", event);    // wake the actor, exactly-once
  }
}

Two paths out of one webhook. Time-sensitive statuses (shipped, delivered) go out immediately. A delayed event schedules a wake — the actor itself sends the notification when it runs, guarded for exactly-once.

Answering the question

async onInboundMessage(msg: InboundMessage) {
  const order  = this.latestOrder();
  const thread = this.messages; // durable MessageLog

  const answer = this.demoMode
    ? buildAnswer(order) // deterministic interpreter — no LLM call in demo
    : await this.env.TELNYX.ai.openai.chat.createCompletion({
        model: this.env.AI_MODEL ?? "zai-org/GLM-5.2",
        messages: [
          { role: "system", content:
            "You are a store's order-status assistant. Answer in one short line. Never invent details." },
          { role: "user", content:
            `Order state: ${JSON.stringify(order)}\n` +
            `Thread: ${thread.map(m => m.text).join(" | ")}\n` +
            `Question: ${msg.text}` },
        ],
      });

  await this.env.TELNYX.messages.send({ to: msg.from, from: this.smsFrom, text: answer });
}

Note the division of labor: the LLM is stateless and stores nothing. The actor is the memory. The model reads the actor's SQL rows and MessageLog and writes one line — "On the way — out for delivery Tue." In DEMO_MODE, a deterministic interpreter answers instead, so tests are reproducible and don't touch inference at all.

Exactly-once delay notifications

async notifyDelay(event: CarrierEvent) {
  const state = (await this.ctx.storage.get<{ lastNotified?: string }>("state")) ?? {};
  if (state.lastNotified === event.orderId) return; // already told them

  state.lastNotified = event.orderId;
  await this.ctx.storage.put("state", state);

  await this.env.TELNYX.messages.send({
    to: this.customer,
    from: this.smsFrom,
    text: `Heads up — order ${event.orderId} is running late. New ETA: ${event.eta}.`,
  });
}

Webhook redelivery, worker restarts, platform retries — the guard holds, because it's checked in durable storage before the send, not in memory that dies with the process.

Zero credentials

Notice what's missing from every snippet above: keys. The TELNYX binding injects auth at the platform level, so messaging and inference calls carry no secrets in code, env files, or logs. The ai.openai.chat.createCompletion seam runs on a Telnyx-hosted model (zai-org/GLM-5.2 by default) — no BYOK key to rotate.

Setup

Prerequisites: Node.js 18+, Docker (compose plugin) for telnyx-edge dev, a Telnyx account with an SMS-capable number (10DLC campaign required for US A2P traffic), and the Telnyx Edge CLI from the releases page.

git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/order-status-self-service

export TELNYX_API_KEY=your_telnyx_api_key_here   # or: telnyx auth set-key KEY…

npm install
npm run typecheck
npm test

DEMO_MODE defaults to true — SMS is logged and the deterministic interpreter answers, so you can exercise the whole flow before touching a real number. For live mode, set DEMO_MODE=false in telnyx.toml [env_vars], buy an SMS-capable number, and pass it as SMS_FROM. Everything above can also be provisioned from the CLI:

telnyx auth set-key KEY…
telnyx number-orders create --profile international --quantity 1
telnyx-edge new-func --actor -l ts -n order-status-self-service

Conclusion

The interesting thing about this sample isn't the LLM — it's that the LLM is the least stateful part of it. The durable actor holds the order rows, the thread, the schedule, and the exactly-once guard; inference just reads that state and writes a sentence. When durable actors, carrier-grade two-way messaging, and hosted inference live in the same runtime, "where's my order?" stops being a support ticket and becomes a one-line answer your infrastructure owns end to end. That's what we mean by AI Communications Infrastructure: state, messaging, and inference as primitives — not integrations.

Grab the code, run it in demo mode, and kill the worker mid-flow to see the restart proof for yourself: https://github.com/team-telnyx/telnyx-code-examples/tree/main/order-status-self-service

Ready to build with low-latency voice AI?

Join developers building the future of real-time conversations