<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Cameron Bernhardt</title>
    <description>The latest articles on DEV Community by Cameron Bernhardt (@astrocb).</description>
    <link>https://dev.to/astrocb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F391445%2Fdf3f099b-fd7c-41de-91d6-629d6230bdc0.jpeg</url>
      <title>DEV Community: Cameron Bernhardt</title>
      <link>https://dev.to/astrocb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/astrocb"/>
    <language>en</language>
    <item>
      <title>AssumeZero Bot: A Facebook Messenger bot for group chats</title>
      <dc:creator>Cameron Bernhardt</dc:creator>
      <pubDate>Thu, 21 May 2020 01:00:26 +0000</pubDate>
      <link>https://dev.to/astrocb/assumezero-bot-a-facebook-messenger-bot-for-group-chats-17ah</link>
      <guid>https://dev.to/astrocb/assumezero-bot-a-facebook-messenger-bot-for-group-chats-17ah</guid>
      <description>&lt;h2&gt;
  
  
  My Final Project
&lt;/h2&gt;

&lt;p&gt;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 &lt;code&gt;git init&lt;/code&gt;'d.&lt;/p&gt;

&lt;p&gt;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 &lt;a href="https://github.com/Schmavery/facebook-chat-api"&gt;facebook-chat-api&lt;/a&gt;, 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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vWogaON8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-28d89282e0daa1e2496205e2f218a44c755b0dd6536bbadf5ed5a44a7ca54716.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Schmavery"&gt;
        Schmavery
      &lt;/a&gt; / &lt;a href="https://github.com/Schmavery/facebook-chat-api"&gt;
        facebook-chat-api
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Unofficial Facebook Chat API for Nodejs
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
Unofficial Facebook Chat API&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://www.npmjs.com/package/facebook-chat-api" rel="nofollow"&gt;&lt;img alt="npm version" src="https://camo.githubusercontent.com/3fb7825036a27969016be090718098a4f8debc01/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f66616365626f6f6b2d636861742d6170692e7376673f7374796c653d666c61742d737175617265"&gt;&lt;/a&gt;
&lt;a href="https://www.npmjs.com/package/facebook-chat-api" rel="nofollow"&gt;&lt;img src="https://camo.githubusercontent.com/30fe45960f5b4f387776b3a235f3d1c138c91fd1/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f646d2f66616365626f6f6b2d636861742d6170692e7376673f7374796c653d666c61742d737175617265" alt="npm downloads"&gt;&lt;/a&gt;
&lt;a href="https://github.com/prettier/prettier"&gt;&lt;img src="https://camo.githubusercontent.com/687a8ae8d15f9409617d2cc5a30292a884f6813a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64655f7374796c652d70726574746965722d6666363962342e7376673f7374796c653d666c61742d737175617265" alt="code style: prettier"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Facebook now has an official API for chat bots &lt;a href="https://developers.facebook.com/docs/messenger-platform" rel="nofollow"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This API is the only way to automate chat functionalities on a user account. We do this by emulating the browser. This means doing the exact same GET/POST requests and tricking Facebook into thinking we're accessing the website normally. Because we're doing it this way, this API won't work with an auth token but requires the credentials of a Facebook account.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Disclaimer&lt;/em&gt;: We are not responsible if your account gets banned for spammy activities such as sending lots of messages to people you don't know, sending messages very quickly, sending spammy looking URLs, logging in and out very quickly... Be responsible Facebook citizens.&lt;/p&gt;
&lt;p&gt;See &lt;a href="https://raw.githubusercontent.com/Schmavery/facebook-chat-api/master/#projects-using-this-api"&gt;below&lt;/a&gt; for projects using this API.&lt;/p&gt;
&lt;p&gt;See the &lt;a href="https://raw.githubusercontent.com/Schmavery/facebook-chat-api/master//CHANGELOG.md"&gt;full changelog&lt;/a&gt; for release details.&lt;/p&gt;
&lt;h2&gt;
Install&lt;/h2&gt;
&lt;p&gt;If you just want to use facebook-chat-api, you should use this command:&lt;/p&gt;
&lt;div class="highlight highlight-source-shell"&gt;&lt;pre&gt;npm install facebook-chat-api&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Schmavery/facebook-chat-api"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Demo Link
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Link to Code
&lt;/h2&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vWogaON8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-28d89282e0daa1e2496205e2f218a44c755b0dd6536bbadf5ed5a44a7ca54716.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/AstroCB"&gt;
        AstroCB
      &lt;/a&gt; / &lt;a href="https://github.com/AstroCB/AssumeZero-Bot"&gt;
        AssumeZero-Bot
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A Facebook Messenger bot for group chats.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
AssumeZero Bot&lt;/h1&gt;
&lt;h2&gt;
About&lt;/h2&gt;
&lt;p&gt;AssumeZero Bot is a highly configurable bot that can be added to Facebook Messenger group chats. It is designed to expose features that may be hidden or made difficult to use by Messenger's UI, both on desktop and mobile. In addition to this functionality, it also connects to several different external services, like &lt;a href="https://spotify.com" rel="nofollow"&gt;Spotify&lt;/a&gt;, &lt;a href="http://wolframalpha.com" rel="nofollow"&gt;Wolfram|Alpha&lt;/a&gt;, and &lt;a href="https://openweathermap.org" rel="nofollow"&gt;OpenWeatherMap&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The bot was written with &lt;a href="https://nodejs.org/" rel="nofollow"&gt;Node.js&lt;/a&gt; and the incredible &lt;a href="https://github.com/Schmavery/facebook-chat-api"&gt;Facebook Chat API&lt;/a&gt;, which allows the bot to emulate a Facebook user who can be added and removed from chats. As of this writing, Facebook's &lt;a href="https://developers.facebook.com/docs/chat" rel="nofollow"&gt;official API&lt;/a&gt; can still only be used in one-on-one conversations.&lt;/p&gt;
&lt;h2&gt;
Usage&lt;/h2&gt;
&lt;p&gt;Most of the bot's features are activated with a "trigger word," which can be changed in &lt;a href="https://raw.githubusercontent.com/AstroCB/AssumeZero-Bot/master/src/config.js"&gt;&lt;code&gt;config.js&lt;/code&gt;&lt;/a&gt;. The default trigger word is "physics" and most commands will be in the form:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;physics command [options]&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;To see a list of commands…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/AstroCB/AssumeZero-Bot"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  How I built it
&lt;/h2&gt;

&lt;p&gt;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!&lt;/p&gt;

&lt;p&gt;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: &lt;a href="https://github.com/AstroCB/BotCore"&gt;BotCore&lt;/a&gt;. 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.&lt;/p&gt;

&lt;p&gt;The bot (and BotCore) are written with NodeJS, fully in JavaScript. There is also a Python library &lt;a href="https://github.com/carpedm20/fbchat/"&gt;fbchat&lt;/a&gt; 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).&lt;/p&gt;

&lt;p&gt;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 &lt;a href="https://www.npmjs.com/package/jimp"&gt;jimp&lt;/a&gt;. 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. &lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

</description>
      <category>octograd2020</category>
      <category>javascript</category>
      <category>node</category>
      <category>npm</category>
    </item>
  </channel>
</rss>
