handonweb-wa-link
v1.0.0
Published
Generate WhatsApp click-to-chat links and buttons with pre-filled messages
Downloads
92
Maintainers
Readme
handonweb-wa-link
Generate WhatsApp click-to-chat links and HTML buttons with pre-filled messages. Zero dependencies.
Install
npm install handonweb-wa-linkUsage
const { waLink, waButton } = require('handonweb-wa-link');
// Simple link
const url = waLink('447471487274', 'Hello!');
// => https://wa.me/447471487274?text=Hello!
// With country code (strips leading zero automatically)
const ukUrl = waLink('07471487274', 'Hi', { countryCode: '44' });
// => https://wa.me/447471487274?text=Hi
// Use api.whatsapp.com instead of wa.me
const apiUrl = waLink('447471487274', 'Hi', { useApi: true });
// => https://api.whatsapp.com/send?phone=447471487274&text=Hi
// Generate an HTML button
const html = waButton('447471487274', 'Need help?');
// => <a href="https://wa.me/..." style="..." target="_blank">Chat on WhatsApp</a>
// Custom button styling
const custom = waButton('447471487274', 'Hi', {
text: 'Message Us',
color: '#128C7E',
textColor: '#fff',
borderRadius: '20px',
fontSize: '14px',
padding: '10px 20px',
});API
waLink(phone, message?, options?)
Returns a WhatsApp chat URL string.
| Param | Type | Description |
|-------|------|-------------|
| phone | string | Phone number (any format — spaces, dashes, brackets OK) |
| message | string | Pre-filled message (optional) |
| options.countryCode | string | Country code to prepend, e.g. "44" |
| options.useApi | boolean | Use api.whatsapp.com instead of wa.me |
waButton(phone, message?, style?)
Returns an HTML anchor tag styled as a button.
| Param | Type | Default |
|-------|------|---------|
| style.text | string | "Chat on WhatsApp" |
| style.color | string | "#25D366" |
| style.textColor | string | "#ffffff" |
| style.borderRadius | string | "8px" |
| style.fontSize | string | "16px" |
| style.padding | string | "12px 24px" |
| style.countryCode | string | — |
| style.useApi | boolean | false |
About Hand On Web
We build AI chatbots, voice agents, and automation tools for businesses.
- 🌐 handonweb.com
- 📧 [email protected]
- 📍 Chester, UK
Licence
MIT
