<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Devanshani Rasanjika on Medium]]></title>
        <description><![CDATA[Stories by Devanshani Rasanjika on Medium]]></description>
        <link>https://medium.com/@devanshanirasanjika-uom?source=rss-29a59e91772------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Y1aWHjYKyR3rbRJetpmUiQ@2x.jpeg</url>
            <title>Stories by Devanshani Rasanjika on Medium</title>
            <link>https://medium.com/@devanshanirasanjika-uom?source=rss-29a59e91772------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 10:04:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@devanshanirasanjika-uom/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to build your Chrome Extension in 5 minutes]]></title>
            <link>https://medium.com/aeturnuminc/how-to-build-your-chrome-extension-in-5-minutes-de6b4f06f393?source=rss-29a59e91772------2</link>
            <guid isPermaLink="false">https://medium.com/p/de6b4f06f393</guid>
            <category><![CDATA[content-script]]></category>
            <category><![CDATA[service-worker]]></category>
            <category><![CDATA[manifest-v3]]></category>
            <category><![CDATA[chrome-extension]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Devanshani Rasanjika]]></dc:creator>
            <pubDate>Mon, 12 Jun 2023 09:11:18 GMT</pubDate>
            <atom:updated>2023-06-12T09:49:32.248Z</atom:updated>
            <content:encoded><![CDATA[<p>Chrome is a well-spread platform that can develop your own Chrome extensions. If you want to make Chrome extensions and are new to Chrome extensions this is the right article for you.</p><p>Chrome extension is a small piece of software that can run inside a Chrome browser. It can enhance Chrome functionalities and create a custom user experience and as well as can track the user’s browser activities. They are built using web technologies such as Javascript, HTML, and CSS and do not need any advanced technologies.</p><p>Chrome extensions run in an isolated manner which does not impact the browser functionality. So any fault in an extension does not bring down the browser process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2dyrhhhYvbUDSW4-42YHrg.jpeg" /></figure><p><strong>File structure</strong></p><ul><li>Manifest.json — Every extension requires a JSON-formatted file named manifest.json that provides important information which is the entry point for the Chrome extension. This file must be located in the extension’s root directory and called manifest.json. This is the configuration file for the extension and it will contain the owner’s name, version, and permissions that we need to allow to access the Chrome APIs, etc.</li><li>Service Worker — Run in the background of your browser &amp; listen to every event that happening in the browser. So here we are going to call it background.js. For example, if you want to write a function such as any information saved to session storage this function should be written in the background script.</li><li>content scripts — Content scripts are run in the context of a web page and have access to the embedding web page DOM which can enhance the UX of the existing web page. So it can manipulate the DOM elements of the browser web page &amp; it also can use the Chrome APIs.</li><li>popup.html — If you want to show an interface when clicking on the extension you can write the logic here.</li><li>popup.css — Do the styling for the HTML.</li><li>popup.js — Writing the logic for the HTML.</li></ul><p><strong>Important Chrome APIs</strong></p><p>Here I will be going to discuss important Chrome APIs that we need to build a simple Chrome extension.</p><ul><li><a href="https://developer.chrome.com/docs/extensions/reference/notifications/">chrome. notifications </a>— Create notifications &amp; send the notifications to users in the system tray.</li><li><a href="https://developer.chrome.com/docs/extensions/reference/runtime/">chrome. runtime</a> — Listen to background.js, and communicate between the service worker &amp; content script.</li><li><a href="https://developer.chrome.com/docs/extensions/reference/storage/">chrome.storage </a>— Read &amp; write to the website&#39;s local storage.</li><li><a href="https://developer.chrome.com/docs/extensions/reference/tabs/">chrome.tabs </a>— Interact with the browser tab system. For example can find the active tab, and modify and rearrange tabs in the browser.</li><li><a href="https://developer.chrome.com/docs/extensions/reference/cookies/">chrome.cookies</a> — Can query the session cookies from any web page, modify the cookies &amp; identify cookies change events.</li></ul><p><strong>Communication between Service Worker &amp; Content Script</strong></p><p>Since Service workers run in the background of your browser and content scripts run in the context of the browser we need to have a specific mechanism to communicate between these scripts. Here we can use chrome.runtime API to send &amp; receive messages.</p><p>Let’s get started!</p><p>First, we need to have the manifest.json configuration file which is the entry point for the Chrome extension as below. Here I will be going to develop the Chrome extension using Manifest version 3.</p><p><strong>Create the Manifest.json:</strong></p><pre>{<br>  &quot;manifest_version&quot;: 3, // Manifest version<br>  &quot;name&quot;: &quot;Demo extension&quot;, // Name of the Extension<br>  &quot;version&quot;: &quot;0.0.1&quot;, //Version number of the Extension<br>  &quot;author&quot;: &quot;Test&quot;, // Author (not mandatory)<br>  &quot;action&quot;: {<br>    &quot;default_popup&quot;: &quot;popup.html&quot;, //Interface when you click on the extension<br>    &quot;default_icon&quot;: &quot;get_started128.png&quot;,<br>    &quot;default_title&quot;: &quot;Demo extension&quot; //Show when you hover the Extension <br>  },<br>  &quot;content_scripts&quot;: [<br>    {<br>      &quot;matches&quot;: [&quot;&lt;all_urls&gt;&quot;],//if you target specific site to inject the Content Script you can put here<br>      &quot;js&quot;: [&quot;contentscript.js&quot;]//Script running in the browser console<br>    }<br>  ],<br>  &quot;background&quot;: {<br>    &quot;service_worker&quot;: &quot;background.js&quot;//Script run in the background &amp; listen to events happening in the browser<br>  },<br>  &quot;permissions&quot;: [&quot;tabs&quot;,&quot;activeTab&quot;,&quot;scripting&quot;,&quot;contextMenus&quot;], //Allow specific permissions<br>  &quot;host_permissions&quot;: [&quot;https://*/&quot;] //Allow access to specific host<br>}</pre><p><strong>Content Script to Service Worker:</strong></p><p>Here in the Content Script, I will be going to call the chrome.runtime.sendMessage API to handle the communication.</p><pre>chrome.runtime.sendMessage(<br>  {<br>    message: &quot;Hi message from content script&quot;,<br>  },<br>  (response) =&gt; {<br>    console.log(response.message);<br>  }<br>);</pre><p>And in the Service Worker, there should be a callback function to receive the response from the Content Script as below.</p><pre>chrome.runtime.onMessage.addListener((message, sender, sendResponse) =&gt; {<br>  console.log(message);<br>  sendResponse({ message: &quot;Response from background js&quot; });<br>});</pre><p><strong>Testing:</strong></p><ul><li>Once the manifest and other files are ready, head over to chrome://extensions in the browser.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ye1mosQNeF2VFtUmuxMGAA.png" /></figure><ul><li>Enable the developer’s mode.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5JuIhH_2_2MZfz-GME57XQ.png" /></figure><ul><li>Click the <strong>LOAD UNPACKED</strong> button and select the extension directory.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z71pjUmFRP17422Hqz0WbA.png" /></figure><ul><li>The extension has been successfully installed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CR3mnp46stHFWY0bkC4iuA.png" /></figure><p>Next, Reload &amp; open a new tab in the browser and inspect the developer tools. you can see the response message from the Service Worker hit in the browser web page console. At the same time click on the service worker inside the installed Chrome extension for debugging. In the service worker console, you can see the received message from the content script.</p><p><strong>Service Worker to Content Script:</strong></p><p>On the other way, we can send messages to the Content Script from the Service Worker to perform the tasks.</p><p>Here I’m going to show how to add a menu item when right-clicking on a browser web page &amp; send a message to the Content Script to change the background color. So we need to include the contextMenus permission under the permissions in the manifest.json file as &quot;permissions&quot;:[&quot;tabs&quot;,&quot;activeTab&quot;,&quot;scripting&quot;,&quot;contextMenus&quot;] .</p><p>Next, the Service Worker needs to register a listener at the time of Chrome Extension installation to create a new context menu item as below.</p><pre>chrome.runtime.onInstalled.addListener(function () {<br>  chrome.contextMenus.create({<br>    id: &quot;changeBgColor&quot;,<br>    title: &quot;Change Background Color&quot;,<br>    contexts: [&quot;all&quot;],<br>  });<br>});</pre><p>Once the menu item gets created should write the click event functionality to send a message to the Content Script to change the background color since the Content Script has the permission to change the DOM of the browser web page.</p><pre>chrome.contextMenus.onClicked.addListener(function (info, tab) {<br>  if (info.menuItemId == &quot;changeBgColor&quot;) {<br>    chrome.tabs.sendMessage(tab.id, { action: &quot;changeBgColor&quot;, color: &quot;red&quot; });<br>  }<br>});</pre><p>And in the Content Script, there should be a listener to listen to the messages from the Service Worker and do the requested changes as below.</p><pre>chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {<br>  if (request.action == &quot;changeBgColor&quot;) {<br>    document.body.style.backgroundColor = request.color;<br>  }<br>});</pre><p>Next, reload the extension to apply the changes and check how the background color change when clicking on the new menu item.</p><p><strong>Build a Simple Chrome Extension to check the Jenkins build status</strong></p><p>Next, I will use the above-explained basics to build a simple Chrome extension that is able to check the Jenkins build status. So to check the Jenkins build status I set up the Jenkins server in the local environment which is running in the <a href="http://localhost:8080.">http://localhost:8080</a> . From the Jenkins [GET]http://localhost:8080/api/json?tree=jobs[name,color] API we can get all the build status in the API response. So next my goal is to integrate Jenkins API via the Chrome extension and upon clicking on the extension should show an interface with all the jobs with their status respectively.</p><p>Let’s get started!</p><ul><li>Create the manifest.json file with the necessary permissions as below. Here we don&#39;t need Content Script since we are not going to change the DOM of browser web pages.</li></ul><pre>{<br>    &quot;manifest_version&quot;:3,<br>    &quot;name&quot;:&quot;Jenkins build status checker&quot;,<br>    &quot;version&quot;: &quot;0.0.1&quot;,<br>    &quot;description&quot;: &quot;Check the status of Jenkins jobs&quot;,<br>    &quot;host_permissions&quot;:[&quot;http://localhost:8080/*&quot;], //Allow access to Jenkins host URL<br>    &quot;background&quot;:{<br>        &quot;service_worker&quot;:&quot;background.js&quot;<br>    },<br>    &quot;permissions&quot;:[&quot;storage&quot;,&quot;tabs&quot;,&quot;notifications&quot;],<br>    &quot;action&quot;:{<br>        &quot;default_popup&quot;:&quot;popup.html&quot;,<br>        &quot;default_icon&quot;: &quot;icon.png&quot;,<br>        &quot;title&quot;: &quot;Jenkins build status checker&quot;<br>    }<br>}</pre><ul><li>Create the Service Worker as background.js and here we need to call the Jenkins API in chrome.runtime.onInstalled &amp; chrome.tabs.onUpdated listeners as below. After receiving the response from the Jenkins API I will be going to write the response to local storage using chrome.storage API.</li></ul><pre>chrome.runtime.onInstalled.addListener(() =&gt; {<br>  callJenkinsApi();<br>});<br><br>callJenkinsApi = () =&gt; {<br>  fetch(&quot;http://localhost:8080/api/json?tree=jobs[name,color]&quot;)<br>    .then((response) =&gt; response.json())<br>    .then((data) =&gt; {<br>      console.log(data.jobs);<br>      chrome.storage.sync.set({ jenkinsData: data.jobs });<br>    });<br>};<br><br>chrome.tabs.onUpdated.addListener(function(id,changeInfo,tab){<br>    callJenkinsApi();<br>})</pre><ul><li>Next, create an interface to show the Jenkins build status in a table view using popup.html.</li></ul><pre>&lt;html&gt;<br>  &lt;style&gt;<br>    table {<br>      font-family: arial, sans-serif;<br>      border-collapse: collapse;<br>      width: 100%;<br>    }<br>    <br>    td, th {<br>      border: 1px solid #dddddd;<br>      text-align: left;<br>      padding: 8px;<br>    }<br>    <br>    tr:nth-child(even) {<br>      background-color: #dddddd;<br>    }<br>    &lt;/style&gt;<br>  &lt;head&gt;<br>    &lt;script src=&quot;popup.js&quot;&gt;&lt;/script&gt;<br>  &lt;/head&gt;<br>  &lt;body style=&quot;width: 400px;&quot;&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><ul><li>Next, I will be going to write the logic to create the table view using popup.js. Here API response will be read from the local storage using chrome.storage API &amp; once the user checks the status of the jobs it will be notified in the system tray as successfully checked the Jenkins build status using chrome.notifications API as below.</li></ul><pre>chrome.notifications.create(`my-notification-${Date.now()}`, {<br>  type: &quot;basic&quot;,<br>  iconUrl: &quot;icon.png&quot;,<br>  title: &quot;Jenkins build status check&quot;,<br>  message: &quot;succesfully checked for all jobs&quot;,<br>});<br><br>function updatePopup() {<br>  chrome.storage.sync.get([&quot;jenkinsData&quot;], function (data) {<br>    var jobs = data.jenkinsData;<br>    var table = document.createElement(&quot;table&quot;);<br>    var th1 = document.createElement(&quot;th&quot;);<br>    th1.innerHTML = &quot;Job&quot;;<br>    var th2 = document.createElement(&quot;th&quot;);<br>    th2.innerHTML = &quot;Status&quot;;<br>    table.appendChild(th1);<br>    table.appendChild(th2);<br>    for (var i = 0; i &lt; jobs.length; i++) {<br>      var tr = document.createElement(&quot;tr&quot;);<br><br>      var td1 = document.createElement(&quot;td&quot;);<br>      var td2 = document.createElement(&quot;td&quot;);<br><br>      var text1 = document.createTextNode(jobs[i].name);<br>      var status = &quot;not built&quot;;<br>      if (jobs[i].color == &quot;red&quot;) {<br>        status = &quot;Failed&quot;;<br>      } else if (jobs[i].color == &quot;blue&quot;) {<br>        status = &quot;Success&quot;;<br>      }<br><br>      var text2 = document.createTextNode(status);<br><br>      td1.appendChild(text1);<br>      td2.appendChild(text2);<br>      tr.appendChild(td1);<br>      tr.appendChild(td2);<br>      table.appendChild(tr);<br>    }<br>    document.body.appendChild(table);<br>  });<br>}<br>document.addEventListener(&quot;DOMContentLoaded&quot;, updatePopup);</pre><p>Hopefully, this helps to understand the usage of background scripts, content scripts, and manifest.json files when you are building out your amazing new Chrome extension.</p><p>You can find the full source code for the Chrome Extension to check the Jenkins build status from <a href="https://github.com/DevanshaniR/chrome-extension">here</a>.</p><p>Thank you for reading!</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de6b4f06f393" width="1" height="1" alt=""><hr><p><a href="https://medium.com/aeturnuminc/how-to-build-your-chrome-extension-in-5-minutes-de6b4f06f393">How to build your Chrome Extension in 5 minutes</a> was originally published in <a href="https://medium.com/aeturnuminc">Aeturnum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Slack integration and posting chat messages using OAuth2 in Node.js]]></title>
            <link>https://devanshanirasanjika-uom.medium.com/slack-integration-and-posting-chat-messages-using-oauth2-in-node-js-758af767330f?source=rss-29a59e91772------2</link>
            <guid isPermaLink="false">https://medium.com/p/758af767330f</guid>
            <category><![CDATA[slack]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[oauth2-provider]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Devanshani Rasanjika]]></dc:creator>
            <pubDate>Mon, 26 Dec 2022 13:25:22 GMT</pubDate>
            <atom:updated>2023-01-03T02:54:53.069Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pej4em0GV-HJAg0P0Ihjhw.png" /></figure><p>OAuth 2.0 is a protocol that lets your app request authorization to access private details in a user’s Slack account without getting their password.</p><p>Typically OAuth 2.0’s most commonly used flow is divided into three main steps:</p><ol><li>Application pop up a new window for the 3rd party authorization app asking the user (who must have an account and be logged in on the system) to grant permission for your application and then be able to take actions on his/her behalf.</li><li>Once properly authenticated and authorized, the third-party app acknowledges the permission and redirects the user to your app via a pre-configured URL.</li><li>Your application exposes an endpoint for such callback operations. It hits the third-party provider API to ask for an access token based on the response code returned by the previous redirect process.</li></ol><p><strong>Environment setup</strong></p><p>For this article, I will be using <a href="https://nodejs.org/en/">Node.js</a> and <a href="https://www.npmjs.com/">npm</a> as the default package manager. Here I will create two different applications one for the client(in React) and another for the server capabilities.</p><p><strong>Slack App config</strong></p><p>Here we use the <a href="https://api.slack.com/">Slack OAuth2 API</a> which allows you to create an application under your account and provides you with some OAuth2 client credentials to use in other applications.</p><p>This way, you can easily allow users of your application to log in via their Slack accounts.</p><p>So, let’s create a new application by clicking this <a href="https://api.slack.com/apps?new_app">link</a>. Make sure to fill in all the fields with the app name and workspace to develop your app in.</p><p>Then go to the basic information section. You will find the app credentials with the client ID and client secret. Next, go to the OAuth &amp; Permissions and add the redirect URLs. The authorization callback URL is the most important field because it demarcates where Slack should redirect the user once the authorization process is finished.</p><p>Here you can enter any URL you prefer as shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*IT6qdkNwxTwZPQw2NL8_Xg.png" /></figure><p>And then you need to add the scopes to indicate what your app can access.</p><p>Here in the bot token scopes, I have added the below permissions as shown below.</p><p><a href="https://api.slack.com/scopes/channels:history">channels:history</a> -View messages and other content in public channels that App has been added to</p><p><a href="https://api.slack.com/scopes/channels:manage">channels:manage</a> -Manage public channels that App has been added to and create new ones</p><p><a href="https://api.slack.com/scopes/chat:write">chat:write</a> -Send messages as TestApp</p><p><a href="https://api.slack.com/scopes/groups:write">groups:write</a> -Manage private channels that App has been added to and create new ones</p><p><a href="https://api.slack.com/scopes/im:write">im:write</a> -Start direct messages with people</p><p><a href="https://api.slack.com/scopes/mpim:write">mpim:write</a> -Start group direct messages with people</p><p><strong>The server project</strong></p><p>Let’s get back to project creation. Pick up a folder of your choice and run the following command:</p><pre>mkdir oauth2-node-server<br>cd oauth2-node-server<br>npm init</pre><p>Again, leave all the options as they’re presented to you until the end. Then, run the following command to install the required NPM dependencies:</p><pre>npm install axios express cors</pre><p><em>Axios</em> will be used to make HTTP request calls to the Slack OAuth2 servers. <em>Express</em> will be our version of the server, and <em>cors</em> is just used to avoid conflicts with the browser’s <em>Same-Origin</em> policies.</p><p>The code for the server is very simple and can be found in the following code. Make sure to add it to a file named <em>index.js</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56cd7f2e8e8bc3c9bb425a03b1065c4d/href">https://medium.com/media/56cd7f2e8e8bc3c9bb425a03b1065c4d/href</a></iframe><p>Here from the <em>/oauth/redirect </em>endpoint<em> </em>you will get a valid access token and then we may redirect the response and all of its content to the React client application listening to port 3000.</p><p>Before heading to the next section, make sure everything’s working fine by running the following command:</p><pre>node index.js</pre><p>which may, in turn, produce the output shown below:</p><pre>➜ Listening at port 8080</pre><p><strong>The client project</strong></p><p>Leave the current server folder and run the following command to create the client project:</p><pre>npx create-react-app oauth2-node-app</pre><p>Then, run the following command to add the required Node dependencies:</p><pre>npm install axios</pre><p>Then substitute your <em>App.js</em> file content with the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56cd7f2e8e8bc3c9bb425a03b1065c4d/href">https://medium.com/media/56cd7f2e8e8bc3c9bb425a03b1065c4d/href</a></iframe><p><strong>Testing</strong></p><p>To test the client implementation, you may run the following command in the client’s root folder:</p><pre>npm start</pre><p>Look for errors in the logs and wait until React loads the application on your web browser.</p><p>You may see the following screen with the <em>Sign in</em> button. Before clicking it, make sure to have both the server app and the proxy up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-3EijoLCU2fvXpV0hRRDIQ.png" /></figure><p>After clicking the <em>Sign in</em> button, you’ll be redirected to the Slack authorization page, as shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BAD5R1HN3oSM_xpJmhA5iw.png" /></figure><p>Click on the <em>Authorize</em> button, and Slack will also take care of the redirecting process after it’s finished and you will get an access token to access slack APIs. So this access token is known as a bearer token and we can use this token to call API methods for channel creation and post messages to the channel using the below APIs which you can see in the server project of the above code.</p><p>1 . conversations.create API to create a channel</p><p>2 . chat.postMessageAPI to post chat messages.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=758af767330f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Facebook scraper bot using Node JS and Mongo DB]]></title>
            <link>https://devanshanirasanjika-uom.medium.com/facebook-scraper-bot-using-node-js-and-mongo-db-cb5864208126?source=rss-29a59e91772------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb5864208126</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[scraping]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[facebook]]></category>
            <dc:creator><![CDATA[Devanshani Rasanjika]]></dc:creator>
            <pubDate>Sun, 15 May 2022 08:23:15 GMT</pubDate>
            <atom:updated>2022-05-17T06:24:04.048Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*JxYs1DB1iefe1QbHKagoVA.png" /></figure><p>I’m working on a app which needs to render Facebook feeds based on topic channels using Facebook oEmbed end points which can find, filter and engage with customers across social media. Facebook oEmbed endpoints allow you to get embed HTML and basic metadata for pages, posts, and videos in order to display them in another website or app. Since Facebook official API documentation deprecated for getting recent media including feed content ,URL ,created timestamp, like/comment and share counts for feeds , I have designed a Facebook scraper to extract these information. Here I’m going to implement my solution using Node JS <a href="https://www.npmjs.com/package/puppeteer">puppeteer</a> as the automation tool and Mongo DB to store the collected feed data.</p><p>Puppeteer is a node library which provides high level API to control chrome or chromium and most of the things we can do manually in the browser can be done using puppeteer.</p><p>There are many 3rd party libraries exist that I have research but there are limitations since Facebook platform do updates for their CSS styles and classes we can not use dynamically generated class styles for our scraping to become a stable solution. So it is not a good practice to depend on a 3rd party solution because we can not ensure whether it going to work with Facebook latest updates. So I have designed a own Facebook wrapper using Node JS , Below I will going to explain step by step of my implementation.</p><p>So let’s get to do it.</p><p><strong>Pre-requisites:</strong></p><ul><li>Basic knowledge of Node JS</li></ul><p><strong>Step 01 :</strong></p><p>As the first step added initPuppeteer() method which import puppeteer library ,starts the browser and creates a new page as well as sets the browser width and height and override permissions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e922b1e619d9932e51bf3b4ef2786d1a/href">https://medium.com/media/e922b1e619d9932e51bf3b4ef2786d1a/href</a></iframe><p><strong>Step 02 :</strong></p><p>In this step I have added some common configuration messages in a separate file as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/087fbd4563a46fca046243e802ecbf0d/href">https://medium.com/media/087fbd4563a46fca046243e802ecbf0d/href</a></iframe><p>Here we’ll add a loginFacebook() which visits Facebook website and wait until network idle and wait until it appears the login UI and perform login action as below.</p><p>I have put random timeouts to wait for actions because if the actions are too fast our bot will be easily detected by Facebook which may result in our account being blocked or blacklisted.</p><p>Here I have select the UI elements by evaluating the inner HTML because selectors are changing randomly in Facebook.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2d4f23d6fe98183fc0f12549bb08844/href">https://medium.com/media/e2d4f23d6fe98183fc0f12549bb08844/href</a></iframe><p><strong>Step 03 :</strong></p><p>In this step We’ll going to start the scraping based on filter tags such as @mentions/keywords/hashtags. So my next step would be to direct to the Facebook page based on the filter tag as below . I have configured base URL in my configuration file.</p><pre>const page_url = config.base_url + filter_tag;</pre><pre>await this.page.goto(page_url, {</pre><pre>waitUntil: &quot;networkidle2&quot;,</pre><pre>});</pre><p>Next , I want to check whether the availability of the page to start the scraping steps as below. Here I have used some UI display text contents which indicate to the user about the page existence. So I have configured these possible messages in the configuration file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff8dfd384653127a3554f0dc042dbecc/href">https://medium.com/media/ff8dfd384653127a3554f0dc042dbecc/href</a></iframe><p><strong>Step 04 :</strong></p><p>Next , if the Facebook page available for the relevant filter tag I will going to scroll over the page and render the feeds to the DOM content as below. Here we can configure the no. of posts to be scraped using post_count parameter. Here I have identified that a single post is wrapped around div[role=&quot;article&quot;] tag. So I’m going to count the no . of div[role=&quot;article&quot;] tags being rendered to the DOM content by scrolling over the page .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9cc8ad519f42bade7b565c7e4d3c5300/href">https://medium.com/media/9cc8ad519f42bade7b565c7e4d3c5300/href</a></iframe><p><strong>Step 05 :</strong></p><p>My next step is to identify the posts to be extracted because in the previous step we finished the scrolling logic based on the div[role=&quot;article&quot;] tag but I have identified that it includes some other text contents too. So we need to filter out those. Here as a unique element I have identified that if its a post to be extracted its ariaLabel is a null value. Based on that I’m going to add a filter as below and for each post I’m going to return text content and inner HTML.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/746a36efb7f443b523b9363921fdd4d6/href">https://medium.com/media/746a36efb7f443b523b9363921fdd4d6/href</a></iframe><p><strong>Step 06 :</strong></p><p>As my next step I’m going to loop over my filter list and extract the post content, reactions count, share count and comments count and the post created timestamp. Here to extract these figures need to parse the post inner HTML through an HTML parser and get the root html as below. For that I have used <a href="https://www.npmjs.com/package/node-html-parser">node-html-parser</a> Which will generate a simplified DOM tree, with element query support.</p><pre>import { parse } from “node-html-parser”;</pre><pre>const root_html = parse(filtered_list[i].html);</pre><p><strong>Extracting post content :</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d81f62b0f45d79508af756d79432af43/href">https://medium.com/media/d81f62b0f45d79508af756d79432af43/href</a></iframe><p><strong>Extracting Comments count :</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86962baae952eed847c5e18d29597e59/href">https://medium.com/media/86962baae952eed847c5e18d29597e59/href</a></iframe><p><strong>Extracting Reactions count :</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f01f6aa35898e9b15b057ccd5430720d/href">https://medium.com/media/f01f6aa35898e9b15b057ccd5430720d/href</a></iframe><p><strong>Extracting Share count :</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/905836fddca29a72d37237d4d6f10f62/href">https://medium.com/media/905836fddca29a72d37237d4d6f10f62/href</a></iframe><p>As my next step , I need to format these data counts as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b6af665e17fbb52cf97b05a13dc42db/href">https://medium.com/media/7b6af665e17fbb52cf97b05a13dc42db/href</a></iframe><p><strong>Extracting post created Timestamp :</strong></p><p>Here , Facebook platform does not allow us to scrape the timestamp directly from the DOM content . They have ordered each element in the timestamp string using style tags. So We need to traverse over the span tags and need to find the style of these elements to find the order of them . Next in my logic I have inserted these elements to an array by using the style order as the array index. Next I have identified there are {display:none;} style classes which injected to these elements with the style order. So I need to skip these elements as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c43244459d4f5ec88aafdc60ce3ff06/href">https://medium.com/media/1c43244459d4f5ec88aafdc60ce3ff06/href</a></iframe><p>Next , We need to format post created time stamp in to a common format to save in the database for that I’m going to return the epoch time by formatting scraped post created timestamp.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49e33b677b5815d6502a60a3e10b0d82/href">https://medium.com/media/49e33b677b5815d6502a60a3e10b0d82/href</a></iframe><p>And after that I can create the post created time to save in the DB as below.</p><pre>const ymd_timestamp = moment</pre><pre>.unix(timestamp / 1000)</pre><pre>.format(config.date_time_format);</pre><p><strong>Step 07 :</strong></p><p>As my next step I need to extract the post URL to render the Facebook feeds in the web app using Facebook oEmbed as below. From the post actions I’m going to extract the feed oEmbed and using this string I will going to extract the post URL and post id as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab6d8e50d45183f46368cb7be8a81511/href">https://medium.com/media/ab6d8e50d45183f46368cb7be8a81511/href</a></iframe><p><strong>Step 08 :</strong></p><p>As the final step I’m going to update the Mongo DB with the extracted Facebook feed record in below format.</p><pre>let dataObj = {</pre><pre>post_id: post_id,</pre><pre>post_text: post_text,</pre><pre>screen_name: filter_tag,</pre><pre>post_created_at: ymd_timestamp,</pre><pre>attributes: {</pre><pre>share_count: share_count,</pre><pre>comment_count: comment_count,</pre><pre>reaction_count: reaction_count,</pre><pre>page_link: page_url,</pre><pre>link: post_url,</pre><pre>},</pre><pre>time_stamp: Math.round(new Date().getTime() / 1000),</pre><pre>};</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/073f144b747193c56f929d1c6ef99b77/href">https://medium.com/media/073f144b747193c56f929d1c6ef99b77/href</a></iframe><p>There are limitations in this solutions as</p><p>Facebook change UI element selectors frequently because of that I have evaluate the page to find out the visible text content and perform scraping. But there is a risk of changing those elements too. So we need to maintain our solution .</p><p>There are security concerns as if the scraper did many actions within a short time Facebook black listed for some time because of exceeding rate limitations.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb5864208126" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Instagram Bot using Python Node JS and RabbitMQ]]></title>
            <link>https://devanshanirasanjika-uom.medium.com/instagram-bot-using-python-node-js-and-rabbitmq-5c8f61d17523?source=rss-29a59e91772------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c8f61d17523</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[rabbitmq]]></category>
            <category><![CDATA[python-flask]]></category>
            <category><![CDATA[instagram]]></category>
            <dc:creator><![CDATA[Devanshani Rasanjika]]></dc:creator>
            <pubDate>Wed, 09 Mar 2022 17:45:58 GMT</pubDate>
            <atom:updated>2022-03-12T05:13:31.264Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*HgqgLPEAmubU7lcuYQeBfg.jpeg" /></figure><p>I’m working on a app which needs to implement Instagram actions which is able to like/unlike posts, follow/unfollow users and add comments for posts. Main purpose of my implementation is that user should be able to perform actions using a REST API. Since Instagram API’s deprecated for above actions we can not use their end points in my implementation directly. So I have designed an Instagram bot to perform those actions in server side using REST API. Here I’m going to implement my solution using Node JS <a href="https://www.npmjs.com/package/puppeteer">puppeteer</a> as the automation tool, <a href="https://www.rabbitmq.com/">RabbitMQ</a> as the message broker to communicate between Python &amp; Node JS and for the REST API implementation I have used Python Flask.</p><p>Puppeteer is a node library which provides high level API to control chrome or chromium and most of the things we can do manually in the browser can be done using puppeteer.</p><p>RabbitMQ is a widely deployed open source message broker or queue manager which gives our application a common platform to send and receive messages.</p><p>Below is the diagram of my implementation .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0nbwJAjCSpJZKVhvEBu1tA.png" /></figure><p>So Let’s get to do it.</p><p><strong>Pre-requisites:</strong></p><ul><li>Basic knowledge of Node JS</li><li>Basic knowledge of Python</li></ul><p><strong>Set up Python message broker :</strong></p><p>I have used python <a href="https://pika.readthedocs.io/en/stable/">pika</a> library to implement the message queue. As AMQP is a two-way RPC protocol where the client can send requests to the server and the server can send requests back to the client, Pika implements or extends IO loops in each of its asynchronous connection adapters.</p><p>So I have implemented message publisher from python and instagram_action_publish() is calling inside a REST API to publish messages to the queue. So here web application calls to the REST API written from python Flask and it will publish messages to the queue.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5470cf21baf97f5caeb1a91603757252/href">https://medium.com/media/5470cf21baf97f5caeb1a91603757252/href</a></iframe><p><strong>Set up Node JS Project :</strong></p><p>I have used npm-init to initialize the Node service and created app.js and executed node app.js command to test the application. Then installed puppeteer using npm i puppeteer npm i puppeteer-extra npm i puppeteer-extra-plugin-stealth for the automation script and installed <a href="https://www.npmjs.com/package/amqplib">RabbitMQ</a> using npm i amqp-connection-manager . This is a wrapper around <a href="http://www.squaremobius.net/amqp.node/">amqplib</a> which provides automatic reconnects.</p><p>And after that I have decided to have following folder structure.</p><ul><li>app.js</li><li>messageBroker/publishers/publisher.js</li><li>messageBroker/subscribers/subscriber.js</li><li>bot/instagramFunctions.js</li><li>bot/config/instagramConfig.js</li><li>nativeActions/instagramActions.js</li></ul><p>Below is the app.js code implementation which integrated log4js to configure logs and here subscribe to the message queue.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ebb3ec93a3c5d7f94dbcad37e086944/href">https://medium.com/media/2ebb3ec93a3c5d7f94dbcad37e086944/href</a></iframe><p>Then as the next step implemented message queue subscriber to subscribe the messages published from python service and call each Instagram action separately. And here I have configured Rabbitmq parameters and subscribed queue id in environment variables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37e05f0a94a9e7bb09776b7eed44e6e9/href">https://medium.com/media/37e05f0a94a9e7bb09776b7eed44e6e9/href</a></iframe><p>Then I have edited my instagramConfig.js file by adding the selectors and other configurations for the Instagram UI elements and network calls as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34dff58902dd158b01fdc25d4dae029e/href">https://medium.com/media/34dff58902dd158b01fdc25d4dae029e/href</a></iframe><p>Then I have edited my instagramFunctions.js file inside the bot folder by adding the automation script for the actions separately.</p><p><strong>Step 01 :</strong></p><p>As the first step added initPuppeteer() method which import puppeteer library ,starts the browser and creates a new page as well as sets the browser width and height.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00fb1422ed30498491cccbf7b1673a7b/href">https://medium.com/media/00fb1422ed30498491cccbf7b1673a7b/href</a></iframe><p><strong>Step 02 :</strong></p><p>In this step we’ll add a visitInstagram() which visits Instagram website and wait until network idle and wait until it appears the login UI and perform login action as below.</p><p>I have put random timeouts to wait for actions because if the actions are too fast our bot will be easily detected by Instagram which may result in our account being blocked or blacklisted.</p><p>Here I have select the UI elements by evaluating the HTML page because selectors are changing frequently in Instagram.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1973ccf9c751d5912a8aa91ca41cd08f/href">https://medium.com/media/1973ccf9c751d5912a8aa91ca41cd08f/href</a></iframe><p><strong>Step 03 :</strong></p><p>In this step we’ll add a likepost() which visits Instagram post using post url and wait until network idle and wait until it visible the post and perform like action and undo like action as below.</p><p>In this scenario I have used aria-label in HTML content to find the like span &gt; svg[aria-label = “Like”] and unlike span &gt; svg[aria-label = &quot;Unlike&quot;]buttons.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/343c7c238d3b61d001b473608f0adef0/href">https://medium.com/media/343c7c238d3b61d001b473608f0adef0/href</a></iframe><p>Here I need to verify that Instagram network call got success and returned a valid Json response by intercepting the like action back end API call as below using puppeteer. So there we can intercept and get the API URL , Json response and response status.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d42cc28890fadbf05225267bcb005b2/href">https://medium.com/media/4d42cc28890fadbf05225267bcb005b2/href</a></iframe><p>As same I implemented for the like action I have done for follow/unfollow users and comment on posts as below. Here I’m going to add the full code implementation for instagramFunctions.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/881c90110a3e842dec1c7d51e5a04108/href">https://medium.com/media/881c90110a3e842dec1c7d51e5a04108/href</a></iframe><p>Here I have added the full code implementation for instagramActions.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06f2320e608e81b54870b3932fa97d1d/href">https://medium.com/media/06f2320e608e81b54870b3932fa97d1d/href</a></iframe><p>Then publisher use to publish response back to python service like below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3401805d636ae36de50e2b7d6b66c656/href">https://medium.com/media/3401805d636ae36de50e2b7d6b66c656/href</a></iframe><p>And in the python service it will going to consume the response messages like below and send the response back to the web application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0336301c6b5160ad8a1c742f9606d594/href">https://medium.com/media/0336301c6b5160ad8a1c742f9606d594/href</a></iframe><p>There are limitations in this solutions as</p><p>Instagram change UI element selectors frequently because of that I have evaluate the page to find out the visible text content and perform click actions. But there is a risk of changing those end user visible text contents also. So we need to maintain our solution .</p><p>Puppeteer module use chromium browser to perform the bot as an automation script. Assume that user is going to login through Instagram credentials and going to perform multiple actions. But user can not perform those concurrently it going to crash the chromium browser. So user needs to wait until it finish previous action.</p><p>If single user needs to perform concurrently we need to handle many back end servers to run the script. So it will cost more.</p><p>There are security concerns as if the user tried many actions within a short time Instagram black listed the user.</p><p>With Puppeteer, Current response time for a single action is around 4–6 seconds. Assume10 users assigned to a particular instance are parallelly posting actions the response time will increase to an average of 20 seconds. This is due to the high memory usage from the chromium web browser instances that are created to run the actions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c8f61d17523" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React native: Implement Time range picker]]></title>
            <link>https://devanshanirasanjika-uom.medium.com/react-native-implement-time-range-module-ee4eacdd10eb?source=rss-29a59e91772------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee4eacdd10eb</guid>
            <category><![CDATA[datetimepicker]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[datepicker]]></category>
            <category><![CDATA[time-picker]]></category>
            <dc:creator><![CDATA[Devanshani Rasanjika]]></dc:creator>
            <pubDate>Wed, 13 Jan 2021 13:03:57 GMT</pubDate>
            <atom:updated>2021-02-25T16:16:32.040Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*m70zSfCc6FQI9w9YRQ77-Q.png" /></figure><p>I have working on a react native app which needs to implement a time range module which is able to input start and end time for the user and validate the start and end times using two min and max cut off times. Main purpose of my implementation is that main user should able to manage the app accessing time of sub users within their time range. In this post I’m going to share how I built it.</p><p>Here’s what the finished time range module looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*mxdsuxib5un6dxpS7ca0KA.gif" /></figure><p>So let’s get to do it!</p><p><strong>Implementation:</strong></p><p>Here I’m using <a href="https://www.npmjs.com/package/react-native-navigation">react-native-navigation</a> to show time picker as an overlay.</p><p>Here’s what the <strong><em>onPress</em></strong> function looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ee0f3c566eb4290dfbbc6f988d3090a/href">https://medium.com/media/0ee0f3c566eb4290dfbbc6f988d3090a/href</a></iframe><p>Here I’m sending start and end time separation data object ,localizations and <em>onpressOkFn</em> <em>function</em> as <em>passprops</em>. Initial format of the time separation object is as below.</p><pre>let time_separation_data = {</pre><pre>hours: 0,</pre><pre>minutes: 0,</pre><pre>is_am: false,</pre><pre>is_pm: false</pre><pre>};</pre><p>If there is a time range already set for the user we need to separate them as below by validating the default times.</p><p><strong>Time validation:</strong></p><pre>const isValidAgentStartEndTime = (time) =&gt; {</pre><pre>let is_valid_time = false;</pre><pre>if (time !== undefined &amp;&amp; time !== null &amp;&amp; time !== &#39;&#39;) {</pre><pre>is_valid_time = true;</pre><pre>}</pre><pre>return is_valid_time;</pre><pre>};</pre><p><strong>Time separation:</strong></p><pre>const separateTimeIn12h = (time) =&gt; {</pre><pre>let time_separation_data = {</pre><pre>hours: 0,</pre><pre>minutes: 0,</pre><pre>is_am: false,</pre><pre>is_pm: false</pre><pre>};</pre><pre>if (isValidAgentStartEndTime(time)) {</pre><pre>let time1 = time.split(&#39;:&#39;);</pre><pre>let hours = time1[0];</pre><pre>let minutes = time1[1];</pre><pre>let am_pm = parseInt(hours) &gt;= 12 ? TIME_LABEL.PM : TIME_LABEL.AM;</pre><pre>hours = parseInt(hours) % 12;</pre><pre>hours = hours ? hours : 12;</pre><pre>minutes = parseInt(minutes) &lt; 10 ? &#39;0&#39; + parseInt(minutes) : parseInt(minutes);</pre><pre>hours = hours &lt; 10 ? &#39;0&#39; + hours : hours;</pre><pre>time_separation_data = {</pre><pre>hours: hours,</pre><pre>minutes: minutes,</pre><pre>is_am: (am_pm === TIME_LABEL.AM) ? true : false,</pre><pre>is_pm: (am_pm === TIME_LABEL.PM) ? true : false,</pre><pre>am_pm: am_pm</pre><pre>};<br>}</pre><pre>return time_separation_data;</pre><pre>};</pre><p><strong>Time range module component:</strong></p><p>Below is the UI implementation of the time range module and initially I’m assigning start and end hours, minutes, am/pm configuration separately to state variables. Next I have implemented <em>TimeInputUIComponent.js </em>to render start and end time input modules. Here I’m using separate files for <em>constants</em> and <em>common functions </em>as it will help to manage the module easily. I will explain those later in my post and also you can find clearly in my source code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0eb7c3de672081d601eb4e820bb432b/href">https://medium.com/media/d0eb7c3de672081d601eb4e820bb432b/href</a></iframe><p><strong>Time input component:</strong></p><p>Below is the implementation of <em>TimeInputUIComponent.js </em>as a functional component. Here I’m using <a href="https://www.npmjs.com/package/react-native-masked-text">react-native-masked-text</a> for the text inputs. For the AM/PM switcher I have implemented a separate functional component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6dc0c178bbf541032504551fc2df0f7/href">https://medium.com/media/b6dc0c178bbf541032504551fc2df0f7/href</a></iframe><p><strong>AM/PM switcher component:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53126eddba24277fa47c9de2ebbeba2b/href">https://medium.com/media/53126eddba24277fa47c9de2ebbeba2b/href</a></iframe><p>Here I have implemented <em>onChangeText</em> function logics separately for start and end time inputs as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ae2f117aad7c6647523585887a4bf85/href">https://medium.com/media/0ae2f117aad7c6647523585887a4bf85/href</a></iframe><p>Here we need to validate the user input hours as below using <em>validateHourInput</em> function.</p><pre>const validateHourInput = (newHoursFromInput) =&gt; {</pre><pre>if (parseInt(newHoursFromInput) &gt; 24) {</pre><pre>console.log(&#39;validateHourInput&#39;);</pre><pre>return 12;</pre><pre>} else {</pre><pre>return convert12HourFormat(newHoursFromInput);</pre><pre>}</pre><pre>};</pre><p>I’m using a separate function to validate user input minutes as below. I have used <em>DEFAULT_TIME_VALUE as ‘00’ </em>which is declared as a Constant.</p><pre>const validateMinuteInput = (newMinutesFromInput) =&gt; {</pre><pre>if (newMinutesFromInput &gt; 59) {</pre><pre>console.log(&#39;validateMinuteInput 2&#39;);</pre><pre>return DEFAULT_TIME_VALUE;</pre><pre>} else {</pre><pre>return newMinutesFromInput;</pre><pre>}</pre><pre>};</pre><p>Further more I have implemented logics to validate user input start and end times with main users time range as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad6672f14bb3170d0c063de418cc3cff/href">https://medium.com/media/ad6672f14bb3170d0c063de418cc3cff/href</a></iframe><p>Finally I need to implement the logic for AM/PM button onPress as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ec2ded206c937873e3d76030311305f/href">https://medium.com/media/7ec2ded206c937873e3d76030311305f/href</a></iframe><p>The supporting functions that I have used to build logics are added separately as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1228eccad35f724a5101b543f168216a/href">https://medium.com/media/1228eccad35f724a5101b543f168216a/href</a></iframe><p>Below are the constants that I have used:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6617cfeefef5a8f5efa1c97c95cfb6c/href">https://medium.com/media/e6617cfeefef5a8f5efa1c97c95cfb6c/href</a></iframe><p>And that’s it for this post! This implementation is simple but you can build on top of it to select user inputs using clock icon and more sophisticated and feature rich.</p><p>You can find the full source code from <a href="https://github.com/DevanshaniR/TimeRangeModule">here</a>.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee4eacdd10eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React native: Creating chat bot assistant with splash screen animation]]></title>
            <link>https://devanshanirasanjika-uom.medium.com/react-native-creating-chat-bot-assistant-with-splash-screen-animation-9b800b65d842?source=rss-29a59e91772------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b800b65d842</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[flatlist]]></category>
            <category><![CDATA[chatbot-development]]></category>
            <category><![CDATA[chatbots]]></category>
            <dc:creator><![CDATA[Devanshani Rasanjika]]></dc:creator>
            <pubDate>Thu, 24 Dec 2020 09:14:00 GMT</pubDate>
            <atom:updated>2021-02-25T16:16:25.986Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xa_g8QGid2LrVMBivZoCSg.jpeg" /></figure><p>I’m working in a react native app which needs to implement a chat bot assistant to answer customer inquiries which is able to continue the conversation based on the answers selected by the customer. The relevant questions and answer sets are the predicted outputs of the trained machine learning model. Here customer selected answers are sent to the back end API and through back end a third party API is calling to get the predicted output of the machine learning model which will be the next question and answer set shown to the customer. In this post I’m going to share how I built it in react native based on machine learning model predictions.</p><p>Here’s what the finished chat bot assistant looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*isvZ5Xx9Y4WfspfjB-o3pw.gif" /></figure><p>So let’s get to do it.</p><h4>Define sample back end Json response:</h4><p>Here I’m defining a type for each array item such as TEXT, LIST . If answer array is empty I’m defining the type of the data item as a TEXT and if there is an answer list I’m defining the type as a LIST. It will helpful to you when creating the UI for conversation items. If you need you can add more types according to the same format to make feature rich output.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe373c2168b07062e9977a86bfcb2258/href">https://medium.com/media/fe373c2168b07062e9977a86bfcb2258/href</a></iframe><h4>Implementation:</h4><p>As my initial implementation I’m calling the back end API in chat bot view <em>componentDidMount </em>method<em>.</em></p><pre>this.props.chatBotInitiate(requestParams, this);</pre><p>Then I need to update the back end response to a redux state. Here I’m going to create another chat temp object to manipulate data in app side as same as the back end response format. Then I update the app side temp object to a different redux state inside a <em>setTimeout</em> method and I called another <em>setTimeout</em> inside it to update only the welcome message of the back end response to the app side temp object. Here my objective is to render dot indicator with a delay in seconds and then render splash screen with the welcome message.</p><p>Below is the implementation of <em>chatBotInitiate </em>function<em>.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c05d8e0276dd7f31ede4208b4ea6a873/href">https://medium.com/media/c05d8e0276dd7f31ede4208b4ea6a873/href</a></iframe><p>Here I’m rendering the content inside <em>ChatBotMainView.js </em>by<em> </em>using the redux state. This is how it looks like in the <em>ChatBotMainView.js. </em>As<em> </em>I explained above in the first <em>setTimeout</em> method I’m updating the redux state with an empty data array and empty welcome message to render <em>dotIndicatorView. </em>Then<em> </em>in the second<em> setTimeout </em>method I’m updating the redux state with welcome message to render splash screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2957d566ed6d75a18389ab95d47f549c/href">https://medium.com/media/2957d566ed6d75a18389ab95d47f549c/href</a></iframe><p>In the second <em>setTimeout </em>method after updating the splash screen next I’m going to render the data list as a Flat list by updating data items recursively using another <em>setTimeout</em>. Here we need to update the welcome message as empty to render the conversion content. Then I’m updating the array items to the redux state recursively. Below is the recursion function that I have implemented.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26c710b8e4bb9596a5ab2f7fdda2e491/href">https://medium.com/media/26c710b8e4bb9596a5ab2f7fdda2e491/href</a></iframe><p>Finally we need to implement the UI of the conversation items using redux state. For that I have used a separate <em>chatItemView.js </em>to render list items. Here LIST and TEXT type items are coming from the back end response which is updated to app side chat temp object . Then we need to update the user selected answer to the same redux state using a different type as UI’s are different in questions, answer list and selected answer. Here I’m using the type as ANSWER. In the <em>clickAnswer </em>function if it is a LIST type item I’m calling <em>updateChatBotAnswers </em>to update the app side redux state.</p><pre>this.props.updateChatBotAnswers(item, this.props.chat_bot_ui_data, this.props.screen_context);</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7bd96b847955f8b256aeefbdef69908/href">https://medium.com/media/f7bd96b847955f8b256aeefbdef69908/href</a></iframe><p>Below is the implementation of <em>updateChatBotAnswers. </em>Here I’m updating the user selected answer to the app side redux state and finally need to call the back end API to get the response based on user selected answer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/463226b3a911e512dc3f647b568b891e/href">https://medium.com/media/463226b3a911e512dc3f647b568b891e/href</a></iframe><p>So from above chat bot example you can create a simple chat bot assistant and you can build on top of it to make you chat bot assistant feature rich and dynamic. Further you can integrate voice to text component and text input to get inquiries from the customer to make it more sophisticated.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b800b65d842" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implement Drag and Drop between multiple lists in a React App and renders web content in a React…]]></title>
            <link>https://devanshanirasanjika-uom.medium.com/implement-drag-and-drop-between-multiple-lists-in-a-react-app-and-renders-web-content-in-a-react-d9378a49be3d?source=rss-29a59e91772------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9378a49be3d</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[drag-and-drop]]></category>
            <category><![CDATA[flatlist]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Devanshani Rasanjika]]></dc:creator>
            <pubDate>Wed, 23 Dec 2020 15:07:34 GMT</pubDate>
            <atom:updated>2021-02-25T16:16:21.077Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Implement Drag and Drop between multiple lists in a React App and renders web content in a React native App</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EFIRrhys6aOAmFX4Qox7oQ.jpeg" /></figure><p>Here I’m going to implement drag and drop items between multiple lists using <a href="https://www.npmjs.com/package/react-beautiful-dnd">react-beautiful-dnd</a> which is able to control the draggable list items dynamically using back end Json response. Further more we can use this implementation as a react web application or deploy web app in a back end server and renders the web content in a react native app using <a href="https://www.npmjs.com/package/react-native-webview">react-native-webview</a>.</p><p>Main purpose of this post is to use this implementation in a react native app as we have some limitations when using gesture handler in react native.</p><p>In this post I’m going to share how I built it. Below we can see how the finished drag and drop dashboard looks like in a android device:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*aqWpArRvWOpHTDeIAwWEDw.gif" /></figure><p>So let’s get to do it.</p><h4>Set up Project:</h4><p>First thing you need to do is create React web app. You can find more information from <a href="https://create-react-app.dev/docs/getting-started/">here</a>.</p><p>Since functionality is dynamic and simple I’m going to do the implementation in the App.js.</p><p>Here’s what the initial component looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afba3893928579d96b189f30371575a9/href">https://medium.com/media/afba3893928579d96b189f30371575a9/href</a></iframe><p><strong>Import dependencies and define sample back end Json response:</strong></p><p>Now let’s import the dependencies and define the format of the back end response of the item list dynamically and assign to a state variable. As this is an initial implementation I have hard coded sample Json response inside App.js. Later we can have back end API to get dashboard item list dynamically according to same format and assign to the state.</p><p>Inside the item list array you can see I have added unique draggable id for each row and each row item has all the properties included as array objects.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b19ed9d144e922d061ac185c89c92d54/href">https://medium.com/media/b19ed9d144e922d061ac185c89c92d54/href</a></iframe><p><strong>Implementation:</strong></p><p>Here whole content is wrapped inside &lt;<em>DragDropContext&gt; </em>and state variable<em> itemList </em>mapped to a list using array map function to render rows dynamically. Each individual row is wrapped inside <em>&lt;Droppable&gt;</em>. For the individual item in each row <em>row_items </em>array which is inside each main item in state mapped to a list using array map function to render each item dynamically. Each individual item is wrapped inside <em>&lt;Draggable</em>&gt;.</p><p>Each &lt;<em>Droppable</em>&gt; and &lt;<em>Draggable</em>&gt; has a unique id and when drag and drop &lt;<em>DragDropContext</em>&gt; triggers <em>onDragEnd</em> method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/749f1f5599b118344a974774192d0ec9/href">https://medium.com/media/749f1f5599b118344a974774192d0ec9/href</a></iframe><p><strong>onDragEnd method implementation:</strong></p><p>Here the function receives the source and destination droppable id’s of the rows and source and destination array indexes of each item . Then we need to find the array indexes of source row and destination row using droppable id and re order items dynamically. If the droppable id’s are same the items are in the same row and I’m using <em>reorder</em> function to implement the logic. If the droppable id’s are different I’m using <em>move</em> function to implement the logic.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3da78ddff4390ead4c7d31795fa5d13/href">https://medium.com/media/b3da78ddff4390ead4c7d31795fa5d13/href</a></iframe><p><strong>Finished implementation:</strong></p><p>Below is the full App.js component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3847922ef60e2d5741dfe98723ebde13/href">https://medium.com/media/3847922ef60e2d5741dfe98723ebde13/href</a></iframe><p><strong>Host React Web app in a back end server:</strong></p><p>As this is an initial implementation I have deployed my web app in GitHub pages. You can find the publishing source configurations from <a href="https://dev.to/yuribenjamin/how-to-deploy-react-app-in-github-pages-2a1f">here</a>.</p><p>You can find the hosted web app from <a href="https://devanshanir.github.io/ReatWebApp/">here</a> and you can try the functionality in your device also.</p><p>As my main objective is to use the web content inside a react native app and do the drag and drop functionality, I’m using <a href="https://www.npmjs.com/package/react-native-webview">react-native-webview</a> to get the final output.</p><pre>&lt;WebView</pre><pre>source = {{uri:&#39;https://devanshanir.github.io/ReatWebApp/&#39;}}</pre><pre>style={{ flex: 1 }}</pre><pre>/&gt;</pre><p>And that’s it for this post! This implementation is simple but you can build on top of it to make your drag and drop between multiple lists more dynamic and feature rich as a React web app or render web content inside a WebView in React native app.</p><p>You can find the full source code from <a href="https://github.com/DevanshaniR/ReatWebApp">here</a>.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9378a49be3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React native : Drag and drop between two lists]]></title>
            <link>https://devanshanirasanjika-uom.medium.com/drag-drop-and-swap-between-two-lists-using-react-native-d864dab43aa9?source=rss-29a59e91772------2</link>
            <guid isPermaLink="false">https://medium.com/p/d864dab43aa9</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[drag-and-drop]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[flatlist]]></category>
            <dc:creator><![CDATA[Devanshani Rasanjika]]></dc:creator>
            <pubDate>Wed, 23 Dec 2020 07:04:39 GMT</pubDate>
            <atom:updated>2021-02-25T16:16:12.412Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>React native : Drag and drop between two lists</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iHrPfj5aw_w3qgoKZ_oiAw.jpeg" /></figure><p>I have working on a react native app which needs to implement drag and drop dashboard which is able to drag drop and swap items between 2 lists dynamically by changing only the back end Json response. For the implementation I have used <a href="https://www.npmjs.com/package/react-native-drax">react-native-drax</a> and need to install dependencies <a href="https://www.npmjs.com/package/react-native-gesture-handler">react-native-gesture-handler</a>. In this post I’m going to share how I built it.</p><p>Here’s what the finished drag drop and swap dashboard looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*lmkxQHGVtGnTsu3AJjgzmw.gif" /></figure><p>So Let’s get to do it!</p><h4><strong>Set up project:</strong></h4><p>The first thing you need to do is set up the project. I have used react native CLI to do and you can find more information from <a href="https://reactnative.dev/docs/getting-started">here</a>.</p><p>Since functionality is dynamic and simple I’m going to do the implementation in the App.js.</p><p>Here’s what the initial component looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5e898a1de81a14fdd9169add62dacf4/href">https://medium.com/media/a5e898a1de81a14fdd9169add62dacf4/href</a></iframe><p><strong>Import dependencies and define sample back end Json response:</strong></p><p>Now let’s import the dependencies and define the format of the back end Json response of the draggable item list and receiving item list and assign both to two different state variables. Here I have used state Hook to declare state variables. For the initial implementation I have hard coded the Json response in the App.js. Later we can have a back end API to get the dashboard item list in the same format and we can assign two arrays to the state hook.</p><p>Inside the draggable item list and receiving item list arrays you can see I have include all the properties of each item as array objects.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4c7f2a86cfe7ed95afb76c058a7718a/href">https://medium.com/media/a4c7f2a86cfe7ed95afb76c058a7718a/href</a></iframe><h4>Receiving zone component :</h4><p>Here state variable <em>receivingItemList</em> mapped to list using array map function to render <em>ReceivingZoneUIComponent</em> dynamically. Here items are swap between two lists inside <em>onReceiveDragDrop </em>function using array index. We can get the array index of the draggable item using <em>event.dragged.payload.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30f954cb388a52813632afa87b68f8c8/href">https://medium.com/media/30f954cb388a52813632afa87b68f8c8/href</a></iframe><h4><strong>Draggable component:</strong></h4><p>Here state variable <em>dragItemMiddleList </em>rendered inside<em> DraxList </em>dynamically using<em> DragUIComponent. </em>We can use the array index as the dragpayload , so draggable item can access using <em>event.dragged.payload </em>inside receiving zone.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/beff811db47eccbd31456bc2f8c2ddfe/href">https://medium.com/media/beff811db47eccbd31456bc2f8c2ddfe/href</a></iframe><h4><strong>Finished implementation:</strong></h4><p>Below is the full App.js component. Finally we need to wrap the view inside <em>GestureHandlerRootView </em>to work with gesture handlers and styles should be added as below.</p><pre>const gestureRootViewStyle = { flex: 1 };</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28af8a76c26911ff75d880972246e4a9/href">https://medium.com/media/28af8a76c26911ff75d880972246e4a9/href</a></iframe><p>And that’s it for this post! This implementation is simple but you can build on top of it to make your drag drop and swap between lists more dynamic and feature rich.</p><p>You can find the full source code from <a href="https://github.com/DevanshaniR/ReactnativeDragDropApp">here</a>.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d864dab43aa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>