Star
Packages ยท SMS

@notifkit/provider-twilio

The Twilio SMS transport. Sends through the Twilio Messages API and verifies status callbacks with X-Twilio-Signature, feeding delivery receipts, hard bounces and STOP replies into notifkit's delivery log and suppression list.

npm install @notifkit/provider-twilio
import { NotifkitServer } from "notifkit";
import { TwilioTransport } from "@notifkit/provider-twilio";

const server = new NotifkitServer({
  services: ["all"],
  providers: [
    new TwilioTransport({
      accountSid: process.env.TWILIO_ACCOUNT_SID!,
      authToken: process.env.TWILIO_AUTH_TOKEN!,
      from: "+15550000001",
      statusCallbackUrl: "https://api.example.com/webhooks/twilio",
    }),
  ],
});

Options

OptionRequiredNotes
accountSidyesYour Twilio Account SID.
authTokenyesYour Twilio Auth Token. Used for API authentication and webhook validation.
fromyesDefault sender phone number in E.164 format (e.g. +15550000001). A template can override this.
statusCallbackUrlnoThe public URL where Twilio sends message status updates. Required for webhook signature verification.
loggernoA notifkit logger instance.
limitsnoProvider sliding-window rate limit. Defaults to { limit: 1000, windowSeconds: 10 }.

Which template keys it reads

Template keyLands as
text or bodyThe SMS body text message.
fromOverrides the constructor's sender phone number for this template. Useful for short codes vs long codes.

Status callbacks & suppressions

With statusCallbackUrl configured, the transport sets webhookPath = "/webhooks/twilio". Twilio signs the URL and POST body with HMAC-SHA1 using your Auth Token, in the X-Twilio-Signature header.

Twilio Callback EventBecomesEffect
delivereddeliveredMarks message delivered in delivery log.
undelivered / failed (Hard bounce)bouncedSuppresses destination if code indicates invalid number or unreachable carrier (codes 21211, 21612, 21614, 30005, 30006).
failed (Error 21610: STOP reply)unsubscribedAutomatically suppresses recipient from future SMS notifications.
Exact URL match required

Twilio signs against the exact URL in statusCallbackUrl. If your reverse proxy or load balancer strips trailing slashes or rewrites headers, verification fails and webhooks are rejected.