@berrysdk/berry-otp
v0.1.9
Published
Official OTP flows for Berry SDK on top of WhatsApp native-flow and fallback buttons.
Readme
@berrysdk/berry-otp
Official OTP flows for Berry SDK using WhatsApp Web transport, native-flow interactive buttons, and fallback legacy mode.
Important notes
- This package does not use the official WhatsApp Business API.
- It relies on WhatsApp Web behavior observed in real tests.
copy-codewas validated in real tests on WhatsApp Web2.3000.x.- WhatsApp can change protocol behavior at any time.
stablemode exists as a fallback.editOnExpirerequiresclient.editMessage(...)support in the SDK.- Once
verify()succeeds, the OTP becomesused, so it will not expire and edit afterward.
Modes
stablecopy-codeexperimental-copy-code
Recommended default:
copy-code
Example
import { BerryClient } from "@berrysdk/core";
import { BerryOTP } from "@berrysdk/berry-otp";
const client = new BerryClient({
sessionId: "otp-session",
});
await client.connectWithQr();
const otp = BerryOTP.createLoginFlow(client, {
issuer: "BerryProtocol",
ttlMs: 2 * 60 * 1000,
mode: "copy-code",
});
const sent = await otp.sendLoginCode("[email protected]", {
userId: "user-001",
metadata: { source: "example" },
});
console.log(sent);