# facebook-batch

> Gracefully batching facebook requests.

Latest version **1.1.0** (published 2021-10-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install facebook-batch
pnpm add facebook-batch
yarn add facebook-batch
bun add facebook-batch
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2021-10-04 |
| First published | 2020-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 2 |
| Unpacked size | 64.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1937 |
| Maintainers | chentsulin |
| Keywords | batch, bottender, facebook, messaging-apis, messenger |

## Links

- npm: https://www.npmjs.com/package/facebook-batch
- Repository: https://github.com/Yoctol/messaging-apis
- Homepage: https://github.com/Yoctol/messaging-apis#readme
- Issues: https://github.com/Yoctol/messaging-apis/issues
- npm.io page: https://npm.io/package/facebook-batch

## Dependencies (2)

- [type-fest](https://npm.io/package/type-fest.md) ^0.15.1
- [messaging-api-messenger](https://npm.io/package/messaging-api-messenger.md) ^1.1.0

## Recent versions

- 1.1.0 (latest) — 2021-10-04
- 1.0.0-beta.34 (next) — 2020-09-07
- 1.0.6 — 2021-09-02
- 1.0.5 — 2021-04-15
- 1.0.4 — 2021-01-11
- 1.0.2 — 2020-09-21
- 1.0.1 — 2020-09-21
- 1.0.0 — 2020-09-07
- 1.0.0-beta.33 — 2020-07-22
- 1.0.0-beta.32 — 2020-07-01
- 1.0.0-beta.31 — 2020-07-01
- 1.0.0-beta.29 — 2020-06-29
- 1.0.0-beta.28 — 2020-06-23
- 1.0.0-beta.27 — 2020-06-23

## README

# facebook-batch

> Gracefully batching facebook requests.

This module is based on the approach described in [Making Batch Requests](https://developers.facebook.com/docs/graph-api/making-multiple-requests/).

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)

## Installation

```sh
npm i --save facebook-batch
```

or

```sh
yarn add facebook-batch
```

<br />

## Usage

```js
const { MessengerClient, MessengerBatch } = require('messaging-api-messenger');
const { FacebookBatchQueue } = require('facebook-batch');

const queue = new FacebookBatchQueue({
  accessToken: ACCESS_TOKEN,
});

(async () => {
  await queue.push(
    MessengerBatch.sendText('psid', 'hello!');
  );

  await queue.push(
    MessengerBatch.sendMessage('psid', {
      attachment: {
        type: 'image',
        payload: {
          url:
            'https://cdn.free.com.tw/blog/wp-content/uploads/2014/08/Placekitten480-g.jpg',
        },
      },
    })
  );

  const profile = await queue.push(MessengerBatch.getUserProfile('psid'));


  console.log(profile);

  queue.stop();
})();
```

Retry for error: `(#613) Calls to this api have exceeded the rate limit.`.

```js
const { FacebookBatchQueue, isError613 } = require('facebook-batch');

const queue = new FacebookBatchQueue(
  {
    accessToken: ACCESS_TOKEN,
  },
  {
    shouldRetry: isError613,
    retryTimes: 2,
  }
);
```

## Options

### delay

Default: `1000`.

### retryTimes

Default: `0`.

### shouldRetry

Default: `() => true`.

---
_Source: https://npm.io/package/facebook-batch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
