Files

39 lines
1.6 KiB
TypeScript

/**
* One Twilio send, nothing else. No server, no database, no auth.
*
* pkgx npx tsx scripts/sms-send.ts [toNumber] [body]
*
* With Twilio test credentials this is a real API round trip that delivers no
* message and costs nothing: From must be +15005550006, and the To has to be a
* number Twilio can validate — a real one, not a fictional 555-01xx. The
* +1500555000x magic numbers force specific failures.
*/
import { missingTwilioConfig, sendSms } from "../src/services/smsService.js";
import { resolveTarget } from "./smokeTarget.js";
const body = process.argv[3] ?? "Gift Economies: smoke test. Reply STOP to end.";
const missing = missingTwilioConfig();
if (missing.length > 0) {
console.error("Twilio is not configured. Missing: " + missing.join(", "));
console.error(
"\nAn account and a token are not enough; a send needs a sender too.\n" +
"With Twilio test credentials, use the magic From number:\n\n" +
" TWILIO_ACCOUNT_SID=ACxxxx TWILIO_AUTH_TOKEN=xxxx \\\n" +
" TWILIO_FROM_NUMBER=+15005550006 pnpm run sms:send " +
(process.argv[2] ?? "+15555550123") +
"\n\nWith a live 10DLC campaign, set TWILIO_MESSAGING_SERVICE_SID=MGxxxx instead."
);
process.exit(1);
}
const to = resolveTarget(process.argv[2], "SMS_SEND_TO");
console.log(`To: ${to}`);
console.log(`From: ${process.env.TWILIO_FROM_NUMBER ?? process.env.TWILIO_MESSAGING_SERVICE_SID ?? "(unset)"}`);
console.log(`Body: ${body} (${body.length} chars)`);
const result = await sendSms(to, body);
console.log("Result:", JSON.stringify(result));
process.exit(result.status === "sent" ? 0 : 1);