Skip to content

CockpitConnect/meta-cloud-api

 
 

Repository files navigation

Meta Cloud API

Meta Cloud API

Meta Cloud API - A powerful TypeScript wrapper for Meta's Cloud API, providing a clean and type-safe interface for WhatsApp Business Platform integration.

GitHub license

Resources

Features

  • Type-Safe Development - Built with TypeScript to provide code completion and catch errors during development
  • Comprehensive Coverage - Full support for WhatsApp Business Platform APIs
  • Clean Interface - Intuitive methods organized by domain for improved code readability
  • Error Handling - Standardized error handling with detailed Meta API error information

Installation

npm install meta-cloud-api
# or
yarn add meta-cloud-api
# or
pnpm add meta-cloud-api

Quick Start

import { WhatsApp } from 'meta-cloud-api';

// Initialize the client
const client = new WhatsApp({
  accessToken: process.env.ACCESS_TOKEN,
  phoneNumberId: process.env.PHONE_NUMBER_ID,
  version: '22'  // API version
});

// Send a WhatsApp message
const response = await client.messages.send({
  to: '+1234567890',
  type: 'text',
  text: {
    body: 'Hello from Meta Cloud API!'
  }
});

console.log(`Message ID: ${response.messages[0].id}`);

Usage Examples

Messaging

Send different types of messages through WhatsApp Business Platform:

Text Message

const result = await client.messages.send({
  to: "15551234567",
  type: "text",
  text: {
    body: "Hello from Meta Cloud API!"
  }
});

Template Message

const result = await client.messages.send({
  to: "15551234567",
  type: "template",
  template: {
    name: "shipping_confirmation",
    language: {
      code: "en_US"
    },
    components: [
      {
        type: "body",
        parameters: [
          {
            type: "text",
            text: "John Doe"
          },
          {
            type: "text",
            text: "12345"
          }
        ]
      }
    ]
  }
});

Media Message

const result = await client.messages.send({
  to: "15551234567",
  type: "image",
  image: {
    link: "https://example.com/image.jpg"
  }
});

Templates

Manage message templates for your WhatsApp Business account:

// List all templates
const templates = await client.templates.list({
  business_id: "1234567890"
});

// Create a new template
const newTemplate = await client.templates.create({
  business_id: "1234567890",
  name: "my_special_template",
  category: "MARKETING",
  components: [
    {
      type: "HEADER",
      format: "TEXT",
      text: "Special Offer"
    },
    {
      type: "BODY",
      text: "Hi {{1}}, we have a special offer for you: {{2}}% off your next purchase!"
    },
    {
      type: "FOOTER",
      text: "Tap the button below to shop now"
    }
  ],
  language: "en_US"
});

Media Management

Upload and retrieve media for your messages:

// Upload media
const mediaUpload = await client.media.upload({
  file: fs.createReadStream("./path/to/image.jpg"),
  type: "image/jpeg"
});

// Get media URL
const media = await client.media.get({
  media_id: mediaUpload.id
});

Business Profile

Update your WhatsApp Business profile information:

const profile = await client.businessProfile.update({
  phone_number_id: "1234567890",
  about: "We provide the best service!",
  address: "123 Business St, City",
  description: "Premium products and services",
  email: "contact@business.com",
  websites: ["https://www.business.com"]
});

Requirements

  • TypeScript 4.5+
  • Node.js 18 LTS or later

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

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

About

The unofficial Typescript library for Meta Cloud API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 93.6%
  • CSS 5.1%
  • JavaScript 1.2%
  • Handlebars 0.1%