I built a zero-dependency, form-first WhatsApp widget for React & plain HTML (with optional BYO-AI, live chat, and lead capture)
Most WhatsApp widgets on npm are just a floating icon that drops visitors into an empty chat box. Businesses end up with vague "Hi" messages, zero context on what page the visitor was viewing, and no record of leads who clicked the button but closed WhatsApp before hitting send. I built whatsapp-chat-widget-react (now at v0.8.0 and already crossing 320+ weekly downloads in its first few days!) to…
WhatsApp widgets on npm often provide a floating icon that transports users to an empty chat box. This results in generic "Hi" messages, missing context regarding the page being viewed, and no record of leads who clicked the button but closed WhatsApp before sending a message. To address these issues, I developed whatsapp-chat-widget-react (recently released at version 0.8.0 and already experiencing over 320 weekly downloads) that utilizes a form-first, zero-dependency, privacy-conscious architecture - plus a standalone script tag build for non-React sites. Try the live interactive playground.
What sets whatsapp-chat-widget-react apart is its form-first pre-qualification approach that requires no backend by default. Visitors fill out a simple contact form with their Name, Subject, and Message, and the formatted draft is sent directly to https://wa.me/... without needing an API key, server, or account.
Privacy-safe page context and UTM attribution are automatically appended to the draft, including page title, URL, and UTM tags (utm_source, utm_medium, utm_campaign). This ensures no query strings or URL hashes leak into chat logs. Visitors can also interact with Teams, setting business hours and timezone-aware agent selection, with the widget preselecting the first online agent based on native Intl.DateTimeFormat.
Optionally, the widget can offer live in-widget chat and webhook transport. By switching to live mode, visitors can stay on the site instead of leaving for WhatsApp. The implementation includes sessionStorage persistence, delivery statuses, retry handling, and a "Continue on WhatsApp" escape hatch. Bring-your-own-AI support is available from version 0.8.0, allowing integration with any /v1/chat/completions endpoint (such as OpenAI, Claude via OpenRouter/LiteLLM, Cloudflare AI Gateway, Groq, or Ollama) via createOpenAICompatibleAI.
This enables features like the "Polish with AI" button inside the textarea and auto-routing/triage to route messages to the appropriate agent or answer FAQs within the widget.
Privacy remains a priority: phone numbers are never sent in AI triage or webhook payloads, and the widget fails open so visitors are never blocked. Popup-blocker safe lead capture using navigator.sendBeacon ensures that even if an async AI or webhook step consumes the browser's click activation, the widget gracefully renders an "Open WhatsApp" button instead of getting blocked by a popup blocker.
The widget offers programmatic control through useWhatsAppWidget(), allowing integration with pricing calculators, navbar CTAs, or page buttons. Quick start guides are available for React/TypeScript and plain HTML/No-React implementations. Visit the interactive playground, GitHub repository, or npm package page for more details.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to
More from Dev.to on urgent.news
Report a problem with this story
Get the day's news by email. Daily, weekly or monthly. Sign up