# messenger-batch

> Gracefully batching messenger requests.

Latest version **0.3.1** (published 2019-09-06) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2019-09-06 |
| First published | 2018-02-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 18.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | chentsulin |
| Keywords | batch, bottender, facebook, messaging-apis, messenger |

## Links

- npm: https://www.npmjs.com/package/messenger-batch
- npm.io page: https://npm.io/package/messenger-batch

## Dependencies (1)

- [invariant](https://npm.io/package/invariant.md) ^2.2.4

## Recent versions

- 0.3.1 (latest) — 2019-09-06
- 0.3.0 — 2018-04-28
- 0.2.1 — 2018-02-21
- 0.2.0 — 2018-02-20
- 0.1.2 — 2018-02-19
- 0.1.1 — 2018-02-18
- 0.1.0 — 2018-02-18
- 0.0.3 — 2018-02-18
- 0.0.2 — 2018-02-18

## README

# messenger-batch

[![npm](https://img.shields.io/npm/v/messenger-batch.svg?style=flat-square)](https://www.npmjs.com/package/messenger-batch)
[![Build Status](https://travis-ci.org/Yoctol/messenger-batch.svg?branch=master)](https://travis-ci.org/Yoctol/messenger-batch)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

> Gracefully batching messenger requests.

## Installation

```sh
npm install messenger-batch
```

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

## Usage

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

const client = MessengerClient.connect({
  accessToken: ACCESS_TOKEN,
});

const queue = new MessengerBatchQueue(client);

(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);
})();
```

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

```js
const { MessengerBatchQueue, isError613 } = require('messenger-batch');

const queue = new MessengerBatchQueue(client, {
  shouldRetry: isError613,
  retryTimes: 2,
});
```

## Options

### delay

Default: `1000`.

### retryTimes

Default: `0`.

### shouldRetry

Default: `() => true`.

## License

MIT © [Yoctol](https://github.com/Yoctol/messenger-batch)

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