<commit_before># api-ai-botkit-facebook

[![npm](https://img.shields.io/npm/v/api-ai-botkit-facebook.svg)](https://www.npmjs.com/package/api-ai-botkit-facebook)

Utility lib for creating Facebook Messenger bots with Botkit and api.ai. Based off of the api-ai-botkit.

For usage sample code see `examples/sample_bot.js`

## Steps for using lib

Install library from npm
```sh
npm install --save api-ai-botkit-facebook
```

Import Library
```js
const apiaibotkit = require('api-ai-botkit-facebook');
```

Create `apiai` object using token from http://api.ai website

```js
const apiai = apiaibotkit(apiaiToken);
```

or to use sticky sessionIds, which generate the api.ai session id from the message channel, so sessions will stick even after a server restart

```js
const apiai = apiaibotkit({ token: apiaiToken, useStickySessions: true });
```

Use `apiai` object in `controller.hears`
```js
controller.hears('.*', 'message_received', function (bot, message) {
    apiai.process(message, bot);
});
```

Implement different reactions to appropriate actions
```js
apiai
  .action('greetings', function (message, resp, bot) {
    var responseText = resp.result.fulfillment.speech;
    bot.reply(message, responseText);
  })
  .action('input.unknown', function (message, resp, bot) {
    bot.reply(message, "Sorry, I don't understand");
  })
  .action(null, function(message, resp, bot) {
    // handle all actions no not specified with
    // other actions (e.g., greetings and input.unknown)
    var responseText = resp.result.fulfillment.speech;
    bot.reply(message, responseText);
  })<commit_msg>13 - update documentation<commit_after># api-ai-botkit-facebook

[![npm](https://img.shields.io/npm/v/api-ai-botkit-facebook.svg)](https://www.npmjs.com/package/api-ai-botkit-facebook)

Utility lib for creating Facebook Messenger bots with Botkit and api.ai. Based off of the api-ai-botkit.

For usage sample code see `examples/sample_bot.js`

## Steps for using lib

Install library from npm
```sh
npm install --save api-ai-botkit-facebook
```

Import Library
```js
const apiaibotkit = require('api-ai-botkit-facebook');
```

Create `apiai` object using token from http://api.ai website

```js
const apiai = apiaibotkit({ token: 'some-<PASSWORD>' });
```

or to use sticky sessionIds, which generate the api.ai session id from the message channel, so sessions will stick even after a server restart

```js
const apiai = apiaibotkit({ token: 'some-<PASSWORD>-token', useStickySessions: true });
```

Use `apiai` object in `controller.hears`
```js
controller.hears('.*', 'message_received', function (bot, message) {
    apiai.process(message, bot);
});
```

Implement different reactions to appropriate actions
```js
apiai
  .action('greetings', function (message, resp, bot) {
    var responseText = resp.result.fulfillment.speech;
    bot.reply(message, responseText);
  })
  .action('input.unknown', function (message, resp, bot) {
    bot.reply(message, "Sorry, I don't understand");
  })
  .action(null, function(message, resp, bot) {
    // handle all actions no not specified with
    // other actions (e.g., greetings and input.unknown)
    var responseText = resp.result.fulfillment.speech;
    bot.reply(message, responseText);
  })
{'fraction_non_alphanumeric': 0.13977167540882443, 'fraction_numerical': 0.000617093489663684, 'mean_word_length': 4.412353923205342, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1128747', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1022, 'n_words': 306}