npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wa-chat-widget

v1.0.3

Published

A simple WhatsApp chat widget for websites

Downloads

313

Readme

WhatsApp Chat Widget

npm version npm downloads commit size hits

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://cdn.jsdelivr.net/npm/[email protected]/dist/wa-chat-widget.js"></script>

or

<script src="https://unpkg.com/[email protected]/dist/wa-chat-widget.js"></script>

Usage

Note: The Phone number should be entered in the international format without the + sign. For eg: If your number is +1 234-567-9898, then you should enter the phone number as 12345679898.

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://cdn.jsdelivr.net/npm/[email protected]/dist/wa-chat-widget.js"></script>
<script>
    const widget = new WaChatWidget({
        phoneNumber: '1234567890',
        message: "Hello! I'm interested in your services"
    });
</script>

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | phoneNumber | string | '' | WhatsApp number in international format without + symbol in front (required) | | message | string | "I'm interested to know more about your offerings." | Default message | | position | string | 'bottom-right' | Widget position ('top-left', 'top-right', 'bottom-left', 'bottom-right') | | backgroundColor | string | '#25D366' | Background color of the widget | | textColor | string | '#fff' | Color of the WhatsApp icon | | size | string | '60px' | Size of the widget | | showTooltip | boolean | true | Show/hide tooltip on hover | | tooltipText | string | '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

| Method | Description | |--------|-------------| | 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)

License

Commercial license

If you want to use this plugin to develop commercial sites, themes, projects, and applications, the Commercial license is the appropriate license. With this option, your source code is kept proprietary. Read more about the commercial license.

Open source license

If you are creating an open source application under a license compatible with the GNU GPL license v3, you may use this project under the terms of the GPLv3.

Author

Raghu Chinnannan

Support

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