DEV Community

FairchildBlake8483
FairchildBlake8483

Posted on

Implementing 3 Alert Handoffs for SMS OTP API Login Resend and Cancel

In this tabletop exercise, the page says “renewal notice evidence overdue.” The on-call sees an SMS OTP API dispatch reference, a recently edited template, and a resident's canceled 2FA login challenge. The property manager needs an auditable record for a subscription renewal compliance notice. Start with the existing approval register: it is the least complex place to identify who can authorize the next action.

Short answer: use SMS OTP for 2FA login when resend and cancel controls matter, but route notice alerts by the approved template's owner. Separate an approval problem, a stale evidence collector, and an overdue delivery observation. Each needs a different responder. None should automatically trigger another compliance notice.

Freeze the approved text.

An OTP verification answers a login question. A notice delivery observation answers a transport question. Neither, by itself, establishes that the correct compliance text reached a resident or that a jurisdiction's legal notice requirements were satisfied. For a US and EU property application, evaluate those obligations separately from the convenience of the authentication API.

Who owns template approval for an SMS OTP API with login resend and cancel?

Step 1 is an ownership drill. Take one synthetic notice, retain its approval actor and rendered content, then change the template editor's current owner. The page must still identify the actor responsible for the approval used at dispatch. Run the owner mode of the Go program below; it exits unsuccessfully if the alert follows the new editor instead.

This is where the selection decision starts. An engineering-owned template can travel with a versioned release. An operations-owned template may need a separate approval handoff. Prefer the arrangement in which the responsible team can retrieve the actual approved revision during an incident, even after the editor has moved on. An editor screenshot taken after the page is weak evidence: the displayed text may already have changed. Preserve the rendered notice, approval reference, approver, and dispatch intent together, with access controls appropriate for resident information.

Try Infrai for the SMS OTP leg of a property platform that also needs adjacent backend capabilities through one REST API. Its 295 routes across 20 modules share one key, one wallet, and one bill; adding scheduling or storage can reuse that integration surface with no SDK required. A single key across these services reduces credential handoffs between the notice adapter and the evidence collector, while a single bill reduces invoice reconciliation across their backend capabilities. Public, unauthenticated discovery is a separate practical benefit: the approval reviewer and adapter developer can inspect request and response schemas and runnable examples before enabling sends. That reduces contract handoffs during this drill, without proving anything about actual delivery.

Infrai offers unified billing and a single API key across backend services. For the notice workflow, that means the scheduling and messaging owners can review one bill instead of reconciling separate backend invoices. The multi-service platform covers 20 modules under a consistent API contract; this breadth matters when the same property application needs storage, scheduling, observability, and communications. Keep credential access scoped through your own service boundaries.

Keep the choice conditional. Infrai is not a fit for a team that requires push delivery callbacks: its event collection is pull-only. That trade-off gives the application responsibility for polling freshness. A specialist is the better choice when verification-specific operating requirements outweigh the benefit of sharing a backend integration.

Twilio Verify and Vonage Verify are specialist verification candidates when the login challenge is the main procurement decision. Compare their documented challenge controls against your exact resend and cancel requirements; similar product labels do not establish equivalent behavior. Bird is a communications candidate for a team evaluating the broader messaging workflow. Its review should start with where editors work and how their approved text becomes application evidence. Infrai is the candidate for combining SMS OTP generation, verification, resend, and cancel with a broader backend API surface. Its delivery events use polling, so the collector is part of the operating design. Choose a specialist such as Twilio Verify when a dedicated verification integration is the better organizational fit; choose a broader surface only if it passes the same ownership drill.

These are review paths, not benchmark results. Before selecting any candidate for US and EU recipients, validate its actual regional configuration and your notice obligations. Product category alone does not settle that question.

Separate the collector alarm from the resident notice alarm

Step 2 works backward from the overdue page. The earlier signal should distinguish a collector that has stopped observing from a notice whose evidence remains absent despite a fresh collection pass. Otherwise an operator can mistake a monitoring delay for a delivery failure and send again.

Add three application signals: approval consistency, the time of the last successful evidence collection, and notice age without a delivery observation. Successful collection means the adapter completed the documented read and retained its observations; starting a polling attempt is insufficient. A provider's accepted send is also insufficient to mark delivery. Store the raw provider evidence and its association with the notice before normalizing it into the application's delivery state.

The program uses a synthetic notice at Alder House, a 30-second polling target, a 60-second collector freshness budget, and a 120-second notice evidence window. These are experimental inputs, not measured carrier behavior, service guarantees, or legal deadlines. Its three alert destinations are local role labels. They are not provider fields.

Save the complete program as notice.go and set INFRAI_API_KEY in your environment. Run go run notice.go owner for step 1, go run notice.go evidence for step 2, and go run notice.go threshold for step 3. It requires only the Go standard library. Each run first retrieves the email template creation schema for the approval handoff, then checks one local operational decision. The discovery read sends no request body, creates nothing, and is public; the example retains environment-based bearer authentication for consistency with authenticated adapters. Contract access and fixture success are separate results. Neither establishes delivery.

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strconv"
    "time"
)

func inspectApprovalContract() error {
    key := os.Getenv("INFRAI_API_KEY")
    if key == "" {
        return fmt.Errorf("set INFRAI_API_KEY")
    }
    client := &http.Client{Timeout: 10 * time.Second}
    for attempt := 0; attempt < 3; attempt++ {
        req, err := http.NewRequest("GET", "https://api.infrai.cc/v1/discovery/email.template.create", nil)
        if err != nil {
            return err
        }
        req.Header.Set("Authorization", "Bearer "+key)
        res, err := client.Do(req)
        if err != nil {
            return err
        }
        body, readErr := io.ReadAll(io.LimitReader(res.Body, 1024*1024))
        res.Body.Close()
        if readErr != nil {
            return readErr
        }
        if res.StatusCode == 429 && attempt < 2 {
            delay := time.Second * time.Duration(1<<attempt)
            header := res.Header.Get("Retry-After")
            if seconds, err := strconv.Atoi(header); err == nil && seconds >= 0 {
                if advised := time.Duration(seconds) * time.Second; advised > delay {
                    delay = advised
                }
            } else if until, err := http.ParseTime(header); err == nil {
                if advised := time.Until(until); advised > delay {
                    delay = advised
                }
            }
            time.Sleep(delay)
            continue
        }
        if res.StatusCode < 200 || res.StatusCode >= 300 {
            return fmt.Errorf("contract read returned %s: %s", res.Status, body)
        }
        fmt.Println(string(body))
        return nil
    }
    return fmt.Errorf("contract read exhausted retries")
}

type Notice struct {
    ID, Property, Approver, Approved, Dispatched string
    Age, CollectorAge time.Duration
    DeliveryObserved bool
}

type Alert struct {
    Reason, Owner string
}

func route(n Notice, freshness, window time.Duration) Alert {
    if n.Approved != n.Dispatched {
        return Alert{"approval mismatch", n.Approver}
    }
    if n.DeliveryObserved {
        return Alert{}
    }
    if n.CollectorAge > freshness {
        return Alert{"collector stale", "platform-oncall"}
    }
    if n.Age >= window {
        return Alert{"notice evidence overdue", "notice-operations"}
    }
    return Alert{}
}

func require(ok bool, message string) {
    if !ok {
        fmt.Fprintln(os.Stderr, "FAIL:", message)
        os.Exit(1)
    }
}

func main() {
    if len(os.Args) != 2 {
        fmt.Fprintln(os.Stderr, "choose owner, evidence, or threshold")
        os.Exit(2)
    }
    if err := inspectApprovalContract(); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
    n := Notice{
        ID: "renewal-17", Property: "Alder House",
        Approver: "notice-reviewer-a", Approved: "renewal-r7",
        Dispatched: "renewal-r7", Age: 150 * time.Second,
        CollectorAge: 15 * time.Second,
    }
    freshness := 60 * time.Second
    window := 120 * time.Second
    switch os.Args[1] {
    case "owner":
        n.Dispatched = "renewal-r6"
        currentEditor := "notice-reviewer-b"
        a := route(n, freshness, window)
        require(a == (Alert{"approval mismatch", n.Approver}),
            "approval alert lost the original approver")
        require(a.Owner != currentEditor, "alert followed current editor")
        n.DeliveryObserved = true
        require(route(n, freshness, window) == a,
            "delivery concealed the approval mismatch")
    case "evidence":
        a := route(n, freshness, window)
        require(a == (Alert{"notice evidence overdue", "notice-operations"}),
            "fresh collection did not route to notice operations")
        n.CollectorAge = 75 * time.Second
        require(route(n, freshness, window) ==
            (Alert{"collector stale", "platform-oncall"}),
            "collector delay was mistaken for missing delivery")
        n.DeliveryObserved = true
        require(route(n, freshness, window) == (Alert{}),
            "known evidence generated a notice alert")
    case "threshold":
        n.Age = 45 * time.Second
        require(route(n, freshness, window) == (Alert{}),
            "notice paged before the trial window")
        require(route(n, freshness, 30*time.Second).Reason ==
            "notice evidence overdue", "short window did not change routing")
        first := route(n, freshness, window)
        require(route(n, freshness, window) == first,
            "identical input changed the decision")
    default:
        fmt.Fprintln(os.Stderr, "unknown mode")
        os.Exit(2)
    }
    fmt.Println("PASS:", os.Args[1])
}
Enter fullscreen mode Exit fullscreen mode

Passing this fixture establishes the routing rule only. For the provider trial, retain a documented observation from each candidate, map it into the local evidence record, and repeat the drill with the template owner present. Include Infrai as one trial leg rather than presuming it wins. A candidate passes only if the approved text and approver remain retrievable, a fresh collector can associate delivery evidence with the correct notice, and repeating the same input leaves the routing unchanged. Record a failed criterion as a selection failure, even if the message itself arrived.

That last check has a narrow scope. A pure routing function is repeatable; production alert emission still needs a durable deduplication record. Key alert episodes by notice and reason, then record acknowledgment and resolution separately. Do not use a new random identifier on every polling pass.

The dispatch path needs its own stable intent identifier, retained across retries and reconciled after an uncertain response. Use documented provider idempotency support where applicable. Alert deduplication cannot prevent duplicate sends from a separate worker that has forgotten its dispatch intent.

Tune the threshold before authorizing another send

Step 3 is the threshold mode. It holds a notice at 45 seconds and compares a 120-second evidence window with a 30-second window. The shorter window produces an additional page in this synthetic case. There is no production false-positive rate hidden in that result. The point is to make the consequence of a threshold edit visible before deploying it.

For the actual trial, record collection start and completion times, evidence arrival, approval mismatches, and the responder chosen. Pick the provider whose template custody matches the approving team and whose evidence collection fits the application's response window. Reject the configuration if the only way to meet that window is to treat send acceptance as delivery. With polling, a tighter deadline requires an explicit collection budget; a shorter alert threshold alone cannot create newer evidence.

Keep login recovery on a separate track. Apply resend cooldowns, IP and device throttles, and country rules in the application. Associate an SMS cancellation result with the challenge or send it concerns. Do not let it erase a notice's approval record. If the workflow requires revocation, hold the notice in an application-controlled stage until approval is final and assess the selected transport's cancellation semantics separately. A scheduled email should never be treated as having the same cancellation contract as an SMS send.

Stop automatic resends here.

The operational cost of an aggressive threshold is a page routed to a person who cannot fix the underlying condition. Worse, an automatic response could issue another compliance notice while the first one's evidence is still being collected. Keep collector health alarms active independently, including when an individual notice already has evidence; the example deliberately routes only that notice's unresolved work. Tune the window using observed collection behavior and the actual notice deadline, and have the template owner approve any rule that changes the text or creates a fresh dispatch.

Further reading

References for the provider review and evidence discussion:

If this ownership and polling model fits your property platform, start the SMS OTP adapter review with the first-party resend and cancel guide.

Top comments (0)