# botmaster-fulfill

> Declarative markup API and engine to integrate internal or external APIs with botmaster

Latest version **5.0.0** (published 2018-06-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install botmaster-fulfill
pnpm add botmaster-fulfill
yarn add botmaster-fulfill
bun add botmaster-fulfill
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2018-06-22 |
| First published | 2016-12-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=9.0 |
| Dependencies | 5 |
| Unpacked size | 311.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Jonathan R Wickens |
| Maintainers | jwickens |
| Keywords | apis, framework, pipeline, bot, chatbot, chat, toolkit |

## Links

- npm: https://www.npmjs.com/package/botmaster-fulfill
- Repository: https://github.com/botmasterai/botmaster-fulfill
- Homepage: https://github.com/botmasterai/botmaster-fulfill#readme
- Issues: https://github.com/botmasterai/botmaster-fulfill/issues
- npm.io page: https://npm.io/package/botmaster-fulfill

## Dependencies (5)

- [async](https://npm.io/package/async.md) ^2.0.1
- [debug](https://npm.io/package/debug.md) ^2.5.2
- [ramda](https://npm.io/package/ramda.md) ^0.22.1
- [posthtml-parser](https://npm.io/package/posthtml-parser.md) ^0.2.0
- [posthtml-render](https://npm.io/package/posthtml-render.md) ^1.0.6

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@atlaskit/theme](https://npm.io/package/@atlaskit/theme.md) — 402.0K weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads

## Recent versions

- 5.0.0 (latest) — 2018-06-22
- 3.0.0 (alpha) — 2017-02-23
- 2.0.0 (next) — 2017-01-26
- 4.0.0 — 2017-05-15
- 3.2.0 — 2017-03-06
- 3.1.3 — 2017-03-04
- 3.1.2 — 2017-03-02
- 3.1.1 — 2017-03-02
- 3.1.0 — 2017-03-01
- 2.1.5 — 2017-02-23
- 2.1.4 — 2017-02-12
- 2.1.3 — 2017-02-07
- 2.1.2 — 2017-02-07
- 2.1.1 — 2017-02-07
- 2.1.0 — 2017-02-07
- … 18 more at https://npm.io/package/botmaster-fulfill/versions

## README

[![Build Status](https://travis-ci.org/botmasterai/botmaster-fulfill.svg?branch=master)](https://travis-ci.org/botmasterai/botmaster-fulfill)
[![Coverage Status](https://coveralls.io/repos/github/botmasterai/botmaster-fulfill-actions/badge.svg?branch=master)](https://coveralls.io/github/botmasterai/botmaster-fulfill-actions?branch=master)

# Botmaster fulfill

Battle-tested middleware for botmaster <https://botmasterai.github.io/>).

Now updated to handle malformed tags! This is a breaking change since it requires negative look-behind in nodejs, so only nodejs > 9 is supported. You can get it at 

Enable chatbots to perform actions on Node.js.

Developers write "action specs" that specify how an XML tag should be replaced in a chatbot response, such as confirming that the action was performed simply returning an empty string so that the tag is removed.

Chatbot designers then place the XML tags in their flows for easy integration.

<!--
Find the full documentation at the main botmaster website: <http://botmasterai.com/middlewares/fulfill/>
-->

Also check out our pre-made actions:

| Actions         | Repository                                                                            |
| --------------- | ------------------------------------------------------------------------------------- |
| pause, greet    | [botmaster-fulfill-actions](https://github.com/botmasterai/botmaster-fulfill-actions) |
| button, buttons | [botmaster-button](https://github.com/botmasterai/botmaster-button)                   |

## Quick start

```js
// 1. Import botmaster and setup your bots, for example telegram
const Botmaster = require('botmaster');
const Telegram = require('botmaster-telegram');
const telegramSettings = require('./my-telegram-bots-settings');
const botmaster = new Botmaster();
const telegramBot = new TelegramBot(telegramSettings);
botmaster.addBot(TelegramBot);

// 2. set up any incoming middleware that you might need

// 3. at the end set up fulfill outgoing ware...
const {fulfillOutgoingWare} = require('botmaster-fulfill');
const actions = {
        hi: {
            controller: () => 'hi there!'
        },
        bye: {
            controller: () => 'bye please come again'
        }
}
botmaster.use(fulfillOutgoingWare({actions}));

// Profit. Any messages that telegram bot sends will be processed by fulfill
telegramBot.sendTextMessageTo('<hi />', 1234);
telegramBot.sendTextMessageTo('<bye />', 1234);
```

## API Reference

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### isPendingActions

Test for remaining actions in a string

**Parameters**

-   `string` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** input string to test for actions
-   `actions` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** actions to test for

Returns **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether any actions were found

### fulfill

Fulfill any actions found in the input text

**Parameters**

-   `actions` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** actions to run
-   `context` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an object of aditional properties to expost though `params`
-   `input` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the string to look for actions in
-   `tree` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)?** provided as a way to speed up recursion. You probably don't need to use this and providing it without fulfillPromise (or vice versa) will cause an error.
-   `fulfillPromise` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)?** Used to let controllers know that fulfill has completed (or hit an error) even though this is a recursed function. You probably don't need to use this.
-   `cb` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** error first callback

### defaultInput

Default function to extraxt input for fulfill from botmaster context. Uses simply message.message.text. If it does not exist then fulfill does not run.

**Parameters**

-   `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** context object consisting of botmaster objects and next
    -   `$0.message` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the botmaster message

### defaultResponse

Default function to update botmaster middleware context with fulfill response and call next. It only sets message.message.text if the response is a non empty string after trimming. Otherwise it calls next with "cancels" which cancels  the outgoing message.

**Parameters**

-   `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** context object consisting of botmaster objects, fulfill response, and next
    -   `$0.message` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** botmaster message
    -   `$0.response` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** respopnse from fulfill
    -   `$0.next` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** next function from botmaster outgoing middleware

### FulfillWare

Generate outgoing middleware for fulfill

**Parameters**

-   `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** options
    -   `options.actions` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the actions to use
    -   `options.inputTransformer` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)?** a function that receives {bot, message, update} and returns the fulfill input or a falsy value to skip running fulfill.
    -   `options.reponseTransformer` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)?** a function that receives ({bot, message, update, response, next}) updates the message and calls next.
    -   `options.params` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** an object of additional names to provide in params.

Returns **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** outgoing middleware

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