<?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: Kevin A Mathew</title>
    <description>The latest articles on DEV Community by Kevin A Mathew (@kevinam99).</description>
    <link>https://dev.to/kevinam99</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%2F513109%2F2c5b5da6-a2a7-412c-82a6-523fb6d1f7dd.jpeg</url>
      <title>DEV Community: Kevin A Mathew</title>
      <link>https://dev.to/kevinam99</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kevinam99"/>
    <language>en</language>
    <item>
      <title>Hacking an IoT App at the Civo Hackathon, 2021</title>
      <dc:creator>Kevin A Mathew</dc:creator>
      <pubDate>Sun, 05 Dec 2021 17:25:53 +0000</pubDate>
      <link>https://dev.to/kevinam99/hacking-an-iot-app-at-the-civo-hackathon-2021-3h3g</link>
      <guid>https://dev.to/kevinam99/hacking-an-iot-app-at-the-civo-hackathon-2021-3h3g</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;&lt;a href="//civo.com/"&gt;Civo&lt;/a&gt; organised its very first &lt;a href="https://civohacks.devpost.com/"&gt;hackathon&lt;/a&gt; and we got a chance to work on a great project with a skilled team. Thanks to Civo for the experience. Our project, &lt;a href="https://devpost.com/software/home-smart-home-h2s"&gt;Home Smart Home&lt;/a&gt;, won the &lt;em&gt;Best IoT Hack&lt;/em&gt; prize.&lt;/p&gt;

&lt;p&gt;See the &lt;a href="https://youtu.be/qWCET0xlMPM"&gt;video demo&lt;/a&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Meet the team&lt;/li&gt;
&lt;li&gt;About the project&lt;/li&gt;
&lt;li&gt;How we built the project&lt;/li&gt;
&lt;li&gt;Our experience with Civo&lt;/li&gt;
&lt;li&gt;What's next for our project&lt;/li&gt;
&lt;li&gt;Repo links&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Meet the team &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Our team comprises of three members with varied experiences and expertise ranging from full-stack web development to programming microcontrollers like NodeMCU ESP8266 and RaspberryPi.&lt;br&gt;
Here's a brief introduction of each of the members:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="//github.com/theonly1me"&gt;Atchyut&lt;/a&gt; is a full-stack developer with expertise on both the front-end and back-end development he was behind the ReactJS PWA UI app we developed as a part of this hackathon.&lt;/li&gt;
&lt;li&gt;
&lt;a href="//github.com/kevinam99"&gt;Kevin&lt;/a&gt; is a backend developer with expertise working with NodeJS, Python and &lt;a href="https://elixir-lang.org/"&gt;Elixir&lt;/a&gt;, which he used to build the back-end application for our app with the &lt;a href="https://www.phoenixframework.org/"&gt;Phoenix web framework&lt;/a&gt;.
&lt;/li&gt;
&lt;li&gt;
&lt;a href="//github.com/hardikchadda"&gt;Hardik&lt;/a&gt; is a lecturer at Dayalbagh Educational Institute, Agra, with expertise with Python, ML, AI &amp;amp; IoT. He built the IoT backend using C++ and a NodeMCU ESP8266 microcontroller which queries our backend API and talks to the smart devices. He's also programmed the microcontroller to turn non-smart devices into smart devices by just attaching it to a switchboard.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While the three of us have strong expertise in what we do, we're all DevOps and cloud enthusiasts and that is the reason we came together and built this project as a part of the Civo hackathon&lt;/p&gt;

&lt;h2&gt;
  
  
  About the project &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://devpost.com/software/home-smart-home-h2s"&gt;Home Smart Home&lt;/a&gt;, H2S, allows its users to register their smart devices and control them remotely. As an MVP, users can turn their devices on and off right from their internet-enable devices, however, we plan to incrementally update this to keep adding new features. &lt;/p&gt;

&lt;p&gt;Our initial goal was to build a simple platform to allow a layperson to be able to get into the world of IoT and smart devices. The innovation behind our app is that, users can even turn their non-smart devices to smart-devices with little to no programming knowledge and highly available hardware using some utilities that our Hardik is currently developing. &lt;/p&gt;

&lt;p&gt;As for the app itself, we initially planned on going with a React Native mobile app, but ended up going with a ReactJS PWA since we wanted the users to not just be limited to using a smartphone to automate their homes. Now, they can pretty much use any smartphone, tablet or computer in order to automate their homes.&lt;/p&gt;

&lt;h2&gt;
  
  
  How we built the project &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Our app consists of a front-end PWA, a back-end API layer and the actual IoT Component. Here's a breakdown for each of these components:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Front-end PWA App&lt;/strong&gt; - This app was built using ReactJS, Tailwind CSS, React hooks for state management and CRA's PWA Capabilities&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Back-end API Layer&lt;/strong&gt; - Our back-end currently consists of the API layer that both, the front-end app as well as the IoT component, use in order enable, disable, turn-on, turn-off, register smart devices into our system. Our app is built on the Phoenix framework using Elixir programming language and PostgreSQL DB. This is the component that we've deployed on a Civo Compute instance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IoT Component&lt;/strong&gt; - Our IoT component contains various utilities that are built using C++ and run on top of an NodeMCU ESP8266 microcontroller. The utilities are subscribed to our back-end API on a pub-sub model whenever there are changes in the DB, they query the API and communicate with the smart devices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Our Experience with Civo &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Our experience with the Civo platform has been great, while we were all new to DevOps, the guides on the Civo website helped us in deploying our backend micro-service on Civo. It's been a great experience and we definitely plan on using the platform as we scale up. It is remarkable how fast the Compute instance and the Kubernetes cluster were created. &lt;/p&gt;

&lt;h2&gt;
  
  
  What's next for our project &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;We plan to make our PWA available to as many users as possible. We've also started enhancing our platform to be able to have more features such as being able to control various aspects of a smart device than only being able to turn it on/off. With this, we're also developing kits that users can use in order to turn their non-smart devices to smart-devices. We believe there's a lot of hidden potential in what we build and that we're onto something really good. &lt;/p&gt;

&lt;p&gt;For now, the goal is to enable as many users as possible to use our platform for free, while the platform itself will always remain free, we plan to add a monetization model the kits that we produce to enable non-smart devices to behave like smart-devices and that would be our fundamental business model. &lt;/p&gt;

&lt;p&gt;However, at the place we're currently at, there's so many directions we can go in and we're really excited to build on top of this. &lt;/p&gt;

&lt;h2&gt;
  
  
  Links to the repos &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/hardikchadda/CIVO-Hackathon-HomeSmartHome"&gt;IoT&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/kevinam99/civo-hack-backend"&gt;API back-end&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/theonly1me/civo-hack-ui"&gt;Front-end&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>hackathon</category>
      <category>esp8266</category>
      <category>react</category>
      <category>elixir</category>
    </item>
    <item>
      <title>Setting Webhooks for Facebook Apps</title>
      <dc:creator>Kevin A Mathew</dc:creator>
      <pubDate>Thu, 27 May 2021 17:38:14 +0000</pubDate>
      <link>https://dev.to/kevinam99/setting-webhooks-for-facebook-apps-4o8c</link>
      <guid>https://dev.to/kevinam99/setting-webhooks-for-facebook-apps-4o8c</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Webhooks are a way to get your application to produce a certain behaviour depending on the occurrence of a specific event. Webhooks contain the data or the payload that you would need to identify the event to trigger the corresponding behaviour.&lt;/p&gt;

&lt;p&gt;For example, imagine you created a bot that monitors the price of a certain product on an ecommerce website. Once the price hits a certain value on the website, the bot will notify you that such an event has occurred. Now, it may be so that the price takes a lot of time, maybe even days, to reach that value that the bot is set to look for and until that time, the bot is always in a running state monitoring the price. This will be an inefficient approach since the code would have to be running 24x7. If you're running it on a cloud server, it's going to be an expensive bot for not that substantial value that it provides.&lt;/p&gt;

&lt;p&gt;But what if the website itself sent a notification to your bot? That would mean that the bot just has to live on a server and doesn't need to be active. It has to be active only when the notification is received from the website. The event will be sent as a POST request to the URL where your bot exists and then the bot does its work. Cool, right? And handy!&lt;/p&gt;

&lt;p&gt;This will also give your bot a real time behaviour.&lt;/p&gt;

&lt;h1&gt;
  
  
  Working with Facebook Apps
&lt;/h1&gt;

&lt;p&gt;Facebook allows developers to create apps that interact with Facebook for various purposes. To do this, Facebook created the &lt;a href="https://developers.facebook.com/docs/graph-api/" rel="noopener noreferrer"&gt;Graph API&lt;/a&gt; which helps in facilitating actions on Facebook for your app. The &lt;a href="https://developers.facebook.com/tools/explorer/" rel="noopener noreferrer"&gt;Graph API Explorer&lt;/a&gt; is an excellent tool that helps you run APIs on the browser. It also helps you to get the correct URLs and structure your requests.&lt;/p&gt;

&lt;p&gt;Here's a quick list of things you need:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A Facebook app.&lt;/li&gt;
&lt;li&gt;A program that can accept HTTP requests. I'll be using Node.js here with the &lt;a href="https://expressjs.com" rel="noopener noreferrer"&gt;Express.js framework&lt;/a&gt; to handle the requests.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://ngrok.com" rel="noopener noreferrer"&gt;Ngrok&lt;/a&gt; to expose your localhost on the internet.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This tutorial assumes that you know how to set up basic &lt;a href="https://developers.facebook.com/apps/" rel="noopener noreferrer"&gt;Facebook apps&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So, let's get cracking.&lt;/p&gt;

&lt;h5&gt;
  
  
  1. Create a server.
&lt;/h5&gt;

&lt;p&gt;Here's the Node.js code that creates a server and listens on port &lt;code&gt;5000&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)()&lt;/span&gt;

   &lt;span class="c1"&gt;// express middleware&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bodyParser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;body-parser&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bodyParser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlencoded&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;extended&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;}))&lt;/span&gt;
   &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bodyParser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;
   &lt;span class="c1"&gt;// start server  &lt;/span&gt;
   &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Listening on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Run this code and the server will be up listening to any&lt;br&gt;
incoming requests.&lt;/p&gt;
&lt;h5&gt;
  
  
  2. Start Ngrok on the same port &lt;code&gt;5000&lt;/code&gt;.
&lt;/h5&gt;

&lt;p&gt;To do this, run the command &lt;code&gt;ngrok http 5000&lt;/code&gt;. On running the command, the following view will appear on the terminal:&lt;br&gt;
    &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcj40q3k1vlmalb2dkvpl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcj40q3k1vlmalb2dkvpl.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
 Here, you can see which URLs are being forwarded and the requests that have been received on those URLs. You want to use the HTTPS URL for this purpose since it's a requirement set by the Graph API. For this example, it is &lt;code&gt;https://7ac66c7f726f.ngrok.io&lt;/code&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  3. Setup the Webhook product.
&lt;/h5&gt;

&lt;p&gt;On your app dashboard, scroll down to &lt;strong&gt;Add Products to Your App&lt;/strong&gt;. Look for Webhooks and click on &lt;code&gt;Set up&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxzm2cnv098t8ytwu8jwe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxzm2cnv098t8ytwu8jwe.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
At the pane on the left hand side, click on &lt;code&gt;Webhooks&lt;/code&gt;. You should see something like this &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft50m6ltfpg5bkp1nd80n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft50m6ltfpg5bkp1nd80n.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  4. Handle webhook endpoint.
&lt;/h5&gt;

&lt;p&gt;Before we add a callback URL, we need to add some more code. This step handles the requests coming to the webhook endpoint. While registering a webhook, Facebook will send a request to the URL that you provide along with the endpoint and it will expect a response from the endpoint, which is the &lt;code&gt;challenge&lt;/code&gt; code. This has to be echoed back to Facebook only then will the URL be registered.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;


&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/webhook&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;VERIFY_TOKEN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;random string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="c1"&gt;// Parse the query params&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hub.mode&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hub.verify_token&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;challenge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hub.challenge&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

      &lt;span class="c1"&gt;// Checks if a token and mode is in the query string of the request&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;// Checks the mode and token sent is correct&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;subscribe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;VERIFY_TOKEN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

          &lt;span class="c1"&gt;// Responds with the challenge token from the request&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;WEBHOOK_VERIFIED&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;challenge&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="c1"&gt;// Responds with '403 Forbidden' if verify tokens do not match&lt;/span&gt;
          &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;      
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;The final code is as follows&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h5&gt;
  
  
  5. Subscribe to an object
&lt;/h5&gt;

&lt;p&gt;Click the drop down menu and select any object you want. I'll select the &lt;code&gt;User&lt;/code&gt; object here and then click on &lt;code&gt;Subscribe to this object&lt;/code&gt; which will open this modal&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1d8n93hdq3ilglq5in6u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1d8n93hdq3ilglq5in6u.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Enter the https URL from Ngrok along with an endpoint. The endpoint can be anything and it should be able to receive HTTP POST requests. The string in the &lt;code&gt;Verify Token&lt;/code&gt; field can be anything. It is just a security measure put in place to see that the request is coming from the right source to the right destination. You may or may not choose to put a check in the code. Then click on &lt;code&gt;Verify and Save&lt;/code&gt;. This will then take you to a page where you can choose the subscriptions you need.&lt;/p&gt;

&lt;p&gt;The GET request is only for registering the callback URL to an object. To handle actual events, make sure to write a POST route to the same endpoint (in this example, &lt;code&gt;webhook&lt;/code&gt;). This route will handle the behaviour of the bot/app. &lt;br&gt;
 Most of these subscriptions are available after verification, but if you click on the &lt;code&gt;Test&lt;/code&gt; button, you'll  be able to see a sample request sent to your endpoint.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh0n30l5qr4u08fdbvey0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh0n30l5qr4u08fdbvey0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Click on &lt;code&gt;Send to My Server&lt;/code&gt; and you'll see the request.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdciazop8bqrjxjzf3mz8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdciazop8bqrjxjzf3mz8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
 If you open Ngrok's web interface, you'll be able to see the details associated with each request on your browser.&lt;/p&gt;

&lt;p&gt;I hope this tutorial helped you in setting your own webhook with your Facebook app. I certainly had some trouble getting it done myself and so, I though of writing up this blog to help anyone else save time.&lt;/p&gt;

&lt;p&gt;Thank you for your time. Until next time, ciao.&lt;/p&gt;

&lt;p&gt;You can reach out to me on&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Email: &lt;a href="mailto:kevinam99.work@gmail.com"&gt;kevinam99.work@gmail.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GitHub: &lt;a href="https://www.github.com/kevinam99" rel="noopener noreferrer"&gt;@kevinam99&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Twitter: &lt;a href="https://www.twitter.com/neverloquacious" rel="noopener noreferrer"&gt;@neverloquacious&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;LinkedIn: &lt;a href="https://www.linkedin.com/in/kevin-a-mathew" rel="noopener noreferrer"&gt;Kevin A Mathew&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>facebook</category>
      <category>graphapi</category>
      <category>ngrok</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
