Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wa-chat-widget

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wa-chat-widget

A simple WhatsApp chat widget for websites

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-16.67%
Maintainers
0
Weekly downloads
 
Created
Source

WhatsApp Chat Widget

npm version license npm downloads

A lightweight, customizable WhatsApp chat widget that adds a floating WhatsApp button to your website. When clicked, it opens a WhatsApp chat with a pre-defined message.

Features

  • 🎨 Fully customizable appearance
  • 📱 Mobile-friendly and responsive
  • 🎯 Multiple position options
  • 💬 Custom pre-defined messages
  • 🔧 Easy to install and configure
  • 🌐 Works with any website
  • 💪 No dependencies
  • ♿ Accessibility friendly
  • 🌙 Dark mode support
  • 🖨️ Print-friendly (hides widget)

Installation

Using npm

npm install wa-chat-widget

Using CDN

<script src="https://unpkg.com/wa-chat-widget@1.0.0/dist/wa-chat-widget.js"></script>

Usage

ES6 Module

import WaChatWidget from 'wa-chat-widget';

const widget = new WaChatWidget({
    phoneNumber: '1234567890',
    message: "Hello! I'm interested in your services"
});

Script Tag

<script src="https://unpkg.com/wa-chat-widget@1.0.0/dist/wa-chat-widget.js"></script>
<script>
    const widget = new WaChatWidget({
        phoneNumber: '1234567890',
        message: "Hello! I'm interested in your services"
    });
</script>

Configuration Options

OptionTypeDefaultDescription
phoneNumberstring''WhatsApp number in international format without + symbol in front (required)
messagestring"I'm interested to know more about your offerings."Default message
positionstring'bottom-right'Widget position ('top-left', 'top-right', 'bottom-left', 'bottom-right')
backgroundColorstring'#25D366'Background color of the widget
textColorstring'#fff'Color of the WhatsApp icon
sizestring'60px'Size of the widget
showTooltipbooleantrueShow/hide tooltip on hover
tooltipTextstring'Chat with us'Text to show in tooltip

Examples

Basic Usage

new WaChatWidget({
    phoneNumber: '1234567890'
});

Custom Styling

new WaChatWidget({
    phoneNumber: '1234567890',
    backgroundColor: '#075e54',
    textColor: '#ffffff',
    size: '70px',
    position: 'top-right'
});

Multi-Language Support

const userLanguage = navigator.language.substring(0, 2);
const messages = {
    en: "Hi, I'd like to know more",
    es: "Hola, me gustaría saber más",
    fr: "Bonjour, j'aimerais en savoir plus"
};

new WaChatWidget({
    phoneNumber: '1234567890',
    message: messages[userLanguage] || messages.en,
    tooltipText: 'Chat with us'
});

Dynamic Control

const widget = new WaChatWidget({
    phoneNumber: '1234567890'
});

// Hide widget
widget.hide();

// Show widget
widget.show();

// Update options
widget.updateOptions({
    backgroundColor: '#128C7E',
    size: '65px'
});

// Destroy widget
widget.destroy();

Business Hours

function isBusinessHours() {
    const now = new Date();
    const hours = now.getHours();
    const day = now.getDay();
    return day >= 1 && day <= 5 && hours >= 9 && hours < 17;
}

new WaChatWidget({
    phoneNumber: '1234567890',
    message: isBusinessHours() 
        ? "Hi, I'd like to speak with your team"
        : "Hi, I'd like to leave a message",
    tooltipText: isBusinessHours()
        ? "Chat with us now!"
        : "Leave us a message",
    backgroundColor: isBusinessHours() ? '#25D366' : '#128C7E'
});

API Methods

MethodDescription
show()Shows the widget
hide()Hides the widget
destroy()Removes the widget from DOM
updateOptions(options)Updates widget configuration

Browser Support

  • Chrome (Latest)
  • Firefox (Latest)
  • Safari (Latest)
  • Edge (Latest)
  • Opera (Latest)

Contributing

  1. Fork the repository
  2. Create your feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add some amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

License

This project is licensed under the GPL-3.0 License - see the LICENSE file for details.

Author

Raghu Chinnannan

Support

For support, please open an issue in the GitHub repository.

Keywords

FAQs

Package last updated on 27 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc