<?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 Ritik on Medium]]></title>
        <description><![CDATA[Stories by Ritik on Medium]]></description>
        <link>https://medium.com/@ritikjain1272?source=rss-739dc89593b4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Ritik on Medium</title>
            <link>https://medium.com/@ritikjain1272?source=rss-739dc89593b4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 19:49:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ritikjain1272/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[Turning nginx into a payment gateway for AI agents]]></title>
            <link>https://ritikjain1272.medium.com/turning-nginx-into-a-payment-gateway-for-ai-agents-5a37bf8a7aee?source=rss-739dc89593b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a37bf8a7aee</guid>
            <category><![CDATA[l402]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Ritik]]></dc:creator>
            <pubDate>Thu, 09 Jul 2026 08:48:26 GMT</pubDate>
            <atom:updated>2026-07-09T08:48:26.693Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u6wmulkjaKKX0NjfNYmR4w.png" /></figure><p>Ever since AI agents took off, one problem keeps resurfacing: how does an agent pay for things on the web?</p><p>Not sign up. Not open a browser and type in a credit card. Not commit to a $20/month subscription it might use twice. Pay autonomously, per request, for exactly what it consumes.</p><p>The web actually reserved space for this decades ago. HTTP status code <strong>402 Payment Required</strong> has sat dormant in the spec since the early days of the internet — reserved “for future use,” waiting for a digital cash system that never arrived.</p><p>That future is finally showing up. In 2025, the 402 status code went from a curiosity to an active battleground: Cloudflare started experimenting with pay-per-crawl for AI bots, Coinbase launched the x402 protocol for stablecoin payments over HTTP, and a growing ecosystem of agent frameworks began treating “402” as a first-class response instead of an error.</p><p>This post is about <strong>L402</strong> — the Lightning-based flavor of that idea — and <strong>ngx_l402</strong>, an open-source nginx module that lets you put a machine-payable paywall in front of any API with a few lines of config.</p><h4>What is L402?</h4><p>L402 is an open-source payment and authentication protocol that lets services monetize API endpoints in a way AI agents can actually participate in. It uses the 402 status code as its handshake and Bitcoin’s Lightning Network as its payment rail.</p><p>If you’ve heard of <a href="https://x402.org/">x402</a>, the goal is similar — machine-native, pay-per-request HTTP payments — but the mechanics differ. x402 settles in stablecoins on-chain, L402 settles over <a href="https://lightning.network/">Lightning</a>, which means instant finality, fees measured in fractions of a cent, and no dependency on any specific blockchain’s gas market. L402 also bundles its own authentication layer (more on that below), so payment and access control travel together in a single token.</p><p><strong>Why does this matter?</strong></p><p>The internet’s billing infrastructure was built for humans: credit cards, sign-up forms, monthly subscriptions. Every one of those steps is a wall for an autonomous agent.</p><p>L402 replaces that with a pay-as-you-go model designed for machine-to-machine commerce. A client pays for exactly what it uses, when it uses it, down to a fraction of a cent — no account, no card on file, no contract.</p><h4><strong>How L402 works</strong></h4><p>Under the hood, L402 combines two technologies: the <strong>Lightning Network</strong> for payments and <strong>macaroons</strong> for access control.</p><p>Lightning is a Layer 2 protocol on top of Bitcoin. It enables instant, near-zero-fee transactions off-chain while anchoring final settlement in Bitcoin’s consensus.</p><p>Macaroons are the more interesting half. A traditional API key is a static string — the server has to look it up in a database on every request to figure out who you are and what you’re allowed to do.</p><p>A macaroon embeds its own permission rules (called <em>caveats</em>) directly inside the token, and any holder can restrict its scope further <strong>without ever talking to the server</strong>. Hold a root token? You can hand your sub-agent a copy capped at 100 requests and expiring in an hour, and the restriction is cryptographically enforced — no server round-trip, no database write. The server validates the whole permission chain locally with math.</p><p>In practice, the handshake looks like this:</p><p><strong>1. The challenge (HTTP 402).</strong> An unauthenticated client hits a protected endpoint. The server returns 402 Payment Required with two things in the headers: a Lightning invoice specifying the exact price in satoshis, and a macaroon whose validity is locked until that invoice is paid.</p><p><strong>2. The payment.</strong> The client’s Lightning wallet decodes the invoice and pays it off-chain. On settlement, the client receives a <strong>preimage</strong> — a secret value whose hash matches the payment hash in the invoice. It’s a cryptographic receipt: possessing the preimage is proof the payment happened, verifiable by anyone with the invoice.</p><p><strong>3. Stateless verification.</strong> The client resends the original request with the macaroon and preimage in the Authorization header. The server checks the receipt against the macaroon, enforces any embedded caveats, and forwards the request to the backend. No user database lookup, no billing ledger query — the verification is entirely local.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1uLIbXUAnRayMe_quxx0Rg.png" /></figure><h4><strong>Enter nginx l402: Bringing L402 to the Edge</strong></h4><p>ngx_l402 is an open-source nginx module that handles this entire lifecycle at the reverse-proxy layer. Instead of writing payment logic into your application, you offload the handshake to the web server itself.</p><p>What that buys you:</p><p><strong>Drop-in monetization.</strong> Wrap any backend API — legacy or modern — in a machine-payable paywall by adding directives to your nginx config.</p><p><strong>Backend isolation.</strong> Your application servers never touch Lightning, nodes, invoices, or macaroons. They receive plain, pre-authenticated HTTP requests only after nginx has confirmed payment.</p><p><strong>Rust under the hood.</strong> The module is written in Rust, so token validation runs with compile-time memory safety and enough throughput to sit in front of heavy agent traffic.</p><p><strong>Bring your own node.</strong> Invoice generation and settlement checks work against LND, CLN, Eclair, LNURL, NWC, and BOLT12 backends.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DHmXb3kcpaYDAGkjm08vDg.png" /></figure><p>Here’s what a pay-per-request paywall looks like in production:</p><pre>location /v1/weather {<br>    # Turn on L402 authentication for this location<br>    l402_auth on;<br>    <br>    # Define the cost per API call in millisatoshis (1000 msat = 1 sat)<br>    l402_amount_msat 10000;<br>    <br>    # Proxy passing directly to your standard, unauthenticated backend<br>    proxy_pass http://weather_backend_service;<br>}</pre><p>That’s the entire integration! <strong>The backend behind has no idea Bitcoin exists.</strong></p><h4>Closing the Loop: Web server as the billing system</h4><p>Remember the problem we started with — <strong>how does an AI agent pay for things on the web?</strong></p><p>By moving payments out of the application and into the infrastructure layer, the question stops being an architectural headache. You don’t rebuild your APIs, you don’t manage user databases, and your backend stays clean.</p><p>The web server itself becomes the billing system — and the dormant 402 spec finally does the job it was reserved for.</p><p>🚀 <strong>Ready to take L402 for a spin?</strong></p><p><strong>ngx_l402</strong> is fully open-source and actively evolving. Hack on it, read the docs, or star the repo to follow along:</p><p><a href="https://gitworkshop.dev/npub1qnw27f2jsqvn05wzpd56m7ykgmepk57p0yrzw8fzc7lfhjkmjmqqmd9r6h/relay.ngit.dev/ngx-l402">https://gitworkshop.dev/npub1qnw27f2jsqvn05wzpd56m7ykgmepk57p0yrzw8fzc7lfhjkmjmqqmd9r6h/relay.ngit.dev/ngx-l402</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a37bf8a7aee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GSoC Final Report — Aossie]]></title>
            <link>https://ritikjain1272.medium.com/gsoc-final-report-aossie-46b654e47885?source=rss-739dc89593b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/46b654e47885</guid>
            <category><![CDATA[aossie]]></category>
            <category><![CDATA[peer-to-peer]]></category>
            <category><![CDATA[gsoc]]></category>
            <dc:creator><![CDATA[Ritik]]></dc:creator>
            <pubDate>Sat, 21 Aug 2021 19:08:32 GMT</pubDate>
            <atom:updated>2021-08-25T09:27:53.302Z</atom:updated>
            <content:encoded><![CDATA[<h3>GSoC Final Report — Aossie</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/231/1*qVSr_NMThAqCD2PbKfipsw.png" /></figure><p>Hello guys, the second evaluation of the GSoC period has begun. The past 10 weeks were full of learning for me and I had a great learning experience. This blog post is a report of the work done that I have accomplished in this GSoC period for the peer-to-peer message transfer project.</p><p>Project link: <a href="https://gitlab.com/aossie/p2p-messaging-react-native">https://gitlab.com/aossie/p2p-messaging-react-native</a></p><h3>Introduction</h3><p>The project aims to design and develop a Peer-to-Peer Messaging app that does not rely on a central server to intermediate the messages across the peers. The app is intended to provide privacy, high communication efficiency, censorship resistance, and extra resilience to the users. Today we are dependent on social media platforms more than ever and these social-media platforms might take unfair advantage of the user data regardless of their privacy concerns. Therefore, a solution to this problem would be an app that does not rely on these intermediate servers (platforms) to relay the messages, hence the vulnerability of the user data would be protected and the much-needed respect would be given to the user&#39;s privacy.</p><p>Also, the app intends to provide users with peer-to-peer communication independent of network connectivity. This can be extremely useful in disaster-prone and remote areas (or even in case of a network outage) where network connectivity might not be a go-to thing. Hence, the app would be reliable and secure at the same time which is the main motivation to develop this application.</p><h3>Implementation</h3><p>The mode of transportation for the payload/messages is Bluetooth/WiFi. We are using the <a href="https://developers.google.com/nearby/connections/overview">Nearby Connection API</a> developed by Google to facilitate P2P offline communication. In order to increase the bandwidth for the communication range, we have introduced a simple hopping architecture based on the GossipSub protocol. So, let’s say there are three devices A, B, and C, where A and C are not in communication but B is in the communication range of both of A and C devices, we will use the B device as an intermediate node to relay our message from A to C. In this way, we can increase the bandwidth of the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*ctBUPAEkJnv8fMUAZiYVmA.png" /></figure><p>Google’s nearby connection API does not have any wrapper for the latest versions of react-native apps. Hence, a module is being developed in this GSoC period in order to port java code to be utilized in react-native. The future goal of this module would be a dedicated npm package for Nearby Connection API that can later be directly used in the app.</p><p>In order to make the app secure and end-to-end encrypted, we have used RSA Asymmetric encryption. In this algorithm, we have a pair of public and private keys. A user encrypts the message with the public key of the target peer. This message can only be decrypted with the private key of the target peer. In this way, an interceptor cannot understand/decrypt the message thereby making the app safe and secure.</p><p>The public keys have to be shared beforehand among the peers before they can start communicating with each other.</p><h3>Technologies used</h3><ul><li>React-Native</li><li>Google Nearby Connection API</li><li>RSA Asymmetric Encryption</li></ul><h3><strong>Merge Requests</strong></h3><ul><li><a href="https://gitlab.com/aossie/p2p-messaging-react-native/-/merge_requests/1">Merge Request 1</a> — Project setup and native code for discovery and advertisement to nearby devices</li><li><a href="https://gitlab.com/aossie/p2p-messaging-react-native/-/merge_requests/2">Merge Request 2</a> — Send and Receive messages from nearby devices</li><li><a href="https://gitlab.com/aossie/p2p-messaging-react-native/-/merge_requests/3">Merge Request 3</a> — Adhoc network implementation using GossipSub</li><li><a href="https://gitlab.com/aossie/p2p-messaging-react-native/-/merge_requests/8">Merge Request 4</a> — Sqlite database integration for the messages</li><li><a href="https://gitlab.com/aossie/p2p-messaging-react-native/-/merge_requests/9">Merge Request 5 </a>— Implementation of RSA encryption algorithm</li><li><a href="https://gitlab.com/aossie/p2p-messaging-react-native/-/merge_requests/10">Merge Request 6</a> — Fixed some bugs and added docs</li></ul><h3>Challenges</h3><p>The main challenge for me in the development of this project was to port the native code to react-native for Google’s Nearby Connection API. In the future, as I have mentioned above the main modus operandi will be to develop an entire npm package for the same which will then become a dependency on the app.</p><h3>Extra Reads</h3><ul><li><a href="https://gitlab.com/aossie/p2p-messaging-react-native">Working prototype (Phase 1)</a></li><li><a href="https://medium.com/nerd-for-tech/peer-to-peer-chat-app-using-webrtc-and-react-native-6c15759f92ec">Pre GSoC Blog</a></li><li><a href="https://docs.google.com/document/d/18DDmPKtJRy-dvH7TcNHWJG05-laCygd2_zg6MCnYrgE/edit">Proposal</a></li></ul><p>Lastly, I am really grateful to my mentors — Bruno, Thuvakaran, Madhav, and Aditya from whom I learned a lot, and also a big thanks to my team members, Harjeet and Tanya for helping me throughout GSoC journey.</p><p>Please feel free to ask any doubts regarding the implementation and I will be contributing further to improve the app.</p><p>Cheers :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46b654e47885" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Peer-to-Peer Chat app using WebRTC and React Native]]></title>
            <link>https://ritikjain1272.medium.com/peer-to-peer-chat-app-using-webrtc-and-react-native-6c15759f92ec?source=rss-739dc89593b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c15759f92ec</guid>
            <category><![CDATA[webrtc]]></category>
            <category><![CDATA[peer-to-peer]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Ritik]]></dc:creator>
            <pubDate>Sun, 23 May 2021 13:24:53 GMT</pubDate>
            <atom:updated>2021-08-21T19:07:28.011Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wondered about using a chat app that does not have any dependency on central servers?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*ra8hPRdS4WvtK04_nfmYSQ.png" /></figure><p>Hey fellow developers! Today we are going to develop a peer-to-peer chat application using react-native leveraging the power of <a href="https://webrtc.org/">WebRTC</a>. The inspiration for this article comes from the research during my pre-GSoC journey for <a href="https://gitlab.com/aossie">AOSSIE</a> organization where we are working on developing a similar application.</p><p>Now, let&#39;s first try to understand the core concepts from a high level, and then we will dig deep into the code. So, what the heck is WebRTC? WebRTC stands for Web Real-time communication. It is a free, <strong>open-source</strong> project that provides web browsers and mobile applications with real-time communication via simple APIs. The WebRTC technology was released as an open-source project by Google in May 2011. Now let’s try to understand how WebRTC works and how the connection is established among peers. I will try to break down the concepts into several points for better understanding.</p><h3><strong>Signaling</strong></h3><p>First of all, for the peers to chat with each other, we need to bridge a connection or a channel between them using which they can start communicating. And, for communication to get established between the peers we need to know who are the peers for which we have to establish the connection for. All the functionalities mentioned above are handled by the signaling server which uses a set of underlying protocols to discover the peers and negotiate/terminate a connection between them. Signaling exchanges configuration information and manages connections between peers/devices.</p><p><strong>In short, Signaling enables one peer to find another peer in the network and establish a channel of communication between them.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FGdB1awozWRRP8vT" /></figure><h3>RTCPeerConnection</h3><p>The Peer Connection is the core of the WebRTC. It provides a way for peers to create direct connections with their peers without the need for an intermediary server. It handles SDP (Session Description Protocol) which is responsible for the exchange of information between the peers for negotiation, codec implementations, NAT Traversal, packet loss, and data transfer.</p><h3>RTCDataChannel</h3><p>The RTCDataChannel is the network channel through which peers communicate with each other. RTCDataChannel is responsible for the exchange of all real-time data that is not audio-visual. Since we are developing a chat(text) application, we will be using this data channel. It offers developers a speedy and secure way to transport data from peer to peer. WebRTC transports its data over <strong>UDP</strong> (User Datagram Protocol). RTCDataChannel allows bi-directional data transfer directly between peers.</p><h3><strong>STUN and TURN Servers</strong></h3><p>The STUN stands for Session Traversal Utilities for NAT which allows clients to discover the public IP addresses of other peers in the network and the type of NAT they are behind. STUN servers, in most cases, are used for the connection setup, and once the connection is established data flow directly between the peers.</p><p>The TURN stands for Traversal Using Relays around NAT is used when STUN servers fail to establish a connection between the peers in certain cases.</p><h3>Codecs</h3><p>Before sending the data/media over a peer connection, it has to be compressed. Raw audio and video are simply too large to send efficiently over the internet. Likewise, after receiving media over a peer connection, it has to be decompressed. A media codec (coder-decoder) does exactly like this.</p><p>We can summarize the steps of working of WebRTC in the following way:<br>1. The initiating peer <strong>offers</strong> a connection to the signal server.</p><p>2. The receiving peer <strong>accepts</strong> the offer of the initiating peer from the signal server.</p><p>3. After accepting the offer, the two peers share config information about each other and negotiates a connection between them.</p><p>4. Once the negotiation is done, RTCPeerConnection is set up and peers can now chat with each other using this connection.</p><blockquote>Note: These concepts are just the tip of the iceberg. There are much more details and underlying protocols that are used in WebRTC. But, I have presented you with a highly abstracted version of it. Do let me know if you want a deep dive of WebRTC and I would be happy to write an article about the same.</blockquote><h3>Prerequisite</h3><ul><li>Basic understanding of <a href="https://reactnative.dev/">React-Native</a> library</li><li>Basic knowledge of <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API">WebRTC</a></li><li>Knowledge of <a href="https://www.tutorialspoint.com/unix_sockets/what_is_socket.htm">sockets</a></li></ul><p>Now, let&#39;s try to simulate the points mentioned above in our code. So, in order to implement the code, we will use the library <strong>react-native-webrtc</strong> which is the WebRTC module for react-native. Let’s make a react-native project. I will be using <strong>react-native-cli</strong> here. So, fire up your terminal and write:</p><pre>react-native init p2p</pre><p>Next, we will install the dependencies.</p><pre>yarn add @react-navigation/native<br>yarn add @react-navigation/stack<br>yarn add react-native-webrtc</pre><p>We will use react-navigation to navigate between different screens. Now, as per the <a href="https://reactnavigation.org/docs/getting-started/">documentation</a> of react-navigation, we need to install additional dependencies for react-navigation.</p><pre>yarn add react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view</pre><blockquote>Note: If you are using a react-native version lower than 0.60, link the dependencies using `<strong>react-native link </strong>command.</blockquote><p>For the discovery of peers in the network and establish a connection between them, we need a signal server. So, let&#39;s first write the implementation of our signal server. I will be using express and sockets for the same. So, we need to install them in our project. So, again in your terminal:</p><pre>yarn add express<br>yarn add socket.io<br>yarn add socket.io-client</pre><p>Now, make a file server.js in the root folder or any other folder (it does not matter) and add the following code. I have added comments for the explanation part of the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/068c5144c596e38fb81034586db829af/href">https://medium.com/media/068c5144c596e38fb81034586db829af/href</a></iframe><p>The socket connections will make much more sense after we implement our app logic. So, our app will work in the following way. The initiating peer will create a room. This room (code) will be shared with the receiving peer (kinda like google meet) and he/she will enter the room code on his/her app. In this way, both the receiving and initiating peer will join the room and can chat with each other.</p><p>So, on the Home screen, we will have a simple text field where users can enter/create a room code. So, make a Home.js file in the <strong>src/screens</strong> directory and add the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6bd18117837ddb9c28d221c3efeff76/href">https://medium.com/media/b6bd18117837ddb9c28d221c3efeff76/href</a></iframe><p>The code for the Home screen is pretty basic. We have added a text field where the peer can enter room code. Otherwise, we have a Create Room button that creates a new room for the initiating peer. Our Home screen will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*ic9AJPvTQffTVe82Ui_y_A.jpeg" /><figcaption>Home Screen</figcaption></figure><p>So, as said before, an initiating peer will simply generate a room and share the room id/code with the receiving peer. The receiving peer will enter the code in the field provided and they will get connected p2p.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*Q0uUdGDrsaByPZ7f2gwhkA.png" /></figure><p>Now, we will make a chat UI and implement the WebRTC logic. For the chat UI, we are going to use <a href="https://github.com/FaridSafi/react-native-gifted-chat"><strong>react-native-gifted-chat</strong></a><strong>. </strong>So, let’s install the library.</p><pre>yarn add react-native-gifted-chat</pre><p>Now, let&#39;s create a Chat screen Chat.js in the src/screens directory and implement the Chat UI and WebRTC logic. In the Chat.js add the following code. Again, I have added comments to explain what the code is actually doing and added some references as well.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3094556e609e9628c50fd4facd209635/href">https://medium.com/media/3094556e609e9628c50fd4facd209635/href</a></iframe><p>Huh, phew quite a long implementation. Now, one last thing we have to do is to update the App.js file so that we can show our Home and Chat screen to the user. Let’s jump to App.js file and make changes as per below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98015bba5ed7cd77a1eb773ad2329b04/href">https://medium.com/media/98015bba5ed7cd77a1eb773ad2329b04/href</a></iframe><p>Finally, we have completed our P2P application. Just start the signal server using node signal.js and we are good to go. Remember to provide IP ADDRESS of your network in the signal.js so that app can communicate with the server in order to run locally. Otherwise, you may also host the signal server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1E3VzKfiATiWibQq0HppjA.png" /><figcaption>P2P Message Transfer</figcaption></figure><p>So, this is our peer-to-peer message transfer using react-native and webrtc. The implementation is long and a little messy, so please don’t hesitate to ask any questions. You can connect with me on <a href="https://www.linkedin.com/in/rits1272/">LinkedIn</a>, <a href="https://twitter.com/Rits1272">Twitter</a>, and <a href="https://www.instagram.com/rits1272/">Instagram</a>.</p><p>You may find the source code for the app from here:</p><p><a href="https://github.com/Rits1272/Peer-to-Peer-Chat/tree/main/p2p">Rits1272/Peer-to-Peer-Chat</a></p><p>I hope you enjoyed and learned something valuable from this article. So, see ya until the next article and never forget to put semi-colons ;)- Adios</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c15759f92ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make a slack bot in python using Slack’s RTM API]]></title>
            <link>https://ritikjain1272.medium.com/how-to-make-a-slack-bot-in-python-using-slacks-rtm-api-335b393563cd?source=rss-739dc89593b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/335b393563cd</guid>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[slackbot]]></category>
            <category><![CDATA[slack]]></category>
            <category><![CDATA[slack-tips-and-tricks]]></category>
            <dc:creator><![CDATA[Ritik]]></dc:creator>
            <pubDate>Sat, 18 Apr 2020 11:37:32 GMT</pubDate>
            <atom:updated>2020-08-28T06:13:36.427Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wondered about creating a slack bot to help you come out of some trivial task you need to do every day?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GmYjL5fpAzkngX3jCLto-Q.png" /></figure><p>Hello developers! How you Doin’ :) I hope that you are spending your time productively. Today we are going to make a slack bot using python by leveraging the power of slack’s RTM API. The slack’s Real-Time Messaging API, RTM API for short is a “<a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API"><strong>WebSocket</strong></a>-based API that allows you to receive events from Slack in <strong>real-time</strong> and <strong>send messages as users</strong>”.</p><p>Slack bots are widely used nowadays as they help us to mitigate boring and time-consuming jobs. For our purpose, <em>we will be creating a bot that will help us find things to do when we’re bored</em>. So, for example, our slack bot can give activity to perform like to “start a book you’ve never gotten around to reading” or maybe “Shred old documents you don’t need any more” to help us get out of boredom. So without further ado let’s get started!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*fcwLWixk10G27dEqiHOM-Q.gif" /></figure><p>Let&#39;s jump-off straight by creating a slack app. A very important note here<em>: New slack apps can not use Real-Time Messaging API methods. So we need to create a </em><strong><em>classic slack</em></strong><em> app</em>. So, make sure that you create a classic slack app and not a new slack app. If you are interested to know the difference between the classic and the new slack apps, you can check it from <a href="https://api.slack.com/authentication/quickstart"><em>here</em></a>.</p><p>So, first of all, hit this <a href="https://api.slack.com/apps?new_classic_app=1">link</a> that redirects you to creating a classic slack app. Sign in to slack if you are not, click on <strong>Create New App </strong>and give your slack app a name and the workspace in which you want to install your app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MGaCC-RNW0wkAXMpvfsmSQ.png" /></figure><p>Here, I am giving my app name <strong>AmuseBot</strong> and the workspace in which I will be interacting with the bot will be <strong>TimelineWave</strong>. Click on <strong>Create App</strong> button. You will be navigated to the<strong> Basic Information</strong> page of your slack app after clicking on the create app button.</p><p>Now in the Basic Information page, we will tell the slack app what features and functionality we need to perform with the app. Since we just need a bot to exchange messages with the user we will choose <strong>Bots</strong> feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uGVbN180cOpEflXOML7h_A.png" /></figure><p>Now, we need to give scopes to our bot. The scope is basically the type of information a bot is allowed to access from the workspace. The scope can be like reading or sending messages from/to the channel etc. The slack provides a <strong>legacy bot user </strong>option<strong> </strong>that provides us with a bundle of scopes that will suffice our bot’s scope needs. So, by simply selecting “legacy bot user” we will get some basic bot scopes that will help us prevent selecting different scopes one by one for our bot from a huge list of scopes that slack app provides.</p><p>So, click on the <strong>Add Legacy Bot User </strong>button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eMXrpDNnxW7wvwBEjLkS_A.png" /></figure><p>Clicking on the button will prompt you to enter a<strong> Display Name </strong>and a <strong>default</strong> <strong>username</strong> for your bot. The display name will be the name of the bot that will appear on the slack workspace. Choose any display name and the default name for the bot of your choice. Here I am giving again the same AmuseBot name to the display name as well as the default username to my bot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OHN8RELajIgx6OQWkXDJSw.png" /></figure><p>So, our slack app part is done. One last thing left is getting the <strong>Bot User OAuth Access Token </strong>of the slack app so that we can receive events from the slack from our python script. So, navigate to the <strong>OAuth &amp; Permissions </strong>tab<strong> </strong>from the sidebar of your app and then install the app on your workspace. After you install the app, you will get the OAuth tokens. Copy the <strong>Bot User OAuth Access Token.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V5Lp5ohyhEyrSkQv2NQXyQ.png" /></figure><p>Just for a recap: we have created a classic slack app. We have then defined the features and functionalities our slack app is going to perform, given scopes to the app and lastly we have given our bot different kinds of name, duh!</p><p>Now, we will move ahead with our python script. The python script will basically read the messages from the slack and in turn sends back an appropriate response to the user. So, fire up your terminal and install <strong>slack client</strong> library that interfaces with the slack’s Real-Time Messaging (RTM) API using pip.</p><pre>pip install slackclient</pre><p>Make a file <strong>slackbot.py</strong> and add the following code into the file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96d0e458bbed0c62c4e1c6edf4d55165/href">https://medium.com/media/96d0e458bbed0c62c4e1c6edf4d55165/href</a></iframe><p>The code here is fairly simple to understand. First, we have imported the RTMClient from slack which provides information about different events occurring on slack. Next, we have made a function <strong>amusebot </strong>that triggers whenever an event of<strong> type message</strong> occurs in the slack. So the function ignores all events which are not related to message type event. So, whenever someone sends a message on slack our amusebot function will trigger. Here <strong>payload</strong> in the amusebot function is an argument that receives the keyworded, variable argument list from the slack. We will extract the relevant data from the payload variable list like the web_client, bot_id, text sent by the user, etc. One more important thing is we have written an if statement to check if the message sent on the slack is not of the bot. If we don’t use this conditional statement then the bot will keep messaging and then replying to itself forever.</p><p>We have used <a href="http://www.boredapi.com/"><strong>bored API</strong></a><strong> </strong>for some activities to be sent to the user. You can try using different APIs like “pokeApi” which gives information on different pokemon. You can also try “wiki API” which can give the user an ability to read the information from Wikipedia on their slack workspace. If you are interested in more ideas on different APIs for your bot, you can check out my friend’s insta page <a href="https://www.instagram.com/ivejo3000/">ivejo3000</a>. The page is all about the information on different cool APIs.</p><p>So we then make a GET request to the bored API, extract out the activity part from the JSON response and send it back to the user using slack’s <strong>chat_postMessage method</strong>.</p><p>And at last, we have created an instance of RTMClient where we have passed the “Bot User OAuth Access Token” and we have started our bot using RTMClient’s start method.</p><p>Now you can interact with the bot after running the script after inviting the bot to your workspace. For inviting the bot simply send a message @YOUR_BOT_DISPLAY_NAME to the workspace in which you have installed the bot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QKnceDQfFudJUR9rJX_z8g.png" /></figure><p>So now whenever you get bored and want some ideas to get rid of boredom you can simply hop over onto your slack and find some amusing thing to do. I hope that you now have got a basic idea of how you can create a slack app that can really help you out in many ways. If you have any doubts feel free to ping me in person or in the comment section. You can also share your slack bot ideas in the comment section. You can connect with me on <a href="https://www.instagram.com/rits1272/">Instagram</a> and <a href="https://twitter.com/Rits1272">Twitter</a>.</p><p>Show some love with claps if you learned something valuable from this article. And yeah the most important thing, <strong>never forget to put semi-colons ;)</strong> <strong>Adios</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*0ViA3hZ-DCRwi1mV0sCboA.gif" /><figcaption>I hope I didn’t remind you of the Friend’s Reunion xd</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=335b393563cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making Drawer Navigator and a splash screen on your react native app!]]></title>
            <link>https://ritikjain1272.medium.com/making-drawer-navigator-and-a-splash-screen-on-your-react-native-app-2fb561ee17f1?source=rss-739dc89593b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fb561ee17f1</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[splash-screen]]></category>
            <dc:creator><![CDATA[Ritik]]></dc:creator>
            <pubDate>Fri, 24 Jan 2020 10:28:55 GMT</pubDate>
            <atom:updated>2020-01-24T10:28:55.299Z</atom:updated>
            <content:encoded><![CDATA[<h3>Making Drawer Navigator and a splash screen in your react native app!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*9k1t4oM8J2vD1mIeVz8fdQ.jpeg" /></figure><p>Hello developers! Welcome to the very new React Native drawer tutorial. So in this tutorial, we are going to make a react native drawer with the help of React Navigation and we are also going to create a splash screen. Pretty nice, huh? So let&#39;s jump right into it!</p><p>So before writing some code I just wanted to show you what we are actually going to make today so that you may have a brief idea of how things are working out before writing code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ILEO1Zl86CHCbt5qXGSQHw.gif" /><figcaption>Final App</figcaption></figure><blockquote>If you directly want to jump to the code you can check out the source code of this tutorial on my Github repo : https://github.com/Rits1272/DrawerNavigation.</blockquote><p>So first we need to create a react native project. I will be using <strong>react-native-cli </strong>here but you can also use expo. So fire up your terminal and write:</p><pre>react-native init app</pre><p>Next, we will install the dependencies. As said before we will be using <strong>React Navigation. </strong>React Navigation is basically a standalone library that allows developers to set up the screen and their navigation within few lines of code. You can check out more on react-navigation from <a href="https://reactnavigation.org/docs/en/getting-started.html">here</a>. So in the terminal inside your project directory install the dependencies:</p><pre>npm i --save react-navigation<br>npm i --save react-navigation-stack<br>npm i --save react-navigation-drawer</pre><p>React-navigation needs some dependencies too as described in the official documentation. So we will install those dependencies:</p><pre>npm i --save react-native-gesture-handler react-native-reanimated   react-native-screens react-native-safe-area-context</pre><p>Now we need to link these dependencies. So in your terminal:</p><pre>react-native link react-native-gesture-handler<br>react-native link react-native-reanimated<br>react-native link react-native-safe-area-context<br>react-native link react-native-screens</pre><p>If you are thinking why we are linking dependencies after installing it is because newly added native modules must be linked because they are out of the “default scope” of the project and in order to be available to the RN platform, they must follow the linking process.</p><p>For the hamburger icon of our drawer, we are going to use react-native-vector-icons. So make sure to install it and link it with our app.</p><pre>npm i --save react-native-vector-icons<br>react-native link react-native-vector-icons</pre><p>So after installation, we are ready to write some code. So the navigator that does the magic of creating a drawer in the app in react-navigation is <strong>createDrawerNavigator.</strong></p><p>In this app we will be creating three screens, one is the Home screen and the other two screens are About screen and Setting screen. We will also be creating a splash screen.</p><p>So going step by step first we will first create three screens Home.js, About.js, and Settings.js. So make an “src” folder and under it create the above the three files. Your project directory should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*QmpznpM73YUYJ3RlNb6x-Q.png" /><figcaption>Project Directory</figcaption></figure><p>In the Home.js file write the following basic code:</p><pre>import React, {Component} from &#39;react&#39;;<br>import {View, Text, StyleSheet, Button} from &#39;react-native&#39;;</pre><pre>export default class Home extends Component {</pre><pre>static navigationOptions = {<br>title : &quot;Home&quot;<br>}</pre><pre>render() {<br>return (<br>&lt;View style={styles.container}&gt;<br>&lt;Text style={{fontSize : 25, marginBottom : 20}}&gt;HOME SCREEN&lt;/Text&gt;&lt;Button<br>title=&#39;About&#39;<br>onPress = {() =&gt; this.props.navigation.navigate(&#39;About&#39;)}<br>/&gt;&lt;/View&gt;<br>);<br>}}</pre><pre>const styles = StyleSheet.create({<br>container: {<br>flex : 1,<br>justifyContent: &#39;center&#39;,<br>alignItems: &#39;center&#39;,<br>},<br>});</pre><p>You can copy-paste the same code to the About and Setting screen replacing the name of the class with About and Setting respectively. Now we have three screens for drawer navigation.</p><p>We will also make a Splash screen here. So make a file Splash.js inside your src folder and write the following code.</p><pre>import React, {Component} from &#39;react&#39;;<br>import {Text, View, StyleSheet} from &#39;react-native&#39;;</pre><pre>export default class Splash extends Component {</pre><pre>async componentDidMount() {<br><em>// You can load api data or any other thing here if you want<br></em>const data = await this.navigateToHome();<br>if (data !== null) {<br>this.props.navigation.navigate(&#39;Home&#39;);<br>}}</pre><pre>navigateToHome = async () =&gt; {<br><em>// Splash screen will remain visible for 2 seconds<br></em>const wait = time =&gt; new Promise((resolve) =&gt; setTimeout(resolve, time));<br>return wait(2000).then(() =&gt; this.props.navigation.navigate(&#39;Home&#39;))<br>};</pre><pre>render() {<br>return (<br>&lt;View style={styles.container}&gt;<br>&lt;Text style={{fontSize: 25}}&gt;SPLASH SCREEN&lt;/Text&gt;<br>&lt;/View&gt;<br>);<br>}}</pre><pre>const styles = StyleSheet.create({<br>container: {<br>flex: 1,<br>justifyContent: &#39;center&#39;,<br>alignItems: &#39;center&#39;,<br>},<br>});</pre><p>In the splash screen basically we are creating a promise. After the promise is resolved we are navigation to the Home Screen. Here you may have noticed that we have used a setTimeout function in which time interval is 2000ms. This time interval determines how much time we want to show the splash screen to the user. Meanwhile, in these 2 seconds you may also load up your API(if any).</p><p>Next comes the main part of making the navigation flow in our app. In the App.js file write up the following code:</p><pre>import React from &#39;react&#39;;<br>import {TouchableOpacity} from &#39;react-native&#39;;</pre><pre><em>// react-navigation<br></em>import {createAppContainer, createSwitchNavigator} from &#39;react-navigation&#39;;<br>import {createStackNavigator} from &#39;react-navigation-stack&#39;;<br>import {createDrawerNavigator} from &#39;react-navigation-drawer&#39;;<br>import Icon from &#39;react-native-vector-icons/FontAwesome&#39;;</pre><pre><em>// importing screens<br></em>import Home from &#39;./src/Home&#39;;<br>import Setting from &#39;./src/Setting&#39;;<br>import About from &#39;./src/About&#39;;<br>import Splash from &#39;./src/Splash&#39;;</pre><pre>// Adding Home and About in the same stack allows us to navigate to // About from Home and from Home to About screen</pre><pre>const <strong>HomeNavigator</strong> = createStackNavigator(<br>{<br>&#39;Home&#39;: {screen: Home,<br>navigationOptions: ({navigation}) =&gt; ({<br>headerLeft: () =&gt; (<br>&lt;TouchableOpacity<br>style={{marginLeft: 20}}<br>onPress={() =&gt; navigation.toggleDrawer()}&gt;<br>&lt;Icon name=&quot;indent&quot; size={25} /&gt;&lt;/TouchableOpacity&gt;<br>)})<br>},<br>&#39;About&#39;: {screen: About}<br>});</pre><pre>// Our second screen in the drawer will be Setting</pre><pre>const <strong>SettingNavigator</strong> = createStackNavigator(<br>{<br>&#39;Setting&#39;: {screen: Setting}<br>},{<br>defaultNavigationOptions: ({navigation}) =&gt; ({<br>headerLeft: () =&gt; (<br>&lt;TouchableOpacity<br>style={{marginLeft: 20}}<br>onPress={() =&gt; navigation.toggleDrawer()}&gt;<br>&lt;Icon name=&quot;indent&quot; size={25} /&gt;<br>&lt;/TouchableOpacity&gt;<br>),<br>}),<br>});</pre><pre><strong>// This navigator makes the drawer</strong></pre><pre>const <strong>DrawerNavigator</strong> = createDrawerNavigator({<br>Home: {<br>navigationOptions: {<br>drawerLabel: &#39;Home&#39;,<strong> // Name shown in the drawer of the screen</strong><br>},<br>screen: HomeNavigator,<br>},</pre><pre>Setting: {<br>navigationOptions: {<br>drawerLabel: &#39;Setting&#39;, <br>},<br>screen: SettingNavigator,<br>}});</pre><pre>// We used createSwitchNavigator because <strong>we don&#39;t want our user to </strong>//<strong> navigate back to Splash screen by pressing back button. </strong>Hence <br>// Splash screen just get seen once by the user.</pre><pre>const <strong>AppSwitchNavigator</strong> = createSwitchNavigator({<br>&#39;Splash&#39; : {screen : Splash},<br>&#39;Drawer&#39; : {screen : DrawerNavigator}<br>},<br>{<br>initialRouteName : &#39;Splash&#39; // Telling the navigator that the first       // route is Splash screen<br>})</pre><pre>const App = createAppContainer(AppSwitchNavigator);</pre><pre>export default App;</pre><p>So let us break down this code. First, we created two stacknavigators using <strong>createStackNavigator</strong>. Our first StackNavigator is “HomeNavigator” and the second one is “SettingNavigator”. StackNavigators, as the name suggests, allows us to create a stack of screens that allows us to navigate between screens easily present in the stack. So as you may have seen in the demo vid shown in the starting that we are navigating from Home to About and from About to Home Screen that is why we added Home Screen and About Screen in the same stack (which is HomeNavigator).</p><p>Next, we created SettingNavigator that is just another similar navigator as HomeNavigator. We have not added additional screens in this navigator. But if you want you can easily add more screens.</p><p>Now comes the DrawerNavigator. We add all the screens that we want to show in the Drawer. We want to show the Home screen and the Setting screen in the drawer. Therefore we added HomeNavigator and SettingNavigator in our DrawerNavigator.</p><p>Finally, we added our Splash Screen. You might be wondering why we have used createSwitchNavigator instead of createStackNavigator. The reason is quite obvious. If we had used StackNavigator then after the user navigates from the Splash screen to the Home screen the user may press the back button and he may get navigated back to the Splash screen and obviously we don&#39;t want that. SwitchNavigator prevents this to happen.</p><p>Last we created AppContainer for the SwitchNavigator.</p><p>So I have made a bird’s eye view of the navigation flow of our app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*z24RnaLYLm7wR7TCkNa4Vw.png" /></figure><p>I hope you may have understood how to create a drawer and splash screen in your app. Personally, I struggled a lot adding these in one of my apps that’s why I thought of writing this article on helping other fellow developers saving their time.</p><p>Thanks a lot! Never forget to put semi-colons ; ). <strong>Adios</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fb561ee17f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase and DialogFlow with React Native made easy(Part 3)]]></title>
            <link>https://medium.com/analytics-vidhya/firebase-and-dialogflow-with-react-native-made-easy-part-3-5bc42793b164?source=rss-739dc89593b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bc42793b164</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[dialogflow]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[chatbots]]></category>
            <dc:creator><![CDATA[Ritik]]></dc:creator>
            <pubDate>Tue, 14 Jan 2020 20:03:42 GMT</pubDate>
            <atom:updated>2020-01-22T04:49:12.422Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to use DialogFlow fulfillments in your react native app</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uXldg_eh7tvq2rmcj2kRnA.jpeg" /><figcaption>DialogFlow with React Native</figcaption></figure><p>Hello awesome developers! Welcome back to the final part of the tutorial series on ‘DialogFlow and Firebase with React Native made easy’. If you have missed out on the last two parts I highly recommend you check them out first from <a href="https://medium.com/@ritikjain1272/firebase-and-dialogflow-with-react-native-made-easy-301891afc4fb"><em>here</em></a>.</p><p>So, in this tutorial, we are going to make a personal savings tracker app. We will make a chatbot through which we can add or minor savings by simply telling the chatbot say ‘Add 500 to savings’ or ‘Remove 200 from savings’. We can also ask the chatbot to tell us about the current saving balance. I know that the idea is quite simple but for the purpose of our learning, it will suffice.</p><p>We will use Firebase for storing the savings data and DialogFlow fulfilments to grab the amount of the savings from the message given to the chatbot while adding/removing balance and then accordingly to add/remove the balance from Firebase. So let’s get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KVy6ikpOjzbPmwBGD0ZKKw.png" /></figure><p>First, we need to make an account on DialogFlow. So go to the official website of <a href="https://dialogflow.com/"><em>DialogFlow</em></a> and sign up with your Google account. After sign in you will see a window like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yiJX--c4K7IVae9vkKZOAA.png" /></figure><p>Here we will create a DialogFlow intent. But first of all what is ‘intent’? An <strong>Intent</strong> is a specific action that the user can invoke by using one of the defined terms in the Dialogflow console. For example, if a user asks “How is the weather today?”, so what intent will do is it will try to recognize this statement and will invoke an action based on what it is predefined for that particular intent’s action. The action invoked here could be like “ The weather is sunny today”.</p><p>So for our application, we will define three intents. The first intent will be for the <strong>current balance</strong>. The second intent will be for <strong>adding savings</strong>. The third intent will be for <strong>removing the balance</strong> from savings.</p><p>But before creating an intent we need to create an agent that will contain all our three intents. So click on <strong>Create Agent. </strong>I am giving the agent name ‘ChatApp’ but you can give any name of your choice. Click the <strong>Create</strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3FIo_e-1OLYKbwaNWI7BvA.gif" /><figcaption>Our first agent</figcaption></figure><p>Therefore, our first agent is created. Now we will create an intent. So in the side navigation menu of DialogFlow click on intents and then click on <strong>Create Intent </strong>button<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MMLsG5Sdjg3F7V6KVLE6iA.gif" /><figcaption>Create Intent</figcaption></figure><p>The first intent that we will create will be to for displaying our current saving balance. We will name this intent as <strong>‘ReadSavings’</strong> :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mqKPm05VPebhmSZSdIqicQ.png" /><figcaption>Intent</figcaption></figure><p>Hit the <strong>Save</strong> button and voila our first intent created. Now we need to give some T<strong>raining phrases</strong> to our intent. The training phases are basically what a user might say to our chatbot to show current savings. For example, a user may say ‘What is my current saving balance?’. So click on <strong>Add Training Phrases </strong>and add some phrases:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yIX-9RfxqVQJ1lBmjAxvWg.gif" /></figure><p>DialogFlow will create more possible phrases based on the given Training phrases that a user may say to our agent. This is the power of pre-trained Dialogflow’s NLP models.</p><p>So we first created an agent and then our intent. Now the intent must invoke an action when it recognizes that the user is asking for the current balance. The current balance data will be fetched from Firebase. But for reading data from Firebase through our agent we will need to enable webhook for the intent which will allow reading and writing operations on Firebase. So simple scroll down and under the Fulfilment subheading click on <strong>Enable webhook call for this intent.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*33Uydf-Rdlhuffk5omHDmg.gif" /><figcaption>Enable Webhook</figcaption></figure><p>Now to read savings from our database we will use <strong>Dialogflow Fulfilment </strong>which will basically send a request to our webhook service which in our case will be<strong> Firebase </strong>to fetch and change data from it<strong>. </strong>So from the side navigation bar go to Fulfilment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*YRkPZD4PacRxdu479LzFRw.gif" /></figure><p>Under the fulfillment, you will see an Inline Editor (disabled by default). Enable it. We write our code in this editor to send requests to the webhook clients.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6hqur45WI0EA9kHiA0pcHA.png" /></figure><p>So in the inline editor delete everything and write the following code:</p><pre>&#39;use strict&#39;;<br> <br>const functions = require(&#39;firebase-functions&#39;);<br>const admin = require(&#39;firebase-admin&#39;);<br>const {WebhookClient} = require(&#39;dialogflow-fulfillment&#39;);<br>const {Card, Suggestion} = require(&#39;dialogflow-fulfillment&#39;);<br> <br>admin.initializeApp({<br> credential: admin.credential.applicationDefault(),<br>   databaseURL:&#39;ws://<strong>your_project_name</strong>.firebaseio.com/&#39; <br><strong>// In the databaseURL give your own firebase url</strong><br>});</pre><pre>process.env.DEBUG = &#39;dialogflow:debug&#39;; // enables lib debugging statements<br> <br>exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) =&gt; {<br>  const agent = new WebhookClient({ request, response });<br>  console.log(&#39;Dialogflow Request headers: &#39; + JSON.stringify(request.headers));<br>  console.log(&#39;Dialogflow Request body: &#39; + JSON.stringify(request.body));<br> <br>  function welcome(agent) {<br>    agent.add(`Welcome to my agent!`);<br>  }<br> <br>  function fallback(agent) {<br>    agent.add(`I didn&#39;t understand`);<br>    agent.add(`I&#39;m sorry, can you try again?`);<br>  }<br>  <br>  function ReadSavings(agent){<br>  return admin.database().ref(&#39;<strong>firbase-project-name</strong>&#39;).once(&#39;value&#39;, snapshot =&gt; {<br>     const value = snapshot.val().notes;<br>        if(value !== null){<br>         agent.add(`Your current saving balance is ${value}`);<br>        }<br>      else{<br>       agent.add(&quot;Oops! It seems that no value has been returned from the database&quot;);<br>      }<br>    });<br>  }<br>  <br>  // Run the proper function handler based on the matched Dialogflow intent name<br>  let intentMap = new Map();<br>  intentMap.set(&#39;Default Welcome Intent&#39;, welcome);<br>  intentMap.set(&#39;Default Fallback Intent&#39;, fallback);<br>  intentMap.set(&#39;ReadSavings&#39;, ReadSavings);<br>  agent.handleRequest(intentMap);<br>});</pre><p>So it seems a quite complex right. Let&#39;s break it down. So based on what the user says to our chatbot the agent categorizes it to perform actions into one of the following intents- First is the <strong>fallback intent </strong>when it is unable to recognize what the user is intended to do. Second is the <strong>welcome intent</strong> where the Dialogflow understands that the user is saying greeting words like “Hi” or “Hello”. So, in this case, our chatbot reverts back with greetings to the user. So fallback and the welcome are the default intents in firebase. The third intent that we have created is <strong>ReadSavings</strong> which will send a request to firebase to read data from it and then show it to the user. So you may see that we have three functions for our intents to perform an action.</p><p>In the first few lines of code, we imported the firebase dependencies and the Dialogflow dependencies since we are going to make request on firebase. Then there are default actions for fallback and welcome intents.</p><p>Then we have defined actions to be performed in the ReadSaving intent. So basically we need to fetch data from the database in the ReadSaving intent. For that, we have used firebase predefined functions for doing that. One thing to note is that you need to add the firebase project name so that the agent knows to which project it has to make the request in the <strong>“databaseURL”</strong> as mentioned in the code above. You can go to the Database tab of the firebase and can opt for the ‘Realtime Database’ there. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AVoYi7ZQxvhe19-EPoJ2aw.png" /></figure><p>Once the agent captures the value it replies to the user with balance as mentioned inside the agent.add method in the above code. So let&#39;s see how it is working. But before doing that we need to first make changes to our react native app adding some configs of Dialogflow. For adding the configs we need to download a JSON file provided by Dialogflow.</p><p>So first go to settings (a cogwheel beside your project name). In the settings, click on the link beside the <strong>service account</strong>. It will redirect you to the Google Cloud Platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EaM-ICVrE-Fk1-ZqrrpYpQ.gif" /></figure><p>Find your project link and click on the three-dot icon under the ACtions and click on ‘<strong>create key’</strong> and download the file in <strong>JSON format</strong>. This file contains the config files of our project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vnghI7-QaXg4jzXUVUVZTg.gif" /></figure><p>Make a .env file and export configs like this of your JSON data:</p><pre>export const dialogflowConfig = {&quot;type&quot;: &quot;service_account&quot;,<br>&quot;project_id&quot;: &quot;your project id here&quot;,<br>&quot;private_key_id&quot;: &quot;your project key id here&quot;,<br>&quot;private_key&quot;: &quot;YOUR PRIVATE KEY&quot;,<br>&quot;client_email&quot;: &quot;your client_email here&quot;,<br>&quot;client_id&quot;: &quot;your client_id here&quot;,<br>&quot;auth_uri&quot;: &quot;your auth_uri here&quot;,<br>&quot;token_uri&quot;: &quot;your token_uri here&quot;,<br>&quot;auth_provider_x509_cert_url&quot;:&quot;Your auth_provider_x509_cert_url here&quot;,<br>&quot;client_x509_cert_url&quot;: &quot; your client_x509_cert_url here&quot;<br>}</pre><p>Also, we need to install DialogFlow dependency for react-native. So fire up your terminal and write :</p><pre>npm install --save react-native-dialogflow</pre><p>Now in your Home.js file add the following code. First, add the following imports.</p><pre>import { Dialogflow_V2 } from &#39;react-native-dialogflow&#39;;<br>import { dialogflowConfig } from &#39;./env&#39;; // env file that we created earlier</pre><p>Now we will load our configuration file. So we will use componentDidMount function. Inside the function write the following lines:</p><pre>componentDidMount() {<br>Dialogflow_V2.setConfiguration(<br>dialogflowConfig.client_email,<br>dialogflowConfig.private_key,<br>Dialogflow_V2.LANG_ENGLISH_US,<br>dialogflowConfig.project_id<br>);}</pre><p>Now inside the onSend function that we created earlier, we will send the user message to the Dialogflow and will receive the response from Dialogflow and will then show it to the user. For that:</p><pre>onSend(messages = []) {<br>this.setState(previousState =&gt; ({<br>messages: GiftedChat.append(previousState.messages, messages)<br>}));</pre><pre>let new_message = messages[0].text; //Latest msg entered by user</pre><pre><em>// This function sends message to the DialogFlow agent.</em>Dialogflow_V2.requestQuery(<br>message,<br>result =&gt; this.DialogFlowAgentResponse(result),<br>error =&gt; console.log(error)<br>);}</pre><pre>// Response from Dialogflow<br>DialogFlowAgentResponse(result) {<br>let text = result.queryResult.fulfillmentMessages[0].text.text[0];<br>this.reply(text); //<br>}</pre><pre><em>// This function will display the response</em><br>reply(text) {<br>let msg = {<br>_id: this.state.messages.length + 1,<br>text,<br>createdAt: new Date(),<br>user: BOT_USER<br>};</pre><pre>this.setState(currentState =&gt; ({<br>messages: GiftedChat.append(currentState.messages, [msg])<br>}));}</pre><p>This will be pretty much for taking the user query for reading the database and then displaying it to the user. Let’s check it out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*NHpbf8Qp9do0Bf8vyz_ikg.jpeg" /></figure><p>Pretty awesome! Huh?</p><p>Now for adding and removing the savings, I just need to define the two functions in the intent that would kinda look like (eg. for adding saving) :</p><pre>function AddSavings(agent){<br>   const text = agent.parameters.text;<br>    let total_savings;<br>    <br>    return admin.database().ref(&#39;notes&#39;).once(&#39;value&#39;, snapshot =&gt; {<br>     var current_savings = snapshot.val().notes;<br>        total_savings = parseInt(current_savings) + parseInt(text);<br>         admin.database().ref(&#39;notes&#39;).set({<br>          notes: total_savings,<br>     });<br>    });<br>  }</pre><p>I think that for grasping the content well you should build something on top of that. So I leave AddSavings and RemoveSavings for you. You need to do a little bit of research on how to take value from the user and pass it to the agent. But I guess that can be done easily and after completing the task you will also feel a sense of accomplishment which really drives us ahead in life.</p><p>So that’s the end of my three-part tutorial series on “React-native with Dialogflow made easy”. I hope you liked it. If you have any doubts feel free to ask in the comment and if you want to see the project, I have a Github link for this project where I also implemented visual graphs for the expenses.</p><blockquote><a href="https://github.com/Rits1272/ArtificialAdvisor">https://github.com/Rits1272/ArtificialAdvisor</a></blockquote><p>And at last, if your code gets break then don’t worry as one poor programmer said:</p><blockquote>Whenever there is code there will be bugs. The point is you need to find the useful code out of bugs before the bugs could find you (by- I guess that’s me ;) )</blockquote><p>Ending this article with the most important <strong>semicolon</strong>, <strong><em>Adios</em>;</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bc42793b164" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/firebase-and-dialogflow-with-react-native-made-easy-part-3-5bc42793b164">Firebase and DialogFlow with React Native made easy(Part 3)</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A beginner’s guide to host your site on GitHub pages]]></title>
            <link>https://ritikjain1272.medium.com/a-beginners-guide-to-host-your-site-on-github-pages-5d09ca933094?source=rss-739dc89593b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d09ca933094</guid>
            <category><![CDATA[hosting]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github-pages]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Ritik]]></dc:creator>
            <pubDate>Tue, 05 Nov 2019 19:57:04 GMT</pubDate>
            <atom:updated>2019-11-05T19:57:04.089Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*NvNxYIH_VybbraQ2MjJwCQ.png" /></figure><p>Hey guys! what’s going on? Today we will see how we can host a website on Github pages. Github Pages is a great way of hosting your static websites on the web.</p><p>In the Github pages, we can host directly from our GitHub repository. A repository is just a container in which you store all your code files. Just <strong>add, commit and push</strong> your code in the repo.</p><p>So, without further ado let’s get started!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*sgklUcvVJmb_zd0kQ6YUGQ.jpeg" /></figure><p>Before starting we must have a Github account. So if you don’t have an account on Github go to <a href="https://github.com/">https://github.com/</a> and make your Github account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ESIMZrtoupE4GyCXxi8T_w.png" /></figure><p>After creating the account, the first thing we need to do is to create a repo that will be hosted on the Github pages. So first click on <strong>New Repository </strong>to<strong> </strong>create a new repo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tQ7ijtwTyYr8cZl9tpqxtQ.png" /></figure><p>Here is a very important step. Always keep in mind that your <strong>repo name</strong> should always be <strong>YOUR_GITHUB_USERNAME.github.io</strong>. If you will not name your repo with your Github username then your website will not get hosted on Github pages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4jkLEsvVu0WAMY9f5vhu4Q.png" /></figure><p>As my Github username is <a href="https://github.com/Rits1272"><strong>rits1272</strong></a><strong> </strong>I will name my repo as ‘rits1272.github.io’. So finally we are done with creating our Github repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ee-obXm08ddp2K4QkyRiBA.png" /></figure><p>Next, we just need to push the content of our site that will be visible in our Github pages.</p><blockquote><strong>NOTE: </strong>Your home page should be named as <strong>index.html</strong>. Because index.html is the page that Github pages look in your repo for hosting your main (home) page.</blockquote><p>So simply push your website code files via git bash or by simply drag and drop interface provided by Github. So finally my final repo looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9FTLBivSzvFDTW5LPnyH9g.png" /></figure><p>You can check out my hosted repo at <a href="https://rits1272.github.io/">https://github.com/rits1272</a>. You can also check out additional resources from <a href="https://pages.github.com/"><em>here</em></a>.</p><p>Thanks a lot for your patience. If you really enjoyed the article let me know with your claps and for any suggestions mention down in the comments. So see you all until the next time!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*ClAlLwdBVJqECidXr8Zn_g.jpeg" /><figcaption>Thanks a lot!</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d09ca933094" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase and DialogFlow with React Native made easy (Part 2)]]></title>
            <link>https://ritikjain1272.medium.com/firebase-and-dialogflow-with-react-native-made-easy-part-2-23381151b445?source=rss-739dc89593b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/23381151b445</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[dialogflow]]></category>
            <dc:creator><![CDATA[Ritik]]></dc:creator>
            <pubDate>Sat, 26 Oct 2019 06:46:19 GMT</pubDate>
            <atom:updated>2019-10-26T06:46:19.878Z</atom:updated>
            <content:encoded><![CDATA[<p>How to integrate Firebase <strong>Authentication</strong> in your React-native app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zTdZMxbTkVdXCOoZlXLnsg.png" /></figure><p>Hello awesome developers! Welcome back to the <strong>second</strong> <strong>part</strong> of the tutorial series. If you haven’t checked out the first part, I highly recommend you to check out the first part from <a href="https://medium.com/@ritikjain1272/firebase-and-dialogflow-with-react-native-made-easy-301891afc4fb">here</a>. So in this post, we will learn how to <strong>integrate Authentication</strong> functionality provided by Firebase in our react-native app.</p><p>So without further ado let’s get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*E_VGCfG__JIMlZGUDqGCTA.jpeg" /></figure><p>First, we need to make a Firebase account. So go to <a href="http://firebase.google.com/">http://firebase.google.com</a> and click on Get Started and then sign in with your Google account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PPOVlk-cO3TDKctUnc9K4w.gif" /><figcaption>Firebase Home Page</figcaption></figure><p>After signing in you with your Google account you will see a page like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*RFbZfimuGSeSYjK8Pw8-sQ.jpeg" /></figure><p>Click on<strong> Add Project.</strong></p><p>After that, we need to give our project a name. So I am giving the name <strong>ChatApp</strong> but you can give any name of your choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RiT1Y57DxokcbGfPmjK0og.gif" /><figcaption>Step 1 of 3</figcaption></figure><p>Hit the <strong>Continue</strong> button and then just follow the basic steps shown in the pictures below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h8T951tB4mSDZiYXjDCvdQ.gif" /><figcaption>Step 2 of 3</figcaption></figure><p>Remember to change to <em>Default Account of Firebase</em> (if not ) in <em>Choose or Create a Google Analytics account </em>under<em> </em>the<em> Configure Google Analytics.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ASFgYnAzh_Ku4tp34tXW2Q.gif" /><figcaption>Step 3 of 3</figcaption></figure><p>Finally, click the <strong>Create Project</strong> button and finally you will be navigated to your console window!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*INRg3VNUcSz9x6Er7AnMDw.png" /><figcaption>Console window</figcaption></figure><p>Now with our account set up, we can start adding the Authentication functionality in our app. We will integrate <strong>Email Authentication</strong> in our react-native app.</p><p>So for using the Email Authentication we will have to create a firebase app. So click on the web-app icon under <em>Get Started by adding Firebase to your app </em>in the console window<em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_MUOt6T77QeMh3HA2jSxuA.gif" /></figure><p>After clicking the web-app icon we need to give our Firebase app a nickname. I have given ChatApp as the name of our Firebase app.</p><p>Click <strong>Register app</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Zv9z9czjkGjqTrgq3o3Zw.png" /></figure><p>The information about our Firebase app which we have just created is present in the <strong>firebaseConfig</strong> object. We will pass this firebaseConfig object in our react-native app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cjjj1GX6CURts15gPN9kew.jpeg" /></figure><p>Copy the firebaseConfig object and click <strong>Continue to console</strong>. As said before we need to pass this <strong>FirebaseConfig object</strong> to our react native app. But before doing that we first need to install firebase dependency in our react-native app. So fire off your terminal and install the Firebase:</p><pre>npm i --save firebase</pre><p>Now in the Login screen of our app, add the Firebaseconfig object that we copied before. We also need to change a little bit of code in the Login screen. So finally our code in the Login.js will look like this:</p><pre>import React, { Component } from &#39;react&#39;;<br>import { Container, Content, Form, Item, Input, Label, Button } from &#39;native-base&#39;;<br>import { Text, Alert } from &#39;react-native&#39;;<br><strong>import * as firebase from &#39;firebase&#39;;</strong></pre><pre>var <strong>firebaseConfig</strong> = {<br>apiKey: &quot;&lt;YOUR API KEY&gt;&quot;,<br>authDomain: &quot;&lt;YOUR AUTH DOMAIN&gt;&quot;,<br>databaseURL: &quot;&lt;YOUR DATABASE URL&gt;&quot;,<br>projectId: &quot;&lt;YOUR PROJECT ID&quot;,<br>storageBucket: &quot;&lt;YOUR STORAGE BUCKET&gt;&quot;,<br>messagingSenderId: &quot;&lt;YOUR MESSAGING SENDERID&gt;&quot;,<br>appId: &quot;&lt;YOUR APP ID&gt;&quot;,<br>measurementId: &quot;&lt;YOUR MEASUREMENT ID&gt;&quot;<br>};</pre><pre>if(!firebase.apps.length){<br>firebase.initializeApp(firebaseConfig);<br>}</pre><pre>export default class Login extends Component {<br>constructor(props){<br>super(props);<br><strong>this.state = {<br>email : &#39;&#39;,<br>password : &#39;&#39;,</strong><br><strong>}</strong>}</pre><pre>static navigationOptions = {<br>title : &#39;Login&#39;,<br>}</pre><pre><strong>loginUser</strong> = () =&gt; {<br>try{<br><strong>firebase.auth().signInWithEmailAndPassword</strong>(this.state.email, this.state.password).then((user) =&gt; {this.props.navigation.navigate(&#39;Home&#39;);})<br>}<br>catch(err){<br>console.log(err.toString());<br>}}</pre><pre><strong>signUpUser</strong> = () =&gt; {<br>try{<br>if(this.state.password &lt; 6){<br>Alert.alert(&#39;The password length is less than 6&#39;);<br>}</pre><pre>else{<br><strong>firebase.auth().createUserWithEmailAndPassword</strong>(this.state.email, this.state.password);<br>this.props.navigation.navigate(&#39;Home&#39;);<br>}}<br>catch(err){<br>console.log(err.toString());<br>}}</pre><pre>render() {<br>return (<br>&lt;Container&gt;<br>&lt;Content&gt;</pre><pre>&lt;Form&gt;<br>&lt;Item floatingLabel&gt;&lt;Label&gt;Username&lt;/Label&gt;<br>&lt;Input<br>onChangeText = {email =&gt; this.setState({email : email})}<br>placeholder = &#39;Username&#39;<br>value = {this.state.email}/&gt;<br>&lt;/Item&gt;</pre><pre>&lt;Item floatingLabel last&gt;&lt;Label&gt;Password&lt;/Label&gt;<br>&lt;Input<br>secureTextEntry<br>onChangeText = {password =&gt; this.setState({password : password})}<br>placeholder = &#39;Password&#39;<br>value = {this.state.password}<br>/&gt;<br>&lt;/Item&gt;</pre><pre>&lt;Button<br>onPress = {() =&gt; this.loginUser()}<br>style={{marginTop : 40}}<br>full dark block&gt;&lt;Text style={{color:&#39;#fff&#39;}}&gt;Login&lt;/Text&gt;<br>&lt;/Button&gt;</pre><pre>&lt;Button<br>onPress = {() =&gt; this.signUpUser()}<br>style={{marginTop : 15}}full dark block&gt;&lt;Text style={{color:&#39;#fff&#39;}}&gt;Register&lt;/Text&gt;&lt;/Button&gt;</pre><pre>&lt;/Form&gt;&lt;/Content&gt;<br>&lt;/Container&gt;<br>);}}</pre><p>In the code, we have added the <em>loginUser</em> and <em>signUpUser</em> functions and we have also created a state for storing the email and password input by the user. Inside the login and sign up functions we are doing nothing special. We are just using the default authentication functions provided by Firebase like for example in the loginUser function we are using firebase.auth().signInWithEmailAndPassword function for signing user in.</p><p>Now we need to tell the Firebase app that we are going to use Email Authentication. So in your console window click on <strong>Authentication</strong> in the left sidebar under the Develop section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*kmQB2KkdtYiXyV7Z92ywmw.png" /></figure><p>In the Authentication click on<strong> Set up sign-in method.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z8nXrLrY-UFNRLFC_x0AlQ.png" /></figure><p>Under the <strong>sign-in providers</strong> click on the <strong>Email/Password</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PRzrK2D70bdcZrfjmV2qjQ.png" /></figure><p><strong>Enable</strong> the Email/Password authentication and hit the <strong>Save</strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hQoe8hwpw9i6MQ8L2yAvTA.png" /></figure><p>And finally, the Authentication in our app is fully functional :). A user can now log in and Register in our app!</p><p>So in the coming last part of the tutorial series, we will learn about the DialogFlow fulfilments and see how we can use DialogFlow with the Firebase app created by us here and to integrate DialogFlow and use Firebase database in our react-native app.</p><p>I just wanted to share a side note that using Firebase and seeing its terms may seem overwhelming at first for a beginner and you may feel like :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*mtguSW3s8-G0OkDBTiJ19Q.gif" /></figure><p>But believe me, after your first hands-on you will get that Firebase is really very easy to use.</p><p>If you are liking this tutorial series do let me know with your <strong>claps</strong> and if you want to give any suggestion please mention down in the comments. So Bye-Bye and see you all until next time!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*2XGeoUliQ3aWdniNnRs3qw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23381151b445" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase and DialogFlow with React Native made easy]]></title>
            <link>https://ritikjain1272.medium.com/firebase-and-dialogflow-with-react-native-made-easy-301891afc4fb?source=rss-739dc89593b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/301891afc4fb</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[dialogflow-fulfillment]]></category>
            <category><![CDATA[dialogflow]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Ritik]]></dc:creator>
            <pubDate>Thu, 17 Oct 2019 19:04:01 GMT</pubDate>
            <atom:updated>2019-10-26T17:21:39.886Z</atom:updated>
            <content:encoded><![CDATA[<p>How to integrate Firebase Authentication and DialogFlow into your React Native app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1EnTazVI9QBzDEiZ3olM7Q.png" /><figcaption>Firebase + Dialogflow + React-Native</figcaption></figure><p>Hello guys! I hope you are doing well. So in this tutorial, we will be making a simple React Native chat application with Dialogflow. We will be using <strong>Dialogflow fulfilments </strong>so that our Dialogflow agent may fetch data stored in our Firebase. Also, we will integrate Firebase Authentication for the login and sign up functionality.</p><p>So after reading this tutorial, we will be able to understand how we can integrate Firebase and Dialogflow and its various functionalities in our react native app.</p><p>We will break down our tutorial into<strong> three parts</strong>. The first part will be a general introduction and UI of our app. In the second part, we will integrate the Firebase and in the third and the last part, we will integrate Dialogflow.</p><p>So first let’s have a brief introduction to Firebase and Dialogflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B0Av_NnFrCKsyC7gN94ytg.png" /></figure><p>So Firebase is a mobile and web app development platform that provides developers with a lot of tools and services to help them develop high-quality apps, grow their user base and earn more profit.</p><p>In our app, we will be using Firebase for authentication and data storage. You may also refer to Firebase’s official site from <a href="https://firebase.google.com/">here</a>.</p><p>Now comes the <a href="https://dialogflow.com/">DialogFlow</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5BHVh-5On_6t4OxkB460hQ.png" /></figure><p>Dialogflow is an end-to-end, build-once deploy-everywhere development suite for creating conversational interfaces for websites, mobile applications, popular messaging platforms, and IoT devices.</p><p>In simpler terms, <strong>Dialogflow</strong> is Google’s natural language understanding tool for building conversational experiences, such as voice apps and chatbots, powered by AI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*8sJrsHqZSsLJ3UVBtuUGRA.jpeg" /></figure><p>Okay, so that’s enough of theory. Let’s start coding. We will be using <a href="https://facebook.github.io/react-native/">React-Native </a>an open-source mobile development framework created by Facebook that lets you build apps for both android and ios with the same codebase.</p><p>So the first thing first. We will first create a react native project so fire up your terminal and start off by typing the commands :</p><pre>react-native init rnapp<br>cd rnapp</pre><p>We will be testing our app in our physical android device. You may refer the documentation if you are not comfortable creating apps without using expo from <a href="https://facebook.github.io/react-native/docs/getting-started">here</a>. Make sure that you run the following command in your <strong>rnapp </strong>directory.</p><pre>adb reverse tcp:8081 tcp:8081</pre><p>This command lets you run the development server running on your laptop to your mobile device.</p><p>So now let’s start the development server :</p><pre>npm start</pre><p>And you will be welcome with the following screen in your mobile app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*DXuIZn5LKDWqJ64hiN-FeA.jpeg" /></figure><p>Before proceeding, we will install the dependencies required for our app. So in your terminal using npm package manager we will install :</p><pre>npm i --save react-native-gesture-handler react-navigation react-navigation-stack</pre><p>We will need to link react-native-gesture-handler because newly added native modules must be linked because they are out of the “default scope” of the project and in order to be available to the RN platform, they must follow the linking process.</p><pre>react-native link react-native-gesture-handler<br>react-native run-android</pre><p>We will use native-base to design our UI part. You can refer to their documentation from <a href="https://docs.nativebase.io/">here</a>. So also let’s install native-base too.</p><pre>npm i --save native-base</pre><p>So in our app, we will be needing just two screens Login screen and Home screen.</p><p>So in your current directory(i.e. rnapp) make a folder named ‘Screens’ and inside the ‘Screens’ folder make two files Login.js file and Home.js file. So finally your file structure should look like :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*iDETM1duBCU4WJix9easHg.png" /><figcaption>Project Structure</figcaption></figure><p>So first set up the navigation flow of our app. On opening our app we will have a Login screen and after a successful login, we will be navigated to the Home screen. So in your <strong>App.js file</strong> remove all the code and add the following code :</p><pre>import {createAppContainer} from &#39;react-navigation&#39;;</pre><pre>import {createStackNavigator} from &#39;react-navigation-stack&#39;;</pre><pre>import Login from &#39;./Screens/Login&#39;;</pre><pre>import Home from &#39;./Screens/Home&#39;;</pre><pre>const MainNavigator = createStackNavigator({</pre><pre>Login : {screen : Login},</pre><pre>Home : {screen : Home},</pre><pre>},{</pre><pre>defaultNavigationOptions : {</pre><pre>headerTintColor : &#39;#fff&#39;,</pre><pre>headerStyle : {</pre><pre>backgroundColor : &#39;#000&#39;<br>}<br>}});<br>const App = createAppContainer(MainNavigator);<br>export default App;</pre><p>Next, add the following code to your <strong>Login</strong> Screen :</p><pre>import React, { Component } from &#39;react&#39;;<br>import { Container, Content, Form, Item, Input, Label, Button } from &#39;native-base&#39;;<br>import { Text } from &#39;react-native&#39;;</pre><pre>export default class Login extends Component {</pre><pre>static navigationOptions = {<br>title : &#39;Login&#39;,<br>}</pre><pre>render() {</pre><pre>return (</pre><pre>&lt;Container&gt;</pre><pre>&lt;Content&gt;</pre><pre>&lt;Form&gt;</pre><pre>&lt;Item floatingLabel&gt;</pre><pre>&lt;Label&gt;Username&lt;/Label&gt;</pre><pre>&lt;Input /&gt;</pre><pre>&lt;/Item&gt;</pre><pre>&lt;Item floatingLabel last&gt;</pre><pre>&lt;Label&gt;Password&lt;/Label&gt;</pre><pre>&lt;Input /&gt;</pre><pre>&lt;/Item&gt;</pre><pre>&lt;Button<br>style={{marginTop : 40}}<br>full dark block&gt;<br>&lt;Text style={{color:&#39;#fff&#39;}}&gt;Login&lt;/Text&gt;<br>&lt;/Button&gt;</pre><pre>&lt;Button<br>style={{marginTop : 15}}<br>full dark block&gt;<br>&lt;Text style={{color:&#39;#fff&#39;}}&gt;Register&lt;/Text&gt;<br>&lt;/Button&gt;</pre><pre>&lt;/Form&gt;</pre><pre>&lt;/Content&gt;<br>&lt;/Container&gt;<br>);<br>}}</pre><p>Now for the Home Screen, we need to implement the chat UI. For this, we don’t need to design it from scratch. Thanks to the react-native-gifted-chat package which we can simply install using npm and import it into our home screen. So back to your terminal :</p><pre>npm i --save react-native-gifted-chat</pre><p>After installation, run your server using npm start and then add the following code to your<strong> Home.js</strong> file</p><pre>import React from &#39;react&#39;</pre><pre>import { GiftedChat } from &#39;react-native-gifted-chat&#39;;</pre><pre>export default class Home extends React.Component {</pre><pre>static navigationOptions = {<br>title : &#39;Home&#39;,<br>}</pre><pre>state = {<br>messages: [],<br>}</pre><pre>componentDidMount() {</pre><pre>this.setState({<br>messages: [<br>{<br>_id: 1,<br>text: &#39;Hello developer&#39;,<br>createdAt: new Date(),</pre><pre>user: {<br>_id: 2,<br>name: &#39;React Native&#39;,<br>avatar: &#39;https://placeimg.com/140/140/any&#39;,<br>},<br>},<br>],<br>})<br>}</pre><pre>onSend(messages = []) {<br>this.setState(previousState =&gt; ({<br>messages: GiftedChat.append(previousState.messages, messages),<br>}))<br>}</pre><pre>render() {</pre><pre>return (<br>&lt;GiftedChat<br>messages={this.state.messages}<br>onSend={messages =&gt; this.onSend(messages)}<br>user={{<br>_id: 1,<br>}}<br>/&gt;</pre><pre>)}<br>}</pre><p>And after you have run the server your Chat UI in your home screen would look like this :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*cPP5Ig6gE_W1lguk2kPBbQ.jpeg" /></figure><p>So finally we are done with the UI part of our app. We will integrate Firebase in our next part of the tutorial.</p><p>I hope you are enjoying this tutorial and let’s catch up in the next part :).</p><p>The link for the second part is <a href="https://medium.com/@ritikjain1272/firebase-and-dialogflow-with-react-native-made-easy-part-2-23381151b445">here</a>.</p><blockquote>Thanks a lot!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*86J-jYybF7OC1ZRfyGmrCg.jpeg" /><figcaption>Thank You!</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=301891afc4fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are Neural Networks?]]></title>
            <link>https://ritikjain1272.medium.com/what-are-neural-networks-20ba68595ffe?source=rss-739dc89593b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/20ba68595ffe</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learni]]></category>
            <dc:creator><![CDATA[Ritik]]></dc:creator>
            <pubDate>Mon, 08 Jul 2019 20:00:25 GMT</pubDate>
            <atom:updated>2020-09-24T02:46:25.897Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ui3IvoiVYBFtaU0auj63ew.gif" /></figure><p>Hello Developers! How you doin’? So, today in this article we will try to understand what neural networks are not from funky mathematical equations and code but from a general perspective or intuition. So without further ado, let&#39;s get started!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*nnbrGfXPUzagbFqJMC1XeA.jpeg" /></figure><p>So first comes the <strong>WHY</strong>? Why we need an artificial neural network? The answer is simple: Human brains interpret the context of real-world situations in a way that computers can’t. So these networks were first developed in the 1950s to address this issue.</p><p>So now comes <strong>WHAT</strong>? What are neural networks? To answer this question, we first need to learn a little about our brain structure from where the inspiration of Artificial Neural Network has come into play.</p><p>So basically our human brain is made up of billions of neuron interconnected with each other thus forming a network giving us the power to do things which makes us the most complex living creatures to ever walked upon the earth.</p><p>But wait! what is a neuron? So remembering our good old school biology classes… A neuron is a cell that takes a piece of information(input), processes it and transmits the processed piece of information (output) to the next adjacent neuron which similarly does the same work again. As obvious a neuron is the fundamental unit of a neural network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NYmcCEyUQy56hgKUn4ZLAA.gif" /><figcaption>A single neuron</figcaption></figure><p>So when these billions of neurons in our brain (interconnected with each other) do the same job: receiving, processing, and transmitting the information, it makes up our whole biological neural network giving us the capability to learn things, recognize patterns, etc.</p><p>So coming back to the point an Artificial Neural Network a.k.a. ANN is a network modeling our biological neural network to do things that our human brain trying to do, basically learning things and recognizing patterns. A neuron in an ANN is known as a node and the interconnections between the neurons are known as a<a href="https://www.quora.com/What-does-weight-mean-in-terms-of-neural-networks"> <strong>weight</strong></a><strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*OdUsJrLlIsYcAnq_nU_ngw.png" /></figure><p>So when these neural networks are applied to real-world data, these neural networks try to learn and recognize data by continuously improving their learning capability by updating their <strong>weight values. </strong>Just like in our neural network the connections get stronger when we learn something better, similarly, in an ANN, the weight values get updated until they further can’t be made better. So in this way by continuously learning from their own mistakes (initial weight values) and updating them an ANN derives the power to do classification, recognize unknown patterns, make predictions, cluster similar types of data, etc.</p><blockquote>So at last we can say that computers now have the ability to understand the world around them in a very human-like manner thanks to the power of artificial neural networks.</blockquote><p>Thank you for giving your valuable time reading this article. If you liked it please appreciate and if felt <strong>any improvements</strong> do not forget to mention down in the comments. So see ya until next time!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V22PNIY_G6hL_iBD" /><figcaption>Photo by Kevin<a href="https://unsplash.com/@kevin_xue_pic?utm_source=medium&amp;utm_medium=referral"> Xue</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20ba68595ffe" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>