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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@wsapichat/client

v1.0.9

Published

A TypeScript SDK for integrating with the WSApi API, enabling developers to send WhatsApp messages, manage groups and chats, and receive real-time events via Webhooks or Server-Sent Events (SSE). This is an independent API and is not affiliated with META

Downloads

143

Readme

WSApi.Client (TypeScript SDK)

A TypeScript/JavaScript SDK for integrating with the WSApi API, enabling developers to send WhatsApp messages, manage groups and chats, and receive real-time events via Webhooks or Server-Sent Events (SSE).

Features

  • HTTP Client: Simple, strongly-typed client for all API commands (messages, groups, chats, contacts, etc).
  • Events: Receive real-time events from the API via:
    • Webhooks: Configure your endpoint to receive HTTP POST events.
    • SSE: Use the built-in SSE client to receive events over a persistent connection.
  • TypeScript Support: Full type safety with comprehensive TypeScript definitions.
  • Dual Error Handling: Both throwing and non-throwing method variants for flexible error handling.
  • Cross-Platform: Works in Node.js, browsers, and other JavaScript environments.

Getting Started

Prerequisites

  • Node.js 16.0 or later (for Node.js environments)
  • Modern browser with fetch API support (for browser environments)
  • Access to the WSApi API (Valid instance with ID and API key)

Installation

From NPM

npm install @wsapichat/client

Or using Yarn:

yarn add @wsapichat/client

Usage

1. Basic Setup

import { HttpClient, WSApiClientFactory } from '@wsapichat/client';

const client = WSApiClientFactory.create({
  apiKey: 'your-api-key',
  instanceId: 'your-instance-id'
});

// Send a text message
const result = await client.messages.sendText({
  to: '[email protected]', // Phone number in WhatsApp format
  text: 'Hello from TypeScript SDK!'
});

console.log('Message sent with ID:', result.messageId);

2. Error Handling

The SDK provides two methods for each API call to handle different error scenarios:

Exception-based (throws on error)

try {
  const result = await client.messages.sendText(request);
  console.log('Message sent with ID:', result.messageId);
} catch (error) {
  if (error instanceof ApiException) {
    console.log('Failed to send message:', error.problem.detail);
  }
}

ApiResponse-based (no exceptions)

const response = await client.messages.trySendText(request);
if (response.isSuccess) {
  console.log('Message sent with ID:', response.result?.messageId);
} else {
  console.log('Failed to send message:', response.error?.detail);
}

3. Receiving Events via SSE

import { WSApiClientFactory, EventFactory } from '@wsapi/client';

const sseClient = WSApiClientFactory.createSSEClient({
  apiKey: 'your-api-key',
  instanceId: 'your-instance-id'
});

sseClient.on('rawEventReceived', (args) => {
  try {
    const event = EventFactory.parseEvent(args.rawJson);
    
    switch (event.eventType) {
      case 'message':
        const messageEvent = event as MessageEvent;
        console.log('Message received:', messageEvent.text);
        break;
      
      case 'logged-in':
        console.log('Session logged in');
        break;
      
      // Handle other event types as needed
    }
  } catch (error) {
    console.error('Error parsing event:', error);
  }
});

sseClient.on('connectionStateChanged', (args) => {
  console.log('Connection state changed to:', args.state);
  if (args.error) {
    console.error('Connection error:', args.error);
  }
});

// Start the SSE client
await sseClient.start();

License

MIT