This is a simple Facebook messenger chat bot. It is easy to customize, all responses and triggers are assigned in a json file. You can also specify which threads it will work in and the delay between each command in the config.js.
- node >= 14.14.0
git clone https://github.com/Olympicene/messenger-undelete
cd simple-messenger-bot
npm install
As of writing this, due to facebook-chat-api being in maintenance mode, login via username and password is impossible. The workaround involves using cookies from the facebook website found in this issue. It's not a long process so I'll summarize it here.
- Install a puppeter extension (I use this one)
- (UPDATE: the chrome store page link is a 404 use firefox or unpack my crx file)
- Login to facebook.com NOT messenger.com
- use puppeter to retrieve the cookies as a JSON file
- rename the file to appstate.json and put it in messenger-undelete/database
- for every cookie object replace "name" with "key" (just find and replace all instances of "name" with "key")
If your appstate.json somewhat looks like example-appstate.json then you did it right.
Next you need to edit config.js
exports.timeout_milliseconds is self explanatory, its how long the bot will wait before it accepts the next command.
//time in between commands
exports.timeout_milliseconds = 1000
exports.prefix is the prefix of the undelete command that the messenger bot will respond to.
//prefix of undelete command, by default it is "!" Ex: !undelete
exports.prefix = "!";
exports.history_length and exports.deleted_length is the number of messages each of the respective json files store.
//history holds 2000 messages
exports.history_length = 2000;
//deleteds holds 1000 messages
exports.deleted_length = 1000;
exports.allowed_threads contains a list of Thread ID's associated with groupchats that the bot is allowed to respond to.
Thread IDs are a number that can be found at the end of urls when you access messenger via browser.
Example
exports.allowed_threads = [
'4341136652627262',
]
Ignore the rest of the settings.
After you finish above sections run
npm test
If you did everything right, you should see this in your terminal:
[ '!undelete' ]
[ 'deleted', 'history' ]
info login Logged in
info login Request to reconnect
info login Done logging in.
While this program is running, the chat bot will respond to "!undelete" if it is added to a groupchat and is that groupchat is in the allowed thread list.
Example