Core
NodeJS Core

Install

1
npm i botbye-node-core
or
1
yarn add botbye-node-core

Configuration

1. Import init from botbye-node-core module:

1
import { init } from "botbye-node-core";

2. Call init with your project server-key (available inside your Project):

1
2
3
4
init({
  // Use your project server-key
  serverKey: "00000000-0000-0000-0000-000000000000"
});

Usage

Use validateRequest on handlers where you need bot protection.

To validateRequest pass token, headrest and requestInfo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { validateRequest } from "botbye-node-core";

/**
 * All request headers
 **/
const headers = {
  'host': 'example.com',
  'some-header': 'value1, value2'
};

/**
 *  Information about the request
 **/
const requestInfo = {
  'request_uri': "/path",
  'request_method': "GET",
  'remote_addr': request.connection.remoteAddress, // User IP
}

/**
 * Additional custom fields for linking request
 **/
const customFields = {
  someKey: "some-value"
}

const options = {
  token, // BotBye token from client-side
  headers,
  requestInfo,
  customFields
}

/**
 * @param {Object} options - Options for request validation
 * @return {Promise} - botByeResponse promise
 */
const botByeResponse = await validateRequest(options);

Examples of BotBye API responses

Bot detected:

1
2
3
4
5
6
7
{
  "reqId": "f77b2abd-c5d7-44f0-be4f-174b04876583",
  "result": {
    "isAllowed": false
  },
  "error": "Automation tool used"
}

Bot not detected:

1
2
3
4
5
6
7
{
  "reqId": "f77b2abd-c5d7-44f0-be4f-174b04876583",
  "result": {
    "isAllowed": true
  },
  "error": null
}

Request banned by custom rule:

1
2
3
4
5
6
7
8
9
{
  "reqId": "f77b2abd-c5d7-44f0-be4f-174b04876583",
  "result": {
    "isAllowed": false
  },
  "error": {
    "message": "Banned by rule: MY_CUSTOM_RULE"
  }
}

Invalid server-key:

1
2
3
4
5
6
7
{
  "reqId": "f77b2abd-c5d7-44f0-be4f-174b04876583",
  "result": null,
  "error": {
    "message": "[BotBye] Bad Request: Invalid Server Key"
  }
}