New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sergiobanhos/whatsapp-api-sdk

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sergiobanhos/whatsapp-api-sdk

SDK for WhatsApp Business API, Whatsapp Cloud API and Instagram API using Node.js and TypeScript

4.1.0
latest
npm
Version published
Weekly downloads
48
84.62%
Maintainers
0
Weekly downloads
 
Created
Source

Here’s a professional and polished README for your WhatsApp SDK, including all the essential sections to guide users:

WhatsApp & Instagram API SDK

npm version License: MIT

The WhatsApp & Instagram API SDK is a powerful and easy-to-use Node.js library for interacting with both the official WhatsApp Cloud API and Instagram Graph API. Designed for scalability and ease of use, it supports message sending, webhook integration, interactive buttons, Instagram messaging, comments, and more—all with TypeScript typings for robust development.

✨ Features

WhatsApp Features

  • Simple Configuration: Initialize the client with minimal setup
  • Send Messages: Text, media, templates, and interactive messages
  • Webhooks: Built-in webhook handling for GET validation and POST callbacks
  • Interactive Buttons: Send Call-to-Action (CTA) buttons and quick replies

Instagram Features

  • Message Management: Send and receive Instagram DMs
  • Comment Handling: Manage Instagram post comments
  • User Information: Access Instagram user data and insights
  • Post Management: Handle Instagram posts and media

General Features

  • TypeScript Support: Complete TypeScript definitions for a seamless development experience
  • Error Handling: Comprehensive error management and logging
  • Multi-platform: Support for both WhatsApp and Instagram in a single SDK

🚀 Installation

Install the SDK using npm:

npm install @sergiobanhos/whatsapp-api-sdk

🛠️ Usage

Initialize the WhatsApp Client

import { WhatsappCloudApiClient, WhatsappBusinessApiClient } from '@sb/whatsapp-api-sdk';

const { wa, waba } = getWhatsappApi({
    whatsapp: {
        accessToken: 'your-meta-access-token',
        phoneNumberId: 'your-phone-number-id',
        whatsappBusinessId: 'your-business-account-id'
    }
});

// The wa client is for general WhatsApp Cloud API operations
// The waba client is for WhatsApp Business API operations

Initialize the Instagram Client

import { InstagramApiClient } from '@sb/whatsapp-api-sdk';

const insta = new InstagramApiClient({
    token: 'your-instagram-access-token',
    phoneNumberId: 'your-instagram-user-id',
    onError: (error) => console.error('Error:', JSON.stringify(error, null, 4)),
});

Sending a WhatsApp Text Message

// Using WhatsApp Cloud API
await wa.sendTextMessage('<CUSTOMER_PHONE_NUMBER>', 'Hello from WhatsApp API SDK!');

// Using Instagram API
await insta.sendMessage('<INSTAGRAM_USER_ID>', 'Hello from Instagram API SDK!');

Sending an Interactive Message with Buttons

await client.sendButtonMessage('<CUSTOMER_PHONE_NUMBER>', {
  body: 'Choose an option:',
  buttons: [
    { type: 'reply', id: '1', title: 'Option 1' },
    { type: 'reply', id: '2', title: 'Option 2' },
  ],
});

Sending a Call-to-Action Button (CTA)

await client.sendCTAMessage('<CUSTOMER_PHONE_NUMBER>', {
  header: { type: 'text', text: 'Header Text' },
  body: 'Visit our website:',
  footer: 'Footer Text',
  buttons: [
    { type: 'url', url: 'https://example.com', title: 'Go to Website' },
  ],
});

Webhook Integration

The SDK provides a built-in webhook handler using Express:

import express from 'express';
import WhatsAppClient from '@sb/whatsapp-api-sdk';

const app = express();
const client = new WhatsAppClient({
  accessToken: 'your-meta-access-token',
  verifyToken: 'your-webhook-verify-token',
});

client.setupWebhookRoutes(app);

app.listen(3000, () => {
  console.log('Webhook server running on port 3000');
});

📚 API Documentation

WhatsAppClient Options

OptionTypeDescription
accessTokenstringYour Meta API access token.
verifyTokenstringToken used for webhook validation.
onErrorFunctionCallback for handling errors from the WhatsApp Cloud API.
webhookCallbackFunctionCallback triggered when webhook events are received.

Available Methods

WhatsApp Cloud API Methods
MethodDescription
sendTextMessageSends a simple text message.
sendButtonMessageSends a message with interactive buttons.
sendCTAMessageSends a Call-to-Action message with links.
setupWebhookRoutesSets up webhook validation and POST routes.
Instagram API Methods

| Method | Description | |-----------------------|------------------------------------------------------|| | sendMessage | Sends a message to an Instagram user | | getComments | Retrieves comments from an Instagram post | | replyToComment | Replies to a specific Instagram comment | | getUserProfile | Gets information about an Instagram user | | getPost | Retrieves information about an Instagram post |

🧪 Testing

To test the library locally, follow these steps:

  • Clone the repository:
    git clone https://github.com/sergipe085/whatsapp-api-sdk.git
    
  • Install dependencies:
    npm install
    
  • Run the test suite:
    npm test
    

📝 License

This project is licensed under the MIT License.

💬 Support

For any questions or issues, please open an issue or contact us at sergiobanhosf@gmail.com.

🌟 Acknowledgments

Special thanks to the WhatsApp Cloud API team and the open-source community for their support and documentation.

Let me know if you'd like to add custom badges, extended documentation, or other sections!

Keywords

whatsapp

FAQs

Package last updated on 10 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts