Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@shibacore/apis

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shibacore/apis

A TypeScript library for interacting with the WhatsApp Business API. It provides a simple and flexible interface to send various types of messages (text, templates, media, interactive components, etc.) using WhatsApp's Graph API.

  • 1.0.5
  • npm
  • Socket score

Version published
Weekly downloads
328
increased by87.43%
Maintainers
1
Weekly downloads
 
Created
Source

Whatsapp Messages API

A TypeScript library for interacting with the WhatsApp Business API. It provides a simple and flexible interface to send various types of messages (text, templates, media, interactive components, etc.) using WhatsApp's Graph API.


Table of Contents

  • Installation
  • Features
  • Getting Started
  • API Reference

Installation

npm install @shibacore/apis

Features

  • Easily send WhatsApp messages using the Graph API.
  • Supports text, media (images, videos), templates, interactive components (buttons, lists), and location messages.
  • Customizable headers and token types for enhanced flexibility.
  • Robust error handling with well-structured responses.

Getting Started

Prerequisites

  1. A valid access token for the WhatsApp Business API.
  2. Your WhatsApp Business phone number ID.
  3. A registered app on the Facebook Developer Dashboard.

Example Usage

import { WhatsappMessages } from "@shibacore/apis";

const accessToken = "your-access-token";
const phoneNumberId = "your-phone-number-id";
const apiVersion = "v20.0";

const whatsapp = new WhatsappMessages(accessToken, apiVersion, phoneNumberId);

// Send a text message
(async () => {
const response = await whatsapp.text("recipient-phone-number", "Hello, World!");
console.log(response);
})();

API Reference

WhatsappMessages

Provides methods to send different types of WhatsApp messages. Constructor

constructor(
  access_token: string,
  version: Version,
  phoneNumberId: PhoneNumberId,
  headerOptions?: HeaderOptions,
  tokenType?: TokenType
)
  • phoneNumberId: The ID of the WhatsApp Business phone number.

Message Types

  1. Template Messages
async template(
  to: string,
  templateName: string,
  language_code: LanguageCode,
  components?: TemplateComponents
): Promise<WhatsappMessageResponse>;
  • Sends a WhatsApp template message.

    Example:

    await whatsapp.template("recipient-phone-number", "hello_world", "en_US");
    
  1. Text Messages
async text(
  to: string,
  bodyText: string,
  preview_url?: boolean
): Promise<WhatsappMessageResponse>;
  • Sends a plain text message.

Example:

await whatsapp.text("recipient-phone-number", "Hello, this is a message!");

3. Media Messages - Image

  async image(
    to: string,
    imageOption: Media
  ): Promise<WhatsappMessageResponse>;

- Video

  async video(
    to: string,
    videoOption: Media
  ): Promise<WhatsappMessageResponse>;

Example:

await whatsapp.image("recipient-phone-number", { id: "media-id" });
  1. Location Messages
async location(
  to: string,
  location: Location
): Promise<WhatsappMessageResponse>;

Example:

await whatsapp.location("recipient-phone-number", {
  latitude: "12.34",
  longitude: "56.78",
  name: "Location Name",
  address: "123 Address St."
});

License

This project is licensed under the MIT License. See the LICENSE file for details.

Key Features of the Document:

  1. Installation & Prerequisites: Details on setting up the library.
  2. Features & Examples: Highlights key functionalities with code samples.
  3. API Reference: Comprehensive details of constructors and methods.

This README.md ensures clarity and usability for users integrating your library.

FAQs

Package last updated on 15 Nov 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc