https://github.com/apimatic/whatsapp-typescript-sdk
https://github.com/apimatic/whatsapp-typescript-sdk
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/apimatic/whatsapp-typescript-sdk
- Owner: apimatic
- License: other
- Created: 2022-06-17T08:50:51.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-17T08:52:49.000Z (about 4 years ago)
- Last Synced: 2025-02-10T14:53:16.478Z (over 1 year ago)
- Language: TypeScript
- Size: 65.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Getting Started with WhatsApp Cloud API
## Introduction
Welcome to the WhatsApp API from Meta.
Individual developers and existing Business Service Providers (BSPs) can now send and receive messages via the WhatsApp API using a cloud-hosted version of the WhatsApp Business API. Compared to the previous solutions, the cloud-based WhatsApp API is simpler to use and is a more cost-effective way for businesses to use WhatsApp. Please keep in mind the following configurations:
| Name | Description |
| --- | --- |
| Version | Latest [Graph API version](https://developers.facebook.com/docs/graph-api/). For example: v13.0 |
| User-Access-Token | Your user access token after signing up at [developers.facebook.com](https://developers.facebook.com). |
| WABA-ID | Your WhatsApp Business Account (WABA) ID. |
| Phone-Number-ID | ID for the phone number connected to the WhatsApp Business API. You can get this with a [Get Phone Number ID request](3184f675-d289-46f1-88e5-e2b11549c418). |
| Business-ID | Your Business' ID. Once you have your Phone-Number-ID, make a [Get Business Profile request](#99fd3743-46cf-46c4-95b5-431c6a4eb0b0) to get your Business' ID. |
| Recipient-Phone-Number | Phone number that you want to send a WhatsApp message to. |
| Media-ID | ID for the media to [send a media message](#0a632754-3788-43bf-b785-ac6a73423d5a) or [media template message](#439c926a-8a6c-4972-ab2c-d99297716da9) to your customers. |
| Media-URL | URL for the media to [download media content](#cbe5ece3-246c-48f3-b338-074187dfef66). |
## Building
### Requirements
The SDK relies on **Node.js** and **npm** (to resolve dependencies). You can download and install Node.js and [npm](https://www.npmjs.com/) from [the official Node.js website](https://nodejs.org/en/download/).
> **NOTE:** npm is installed by default when Node.js is installed.
### Verify Successful Installation
Run the following commands in the command prompt or shell of your choice to check if Node.js and npm are successfully installed:
* Node.js: `node --version`
* npm: `npm --version`

### Install Dependencies
- To resolve all dependencies, go to the **SDK root directory** and run the following command with npm:
```bash
npm install
```
- This will install all dependencies in the **node_modules** folder.

## Installation
The following section explains how to use the generated library in a new project.
### 1. Initialize the Node Project
- Open an IDE/text editor for JavaScript like Visual Studio Code. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
- Click on **File** and select **Open Folder**. Select an empty folder of your project, the folder will become visible in the sidebar on the left.

- To initialize the Node project, click on **Terminal** and select **New Terminal**. Execute the following command in the terminal:
```bash
npm init --y
```

### 2. Add Dependencies to the Client Library
- The created project manages its dependencies using its `package.json` file. In order to add a dependency on the *WhatsApp Cloud APILib* client library, double click on the `package.json` file in the bar on the left and add the dependency to the package in it.

- To install the package in the project, run the following command in the terminal:
```bash
npm install
```

## Initialize the API Client
**_Note:_** Documentation for the client can be found [here.](doc/client.md)
The following parameters are configurable for the API Client:
| Parameter | Type | Description |
| --- | --- | --- |
| `version` | `string` | *Default*: `'v13.0'` |
| `environment` | Environment | The API environment.
**Default: `Environment.Production`** |
| `timeout` | `number` | Timeout for API calls.
*Default*: `0` |
| `httpClientOptions` | `Partial` | Stable configurable http client options. |
| `unstableHttpClientOptions` | `any` | Unstable configurable http client options. |
| `accessToken` | `string` | The OAuth 2.0 Access Token to use for API requests. |
### HttpClientOptions
| Parameter | Type | Description |
| --- | --- | --- |
| `timeout` | `number` | Timeout in milliseconds. |
| `httpAgent` | `any` | Custom http agent to be used when performing http requests. |
| `httpsAgent` | `any` | Custom https agent to be used when performing http requests. |
| `retryConfig` | `Partial` | Configurations to retry requests. |
### RetryConfiguration
| Parameter | Type | Description |
| --- | --- | --- |
| `maxNumberOfRetries` | `number` | Maximum number of retries.
*Default*: `0` |
| `retryOnTimeout` | `boolean` | Whether to retry on request timeout.
*Default*: `true` |
| `retryInterval` | `number` | Interval before next retry. Used in calculation of wait time for next request in case of failure.
*Default*: `1` |
| `maximumRetryWaitTime` | `number` | Overall wait time for the requests getting retried.
*Default*: `0` |
| `backoffFactor` | `number` | Used in calculation of wait time for next request in case of failure.
*Default*: `2` |
| `httpStatusCodesToRetry` | `number[]` | Http status codes to retry against.
*Default*: `[408, 413, 429, 500, 502, 503, 504, 521, 522, 524]` |
| `httpMethodsToRetry` | `HttpMethod[]` | Http methods to retry against.
*Default*: `['GET', 'PUT']` |
The API client can be initialized as follows:
```ts
const client = new Client({
timeout: 0,
environment: Environment.Production,
accessToken: 'AccessToken',
})
```
## Authorization
This API uses `OAuth 2 Bearer token`.
## List of APIs
* [Business Profiles](doc/controllers/business-profiles.md)
* [Phone Numbers](doc/controllers/phone-numbers.md)
* [Two-Step Verification](doc/controllers/two-step-verification.md)
* [Messages](doc/controllers/messages.md)
* [Registration](doc/controllers/registration.md)
* [Media](doc/controllers/media.md)
## Classes Documentation
* [ApiResponse](doc/api-response.md)
* [ApiError](doc/api-error.md)