Skip to content

An implementation of whatsapp client written in typescript to run in nodejs, browser, etc

Notifications You must be signed in to change notification settings

jlucaso1/wha.ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wha.ts

A modern TypeScript library for interacting with the WhatsApp Web API.

Overview

wha.ts provides a robust, type-safe interface to the WhatsApp Web protocol, allowing developers to build applications that can interact with WhatsApp. This library handles the complex authentication, encryption, and communication protocols required to interact with WhatsApp's services.

Features

  • 🔒 End-to-end encryption - All communication is properly encrypted using WhatsApp's security protocols
  • 📱 Multi-device support - Works with WhatsApp's multi-device architecture
  • 🧩 Modular design - Use only the components you need
  • 🔍 Type safety - Full TypeScript support with comprehensive type definitions
  • 🌐 Cross-platform - Works in both Node.js and browser environments
  • 🧪 Protocol Buffer integration - Uses protocol buffers for efficient message serialization

Installation

# Using bun
bun add @wha.ts/core

# Using npm
npm install @wha.ts/core

# Using yarn
yarn add @wha.ts/core

Quick Start

Here's a simple example of connecting to WhatsApp and listening for connection updates:

import { createWAClient } from "@wha.ts/core";
import { GenericAuthState } from "@wha.ts/core/src/state/providers/generic-auth-state";
import { createStorage } from "unstorage";
import fsDriver from "unstorage/drivers/fs-lite";

async function main() {
  // Set up storage for authentication state
  const storage = createStorage({ 
    driver: fsDriver({ base: "./whatsapp-storage" }) 
  });

  // Initialize authentication state
  const authState = await GenericAuthState.init(storage);

  // Create WhatsApp client
  const client = createWAClient({
    auth: authState,
    logger: console,
  });

  // Listen for connection updates
  client.addListener("connection.update", (update) => {
    console.log("Connection update:", update);
    
    // Handle QR code for authentication
    if (update.qr) {
      console.log("Scan this QR code to log in:", update.qr);
    }
    
    // Connection is open and ready
    if (update.connection === "open") {
      console.log("Connected to WhatsApp!");
    }
  });

  // Connect to WhatsApp
  await client.connect();
}

main().catch(console.error);

Project Structure

This project is organized as a monorepo with the following packages:

  • @wha.ts/core - Core functionality for WhatsApp communication
  • @wha.ts/extension - Browser extension integrations
  • @wha.ts/binary - Utilities for handling binary data
  • @wha.ts/proto - Protocol Buffer definitions
  • example - Example implementations
  • test - Testing utilities

Documentation

For more detailed documentation, see the following resources:

Development

Prerequisites

  • Bun (for package management and running scripts)
  • Node.js (v18 or higher recommended)

Setup

# Clone the repository
git clone https://github.com/yourusername/wha.ts.git
cd wha.ts

# Install dependencies
bun install

Build

# Build all packages
bun run build

# Build specific packages
bun run build:core
bun run build:extension

Linting and Formatting

# Check and fix code style issues
bun run lint

# Format code
bun run format

Testing

# Run tests
bun test

Contributing

Contributions are welcome! Please see the CONTRIBUTING.md file for guidelines.

License

MIT

Disclaimer

This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or its affiliates. The official WhatsApp website can be found at https://whatsapp.com.

This library is intended for legitimate purposes only. Users are responsible for ensuring their use complies with WhatsApp's Terms of Service.

About

An implementation of whatsapp client written in typescript to run in nodejs, browser, etc

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published