Http
NodeJS HTTP
Install
1
npm i botbye-node-http
or
1
yarn add botbye-node-http
Configuration
1. Import init from botbye-node-http module:
1
import { init } from "botbye-node-http";
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:
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
import { validateRequest } from "botbye-node-http";
http.createServer(async (req, res) => {
// Get token from header or any place you store it.
// For example in "x-botbye-token" header
const botbyeToken = req.headers["x-botbye-token"]
// Additional custom fields for linking request
const customFields = {
someKey: "some-value"
}
const options = {
token: botbyeToken,
request: req,
customFields
}
/**
* @param {Object} options - Options for request validation
* @return {Promise} - botByeResponse promise
*/
const botByeResponse = await botbye.validateRequest(options);
if (botByeResult.result?.isBot) {
...
}
...
})
Examples of BotBye API responses
Blocked (bot detected):
1
2
3
4
5
6
7
8
{
"request_id": "f77b2abd-c5d7-44f0-be4f-174b04876583",
"decision": "BLOCK",
"risk_score": 0.95,
"scores": { "bot": 0.95 },
"signals": ["AutomationTool"],
"config": { "bypass_bot_validation": false }
}
Allowed:
1
2
3
4
5
6
7
8
{
"request_id": "f77b2abd-c5d7-44f0-be4f-174b04876583",
"decision": "ALLOW",
"risk_score": 0.05,
"scores": { "bot": 0.05, "ato": 0.02 },
"signals": [],
"config": { "bypass_bot_validation": false }
}
Challenge:
1
2
3
4
5
6
7
8
9
{
"request_id": "f77b2abd-c5d7-44f0-be4f-174b04876583",
"decision": "CHALLENGE",
"risk_score": 0.65,
"scores": { "bot": 0.65 },
"signals": ["SuspiciousFingerprint"],
"challenge": { "type": "captcha", "token": "..." },
"config": { "bypass_bot_validation": false }
}
Invalid server-key:
1
2
3
4
5
{
"decision": "ALLOW",
"config": { "bypass_bot_validation": true },
"error": { "message": "[BotBye] Bad Request: Invalid Server Key" }
}