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

@frugan/whatsapp-widget

v1.3.3

Published

A simple WhatsApp live chat widget for your website.

Downloads

7

Readme

npm version JS gzip size CSS gzip size Code license

WhatsApp Widget

A simple WhatsApp live chat widget for your website.

Table of content

Getting started

There are some ways to import the package

Usage

Include the css inside head tag and javascript file inside body tag of your html file.

<link rel="stylesheet" href="/dist/css/whatsapp-widget.min.css">
<script src="/dist/js/whatsapp-widget.min.js"></script>

Built in form

To use our built-in chat form, copy and paste this HTML code inside <body> tag. Replace {phone_number} with your number in international format (Leading zero replaced with country code) and omit any brackets and dashes.

<form id="whatsapp" class="wa-widget" action="{phone_number}" data-chat="whatsapp"></form>

To initiate the built in widget, place this script before </body> closing tag.

<script>
    // WhatsAppWidget(element, { configs }, [ inputs ])

    const chat = new WhatsAppWidget(document.getElementById('whatsapp'), {
        // configs...
    }, [
        // array of input object
    ]);
</script>

From v1.2.0, you can create as many inputs as you want with built-in form by creating an array of input object with name, type, and required properties.

Example:

[{
    name: 'domain',
    type: 'hidden',
    value: 'domain.tld',
    required: false,
}, {
    name: 'name',
    type: 'text',
    required: true,
    placeholder: 'Your name',
}, {
    name: 'email',
    type: 'email',
    required: false,
    placeholder: 'Your email',
}, {
    name: 'message',
    type: 'text',
    required: true,
    placeholder: 'Your message',
}]

This will create four inputs.

  1. Domain input with hidden type and domain.tld value
  2. Name input with text type and it's required / mandatory
  3. Email input with email type and it's optional
  4. Message input with text type and it's required / mandatory

Custom form

To make a custom form, first you have to create form element with an id attribute, data-chat attribute and action attribute to put your phone number. Inside the form you have to add an element with wa-widget-content class.

<form id="billing-support" action="{phone_number}" data-chat="billing-support">
    <div class="wa-widget-content">
        <!-- your input -->
    </div>
</form>

And for the input form to write a chat or message, you only need to create an input element with name attribute inside the form element. You can add an input as many as you want as long as it has name attribute.

<input name="name" type="text" placeholder="Your name" required>
<input name="message" type="text" placeholder="Your message">
<!-- more input -->

Lastly, add a button inside the form with submit type and data-toggle="wa-send" attribute to send the chat.

<button type="submit" data-toggle="wa-send">Chat</button>

The custom form will automaticaly initiated without a script.

Toggleable custom form

If you want to make your custom form toggleable (show and hide) with a click. Just create a link element a or a button element with data-toggle="wa-chat" and data-target="#{form_id}".

<a class="button" data-toggle="wa-chat" data-target="#billing-support" href="#billing-support">Link</a>

<!-- OR -->

<button class="button" data-toggle="wa-chat" data-target="#customer-support">Button</button>

On button toggled, it will automaticaly add expanded class on it self and on the form element on show, and will remove expanded class on hide.

Configs

Name | Type | Default | Description ---- | ---- | ------- | ----------- name | string | '' | Chat / person name division | string | '' | Division name photo | string | '' | Company logo or person photo introduction | string | '' | Chat introduction

License

Copyright (c) 2020 - Fajar Setya Budi.

WhatsApp Widget released under the MIT License.