Skip to content

Olympicene/simple-messenger-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-messenger-bot

code style: prettier

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.

Requirements

  • node >= 17.0

Installation

  git clone https://github.com/Olympicene/simple-messenger-bot.git
  cd simple-messenger-bot
  npm install

Login

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 simple-messenger-bot/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.

Config

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.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', 
]

Usage

After you finish above sections run

npm test

If you did everything right, you should see this in your terminal:

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 any triggers outlined in response.json
To stop the bot, stop the program with Ctrl+C

Customization

edit response.json

{
    "hello": "hello my name is robot",
    "goodbye": "goodbye nice to meet you"
}

The key is the trigger for the bot and the value is the response it will type back.

About

A simple chat bot for Facebook messenger.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published