1.1.0 • Published 6 months ago

aronium-whatsapp-messenger v1.1.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
6 months ago

About

This package sends messages to customers through whatsapp in their saved numbers in aronium pos application. Currently sending invoice is only supported.

The library currently only supports sending of invoice to cutomers on sale. It polls the aronium database for changes and sent invoice to the corresponding customer. Uses whatsapp-web.js library for sending messages and prisma for querying aronium database.

!IMPORTANT Excerpt from whatsapp-web.js npm homepage : WhatsApp does not allow bots or unofficial clients on their platform, so this shouldn't be considered totally safe.

Installation

npm i aronium-whatsapp-messenger

!NOTE Node v18+ is required.

Example usage

Wait for qr code to be shown in terminal and link it with your store mobile's whatsapp or any other whatsapp number.

ESM

import { run_messenger } from 'aronium-whatsapp-messenger';
run_messenger({
    database_path: "<path_to_db>/pos.db",
    options: {
        ping: {
        numbers: ['000000000'],
      },
      invoice: {
        poll_interval: 10,
        numbers: ['<phone_number_for_sending_warning>'],
        date_format: 'DD-MM-YYYY, hh:mm a'
      },

    }
})

Common JS

const { run_messenger } = require('aronium-whatsapp-messenger');
run_messenger({
    database_path: "<path_to_db>/pos.db",
    options: {
        ping: {
            interval: 10,
            numbers: ['000000000']
        },
        invoice: {
          poll_interval: 10,
          numbers: ['<phone_number_for_sending_warning>'],
          date_format: 'DD-MM-YYYY, hh:mm a'
        },
    }
})

Config

    /** path to aronium database */
    database_path: string;

    /** country code eg. +91*/
    country_code: string = '91';

    options?: {

      ping?: {
        /** Whether to send ping message or not (to inform client is running)*/
        required?: boolean = true;

        /** interval for ping message to be sent (in seconds)*/
        interval?: number = 600;

        /** ping message */
        message?: string = 'ping';

        /** numbers to which ping message is to be sent*/
        numbers?: string[] = [];

      };
      invoice?: {
        /** Whether to send invoice or not */
        required?: boolean = true;

        /** date format same as moment.js formatting */
        date_format?: string = 'DD-MM-YYYY, hh:mm a';

        /** interval for polling database in seconds*/
        poll_interval?: number = 10;

        /** invoice template */
        template?: {

          header?: string = `*{company.Name}*
            *Invoice No.* {invoice.Number}
            *Date:* {invoice.Date}      
            `;

          body?: string = `{Index}. {Product.Name}
            *₹ {Price}* x *{Quantity}* = *{Total}*
            `;

          footer?: string = `Total: *₹ {invoice.Total}*
            _Thank you for your purchase._`,
        };
      
        /** numbers to send invoice in case customer is not selected/phone number not found in aronium */
        numbers?: string[] = [];

        /** company or store banner image. can be url or filepath 
         * if provided, template will be sent as a caption to the banner
        */
        company_banner_path?: string;
      };
    };

exposed fields in invoice template header and footer

{
  'company.Id',
  'company.Address',
  'company.Name',
  'company.Email',
  'company.PhoneNumber',

  'invoice.Id',
  'invoice.Customer.Name',
  'invoice.Customer.PhoneNumber',
  'invoice.Number',
  'invoice.Total',
  'invoice.Date',
}

exposed fields in invoice template body (list of items purchased)

{
  'Product.Name',
  'Quantity',
  'Price',
  'Total',
  'Index',
}

Supported features

Feature

| Sending invoice based on template with banner | Sending ping messages to announce client alive

Planned features

Feature

| Promotion message to all customers (template based and image) | Low stock alert message per item | Low stock list message | Daily Sale amount message | Expose more fields on invoice templates

Disclaimer

This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp, Aronium or any of its subsidiaries or its affiliates. The official WhatsApp website can be found at whatsapp.com and of aronium at aronium.com. "WhatsApp", "Aronium" as well as related names, marks, emblems and images are registered trademarks of their respective owners.

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this project except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.