WaForgeDevelopers

OTP and website

OTP widget for websites

Send OTP via WhatsApp from any web page with a ready-made phone check: one <div> and one script tag. The visitor enters their WhatsApp number, receives a code, types it, and your page gets a waforge:verified event. It uses a widget key, never your secret key.

1. Create a widget key #

  1. Dashboard, API keys, New widget key.
  2. Enter the exact host names of the pages that will show the widget, separated by commas: example.com, www.example.com, shop.example.com. For local testing add localhost.
  3. Create widget key and copy the wf_pk_... value. It is shown once.

Allowed domains are matched exactly against the host of the page (from the browser's Origin header, or Referer). www.example.com and example.com are two different hosts; subdomains are not included automatically; the port is ignored. A key with no domains refuses every request with 403 origin_not_allowed.

2. Embed it #

Put the <div> before the script tag: the script looks for #waforge-otp when it runs.

HTML
<div id="waforge-otp"></div>
<script src="https://waforge.online/widget.js" data-key="wf_pk_your_widget_key"></script>

The script is self-contained: no dependencies, no cookies, no tracking. It adds its own small stylesheet (classes prefixed wf-otp) and calls /api/v1/otp/send and /api/v1/otp/verify on waforge.online with your widget key.

3. React to the verification #

HTML
<script>
  document.getElementById('waforge-otp').addEventListener('waforge:verified', function (e) {
    // e.detail = { requestId: "9d5c2f1e-...", phone: "+97455551234" }
    document.querySelector('#phone-field').value = e.detail.phone;
    document.querySelector('#otp-request-id').value = e.detail.requestId;
    document.querySelector('#continue').disabled = false;
  });
</script>

The event bubbles, so you can also listen on document.

What the visitor sees #

  1. A phone field ("Your WhatsApp number, e.g. +213500000000") and a Send code button.
  2. "We sent a code to ... on WhatsApp", a 6-digit code field, Verify, and "Use a different number".
  3. "Verified" on success, "Invalid code, try again." or "Code expired. Request a new one." otherwise.

The widget text is in English. If a send fails, the widget shows the API error code (for example rate_limited); see error codes.

Is the widget enough for login or sign-up? #

Treat the widget as a convenience check, not as proof on your server. The waforge:verified event happens in the visitor's browser, and the API does not return the phone number for a request id. Someone could verify their own number and then submit a different number to your form.

When the result matters (account sign-up, login, payouts), use the server-side OTP API for WhatsApp OTP login: your server chooses the phone, sends the code, keeps the request_id in the session and verifies it. Keep your secret key on the server.

Troubleshooting #

SymptomCause
Nothing appearsThe <div id="waforge-otp"> is after the script, or data-key is missing.
origin_not_allowedThe page's host is not in the key's allowed domains (check www.), or you are testing on localhost without listing it.
invalid_api_keyThe key was revoked, or you pasted a different key.
instance_not_connected or send_failedYour WhatsApp number is disconnected. Reconnect it in the dashboard.
network_errorThe browser could not reach waforge.online (offline, blocked by an extension or a Content Security Policy). Allow https://waforge.online in script-src and connect-src.