Overview
Invia codici monouso utilizzando gli stessi endpoint che usi per qualsiasi messaggio. Genera il codice nel tuo backend, invialo con POST /sms/sendSms (o come modello di autenticazione WhatsApp con POST /whatsapp/message/sendbulk) e verifica cosa digita l'utente confrontandolo con il codice che hai memorizzato. Per la generazione e la convalida del codice come servizio gestito, consulta la pagina del prodotto OTP.
Esempio
Copia, incolla, sostituisci i segnaposto: questi esempi chiamano l'API di produzione così come sono.
import { randomInt } from "node:crypto";
import { Configuration, SMSSMSApi } from "@broadnet/cpaas-sdk";
const sms = new SMSSMSApi(
new Configuration({
basePath: "https://api.broadnet.me",
accessToken: process.env.BROADNET_TOKEN!,
}),
);
// 1. Generate and store the code (hash it, with an expiry).
const code = String(randomInt(100000, 1000000));
await otpStore.save("447700900123", code, { ttlSeconds: 300 });
// 2. Send it as a normal SMS.
await sms.smsSendsmsPost({
sMSSmsRequest: {
senderId: "BroadNet",
destinationNumber: "447700900123",
message: `Your verification code is ${code}`,
messageType: "TEXT",
},
});
// 3. Later: compare the code the user typed with the stored one.