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

whatsapp.ts

v1.1.0

Published

A simple Node.js library for simplifying WhatsApp Web socket connection using the WhiskeySockets/Baileys library.

Downloads

12

Readme

whatsapp.ts

A simple Node.js library for simplifying WhatsApp Web socket connection using the WhiskeySockets/Baileys library.

Installation

You can install whatsapp.ts via npm:

npm install whatsapp.ts

Purpose

The primary purpose of this library is to provide a more user-friendly and streamlined way of creating WhatsApp Web socket connections using the WhiskeySockets/Baileys library. It simplifies the process and offers additional functionalities.

Features

All Baileys Socket Options Supported

You can pass all the socket configuration options supported by the Baileys library through the baileysOptions parameter in the constructor of the WhatsAppAPI class.

Direct Access to Baileys Socket

With whatsapp.ts, you can access the underlying socket created by Baileys directly using the wp.socket property. This means that you can utilize any events and functions that are available in Baileys but not included in this library.

Events

  • qr: Triggered when a QR code is received. The QR code data is passed as a parameter.
  • ready: Fired when a successful login to WhatsApp is established. Account information is passed as a parameter.
  • disconnect: Triggered when you log out of WhatsApp. The reason for disconnection is passed as a parameter.
  • message: Triggered when a message is received. The full message details are passed as a parameter.
  • /command: Triggered when a message with a command (starting with /) is received. The full message details are passed as a parameter.

Functions

sendText(to, message)

Sends a text message to the specified phone number. The first parameter should be in the WhatsApp number format (e.g., [email protected] or [email protected]). The second parameter is the message you want to send.

message.reply(text)

This function is used to reply to a received message. You can pass the text parameter to send a response to the message that triggered the event.

Example

Below is an example of how to use the whatsapp.ts library:

import { WhatsAppAPI } from 'whatsapp.ts';
import qrcode from 'qrcode-terminal';

let wp = new WhatsAppAPI({
    deviceName: 'My Device',
    sessionPath: './wp-session',
    baileysOptions: {},
});

wp.on('qr', (qr) => {
    qrcode.generate(qr, { small: true });
});

wp.on('ready', async (data) => {
    console.log(data);
});

wp.on('disconnect', (reason) => {
    console.log('Disconnected: ' + reason);
    wp.initialize();
});

wp.on('message', (message) => {
    if (message.text.includes('ping')) {
        message.reply('pong');
    }
});

wp.on('/test', (message) => {
    message.reply(message.text);
});

wp.initialize();

License

This section can be found in LICENSE file.