AssumeZero Bot: A Facebook Messenger bot for group chats
Tags: octograd2020, javascript, node, npm
Published: 2020-05-21 01:00:26

## My Final Project

For my final project, I thought I'd submit a project I've been working on throughout my entire college career. In a lot of ways, it has grown with me in that time, from a small toy script to a full codebase reflective of all the skills I've learned since I first `git init`'d.

The simplest description of AssumeZero Bot is this: a chat bot that can be added to Facebook Messenger conversations to control and expose features either hidden or limited by the actual UI. It does this by interfacing with Schmavery's [facebook-chat-api](https://github.com/Schmavery/facebook-chat-api), an unofficial Messenger API that works by mimicking user requests made in the browser to trick Messenger into thinking that a real user sent them.

This allows it to be much more functional than Facebook's official API for bots, which only permits direct one-on-one communication with the bot. Pull requests to facebook-chat-api were some of my first open source contributions as I endeavored to add features to my bot that were not yet available in the API.

{% github https://github.com/Schmavery/facebook-chat-api %}

## Demo Link
The bot is available on Facebook Messenger, but I won't list the profile here to make it an easy target for being taken down. If you're interested in trying it out, I have instructions for cloning your own instance in the README of the repo.
## Link to Code

{% github https://github.com/AstroCB/AssumeZero-Bot %}

## How I built it

From this simple start, I've added tons of features to the bot over the past 4 years, including utility commands for splitting prices, looking up information, doing calculations, creating events and reminders (which Messenger itself no longer supports), and all kinds of other automated tasks that are useful for a group chat. I even added pinging (@ing other users in the chat) before Messenger itself had that feature!

Today, the bot is a fully-fledged service with automated deploys, easy configuration, and most recently, a framework that I've abstracted away to support other bots that I create and spin up new ones quickly: [BotCore](https://github.com/AstroCB/BotCore). AssumeZero Bot and my other Messenger bot projects are now built on BotCore, but BotCore itself was written by pulling out infrastructure that I wrote specifically for AssumeZero Bot and generalizing it to support a network of bot instances.

The bot (and BotCore) are written with NodeJS, fully in JavaScript. There is also a Python library [fbchat](https://github.com/carpedm20/fbchat/) similar to facebook-chat-api, but I decided to write it using JavaScript because I find it easiest to use for getting projects off the ground quickly, particularly ones that involve a web server. I also wanted to structure the bot's response system asynchronously, and I knew that JavaScript would be my best option for this (particularly back in 2016-2017).

Using Node gave me access to a huge number of packages through npm, which enabled me to add tons of functionality to the bot with ease. For example, the bot contains several image-editing commands powered by [jimp](https://www.npmjs.com/package/jimp). Whenever I was looking for a third-party solution to something, there was always an npm package at the top of the search results that gave me just what I needed. 

This probably sounds like an ad for GitHub and its newly-acquired package manager, but I promise it's not! I have just seriously appreciated all of these services over the years, and I want to give credit where credit is due. The open source community has been a joy to work with while building this project and many others throughout college, and I see in hindsight how useful it was for me to have these tools at my disposal.