├── .gitignore ├── .gitattributes ├── docs ├── assets │ ├── images │ │ ├── icons.png │ │ ├── icons@2x.png │ │ ├── widgets.png │ │ └── widgets@2x.png │ └── js │ │ └── search.js ├── modules.html ├── index.html ├── modules │ ├── monitoring.html │ ├── banned.html │ ├── login.html │ └── types.html └── interfaces │ └── types.logincredentials.html ├── index.ts ├── README.md ├── examples ├── credentials.sh ├── python_run.sh ├── login.js ├── credentials.js └── python_login.js ├── .eslintrc.json ├── LICENSE.md ├── package.json ├── src ├── banned.ts ├── monitoring.ts ├── types.ts └── login.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | dist/ -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | docs/* linguist-generated 2 | -------------------------------------------------------------------------------- /docs/assets/images/icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroCB/BotCore/HEAD/docs/assets/images/icons.png -------------------------------------------------------------------------------- /docs/assets/images/icons@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroCB/BotCore/HEAD/docs/assets/images/icons@2x.png -------------------------------------------------------------------------------- /docs/assets/images/widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroCB/BotCore/HEAD/docs/assets/images/widgets.png -------------------------------------------------------------------------------- /docs/assets/images/widgets@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AstroCB/BotCore/HEAD/docs/assets/images/widgets@2x.png -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | // Login API 2 | export * as login from "./src/login"; 3 | 4 | // Monitoring API 5 | export * as monitoring from "./src/monitoring"; 6 | 7 | // Ban API 8 | export * as banned from "./src/banned"; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BotCore 2 | 3 | BotCore is a framework for writing and managing multiple Facebook Messenger bots through a common layer. It supports interfacing with [facebook-chat-api](https://github.com/Schmavery/facebook-chat-api) and [fbchat](https://github.com/carpedm20/fbchat/). 4 | 5 | Check out [the docs](http://cameronbernhardt.com/BotCore/), or dive right in with [examples](/examples)! 6 | 7 | ## Installation 8 | 9 | ``` 10 | npm install --save messenger-botcore 11 | ``` -------------------------------------------------------------------------------- /examples/credentials.sh: -------------------------------------------------------------------------------- 1 | # This is an example script you can run to set up your environment variables to 2 | # be used as a credentials object (see docs) for logging in to BotCore. Change 3 | # the values to your actual information and add these lines to your 4 | # .bashrc/.zshrc or equivalent. 5 | 6 | export MEMCACHIER_USERNAME="1234A" 7 | export MEMCACHIER_PASSWORD="ABCDEFGHIJKLMNOPQRSTUVWXYZ12345" 8 | export MEMCACHIER_SERVERS="mc1.dev.ec2.memcachier.com:00000" 9 | export FACEBOOK_EMAIL="email@example.com" 10 | export FACEBOOK_PASSWORD="example_password" -------------------------------------------------------------------------------- /examples/python_run.sh: -------------------------------------------------------------------------------- 1 | # This is an example script for running Python bots using BotCore 2 | # Login and conversion from facebook-chat-api appstate to fbchat session are 3 | # done in python_login.js, and the Python bot is started up if this succeeds. 4 | 5 | if (node python_login.js) then 6 | # Can remove stored JS appstate if Python conversion successful 7 | rm appstate.json 8 | # Start up the fbchat bot (stored in bot.py) and pass in any provided args 9 | python bot.py $@ 10 | else 11 | echo "Login/conversion from BotCore failed" 12 | exit 1 13 | fi 14 | -------------------------------------------------------------------------------- /examples/login.js: -------------------------------------------------------------------------------- 1 | /* 2 | Simplest way to login and begin listening for messages. Assumes that the 3 | required Memcachier credentials (MEMCACHIER_USERNAME, MEMCACHIER_PASSWORD, 4 | MEMCACHIER_SERVERS) are stored as environment variables. 5 | */ 6 | 7 | const botcore = require("messenger-botcore"); 8 | 9 | botcore.login.login(process.env, (err, api) => { 10 | if (err) { 11 | console.error(err); 12 | } else { 13 | // From here, you have access to the facebook-chat-api api object for 14 | // this login, and you can use all of the available functions from the 15 | // API, including sending and listening for messages. For example... 16 | api.listen(msgReceived); 17 | } 18 | }); 19 | 20 | function msgReceived(msg) { 21 | // Handle message 22 | } -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true, 4 | "es2021": true 5 | }, 6 | "extends": [ 7 | "eslint:recommended", 8 | "plugin:@typescript-eslint/recommended" 9 | ], 10 | "parser": "@typescript-eslint/parser", 11 | "parserOptions": { 12 | "ecmaVersion": 12, 13 | "sourceType": "module" 14 | }, 15 | "plugins": [ 16 | "@typescript-eslint" 17 | ], 18 | "rules": { 19 | "indent": [ 20 | "error", 21 | 4 22 | ], 23 | "linebreak-style": [ 24 | "error", 25 | "unix" 26 | ], 27 | "quotes": [ 28 | "error", 29 | "double" 30 | ], 31 | "semi": [ 32 | "error", 33 | "always" 34 | ] 35 | } 36 | } -------------------------------------------------------------------------------- /examples/credentials.js: -------------------------------------------------------------------------------- 1 | /* 2 | This is an example of a credentials file that can be used to store your 3 | credentials object (see docs), which can be imported as a JavaScript module 4 | at runtime and passed directly to the login function like this: 5 | 6 | ```js 7 | const botcore = require("messenger-botcore"); 8 | const credentials = require("credentials.js"); 9 | 10 | botcore.login.login(credentials, (err, api) => { 11 | // ... 12 | }); 13 | ``` 14 | 15 | REMEMBER TO ADD THIS FILE TO YOUR .GITIGNORE!!! 16 | */ 17 | 18 | exports.MEMCACHIER_USERNAME = "1234A"; 19 | exports.MEMCACHIER_PASSWORD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ12345"; 20 | exports.MEMCACHIER_SERVERS = "mc1.dev.ec2.memcachier.com:00000"; 21 | exports.FACEBOOK_EMAIL = "email@example.com"; 22 | exports.FACEBOOK_PASSWORD = "example_password"; -------------------------------------------------------------------------------- /examples/python_login.js: -------------------------------------------------------------------------------- 1 | /* 2 | This script is an example of how BotCore can be used with Python projects 3 | using the fbchat package. To see how this would be invoked (i.e. how to 4 | start up a Python bot relying on BotCore), see python_run.sh. 5 | */ 6 | 7 | const botcore = require("messenger-botcore"); 8 | const fs = require("fs"); 9 | 10 | // fbchat stores logins in a file called "session.txt" by convention 11 | // FBCHAT_SESSION can be changed to reflect wherever you expect session files 12 | // to be stored in your Python code 13 | const BOTCORE_SESSION = "appstate.json"; 14 | const FBCHAT_SESSION = "session.txt"; 15 | 16 | botcore.login.login(process.env, (err, api) => { 17 | if (!err) { 18 | fs.writeFileSync(BOTCORE_SESSION, JSON.stringify(api.getAppState())); 19 | botcore.login.convertToFile(BOTCORE_SESSION, FBCHAT_SESSION, err => { 20 | process.exit(err ? 1 : 0); 21 | }); 22 | } else { 23 | console.log(err); 24 | process.exit(1); 25 | } 26 | }); 27 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright © 2020 [Cameron Bernhardt](https://cameronbernhardt.com) 5 | 6 | Permission is hereby granted, free of charge, to any person 7 | obtaining a copy of this software and associated documentation 8 | files (the “Software”), to deal in the Software without 9 | restriction, including without limitation the rights to use, 10 | copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following 13 | conditions: 14 | 15 | The above copyright notice and this permission notice shall be 16 | included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "messenger-botcore", 3 | "version": "3.0.5", 4 | "description": "A collection of tools for writing Facebook Messenger bots.", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "scripts": { 8 | "prepublish": "npm run build", 9 | "build": "tsc" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git://github.com/AstroCB/BotCore.git" 14 | }, 15 | "keywords": [ 16 | "bot", 17 | "messenger", 18 | "facebook" 19 | ], 20 | "author": "Cameron Bernhardt (AstroCB)", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/AstroCB/BotCore/issues" 24 | }, 25 | "homepage": "https://github.com/AstroCB/BotCore#readme", 26 | "files": [ 27 | "dist/**/*" 28 | ], 29 | "dependencies": { 30 | "argparse": "^1.0.10", 31 | "facebook-chat-api": "github:AstroCB/facebook-chat-api#lookup-by-mid", 32 | "memjs": "^1.2.2" 33 | }, 34 | "devDependencies": { 35 | "@types/argparse": "^2.0.5", 36 | "@types/facebook-chat-api": "github:AstroCB/typed-facebook-chat-api#update-send-message", 37 | "@types/memjs": "^1.2.2", 38 | "@typescript-eslint/eslint-plugin": "^4.17.0", 39 | "@typescript-eslint/parser": "^4.17.0", 40 | "eslint": "^7.21.0", 41 | "typedoc": "^0.20.32", 42 | "typescript": "^4.2.3" 43 | } 44 | } -------------------------------------------------------------------------------- /src/banned.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Ban API 3 | * 4 | * Provides various utilities for universally banning/unbanning users across 5 | * any number of bot instances 6 | * 7 | * Note: because this API relies on the data store initialized in the login 8 | * module, none of its functions will work unless you've logged in already 9 | * via a call to `login.login`. 10 | * 11 | * @module banned 12 | */ 13 | 14 | import { getMemCache } from "./login"; 15 | import { criticalError } from "./monitoring"; 16 | import { BannedUserList, IsBannedCallback, SuccessCallback, UsersCallback } from "./types"; 17 | 18 | const colName = "banned"; 19 | let cachedUserList: BannedUserList; 20 | 21 | /** 22 | * Provides a list of user IDs representing users who are currently banned. 23 | * 24 | * @param callback 25 | */ 26 | export const getUsers = (callback: UsersCallback): void => { 27 | let usedCache = false; 28 | if (cachedUserList !== undefined) { 29 | usedCache = true; 30 | callback(null, cachedUserList); 31 | } 32 | 33 | const mem = getMemCache(); 34 | mem.get(colName, (err: Error | null, data: Buffer | null) => { 35 | if (err) return callback(new Error("Failed to retrieve memory instance")); 36 | 37 | cachedUserList = data ? JSON.parse(data.toString()) : []; 38 | 39 | if (!usedCache) callback(null, cachedUserList); 40 | }); 41 | }; 42 | 43 | /** 44 | * Tests whether the given user is banned 45 | * @param userId 46 | * @param callback 47 | */ 48 | export const isUser = (userId: string, callback: IsBannedCallback): void => { 49 | getUsers((err, users) => { 50 | if (err) { 51 | // In case of a db error, return that the user is banned to be safe 52 | // Alert maintainer if monitoring is on so that it doesn't just 53 | // look like a silent failure 54 | criticalError(`Failed to determine user ban status: ${err}`); 55 | callback(true); 56 | } 57 | 58 | const isBanned = users ? users.includes(userId) : false; 59 | callback(isBanned, users); 60 | }); 61 | }; 62 | 63 | /** 64 | * Adds the user represented by the provided user ID to the list of banned 65 | * users 66 | * 67 | * @param userId ID of the user to ban 68 | * @param callback 69 | */ 70 | export const addUser = (userId: string, callback: SuccessCallback): void => { 71 | const mem = getMemCache(); 72 | 73 | isUser(userId, (isBanned, users) => { 74 | if (!isBanned && users) { 75 | users.push(userId); 76 | mem.set(colName, JSON.stringify(users), {}); 77 | cachedUserList = users; 78 | } 79 | callback(!isBanned); 80 | }); 81 | }; 82 | 83 | /** 84 | * Removes the user represented by the provided user ID to the list of banned 85 | * users 86 | * 87 | * @param userId ID of the user to ban 88 | * @param callback 89 | */ 90 | export const removeUser = (userId: string, callback: SuccessCallback): void => { 91 | const mem = getMemCache(); 92 | 93 | isUser(userId, (isBanned, users) => { 94 | if (isBanned && users) { 95 | users = users.filter(id => id != userId); 96 | mem.set(colName, JSON.stringify(users), {}); 97 | cachedUserList = users; 98 | } 99 | callback(isBanned); 100 | }); 101 | }; 102 | 103 | /** 104 | * Utility function to quickly check whether to accept a message based on 105 | * whether its sender is banned 106 | * 107 | * @param msg 108 | * @param callback 109 | */ 110 | export const isMessage = (msg: Facebook.IReceivedMessage, callback: IsBannedCallback): void => { 111 | isUser(msg.senderID, callback); 112 | }; -------------------------------------------------------------------------------- /src/monitoring.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Monitoring API 3 | * 4 | * Provides a basic utility for monitoring a running bot process. It is 5 | * configurable, with options to notify a maintainer if the bot goes down, 6 | * automatically retry logins for stale processes, and restart the bot process 7 | * entirely if all else fails. 8 | * 9 | * @module monitoring 10 | */ 11 | 12 | import { spawn } from "child_process"; 13 | import { login } from "./login"; 14 | import { LoginCredentials } from "./types"; 15 | 16 | // Required monitoring config vars 17 | let monitoringInterval: NodeJS.Timeout; 18 | let api: Facebook.API; 19 | let maintainer: string; 20 | let name: string; 21 | let credentials: LoginCredentials; 22 | let botProcess: NodeJS.Process; 23 | let retryFunc: (api: Facebook.API) => void; 24 | 25 | /** 26 | * Begins monitoring a specified API instance. 27 | * 28 | * @param apiInstance An instance of the facebook-chat-api to monitor 29 | * @param maintainerId User ID of the maintainer to notify on failures 30 | * @param botName Name of the bot running 31 | * @param credentialsObj Object containing the user credentials 32 | * @param botProcessRef Node.js process to monitor (optional) 33 | * @param retryLoginCallback A callback to send a new API 34 | * instance to if login failed and a re-attempted login succeeded (optional – 35 | * omitting this callback is equivalent to disabling the retry login feature) 36 | * @param [pingIntervalInMinutes=10] The number of minutes between 37 | * checks that the bot is still running 38 | */ 39 | export const monitor = ( 40 | apiInstance: Facebook.API, 41 | maintainerId: string, 42 | botName: string, 43 | credentialsObj: LoginCredentials, 44 | botProcessRef: NodeJS.Process, 45 | retryLoginCallback: (api: Facebook.API) => void, 46 | pingIntervalInMinutes = 10, 47 | ): void => { 48 | if (monitoringInterval) return console.error("Already monitoring an instance"); 49 | 50 | const pingInterval = pingIntervalInMinutes * 60 * 1000; 51 | monitoringInterval = setInterval(monitorLoop, pingInterval); 52 | api = apiInstance; 53 | maintainer = maintainerId; 54 | name = botName; 55 | credentials = credentialsObj; 56 | botProcess = botProcessRef; 57 | retryFunc = retryLoginCallback; 58 | }; 59 | 60 | /** 61 | * Cancels the monitoring of the current bot process. 62 | */ 63 | export const cancelMonitoring = (): void => { 64 | if (monitoringInterval) { 65 | clearInterval(monitoringInterval); 66 | } 67 | }; 68 | 69 | /** 70 | * Safe function to call from other packages that will alert the maintainer if 71 | * monitoring is on, and no-op otherwise. 72 | * 73 | * @param msg Message for the maintainer about the issue 74 | */ 75 | export const criticalError = (msg: string): void => { 76 | if (maintainer) { 77 | api.sendMessage(`Critical error detected: ${msg}`, maintainer); 78 | } 79 | }; 80 | 81 | 82 | function monitorLoop() { 83 | // Try a basic operation to see if login is still valid 84 | try { 85 | api.getFriendsList((err) => { 86 | if (err) { 87 | sendError(err); 88 | } 89 | }); 90 | } catch (e) { 91 | sendError(e); 92 | } 93 | } 94 | 95 | const sendError = (e: Facebook.IError): void => { 96 | const errMsg = `Error detected with ${name}: ${JSON.stringify(e)}.`; 97 | // Attempt to re-login 98 | if (retryFunc) { 99 | login(credentials, (err, api) => { 100 | if (!err) { 101 | retryFunc(api); 102 | api.sendMessage(`${errMsg} Re-login successful; passing new login to retry callback...`, maintainer); 103 | } else { 104 | // Login failed; just restart the process 105 | restartProcess(); 106 | } 107 | }); 108 | } else { 109 | // Attempt to send message to maintainer, although it will likely fail 110 | api.sendMessage(errMsg, maintainer); 111 | restartProcess(); 112 | } 113 | }; 114 | 115 | const restartProcess = (): void => { 116 | spawn(botProcess.argv[1], botProcess.argv.slice(2), { 117 | detached: true, 118 | stdio: ["ignore"] 119 | }).unref(); 120 | botProcess.exit(); 121 | }; -------------------------------------------------------------------------------- /docs/modules.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | messenger-botcore 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 | 28 |
29 |
30 | Options 31 |
32 |
33 | All 34 |
    35 |
  • Public
  • 36 |
  • Public/Protected
  • 37 |
  • All
  • 38 |
39 |
40 | 41 | 42 | 43 | 44 |
45 |
46 | Menu 47 |
48 |
49 |
50 |
51 |
52 |
53 |

messenger-botcore

54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |

Index

62 |
63 |
64 |
65 |

Modules

66 | 72 |
73 |
74 |
75 |
76 |
77 | 102 |
103 |
104 | 118 |
119 |

Generated using TypeDoc

120 |
121 |
122 | 123 | 124 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | messenger-botcore 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 | 28 |
29 |
30 | Options 31 |
32 |
33 | All 34 |
    35 |
  • Public
  • 36 |
  • Public/Protected
  • 37 |
  • All
  • 38 |
39 |
40 | 41 | 42 | 43 | 44 |
45 |
46 | Menu 47 |
48 |
49 |
50 |
51 |
52 |
53 |

messenger-botcore

54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | 62 |

BotCore

63 |
64 |

BotCore is a framework for writing and managing multiple Facebook Messenger bots through a common layer. It supports interfacing with facebook-chat-api and fbchat.

65 |

Check out the docs, or dive right in with examples!

66 | 67 |

Installation

68 |
69 |
npm install --save messenger-botcore
 70 | 
71 |
72 |
73 | 98 |
99 |
100 | 114 |
115 |

Generated using TypeDoc

116 |
117 |
118 | 119 | 120 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Logging into BotCore 3 | * 4 | * The `LoginCredentials` object is required for logging in to any application using BotCore. The 5 | * idea of it is to store your (sensitive) credentials separately from the source of your project, in a 6 | * place that won't be accidentally committed to a repo and published for the world to see. It consists 7 | * of several required keys that allow BotCore to log in to both Facebook and the MemCachier service 8 | * (used to cache logins) on your behalf. The keys are listed and explained below. 9 | * 10 | * > **NOTE**: to obtain the values for the `MEMCACHIER_` variables, you must [sign up for a free 11 | * MemCachier account](https://www.memcachier.com/users/signup) and create a cache. From there, you 12 | * will be able to retrieve the requisite info from your dashboard. 13 | * 14 | * I recommend the following two methods for storing your credentials object due to their ease of use: 15 | * 16 | * 1. *Environment variables*: you can store these keys as environment variables, which will prevent 17 | * them from being stored in any file in your project. When logging in, simply pass `process.env` as your 18 | * credentials object, because it will contain all of the required keys needed to log in successfully! 19 | * You can find an example of how to configure your credentials this way in `examples/credentials.sh` 20 | * in the BotCore repo. 21 | * 22 | * 2. *A gitignored credentials file*: you can create a file (`credentials.js` or similar) that contains 23 | * all of your required credentials keys as exported variables, and then simply import this as a JS 24 | * module wherever you need to log in. Don't forget to add this credentials file to your `.gitignore` 25 | * so that your credentials aren't exposed! You can find an example of how to configure your credentials 26 | * this way in `examples/credentials.js` in the BotCore repo. 27 | * 28 | * These are two of many possible ways you could choose to store this information. Keep in mind that 29 | * regardless of which method you choose, you will have to eventually pass a JavaScript object containing 30 | * the following keys to the {@link login} function, so you will need to be able to access this 31 | * information at runtime. 32 | * 33 | * Also keep in mind that the `FACEBOOK_EMAIL` and `FACEBOOK_PASSWORD` keys are only required for login 34 | * if you do not have an active Facebook login session stored in BotCore (i.e. you have logged in 35 | * recently, and Facebook hasn't decided to terminate your session yet). BotCore caches your recent 36 | * logins to prevent too many hard (username/password) logins, unless you use the `forceLogin` option. 37 | * If you are using several bots with BotCore, consider storing your `FACEBOOK_EMAIL` and 38 | * `FACEBOOK_PASSWORD` keys with only one of them, and only using your `MEMCACHIER_` variables to log in 39 | * from other bots. 40 | */ 41 | export interface LoginCredentials { 42 | /** 43 | * Facebook account email for login (optional if already logged in once) 44 | */ 45 | FACEBOOK_EMAIL?: string, 46 | /** 47 | * Facebook account password for login (optional if already logged in once) 48 | */ 49 | FACEBOOK_PASSWORD?: string, 50 | /** 51 | * Memcachier servers (from [dashboard](https://www.memcachier.com/caches) 52 | * or Heroku) for storage 53 | */ 54 | MEMCACHIER_SERVERS: string, 55 | /** 56 | * Memcachier username (from [dashboard](https://www.memcachier.com/caches) 57 | * or Heroku) for storage 58 | */ 59 | MEMCACHIER_USERNAME: string, 60 | /** 61 | * Memcachier password (from [dashboard](https://www.memcachier.com/caches) 62 | * or Heroku) for storage 63 | */ 64 | MEMCACHIER_PASSWORD: string, 65 | } 66 | 67 | /** 68 | * A list of users who are currently banned across all BotCore instances 69 | */ 70 | export type BannedUserList = string[]; 71 | 72 | export type StringDict = { [key: string]: string }; 73 | 74 | /** 75 | * @callback UsersCallback 76 | * @param err indicates errors (null if user retrieval is successful) 77 | * @param users list of IDs of users currently banned in the system 78 | */ 79 | export type UsersCallback = (err: Error | null, users?: BannedUserList | null) => void; 80 | 81 | /** 82 | * @callback IsBannedCallback 83 | * @param isBanned true if the user is banned, false otherwise 84 | * @param users list of IDs of users currently banned in the system 85 | */ 86 | export type IsBannedCallback = (isBanned: boolean, users?: string[] | null) => void; 87 | 88 | /** 89 | * @callback SuccessCallback 90 | * @param success true if the operation succeeded (i.e. the user was 91 | * banned or unbanned), false otherwise (if the user was already banned/ 92 | * unbanned to begin with) 93 | */ 94 | export type SuccessCallback = (success: boolean) => void; 95 | 96 | /** 97 | * @callback LoginCallback 98 | * @param err indicates errors (null if login is successful) 99 | * @param api null if login fails, see 100 | * [facebook-chat-api](https://github.com/Schmavery/facebook-chat-api) for details 101 | */ 102 | export type LoginCallback = (err: Facebook.ILoginError, api: Facebook.API) => void; 103 | 104 | /** 105 | * @callback GenericErrCallback 106 | * @param err Message specifying the error (or null if none) 107 | */ 108 | export type GenericErrCallback = (err: Error | null) => void; 109 | 110 | /** 111 | * @callback ErrDataCallback 112 | * @param err Message specifying the error (or null if none) 113 | * @param success Data returned from the successful operation 114 | */ 115 | 116 | export type ErrDataCallback = (err: Error | null, data?: unknown) => void; 117 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | /* Basic Options */ 5 | // "incremental": true, /* Enable incremental compilation */ 6 | "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ 7 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ 8 | // "lib": [], /* Specify library files to be included in the compilation. */ 9 | // "allowJs": true, /* Allow javascript files to be compiled. */ 10 | // "checkJs": true, /* Report errors in .js files. */ 11 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ 12 | "declaration": true, /* Generates corresponding '.d.ts' file. */ 13 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 14 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 15 | // "outFile": "./", /* Concatenate and emit output to single file. */ 16 | "outDir": "./dist", /* Redirect output structure to the directory. */ 17 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 18 | // "composite": true, /* Enable project compilation */ 19 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ 20 | // "removeComments": true, /* Do not emit comments to output. */ 21 | // "noEmit": true, /* Do not emit outputs. */ 22 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 23 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 24 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 25 | /* Strict Type-Checking Options */ 26 | "strict": true, /* Enable all strict type-checking options. */ 27 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 28 | // "strictNullChecks": true, /* Enable strict null checks. */ 29 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 30 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ 31 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 32 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 33 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 34 | /* Additional Checks */ 35 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 36 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 37 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 38 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 39 | // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ 40 | // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ 41 | /* Module Resolution Options */ 42 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 43 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 44 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 45 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 46 | "typeRoots": [ 47 | "./node_modules/@types", 48 | "./src" 49 | ], /* List of folders to include type definitions from. */ 50 | // "types": [], /* Type declaration files to be included in compilation. */ 51 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 52 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 53 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 54 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 55 | /* Source Map Options */ 56 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 57 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 58 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 59 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 60 | /* Experimental Options */ 61 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 62 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 63 | /* Advanced Options */ 64 | "skipLibCheck": true, /* Skip type checking of declaration files. */ 65 | "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ 66 | } 67 | } -------------------------------------------------------------------------------- /src/login.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Login API 3 | * 4 | * Provides various utilities for managing the login process, including 5 | * login/logout and import/export of appstate files. 6 | * 7 | * Encapsulates the login by caching the appstate in memory. 8 | * 9 | * @module login 10 | */ 11 | 12 | import messenger from "facebook-chat-api"; // Chat API 13 | import { writeFileSync, readFile, writeFile } from "fs"; 14 | import { ArgumentParser } from "argparse"; 15 | import { Client } from "memjs"; 16 | import { ErrDataCallback, GenericErrCallback, LoginCallback, LoginCredentials, StringDict } from "./types"; 17 | 18 | // Default behavior: minimal logging and auto-approve recent logins 19 | const defaultOptions: Facebook.IOptions = { 20 | "logLevel": "error", 21 | "forceLogin": true, 22 | // TODO: Get rid of this option. We currently have to use this outdated user agent to force Facebook 23 | // to give us an older version of the login page that doesn't include new checks that break the API. 24 | "userAgent": "Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Mobile Safari/537.36" 25 | }; 26 | 27 | let mem: Client; 28 | 29 | /** 30 | * Call this to initialize the login module and log into Facebook using 31 | * [facebook-chat-api](https://github.com/Schmavery/facebook-chat-api). 32 | * See examples/ for example usage. 33 | * 34 | * @param credentials 35 | * @param callback called after login completed (successfully or unsuccessfully) 36 | * @param [forceCreds=false] if true, forces a login with credentials even if appstate exists 37 | * @param [options=defaultOptions] any options you wish to pass to the API on login; 38 | * by default, sets `logLevel` to `error` and `forceLogin` to `true` (auto-approves errors asking 39 | * for approval of recent logins for simplicity) 40 | */ 41 | export const login = (credentials: LoginCredentials, callback: LoginCallback, forceCreds = false, options = defaultOptions): void => { 42 | // Initialize mem variable for external storage API (Memcachier) 43 | mem = Client.create(credentials.MEMCACHIER_SERVERS, { 44 | username: credentials.MEMCACHIER_USERNAME, 45 | password: credentials.MEMCACHIER_PASSWORD 46 | }); 47 | 48 | // Login utility funcs 49 | function withAppstate(appstate: string, callback: LoginCallback) { 50 | console.log("Logging in with saved appstate..."); 51 | messenger({ 52 | appState: JSON.parse(appstate) 53 | }, options, (err, api) => { 54 | if (err) { 55 | withCreds(callback); 56 | } else { 57 | callback(err, api); 58 | } 59 | }); 60 | } 61 | function withCreds(callback: LoginCallback) { 62 | console.log("Logging in with credentials..."); 63 | if (!credentials.FACEBOOK_EMAIL || !credentials.FACEBOOK_PASSWORD) { 64 | return console.error("Fatal error: no login credentials provided"); 65 | } 66 | 67 | messenger({ 68 | email: credentials.FACEBOOK_EMAIL, 69 | password: credentials.FACEBOOK_PASSWORD 70 | }, options, (err, api) => { 71 | if (err) return console.error("Fatal error: failed login with credentials"); 72 | 73 | mem.set("appstate", JSON.stringify(api.getAppState()), {}, merr => { 74 | if (err) { 75 | return console.error(merr); 76 | } else { 77 | callback(err, api); 78 | } 79 | }); 80 | }); 81 | } 82 | 83 | if (forceCreds) { 84 | // Force login with credentials 85 | withCreds(callback); 86 | } else { 87 | // Use stored appstate if exists, otherwise fallback to creds 88 | mem.get("appstate", (err, val) => { 89 | if (!err && val) { 90 | withAppstate(val.toString(), callback); 91 | } else { 92 | withCreds(callback); 93 | } 94 | }); 95 | } 96 | }; 97 | 98 | /** 99 | * Dumps the current login into a specified file. 100 | * 101 | * @param filename Name of the file specifying where to store the login 102 | * @param callback Callback to use after writing the file 103 | */ 104 | export const dumpLogin = (filename: string, callback: GenericErrCallback): void => { 105 | mem.get("appstate", (err, val) => { 106 | if (!err && val) { 107 | writeFileSync(filename, val.toString()); 108 | } 109 | callback(err); 110 | }); 111 | }; 112 | 113 | /** 114 | * Reads a new login into memory from a file. 115 | * @param filename Name of the file specifying where the imported login 116 | * is stored 117 | * @param callback Callback to use after reading the login 118 | */ 119 | export const loadLogin = (filename: string, callback: GenericErrCallback): void => { 120 | readFile(filename, (err, val) => { 121 | if (!err) { 122 | mem.set("appstate", JSON.stringify(JSON.parse(val.toString())), {}); 123 | } 124 | callback(err); 125 | }); 126 | }; 127 | 128 | /** 129 | * Logs out of Facebook. 130 | * @param callback 131 | */ 132 | export const logout = (callback: ErrDataCallback): void => { 133 | mem.delete("appstate", err => { 134 | let success = true; 135 | if (err) { 136 | console.log(`Error logging out: ${err}`); 137 | success = false; 138 | } else { 139 | console.log("Logged out successfully."); 140 | } 141 | callback(err, success); 142 | }); 143 | }; 144 | 145 | /** 146 | * Converts a (NodeJS) facebook-chat-api appstate into a (Python) fbchat 147 | * session. See the examples/ directory for how this can be used to create 148 | * an fbchat bot with BotCore. 149 | * 150 | * @param filename Name of the file whose location contains the 151 | * appstate data to be converted 152 | * @param callback Callback to use after conversion completed, 153 | * passed the converted session 154 | */ 155 | export const convert = (filename: string, callback: ErrDataCallback): void => { 156 | readFile(filename, (err, file) => { 157 | if (err) { 158 | callback(err); 159 | } else { 160 | // Extract the required information from the appstate 161 | const data = JSON.parse(file.toString()); 162 | const attrs = ["c_user", "datr", "fr", "sb", "spin", "xs"]; 163 | const output = attrs.reduce((obj: StringDict, key) => { 164 | obj[key] = searchAttribute(data, key); 165 | return obj; 166 | }, {}); 167 | output["noscript"] = "1"; // Special attr 168 | 169 | callback(null, output); 170 | } 171 | }); 172 | }; 173 | 174 | /** 175 | * A variant of `convert` that directly outputs the converted session to a file. 176 | * 177 | * @param appstate Location of appstate to be converted 178 | * @param output Where to place the converted session 179 | * @param callback Callback called after conversion 180 | */ 181 | export const convertToFile = (appstate: string, output: string, callback: GenericErrCallback): void => { 182 | convert(appstate, (err, session) => { 183 | if (err) { 184 | callback(err); 185 | } else { 186 | writeFile(output, JSON.stringify(session), null, callback); 187 | } 188 | }); 189 | }; 190 | 191 | /** 192 | * Exposes the underlying memjs memcache instance, which can be used for 193 | * temporary storage. Use wisely, or you may break your BotCore installation! 194 | * 195 | * > NOTE: if you call this before logging in with {@link login}, 196 | * it will return nothing; the memcache is not initialized until you log in. 197 | * 198 | * @returns {Object} The underlying BotCore [memjs](https://memjs.netlify.app) 199 | * instance 200 | */ 201 | export const getMemCache = (): Client => { 202 | return mem; 203 | }; 204 | 205 | /** 206 | * facebook-chat-api appstates are an array of objects containing "key" and 207 | * "value" keys and additional properties (that the Python API doesn't use). 208 | * 209 | * This function searches and extracts the value for the given key, discarding 210 | * the other information. 211 | * 212 | * @param data facebook-chat-api appstate 213 | * @param key The key to locate 214 | * @returns {string} The value of the key (or null if not found) 215 | */ 216 | function searchAttribute(data: Array, key: string): string { 217 | for (let i = 0; i < data.length; i++) { 218 | if (data[i].key == key) { 219 | return data[i].value; 220 | } 221 | } 222 | return ""; 223 | } 224 | 225 | if (require.main === module) { 226 | const parser = new ArgumentParser({ add_help: true }); 227 | parser.add_argument("--MEMCACHIER-USERNAME", { required: true }); 228 | parser.add_argument("--MEMCACHIER-PASSWORD", { required: true }); 229 | parser.add_argument("--MEMCACHIER-SERVERS", { required: true }); 230 | parser.add_argument("--logout", { nargs: 0 }); 231 | parser.add_argument("--dump-login", { nargs: 0 }); 232 | parser.add_argument("--load-login", { nargs: 0 }); 233 | parser.add_argument("--convert-login", { nargs: 0 }); 234 | const args = parser.parse_args(); 235 | 236 | login(args, () => { 237 | if (args.logout !== null) { 238 | logout(() => { 239 | process.exit(); 240 | }); 241 | } else if (args.dump_login !== null) { 242 | dumpLogin("appstate.json", () => { 243 | process.exit(); 244 | }); 245 | } else if (args.load_login !== null) { 246 | loadLogin("appstate.json", () => { 247 | process.exit(); 248 | }); 249 | } else if (args.convert_login !== null) { 250 | convertToFile("appstate.json", "session.txt", () => { 251 | process.exit(); 252 | }); 253 | } else { 254 | process.exit(); 255 | } 256 | }); 257 | } 258 | -------------------------------------------------------------------------------- /docs/assets/js/search.js: -------------------------------------------------------------------------------- 1 | window.searchData = {"kinds":{"1":"Module","64":"Function","256":"Interface","1024":"Property","65536":"Type literal","4194304":"Type alias"},"rows":[{"id":0,"kind":1,"name":"banned","url":"modules/banned.html","classes":"tsd-kind-module"},{"id":1,"kind":64,"name":"getUsers","url":"modules/banned.html#getusers","classes":"tsd-kind-function tsd-parent-kind-module","parent":"banned"},{"id":2,"kind":64,"name":"isUser","url":"modules/banned.html#isuser","classes":"tsd-kind-function tsd-parent-kind-module","parent":"banned"},{"id":3,"kind":64,"name":"addUser","url":"modules/banned.html#adduser","classes":"tsd-kind-function tsd-parent-kind-module","parent":"banned"},{"id":4,"kind":64,"name":"removeUser","url":"modules/banned.html#removeuser","classes":"tsd-kind-function tsd-parent-kind-module","parent":"banned"},{"id":5,"kind":64,"name":"isMessage","url":"modules/banned.html#ismessage","classes":"tsd-kind-function tsd-parent-kind-module","parent":"banned"},{"id":6,"kind":1,"name":"login","url":"modules/login.html","classes":"tsd-kind-module"},{"id":7,"kind":64,"name":"login","url":"modules/login.html#login-1","classes":"tsd-kind-function tsd-parent-kind-module","parent":"login"},{"id":8,"kind":64,"name":"dumpLogin","url":"modules/login.html#dumplogin","classes":"tsd-kind-function tsd-parent-kind-module","parent":"login"},{"id":9,"kind":64,"name":"loadLogin","url":"modules/login.html#loadlogin","classes":"tsd-kind-function tsd-parent-kind-module","parent":"login"},{"id":10,"kind":64,"name":"logout","url":"modules/login.html#logout","classes":"tsd-kind-function tsd-parent-kind-module","parent":"login"},{"id":11,"kind":64,"name":"convert","url":"modules/login.html#convert","classes":"tsd-kind-function tsd-parent-kind-module","parent":"login"},{"id":12,"kind":64,"name":"convertToFile","url":"modules/login.html#converttofile","classes":"tsd-kind-function tsd-parent-kind-module","parent":"login"},{"id":13,"kind":64,"name":"getMemCache","url":"modules/login.html#getmemcache","classes":"tsd-kind-function tsd-parent-kind-module","parent":"login"},{"id":14,"kind":1,"name":"monitoring","url":"modules/monitoring.html","classes":"tsd-kind-module"},{"id":15,"kind":64,"name":"monitor","url":"modules/monitoring.html#monitor","classes":"tsd-kind-function tsd-parent-kind-module","parent":"monitoring"},{"id":16,"kind":64,"name":"cancelMonitoring","url":"modules/monitoring.html#cancelmonitoring","classes":"tsd-kind-function tsd-parent-kind-module","parent":"monitoring"},{"id":17,"kind":64,"name":"criticalError","url":"modules/monitoring.html#criticalerror","classes":"tsd-kind-function tsd-parent-kind-module","parent":"monitoring"},{"id":18,"kind":1,"name":"types","url":"modules/types.html","classes":"tsd-kind-module"},{"id":19,"kind":256,"name":"LoginCredentials","url":"interfaces/types.logincredentials.html","classes":"tsd-kind-interface tsd-parent-kind-module","parent":"types"},{"id":20,"kind":1024,"name":"FACEBOOK_EMAIL","url":"interfaces/types.logincredentials.html#facebook_email","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"types.LoginCredentials"},{"id":21,"kind":1024,"name":"FACEBOOK_PASSWORD","url":"interfaces/types.logincredentials.html#facebook_password","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"types.LoginCredentials"},{"id":22,"kind":1024,"name":"MEMCACHIER_SERVERS","url":"interfaces/types.logincredentials.html#memcachier_servers","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"types.LoginCredentials"},{"id":23,"kind":1024,"name":"MEMCACHIER_USERNAME","url":"interfaces/types.logincredentials.html#memcachier_username","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"types.LoginCredentials"},{"id":24,"kind":1024,"name":"MEMCACHIER_PASSWORD","url":"interfaces/types.logincredentials.html#memcachier_password","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"types.LoginCredentials"},{"id":25,"kind":4194304,"name":"BannedUserList","url":"modules/types.html#banneduserlist","classes":"tsd-kind-type-alias tsd-parent-kind-module","parent":"types"},{"id":26,"kind":4194304,"name":"StringDict","url":"modules/types.html#stringdict","classes":"tsd-kind-type-alias tsd-parent-kind-module","parent":"types"},{"id":27,"kind":65536,"name":"__type","url":"modules/types.html#stringdict.__type-4","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias","parent":"types.StringDict"},{"id":28,"kind":4194304,"name":"UsersCallback","url":"modules/types.html#userscallback","classes":"tsd-kind-type-alias tsd-parent-kind-module","parent":"types"},{"id":29,"kind":65536,"name":"__type","url":"modules/types.html#userscallback.__type-6","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias","parent":"types.UsersCallback"},{"id":30,"kind":4194304,"name":"IsBannedCallback","url":"modules/types.html#isbannedcallback","classes":"tsd-kind-type-alias tsd-parent-kind-module","parent":"types"},{"id":31,"kind":65536,"name":"__type","url":"modules/types.html#isbannedcallback.__type-2","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias","parent":"types.IsBannedCallback"},{"id":32,"kind":4194304,"name":"SuccessCallback","url":"modules/types.html#successcallback","classes":"tsd-kind-type-alias tsd-parent-kind-module","parent":"types"},{"id":33,"kind":65536,"name":"__type","url":"modules/types.html#successcallback.__type-5","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias","parent":"types.SuccessCallback"},{"id":34,"kind":4194304,"name":"LoginCallback","url":"modules/types.html#logincallback","classes":"tsd-kind-type-alias tsd-parent-kind-module","parent":"types"},{"id":35,"kind":65536,"name":"__type","url":"modules/types.html#logincallback.__type-3","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias","parent":"types.LoginCallback"},{"id":36,"kind":4194304,"name":"GenericErrCallback","url":"modules/types.html#genericerrcallback","classes":"tsd-kind-type-alias tsd-parent-kind-module","parent":"types"},{"id":37,"kind":65536,"name":"__type","url":"modules/types.html#genericerrcallback.__type-1","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias","parent":"types.GenericErrCallback"},{"id":38,"kind":4194304,"name":"ErrDataCallback","url":"modules/types.html#errdatacallback","classes":"tsd-kind-type-alias tsd-parent-kind-module","parent":"types"},{"id":39,"kind":65536,"name":"__type","url":"modules/types.html#errdatacallback.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias","parent":"types.ErrDataCallback"}],"index":{"version":"2.3.9","fields":["name","parent"],"fieldVectors":[["name/0",[0,18.418]],["parent/0",[]],["name/1",[1,33.081]],["parent/1",[0,1.762]],["name/2",[2,33.081]],["parent/2",[0,1.762]],["name/3",[3,33.081]],["parent/3",[0,1.762]],["name/4",[4,33.081]],["parent/4",[0,1.762]],["name/5",[5,33.081]],["parent/5",[0,1.762]],["name/6",[6,14.623]],["parent/6",[]],["name/7",[6,14.623]],["parent/7",[6,1.399]],["name/8",[7,33.081]],["parent/8",[6,1.399]],["name/9",[8,33.081]],["parent/9",[6,1.399]],["name/10",[9,33.081]],["parent/10",[6,1.399]],["name/11",[10,33.081]],["parent/11",[6,1.399]],["name/12",[11,33.081]],["parent/12",[6,1.399]],["name/13",[12,33.081]],["parent/13",[6,1.399]],["name/14",[13,22.095]],["parent/14",[]],["name/15",[14,33.081]],["parent/15",[13,2.113]],["name/16",[15,33.081]],["parent/16",[13,2.113]],["name/17",[16,33.081]],["parent/17",[13,2.113]],["name/18",[17,13.622]],["parent/18",[]],["name/19",[18,33.081]],["parent/19",[17,1.303]],["name/20",[19,33.081]],["parent/20",[20,1.921]],["name/21",[21,33.081]],["parent/21",[20,1.921]],["name/22",[22,33.081]],["parent/22",[20,1.921]],["name/23",[23,33.081]],["parent/23",[20,1.921]],["name/24",[24,33.081]],["parent/24",[20,1.921]],["name/25",[25,33.081]],["parent/25",[17,1.303]],["name/26",[26,33.081]],["parent/26",[17,1.303]],["name/27",[27,16.987]],["parent/27",[28,3.164]],["name/28",[29,33.081]],["parent/28",[17,1.303]],["name/29",[27,16.987]],["parent/29",[30,3.164]],["name/30",[31,33.081]],["parent/30",[17,1.303]],["name/31",[27,16.987]],["parent/31",[32,3.164]],["name/32",[33,33.081]],["parent/32",[17,1.303]],["name/33",[27,16.987]],["parent/33",[34,3.164]],["name/34",[35,33.081]],["parent/34",[17,1.303]],["name/35",[27,16.987]],["parent/35",[36,3.164]],["name/36",[37,33.081]],["parent/36",[17,1.303]],["name/37",[27,16.987]],["parent/37",[38,3.164]],["name/38",[39,33.081]],["parent/38",[17,1.303]],["name/39",[27,16.987]],["parent/39",[40,3.164]]],"invertedIndex":[["__type",{"_index":27,"name":{"27":{},"29":{},"31":{},"33":{},"35":{},"37":{},"39":{}},"parent":{}}],["adduser",{"_index":3,"name":{"3":{}},"parent":{}}],["banned",{"_index":0,"name":{"0":{}},"parent":{"1":{},"2":{},"3":{},"4":{},"5":{}}}],["banneduserlist",{"_index":25,"name":{"25":{}},"parent":{}}],["cancelmonitoring",{"_index":15,"name":{"16":{}},"parent":{}}],["convert",{"_index":10,"name":{"11":{}},"parent":{}}],["converttofile",{"_index":11,"name":{"12":{}},"parent":{}}],["criticalerror",{"_index":16,"name":{"17":{}},"parent":{}}],["dumplogin",{"_index":7,"name":{"8":{}},"parent":{}}],["errdatacallback",{"_index":39,"name":{"38":{}},"parent":{}}],["facebook_email",{"_index":19,"name":{"20":{}},"parent":{}}],["facebook_password",{"_index":21,"name":{"21":{}},"parent":{}}],["genericerrcallback",{"_index":37,"name":{"36":{}},"parent":{}}],["getmemcache",{"_index":12,"name":{"13":{}},"parent":{}}],["getusers",{"_index":1,"name":{"1":{}},"parent":{}}],["isbannedcallback",{"_index":31,"name":{"30":{}},"parent":{}}],["ismessage",{"_index":5,"name":{"5":{}},"parent":{}}],["isuser",{"_index":2,"name":{"2":{}},"parent":{}}],["loadlogin",{"_index":8,"name":{"9":{}},"parent":{}}],["login",{"_index":6,"name":{"6":{},"7":{}},"parent":{"7":{},"8":{},"9":{},"10":{},"11":{},"12":{},"13":{}}}],["logincallback",{"_index":35,"name":{"34":{}},"parent":{}}],["logincredentials",{"_index":18,"name":{"19":{}},"parent":{}}],["logout",{"_index":9,"name":{"10":{}},"parent":{}}],["memcachier_password",{"_index":24,"name":{"24":{}},"parent":{}}],["memcachier_servers",{"_index":22,"name":{"22":{}},"parent":{}}],["memcachier_username",{"_index":23,"name":{"23":{}},"parent":{}}],["monitor",{"_index":14,"name":{"15":{}},"parent":{}}],["monitoring",{"_index":13,"name":{"14":{}},"parent":{"15":{},"16":{},"17":{}}}],["removeuser",{"_index":4,"name":{"4":{}},"parent":{}}],["stringdict",{"_index":26,"name":{"26":{}},"parent":{}}],["successcallback",{"_index":33,"name":{"32":{}},"parent":{}}],["types",{"_index":17,"name":{"18":{}},"parent":{"19":{},"25":{},"26":{},"28":{},"30":{},"32":{},"34":{},"36":{},"38":{}}}],["types.errdatacallback",{"_index":40,"name":{},"parent":{"39":{}}}],["types.genericerrcallback",{"_index":38,"name":{},"parent":{"37":{}}}],["types.isbannedcallback",{"_index":32,"name":{},"parent":{"31":{}}}],["types.logincallback",{"_index":36,"name":{},"parent":{"35":{}}}],["types.logincredentials",{"_index":20,"name":{},"parent":{"20":{},"21":{},"22":{},"23":{},"24":{}}}],["types.stringdict",{"_index":28,"name":{},"parent":{"27":{}}}],["types.successcallback",{"_index":34,"name":{},"parent":{"33":{}}}],["types.userscallback",{"_index":30,"name":{},"parent":{"29":{}}}],["userscallback",{"_index":29,"name":{"28":{}},"parent":{}}]],"pipeline":[]}} -------------------------------------------------------------------------------- /docs/modules/monitoring.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | monitoring | messenger-botcore 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 | 28 |
29 |
30 | Options 31 |
32 |
33 | All 34 |
    35 |
  • Public
  • 36 |
  • Public/Protected
  • 37 |
  • All
  • 38 |
39 |
40 | 41 | 42 | 43 | 44 |
45 |
46 | Menu 47 |
48 |
49 |
50 |
51 |
52 |
53 | 61 |

Module monitoring

62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |

Monitoring API

72 |
73 |

Provides a basic utility for monitoring a running bot process. It is 74 | configurable, with options to notify a maintainer if the bot goes down, 75 | automatically retry logins for stale processes, and restart the bot process 76 | entirely if all else fails.

77 |
78 |
79 |
80 |

Index

81 |
82 |
83 |
84 |

Functions

85 | 90 |
91 |
92 |
93 |
94 |
95 |

Functions

96 |
97 | 98 |

Const cancelMonitoring

99 |
    100 |
  • cancelMonitoring(): void
  • 101 |
102 |
    103 |
  • 104 | 109 |
    110 |
    111 |

    Cancels the monitoring of the current bot process.

    112 |
    113 |
    114 |

    Returns void

    115 |
  • 116 |
117 |
118 |
119 | 120 |

Const criticalError

121 |
    122 |
  • criticalError(msg: string): void
  • 123 |
124 |
    125 |
  • 126 | 131 |
    132 |
    133 |

    Safe function to call from other packages that will alert the maintainer if 134 | monitoring is on, and no-op otherwise.

    135 |
    136 |
    137 |

    Parameters

    138 |
      139 |
    • 140 |
      msg: string
      141 |
      142 |

      Message for the maintainer about the issue

      143 |
      144 |
    • 145 |
    146 |

    Returns void

    147 |
  • 148 |
149 |
150 |
151 | 152 |

Const monitor

153 |
    154 |
  • monitor(apiInstance: API, maintainerId: string, botName: string, credentialsObj: LoginCredentials, botProcessRef: Process, retryLoginCallback: (api: API) => void, pingIntervalInMinutes?: number): void
  • 155 |
156 |
    157 |
  • 158 | 163 |
    164 |
    165 |

    Begins monitoring a specified API instance.

    166 |
    167 |
    168 |

    Parameters

    169 |
      170 |
    • 171 |
      apiInstance: API
      172 |
      173 |

      An instance of the facebook-chat-api to monitor

      174 |
      175 |
    • 176 |
    • 177 |
      maintainerId: string
      178 |
      179 |

      User ID of the maintainer to notify on failures

      180 |
      181 |
    • 182 |
    • 183 |
      botName: string
      184 |
      185 |

      Name of the bot running

      186 |
      187 |
    • 188 |
    • 189 |
      credentialsObj: LoginCredentials
      190 |
      191 |

      Object containing the user credentials

      192 |
      193 |
    • 194 |
    • 195 |
      botProcessRef: Process
      196 |
      197 |

      Node.js process to monitor (optional)

      198 |
      199 |
    • 200 |
    • 201 |
      retryLoginCallback: (api: API) => void
      202 |
      203 |

      A callback to send a new API 204 | instance to if login failed and a re-attempted login succeeded (optional – 205 | omitting this callback is equivalent to disabling the retry login feature)

      206 |
      207 |
        208 |
      • 209 |
          210 |
        • (api: API): void
        • 211 |
        212 |
          213 |
        • 214 |

          Parameters

          215 |
            216 |
          • 217 |
            api: API
            218 |
          • 219 |
          220 |

          Returns void

          221 |
        • 222 |
        223 |
      • 224 |
      225 |
    • 226 |
    • 227 |
      pingIntervalInMinutes: number = 10
      228 |
    • 229 |
    230 |

    Returns void

    231 |
  • 232 |
233 |
234 |
235 |
236 | 270 |
271 |
272 | 286 |
287 |

Generated using TypeDoc

288 |
289 |
290 | 291 | 292 | -------------------------------------------------------------------------------- /docs/modules/banned.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | banned | messenger-botcore 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 | 28 |
29 |
30 | Options 31 |
32 |
33 | All 34 |
    35 |
  • Public
  • 36 |
  • Public/Protected
  • 37 |
  • All
  • 38 |
39 |
40 | 41 | 42 | 43 | 44 |
45 |
46 | Menu 47 |
48 |
49 |
50 |
51 |
52 |
53 | 61 |

Module banned

62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |

Ban API

72 |
73 |

Provides various utilities for universally banning/unbanning users across 74 | any number of bot instances

75 |

Note: because this API relies on the data store initialized in the login 76 | module, none of its functions will work unless you've logged in already 77 | via a call to login.login.

78 |
79 |
80 |
81 |

Index

82 |
83 |
84 |
85 |

Functions

86 | 93 |
94 |
95 |
96 |
97 |
98 |

Functions

99 |
100 | 101 |

Const addUser

102 | 105 |
    106 |
  • 107 | 112 |
    113 |
    114 |

    Adds the user represented by the provided user ID to the list of banned 115 | users

    116 |
    117 |
    118 |

    Parameters

    119 |
      120 |
    • 121 |
      userId: string
      122 |
      123 |

      ID of the user to ban

      124 |
      125 |
    • 126 |
    • 127 |
      callback: SuccessCallback
      128 |
      129 |
      130 |
    • 131 |
    132 |

    Returns void

    133 |
  • 134 |
135 |
136 |
137 | 138 |

Const getUsers

139 | 142 |
    143 |
  • 144 | 149 |
    150 |
    151 |

    Provides a list of user IDs representing users who are currently banned.

    152 |
    153 |
    154 |

    Parameters

    155 | 162 |

    Returns void

    163 |
  • 164 |
165 |
166 |
167 | 168 |

Const isMessage

169 |
    170 |
  • isMessage(msg: IReceivedMessage, callback: IsBannedCallback): void
  • 171 |
172 |
    173 |
  • 174 | 179 |
    180 |
    181 |

    Utility function to quickly check whether to accept a message based on 182 | whether its sender is banned

    183 |
    184 |
    185 |

    Parameters

    186 |
      187 |
    • 188 |
      msg: IReceivedMessage
      189 |
    • 190 |
    • 191 |
      callback: IsBannedCallback
      192 |
      193 |
      194 |
    • 195 |
    196 |

    Returns void

    197 |
  • 198 |
199 |
200 |
201 | 202 |

Const isUser

203 | 206 |
    207 |
  • 208 | 213 |
    214 |
    215 |

    Tests whether the given user is banned

    216 |
    217 |
    218 |

    Parameters

    219 |
      220 |
    • 221 |
      userId: string
      222 |
    • 223 |
    • 224 |
      callback: IsBannedCallback
      225 |
      226 |
      227 |
    • 228 |
    229 |

    Returns void

    230 |
  • 231 |
232 |
233 |
234 | 235 |

Const removeUser

236 | 239 |
    240 |
  • 241 | 246 |
    247 |
    248 |

    Removes the user represented by the provided user ID to the list of banned 249 | users

    250 |
    251 |
    252 |

    Parameters

    253 |
      254 |
    • 255 |
      userId: string
      256 |
      257 |

      ID of the user to ban

      258 |
      259 |
    • 260 |
    • 261 |
      callback: SuccessCallback
      262 |
      263 |
      264 |
    • 265 |
    266 |

    Returns void

    267 |
  • 268 |
269 |
270 |
271 |
272 | 312 |
313 |
314 | 328 |
329 |

Generated using TypeDoc

330 |
331 |
332 | 333 | 334 | -------------------------------------------------------------------------------- /docs/interfaces/types.logincredentials.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | LoginCredentials | messenger-botcore 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 | 28 |
29 |
30 | Options 31 |
32 |
33 | All 34 |
    35 |
  • Public
  • 36 |
  • Public/Protected
  • 37 |
  • All
  • 38 |
39 |
40 | 41 | 42 | 43 | 44 |
45 |
46 | Menu 47 |
48 |
49 |
50 |
51 |
52 |
53 | 64 |

Interface LoginCredentials

65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |

Logging into BotCore

75 |
76 |

The LoginCredentials object is required for logging in to any application using BotCore. The 77 | idea of it is to store your (sensitive) credentials separately from the source of your project, in a 78 | place that won't be accidentally committed to a repo and published for the world to see. It consists 79 | of several required keys that allow BotCore to log in to both Facebook and the MemCachier service 80 | (used to cache logins) on your behalf. The keys are listed and explained below.

81 |
82 |

NOTE: to obtain the values for the MEMCACHIER_ variables, you must sign up for a free 83 | MemCachier account and create a cache. From there, you 84 | will be able to retrieve the requisite info from your dashboard.

85 |
86 |

I recommend the following two methods for storing your credentials object due to their ease of use:

87 |
    88 |
  1. Environment variables: you can store these keys as environment variables, which will prevent 89 | them from being stored in any file in your project. When logging in, simply pass process.env as your 90 | credentials object, because it will contain all of the required keys needed to log in successfully! 91 | You can find an example of how to configure your credentials this way in examples/credentials.sh 92 | in the BotCore repo.

    93 |
  2. 94 |
  3. A gitignored credentials file: you can create a file (credentials.js or similar) that contains 95 | all of your required credentials keys as exported variables, and then simply import this as a JS 96 | module wherever you need to log in. Don't forget to add this credentials file to your .gitignore 97 | so that your credentials aren't exposed! You can find an example of how to configure your credentials 98 | this way in examples/credentials.js in the BotCore repo.

    99 |
  4. 100 |
101 |

These are two of many possible ways you could choose to store this information. Keep in mind that 102 | regardless of which method you choose, you will have to eventually pass a JavaScript object containing 103 | the following keys to the login function, so you will need to be able to access this 104 | information at runtime.

105 |

Also keep in mind that the FACEBOOK_EMAIL and FACEBOOK_PASSWORD keys are only required for login 106 | if you do not have an active Facebook login session stored in BotCore (i.e. you have logged in 107 | recently, and Facebook hasn't decided to terminate your session yet). BotCore caches your recent 108 | logins to prevent too many hard (username/password) logins, unless you use the forceLogin option. 109 | If you are using several bots with BotCore, consider storing your FACEBOOK_EMAIL and 110 | FACEBOOK_PASSWORD keys with only one of them, and only using your MEMCACHIER_ variables to log in 111 | from other bots.

112 |
113 |
114 |
115 |

Hierarchy

116 |
    117 |
  • 118 | LoginCredentials 119 |
  • 120 |
121 |
122 |
123 |

Index

124 |
125 |
126 |
127 |

Properties

128 | 135 |
136 |
137 |
138 |
139 |
140 |

Properties

141 |
142 | 143 |

Optional FACEBOOK_EMAIL

144 |
FACEBOOK_EMAIL: string
145 | 150 |
151 |
152 |

Facebook account email for login (optional if already logged in once)

153 |
154 |
155 |
156 |
157 | 158 |

Optional FACEBOOK_PASSWORD

159 |
FACEBOOK_PASSWORD: string
160 | 165 |
166 |
167 |

Facebook account password for login (optional if already logged in once)

168 |
169 |
170 |
171 |
172 | 173 |

MEMCACHIER_PASSWORD

174 |
MEMCACHIER_PASSWORD: string
175 | 180 |
181 |
182 |

Memcachier password (from dashboard 183 | or Heroku) for storage

184 |
185 |
186 |
187 |
188 | 189 |

MEMCACHIER_SERVERS

190 |
MEMCACHIER_SERVERS: string
191 | 196 |
197 |
198 |

Memcachier servers (from dashboard 199 | or Heroku) for storage

200 |
201 |
202 |
203 |
204 | 205 |

MEMCACHIER_USERNAME

206 |
MEMCACHIER_USERNAME: string
207 | 212 |
213 |
214 |

Memcachier username (from dashboard 215 | or Heroku) for storage

216 |
217 |
218 |
219 |
220 |
221 | 294 |
295 |
296 | 311 |
312 |

Generated using TypeDoc

313 |
314 |
315 | 316 | 317 | -------------------------------------------------------------------------------- /docs/modules/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | login | messenger-botcore 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 | 28 |
29 |
30 | Options 31 |
32 |
33 | All 34 |
    35 |
  • Public
  • 36 |
  • Public/Protected
  • 37 |
  • All
  • 38 |
39 |
40 | 41 | 42 | 43 | 44 |
45 |
46 | Menu 47 |
48 |
49 |
50 |
51 |
52 |
53 | 61 |

Module login

62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |

Login API

72 |
73 |

Provides various utilities for managing the login process, including 74 | login/logout and import/export of appstate files.

75 |

Encapsulates the login by caching the appstate in memory.

76 |
77 |
78 |
79 |

Index

80 |
81 |
82 |
83 |

Functions

84 | 93 |
94 |
95 |
96 |
97 |
98 |

Functions

99 |
100 | 101 |

Const convert

102 | 105 |
    106 |
  • 107 | 112 |
    113 |
    114 |

    Converts a (NodeJS) facebook-chat-api appstate into a (Python) fbchat 115 | session. See the examples/ directory for how this can be used to create 116 | an fbchat bot with BotCore.

    117 |
    118 |
    119 |

    Parameters

    120 |
      121 |
    • 122 |
      filename: string
      123 |
      124 |

      Name of the file whose location contains the 125 | appstate data to be converted

      126 |
      127 |
    • 128 |
    • 129 |
      callback: ErrDataCallback
      130 |
      131 |

      Callback to use after conversion completed, 132 | passed the converted session

      133 |
      134 |
    • 135 |
    136 |

    Returns void

    137 |
  • 138 |
139 |
140 |
141 | 142 |

Const convertToFile

143 |
    144 |
  • convertToFile(appstate: string, output: string, callback: GenericErrCallback): void
  • 145 |
146 |
    147 |
  • 148 | 153 |
    154 |
    155 |

    A variant of convert that directly outputs the converted session to a file.

    156 |
    157 |
    158 |

    Parameters

    159 |
      160 |
    • 161 |
      appstate: string
      162 |
      163 |

      Location of appstate to be converted

      164 |
      165 |
    • 166 |
    • 167 |
      output: string
      168 |
      169 |

      Where to place the converted session

      170 |
      171 |
    • 172 |
    • 173 |
      callback: GenericErrCallback
      174 |
      175 |

      Callback called after conversion

      176 |
      177 |
    • 178 |
    179 |

    Returns void

    180 |
  • 181 |
182 |
183 |
184 | 185 |

Const dumpLogin

186 | 189 |
    190 |
  • 191 | 196 |
    197 |
    198 |

    Dumps the current login into a specified file.

    199 |
    200 |
    201 |

    Parameters

    202 |
      203 |
    • 204 |
      filename: string
      205 |
      206 |

      Name of the file specifying where to store the login

      207 |
      208 |
    • 209 |
    • 210 |
      callback: GenericErrCallback
      211 |
      212 |

      Callback to use after writing the file

      213 |
      214 |
    • 215 |
    216 |

    Returns void

    217 |
  • 218 |
219 |
220 |
221 | 222 |

Const getMemCache

223 |
    224 |
  • getMemCache(): Client
  • 225 |
226 |
    227 |
  • 228 | 233 |
    234 |
    235 |

    Exposes the underlying memjs memcache instance, which can be used for 236 | temporary storage. Use wisely, or you may break your BotCore installation!

    237 |
    238 |
    239 |

    NOTE: if you call this before logging in with login, 240 | it will return nothing; the memcache is not initialized until you log in.

    241 |
    242 |
    243 |

    Returns Client

    244 |

    The underlying BotCore memjs 245 | instance

    246 |
  • 247 |
248 |
249 |
250 | 251 |

Const loadLogin

252 | 255 |
    256 |
  • 257 | 262 |
    263 |
    264 |

    Reads a new login into memory from a file.

    265 |
    266 |
    267 |

    Parameters

    268 |
      269 |
    • 270 |
      filename: string
      271 |
      272 |

      Name of the file specifying where the imported login 273 | is stored

      274 |
      275 |
    • 276 |
    • 277 |
      callback: GenericErrCallback
      278 |
      279 |

      Callback to use after reading the login

      280 |
      281 |
    • 282 |
    283 |

    Returns void

    284 |
  • 285 |
286 |
287 |
288 | 289 |

Const login

290 | 293 |
    294 |
  • 295 | 300 |
    301 |
    302 |

    Call this to initialize the login module and log into Facebook using 303 | facebook-chat-api. 304 | See examples/ for example usage.

    305 |
    306 |
    307 |

    Parameters

    308 |
      309 |
    • 310 |
      credentials: LoginCredentials
      311 |
    • 312 |
    • 313 |
      callback: LoginCallback
      314 |
      315 |

      called after login completed (successfully or unsuccessfully)

      316 |
      317 |
    • 318 |
    • 319 |
      forceCreds: boolean = false
      320 |
    • 321 |
    • 322 |
      options: IOptions = ...
      323 |
    • 324 |
    325 |

    Returns void

    326 |
  • 327 |
328 |
329 |
330 | 331 |

Const logout

332 | 335 |
    336 |
  • 337 | 342 |
    343 |
    344 |

    Logs out of Facebook.

    345 |
    346 |
    347 |

    Parameters

    348 | 355 |

    Returns void

    356 |
  • 357 |
358 |
359 |
360 |
361 | 407 |
408 |
409 | 423 |
424 |

Generated using TypeDoc

425 |
426 |
427 | 428 | 429 | -------------------------------------------------------------------------------- /docs/modules/types.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | types | messenger-botcore 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 | 28 |
29 |
30 | Options 31 |
32 |
33 | All 34 |
    35 |
  • Public
  • 36 |
  • Public/Protected
  • 37 |
  • All
  • 38 |
39 |
40 | 41 | 42 | 43 | 44 |
45 |
46 | Menu 47 |
48 |
49 |
50 |
51 |
52 |
53 | 61 |

Module types

62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |

Index

70 |
71 |
72 |
73 |

Interfaces

74 | 77 |
78 |
79 |

Type aliases

80 | 90 |
91 |
92 |
93 |
94 |
95 |

Type aliases

96 |
97 | 98 |

BannedUserList

99 |
BannedUserList: string[]
100 | 105 |
106 |
107 |

A list of users who are currently banned across all BotCore instances

108 |
109 |
110 |
111 |
112 | 113 |

ErrDataCallback

114 |
ErrDataCallback: (err: Error | null, data?: unknown) => void
115 | 120 |
121 |
122 |
param
123 |

Message specifying the error (or null if none)

124 |
125 |
param
126 |

Data returned from the successful operation

127 |
128 |
129 |
130 |
131 |

Type declaration

132 |
    133 |
  • 134 |
      135 |
    • (err: Error | null, data?: unknown): void
    • 136 |
    137 |
      138 |
    • 139 |

      Parameters

      140 |
        141 |
      • 142 |
        err: Error | null
        143 |
      • 144 |
      • 145 |
        Optional data: unknown
        146 |
      • 147 |
      148 |

      Returns void

      149 |
    • 150 |
    151 |
  • 152 |
153 |
154 |
155 |
156 | 157 |

GenericErrCallback

158 |
GenericErrCallback: (err: Error | null) => void
159 | 164 |
165 |
166 |
param
167 |

Message specifying the error (or null if none)

168 |
169 |
170 |
171 |
172 |

Type declaration

173 |
    174 |
  • 175 |
      176 |
    • (err: Error | null): void
    • 177 |
    178 |
      179 |
    • 180 |

      Parameters

      181 |
        182 |
      • 183 |
        err: Error | null
        184 |
      • 185 |
      186 |

      Returns void

      187 |
    • 188 |
    189 |
  • 190 |
191 |
192 |
193 |
194 | 195 |

IsBannedCallback

196 |
IsBannedCallback: (isBanned: boolean, users?: string[] | null) => void
197 | 202 |
203 |
204 |
param
205 |

true if the user is banned, false otherwise

206 |
207 |
param
208 |

list of IDs of users currently banned in the system

209 |
210 |
211 |
212 |
213 |

Type declaration

214 |
    215 |
  • 216 |
      217 |
    • (isBanned: boolean, users?: string[] | null): void
    • 218 |
    219 |
      220 |
    • 221 |

      Parameters

      222 |
        223 |
      • 224 |
        isBanned: boolean
        225 |
      • 226 |
      • 227 |
        Optional users: string[] | null
        228 |
      • 229 |
      230 |

      Returns void

      231 |
    • 232 |
    233 |
  • 234 |
235 |
236 |
237 |
238 | 239 |

LoginCallback

240 |
LoginCallback: (err: Facebook.ILoginError, api: Facebook.API) => void
241 | 246 |
247 |
248 |
param
249 |

indicates errors (null if login is successful)

250 |
251 |
param
252 |

null if login fails, see 253 | facebook-chat-api for details

254 |
255 |
256 |
257 |
258 |

Type declaration

259 |
    260 |
  • 261 |
      262 |
    • (err: Facebook.ILoginError, api: Facebook.API): void
    • 263 |
    264 |
      265 |
    • 266 |

      Parameters

      267 |
        268 |
      • 269 |
        err: Facebook.ILoginError
        270 |
      • 271 |
      • 272 |
        api: Facebook.API
        273 |
      • 274 |
      275 |

      Returns void

      276 |
    • 277 |
    278 |
  • 279 |
280 |
281 |
282 |
283 | 284 |

StringDict

285 |
StringDict: {}
286 | 291 |
292 |

Type declaration

293 |
    294 |
  • 295 |
    [key: string]: string
    296 |
  • 297 |
298 |
299 |
300 |
301 | 302 |

SuccessCallback

303 |
SuccessCallback: (success: boolean) => void
304 | 309 |
310 |
311 |
param
312 |

true if the operation succeeded (i.e. the user was 313 | banned or unbanned), false otherwise (if the user was already banned/ 314 | unbanned to begin with)

315 |
316 |
317 |
318 |
319 |

Type declaration

320 |
    321 |
  • 322 |
      323 |
    • (success: boolean): void
    • 324 |
    325 |
      326 |
    • 327 |

      Parameters

      328 |
        329 |
      • 330 |
        success: boolean
        331 |
      • 332 |
      333 |

      Returns void

      334 |
    • 335 |
    336 |
  • 337 |
338 |
339 |
340 |
341 | 342 |

UsersCallback

343 |
UsersCallback: (err: Error | null, users?: BannedUserList | null) => void
344 | 349 |
350 |
351 |
param
352 |

indicates errors (null if user retrieval is successful)

353 |
354 |
param
355 |

list of IDs of users currently banned in the system

356 |
357 |
358 |
359 |
360 |

Type declaration

361 |
    362 |
  • 363 |
      364 |
    • (err: Error | null, users?: BannedUserList | null): void
    • 365 |
    366 |
      367 |
    • 368 |

      Parameters

      369 |
        370 |
      • 371 |
        err: Error | null
        372 |
      • 373 |
      • 374 |
        Optional users: BannedUserList | null
        375 |
      • 376 |
      377 |

      Returns void

      378 |
    • 379 |
    380 |
  • 381 |
382 |
383 |
384 |
385 |
386 | 438 |
439 |
440 | 454 |
455 |

Generated using TypeDoc

456 |
457 |
458 | 459 | 460 | --------------------------------------------------------------------------------