<?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 Onwuka Gideon on Medium]]></title>
        <description><![CDATA[Stories by Onwuka Gideon on Medium]]></description>
        <link>https://medium.com/@onwuka_gideon?source=rss-adbc4f40f48------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ZHRPVK331bkcZEit.</url>
            <title>Stories by Onwuka Gideon on Medium</title>
            <link>https://medium.com/@onwuka_gideon?source=rss-adbc4f40f48------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 14:43:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@onwuka_gideon/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[I Built a Local Gateway for Using ChatGPT and Gemini from VS Code]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-link"><a href="https://medium.com/@onwuka_gideon/i-built-a-local-gateway-for-using-chatgpt-and-gemini-from-vs-code-301f1f47772b?source=rss-adbc4f40f48------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@onwuka_gideon/i-built-a-local-gateway-for-using-chatgpt-and-gemini-from-vs-code-301f1f47772b?source=rss-adbc4f40f48------2</link>
            <guid isPermaLink="false">https://medium.com/p/301f1f47772b</guid>
            <category><![CDATA[model]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[google-gemini]]></category>
            <dc:creator><![CDATA[Onwuka Gideon]]></dc:creator>
            <pubDate>Tue, 08 Sep 2026 11:44:01 GMT</pubDate>
            <atom:updated>2026-09-08T11:46:07.952Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Laravel Illuminate\Contracts\Container\BindingResolutionException]]></title>
            <link>https://medium.com/@onwuka_gideon/laravel-illuminate-contracts-container-bindingresolutionexception-70fda953e7af?source=rss-adbc4f40f48------2</link>
            <guid isPermaLink="false">https://medium.com/p/70fda953e7af</guid>
            <category><![CDATA[middleware-class]]></category>
            <category><![CDATA[resolutionexception]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Onwuka Gideon]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 19:33:33 GMT</pubDate>
            <atom:updated>2021-12-29T19:35:16.707Z</atom:updated>
            <content:encoded><![CDATA[<p>After a while off the PHP land, I started a project where I have a middleware that checks if a logged-in user is a user or admin, then redirects them to their respective route.</p><p>As usual, I faced an error that bugged me for a while :) :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yxYvdDPstR5WTTbEVEODBg.png" /></figure><p>Looking innocently, I don’t think I did something wrong. It works locally! but when I push it to production, I keep getting the error:</p><pre>Target class [App\Http\Middleware\IsUser] does not exist.</pre><ol><li>I have created the middleware class `IsUser` in the correct folder — `/app/Http/Middleware/isUser.php`</li><li>And you can see the class file well placed:</li></ol><pre>&lt;?php</pre><pre>namespace App\Http\Middleware;<br></pre><pre>use Closure;</pre><pre>use Illuminate\Http\Request;</pre><pre>use Illuminate\Support\Facades\Auth;</pre><pre>use App\Providers\RouteServiceProvider;</pre><pre>class IsUser</pre><pre>{</pre><pre><em>/**</em></pre><pre><em>* Handle an incoming request.</em></pre><pre><em>*</em></pre><pre><em>* @param  \Illuminate\Http\Request  $request</em></pre><pre><em>* @param  \Closure  $next</em></pre><pre><em>* @return mixed</em></pre><pre><em>*/</em></pre><pre>public function handle(Request $request, Closure $next)</pre><pre>{</pre><pre>   if (Auth::check()) {</pre><pre>       if (Auth::user()-&gt;isAdmin()) {</pre><pre>           return redirect(RouteServiceProvider::ADMIN_HOME);</pre><pre>        }</pre><pre>        return $next($request);</pre><pre>   }</pre><pre>   return redirect(&#39;/login&#39;);</pre><pre>  }</pre><pre>}</pre><p>3. And of course, I registered the middleware in the kernel.php file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iEpguKGH5Tqh017CxgIm-g.png" /></figure><p>So what now?</p><h4>How I fixed it</h4><p>It turns out to be an issue of case sensitivity. Since it’s working fine locally with the code, and if I push the code properly into the server, it does not work.</p><p>Notice, I registered the middleware in the kernel.php file as :</p><pre>\App\Http\Middleware\IsUser::class</pre><p>I have saved my class earlier as `isUser.php` instead of `IsUser.php` to match the middle class I registered in the kernel.php file.</p><p>So just changing the file from `isUser.php` to `IsUser.php` fixed it for me.</p><h4>Conclusion</h4><p>If you are facing the same issue, make sure your file name matches the class middleware you registered to the kernel.php file.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70fda953e7af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to integrate voice messages into your Stream chat application]]></title>
            <link>https://medium.com/@onwuka_gideon/how-to-integrate-voice-messages-into-your-stream-chat-application-2ccabd9ff1ad?source=rss-adbc4f40f48------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ccabd9ff1ad</guid>
            <category><![CDATA[stream-chat]]></category>
            <category><![CDATA[stream]]></category>
            <category><![CDATA[getstream]]></category>
            <category><![CDATA[chat]]></category>
            <category><![CDATA[voices]]></category>
            <dc:creator><![CDATA[Onwuka Gideon]]></dc:creator>
            <pubDate>Fri, 04 Sep 2020 12:36:39 GMT</pubDate>
            <atom:updated>2020-09-05T20:17:21.056Z</atom:updated>
            <content:encoded><![CDATA[<p>A voice message is a message containing audio of one’s voice. They have been around for quite a while and have been widely adopted by users around the world as a convenient way of sending normal or time-sensitive messages.</p><p>In this article, I’ll walk you through integrating a voice messages feature into your stream chat app using the <a href="https://getstream.io/chat/docs/?language=js">Stream Chat SDK</a> and Vanilla <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript">JavaScript</a>. Knowledge from this tutorial will help you integrate a similar feature into any javaScript framework that you use.</p><p>You can get the complete source code of this tutorial on <a href="https://github.com/dongido001/stream-voice-message.git">GitHub</a>.</p><p>Here is a preview of what we will be building:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/0*NjXBL2ILmoNztnx0" /></figure><h3>Prerequisite</h3><p>You should have a basic understanding of <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript">JavaScript</a> and <a href="https://nodejs.org/">Node.js</a> to be able to follow this tutorial conveniently.</p><p>Install <a href="https://nodejs.org/">Node.js</a> if you don’t have it installed already. You can confirm if you have Node.js installed by running the below command on your terminal:</p><pre>node -v</pre><p>If Node.js is installed, you will see the node version printed out. Otherwise, you will get an output similar to command not found: node.</p><p>Finally, I recommend that you install the <a href="https://www.npmjs.com/package/nodemon">nodemon</a> package, which will automatically restart the node application when it detects file changes in your directory (no more reloading!):</p><pre>npm install -g nodemon </pre><p>Once you have the necessary tools installed, let’s get started!</p><h3>Creating a Stream Account</h3><p>Let’s create a Stream account so that we can use the Stream API. We can do this by navigating to the <a href="https://getstream.io/chat/">Stream website</a> and clicking the <strong>SIGNUP</strong> button.</p><p>On the modal that pops up, fill in your <strong>USERNAME</strong>, <strong>EMAIL ADDRESS</strong>, and <strong>PASSWORD</strong> and click the <strong>CREATE FREE ACCOUNT</strong> button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Qu2A3ZG5BGA2PDVG" /></figure><p>On your Stream Dashboard (where you’ll be directed after creating an account), you’ll find your <strong>APP ID</strong>, <strong>API KEY</strong>, and <strong>API SECRET</strong>, which we’ll use in a bit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YWNL4RXwVnQvWSdu" /></figure><blockquote><em>Take note of these keys as we will be using them in the next steps. Also, don’t forget to keep them safe and private.</em></blockquote><h3>Creating the Project</h3><p>Let’s create a simple file structure for our project. Create a folder named <strong>stream-voice-message</strong> in any convenient location on your system.</p><pre>mkdir stream-voice-message &amp;&amp; cd stream-voice-message</pre><p>In the <strong>stream-voice-message</strong> directory you just created, create the below files/folders into it:</p><ul><li>public (directory that holds our front-end files)</li><li>server.js (our Node server file)</li></ul><p>Next, create the below files inside the <strong>public</strong> directory:</p><p>The structure is in this manner:</p><pre><strong>── public</strong></pre><pre><strong>  ├── custom.js</strong></pre><pre><strong>  ├── index.html</strong></pre><pre><strong>  │── style.css</strong></pre><pre><strong>  └── server.js</strong></pre><p>Next, let’s initialize NPM so that we can install packages; open your terminal and make sure you are in the project’s root directory ( stream-chat-javascript), then run:</p><p>On the prompt that appears, press enter for all the prompts; the defaults for each will work for our application.</p><h3>Creating a Node Server</h3><p>To use Stream chat JavaScript client SDK, it requires us to generate a valid token using our API keys.</p><p>We’ll spin up a Node server that we will to server our client files and also create an endpoint where we’ll use the Node Server SDK to generate tokens.</p><p>First, install <a href="https://expressjs.com/">express</a> and the <a href="https://github.com/GetStream/stream-chat-js">Stream Chat server SDK</a>:</p><pre>npm install express stream-chat</pre><p>Now, spin up a new Node server by adding the below code to the server.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7e352f4dbed2546f25b74e924f06e42/href">https://medium.com/media/b7e352f4dbed2546f25b74e924f06e42/href</a></iframe><p>Then, start up the server from your terminal by running this command:</p><pre>nodemon server.js</pre><p>Here, we have created a Node server that will be running on port 8800. You can now access the project on <a href="http://localhost:3000.">http://localhost:3000.</a></p><p>We need tokens to initialize the Stream Chat client SDK. We will use the token for getting realtime updates of what is happening in our chat.</p><p>Add a token for generating new tokens by adding the below code to the server.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85ac800f944b725e05a3683a6b191a4d/href">https://medium.com/media/85ac800f944b725e05a3683a6b191a4d/href</a></iframe><p>In the above code, we created a /token <strong>GET</strong> endpoint for creating tokens using the username parameter passed to the endpoint. If we want to generate a token, we just need to call the endpoint like so: /token?username=username.</p><blockquote><em>Make sure to update the </em><em>&lt;STREAM_API_KEY&gt; and </em><em>&lt;STREAM_API_SECRET&gt; placeholders with the ones we grabbed above.</em></blockquote><p>Currently, if you visit our development server; <a href="http://localhost:3000/">http://localhost:3000</a>, you will notice that the page is blank. This is because all our front-end files are still empty.</p><p>We’ll get started with a simple layout for our chat app. Feel free to modify the code to suit your need. Now, add the below markup file to the public/index.html file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e2813e9446293023191add0bfce4d5e/href">https://medium.com/media/5e2813e9446293023191add0bfce4d5e/href</a></iframe><p>The three &lt;script&gt;s at the end of this code allow us to connect into Stream, make HTTP requests (using <a href="https://github.com/axios/axios#axios">Axios</a>), and connect into the actions for the page, from our custom.js file.</p><p>Next, add the styling of the chat to the public/style.css file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7227cdd49db696d2cbba83224846f9b/href">https://medium.com/media/b7227cdd49db696d2cbba83224846f9b/href</a></iframe><p>At this point, the development server should show a page similar to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LJEk_CNJ6tA2qXIj" /></figure><p>The input box is what we’ll use to get them a unique username from the user accessing the chat app. The username is what we will use to initialize the Stream Chat JavaScript SDK.</p><p>Now that our chat interface is ready, the next thing we’ll do is to initialize the Stream Chat JavaScript SDK.</p><p>To start, add a function for generating tokens to the public/custom.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0c8afb3b8f44e24c6f8e5b545b2d561/href">https://medium.com/media/b0c8afb3b8f44e24c6f8e5b545b2d561/href</a></iframe><p>Next, add the function that initializes the SDK to the public/custom.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b44b55119fccd2a5dbbf3aa296f25a5/href">https://medium.com/media/4b44b55119fccd2a5dbbf3aa296f25a5/href</a></iframe><blockquote><em>Make sure to replace </em><em>&lt;STREAM_API_KEY&gt; key with your correct Stream API Key.</em></blockquote><p>When we need to initialize the client SDK, we just need to call the initializeClient() function.</p><p>Currently, when you load the page, you will see an input text just staring at you. When you enter your username and hit enter, it does not respond. But we want to happen is, when the user enters a username and hits enter, they are shown the chatting area. Let’s fix it! When we need to initialize the client SDK, we will call the initializeClient() function.</p><p>Add the below code to the public/custom.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa946ed476b77073a2f1fd1bce27163b/href">https://medium.com/media/fa946ed476b77073a2f1fd1bce27163b/href</a></iframe><p>Here, in the input element, we added a keyup event listener where we then check if a user hits enter. Once the user enters a username and hits enter, we will call the checkAuthState() function.</p><p>The checkAuthState function checks if a username is available and then show the chatting area to the user. Then calls the initializeClient() function which initializes the JavaScript SDK client.</p><p>Now when you enter a username and hits enter, the chat are appeared:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/0*zBf4dt9UY03AH6U5" /></figure><p>Conversation happens in channels. For our app, we’ll be making use of a group channel. Initialize the channel when we initialize the client by adding the below code to the initializeClient() function in the public/custom.js file, just before the *return* client line:</p><pre>// [...] </pre><pre>channel = client.channel(<br>    &#39;messaging&#39;, <br>    &#39;general-chat-channel&#39;, <br>    {  <br>       name: &quot;General Chat Room&quot;, <br>       image: &quot;https://bit.ly/2F3KEoM&quot;, <br>       members: [], <br>       session: 8 // custom field, you can add as many as you want </pre><pre>    }); </pre><pre>await channel.watch(); </pre><pre>// [...]</pre><p>Here, we subscribe to a channel named general-chat-channel. We are now ready to get realtime events like messages coming to this room!</p><p>When you enter a channel, there might be message already in the channel. Let’s display this message by adding the below code to the initializeClient() function in the public/custom.js file, just before the *return* client line:</p><pre>// [...]<br> <br>// New message <br>channel.on(&quot;message.new&quot;, event =&gt; { <br>    appendMessage(event.message) <br>}); </pre><pre>// Messages already in the room </pre><pre>channel<br>      .state<br>      .messages<br>      .forEach(<br>         message =&gt; { appendMessage(message) <br>      }); </pre><pre>// [...]</pre><p>Next, create a function for creating an audio element by adding the below code to the public/custom.js file:</p><pre>// [...] </pre><pre>function getAudioElement(src) { <br>   const audioElement = document.createElement(&quot;audio&quot;)<br>   audioElement.src = src <br>   audioElement.controls = true <br>   return audioElement <br>}</pre><p>Now create the appendMessage function called above that creates a div element and nicely place the new message to the DOM. Add this function to the public/custom.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/578e3e5736849496880df3ff5eb73724/href">https://medium.com/media/578e3e5736849496880df3ff5eb73724/href</a></iframe><p>Our voice messages will be sent to the channel as an attachment. In the above code, we check if a message has an attachment and then create an audio element and attaching to the DOM.</p><p>Stream messaging allows us to send text and files. Using the capability of sending files, we will send voice messages as an audio file that will upload to Stream CDN.</p><p>Now, add a function for sending messages to the public/custom.js file:</p><pre>// [...] </pre><pre>async function sendMessage(message, attachments) { <br>   return await channel.sendMessage({ <br>       text: message, <br>        attachments: attachments <br>   }); <br>}</pre><p>The first parameter of the function accepts texts while the second parameter of the function is an array of files/attachments we want to send along.</p><p>Once you enter your username and hits enter, you will see a text input and a record button. The sending of text messages and recoding does not work yet. Let’s make it work!</p><p>What we want is for a user to enter a text message they want to send into the text input and then hit <strong>enter</strong> to send the message. To send an audio message, we want the user to hold down the <strong>record</strong> button, then start recording their voice. Then we send their voice when they release the button.</p><p>Listen and send a message when the user submits by adding the below code to the public/custom.js file:</p><pre>// [...] </pre><pre>const inputElement = document.getElementById(&quot;message-input&quot;); inputElement.addEventListener(&quot;keyup&quot;, function(event) { <br>   if (event.key === &quot;Enter&quot;) { <br>       sendMessage(inputElement.value) <br>       inputElement.value = &quot;&quot; <br>    } <br>});</pre><p>Text messaging now works! To test, refresh the page and enter a text and then hit enter to send the message.</p><p>Now, we need to make the recording of audio to work. First, add a function that helps us to record the audio from a <a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia">stream</a>:</p><pre>// [...] </pre><pre>function startRecording(stream) { <br>    recorder = new MediaRecorder(stream); <br>    let data = []; <br>    recorder.ondataavailable = event =&gt; data.push(event.data); <br>    recorder.start(); </pre><pre>    let stopped = new Promise((resolve, reject) =&gt; { <br>        recorder.onstop = resolve; <br>        recorder.onerror = event =&gt; reject(event.name); <br>    }); <br>  <br>    return stopped.then(() =&gt; data); <br>}</pre><p>This function returns a <a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia">Blob</a> of recorded data.</p><p>Next, listen for when the user presses and holds the <strong>record</strong> button so we can call the above function to start recording their voice. Add the below code to the public/custom.js file:</p><pre>// [...] </pre><pre>const recording = document.getElementById(&quot;recording&quot;); <br>let stream </pre><pre>( async () =&gt; { <br>    stream = await navigator.mediaDevices.getUserMedia({ <br>         audio: true, <br>         video: false // we don&#39;t want video <br>    }) <br>})(); </pre><pre>recording.addEventListener(&quot;pointerdown&quot;, async () =&gt; { <br>     recordedChunks = startRecording(stream) <br>}, false);</pre><p>If you reload the page now, the page will prompt for permission to access your camera. Click on the <strong>Allow</strong> button to give it that permission.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/0*T_kDl_H05R9Ubikk" /></figure><p>Then listen to when the user releases the record button, so we can stop the recording and send the file as an attachment:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef881c3a6921e8bb0df5498937709ce0/href">https://medium.com/media/ef881c3a6921e8bb0df5498937709ce0/href</a></iframe><p>Congrats! you just added a voice messaging functionality to your Stream Chat app. Let’s test what we have built.</p><ol><li>Open the app in two tabs.</li><li>Input two different username (any username will work) in both tabs and hit enter.</li><li>Now, on one tab, press and hold the <strong>record</strong> button then start voicing your messages. Once you are done, release the button so the recorded voice to be sent to the channel.</li></ol><h3>Wrapping Up</h3><p>In this post, we walked through how to integrate voice messaging into a stream chat application by utilizing the <a href="https://getstream.io/chat/docs/file_uploads/?language=js">attachment</a> feature. Although we used Vanilla <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript">JavaScript</a> and <a href="https://nodejs.org/">Node</a> to build the app, the idea from this post will help you integrate into other frameworks and Backends.</p><p>We can’t wait to see what you build! Let’s also know how you modified the idea from this post to build upon your chat application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ccabd9ff1ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[⚠ functions: Cannot find module ‘./tsconfig.json’ — How I fixed it]]></title>
            <link>https://medium.com/@onwuka_gideon/functions-cannot-find-module-tsconfig-json-how-i-fixed-it-70d7c4769174?source=rss-adbc4f40f48------2</link>
            <guid isPermaLink="false">https://medium.com/p/70d7c4769174</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[cannot-find-module]]></category>
            <category><![CDATA[cannot-find]]></category>
            <category><![CDATA[tsconfig]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Onwuka Gideon]]></dc:creator>
            <pubDate>Thu, 11 Jun 2020 18:25:04 GMT</pubDate>
            <atom:updated>2020-06-16T12:59:06.883Z</atom:updated>
            <content:encoded><![CDATA[<h3>⚠ functions: Cannot find module ‘./tsconfig.json’ — How I fixed it</h3><blockquote>tldr; There seems to be a bug on version <strong>8.4.2</strong> of firebase-tools, so try downgrading/upgrading to a version other than <strong>8.4.2</strong>.</blockquote><p>I got this error when I tried to serve my firebase functions using:</p><pre>firebase serve</pre><p>Which gives the below output:</p><pre>➜  remote-chat-finn git:(local-server) ✗ firebase serve</pre><pre>=== Serving from &#39;/Users/dongido/projects&#39;...</pre><pre>i  functions: Watching &quot;/Users/dongido/projects/functions&quot; for Cloud Functions...<br>i  hosting: Serving hosting files from: dist<br>✔  hosting: Local server: <a href="http://localhost:5000/">http://localhost:5000</a><br>⚠  functions: Cannot find module &#39;./tsconfig.json&#39;<br>⚠  Your function was killed because it raised an unhandled error.</pre><p>The error is not really explicit as I don’t know what I got wrong or where I should look to. I don’t have a `‘./tsconfig.json’` neither am I using Typescript.</p><p>…And my current versions were:</p><ul><li>firebase-tools — <strong>`8.4.2`</strong></li></ul><p>After a long hour of debugging and blaming my system, I decided to try another system.</p><p>I tried another system that has the following versions:</p><ul><li>firebase-tools — `<strong>8.4.1`</strong></li></ul><p>Now there is something interesting here; the error is different when I run `firebase serve`. The error was explicit as I had an import that has an incorrect path in my functions code and the line!</p><p>So I quietly went back to my system and fixed the import error and gbam! It worked!</p><h3>Conclusion</h3><p>It’s possible there is an error in the latest firebase-tool (`8.4.2`) which does not explicitly tell you that you have an error in your functions code. So if you are getting this kind of error, try to downgrade to an old version of firebase-tools as with mine above or make sure your function code does not have any error.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70d7c4769174" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[database: Error: Invalid or corrupt jarfile…]]></title>
            <link>https://medium.com/@onwuka_gideon/database-error-invalid-or-corrupt-jarfile-3390750ed7ee?source=rss-adbc4f40f48------2</link>
            <guid isPermaLink="false">https://medium.com/p/3390750ed7ee</guid>
            <category><![CDATA[jar-file]]></category>
            <category><![CDATA[database-error]]></category>
            <category><![CDATA[currupt-jarfile]]></category>
            <category><![CDATA[corrupt]]></category>
            <dc:creator><![CDATA[Onwuka Gideon]]></dc:creator>
            <pubDate>Thu, 11 Jun 2020 08:17:58 GMT</pubDate>
            <atom:updated>2020-06-12T16:39:15.167Z</atom:updated>
            <content:encoded><![CDATA[<h3>database: Error: Invalid or corrupt jarfile /.cache/firebase/emulators/firebase-database-emulator-v3.5.0.jar</h3><p>So I was trying to set up the firebase database emulator by running the below command:</p><pre>firebase setup:emulators:database</pre><p>But when I try to serve the database using — `firebase setup:emulators:database`, I get an errror; `error: Invalid or corrupt jarfile /.cache/firebase/emulators/firebase-database-emulator-v3.5.0.jar`</p><p>Sometimes, the error is usually caused due to incomplete download. what fixed it for me was to simply delete the `firebase-database-emulator-v3.5.0.jar` file and re-ran the command:</p><pre>firebase setup:emulators:database</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3390750ed7ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding Chatbots to Your Stream Chat App Using Google’s Dialogflow]]></title>
            <link>https://blog.chatbotslife.com/adding-chatbots-to-your-stream-chat-app-using-googles-dialogflow-the-stream-blog-51edbc6ae35b?source=rss-adbc4f40f48------2</link>
            <guid isPermaLink="false">https://medium.com/p/51edbc6ae35b</guid>
            <category><![CDATA[chatbot-design]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[faq]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[chatbots]]></category>
            <dc:creator><![CDATA[Onwuka Gideon]]></dc:creator>
            <pubDate>Thu, 23 May 2019 16:05:15 GMT</pubDate>
            <atom:updated>2019-05-29T15:29:59.882Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Originally published at </em><a href="https://getstream.io/blog/adding-chatbots-to-your-stream-chat-app-using-googles-dialogflow/"><em>https://getstream.io/blo</em></a><em>g/.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p4Q04dYnrW16s7mVfXhXRQ.png" /></figure><p>Most tasks are repetitive and time-consuming. What if we could use a bot to help in doing the tasks instead? This will hugely increase productivity. Chatbots are fantastic for this.</p><p>In this tutorial, I’ll walk you through steps to adding a <a href="https://chatbotslife.com/">chatbot</a> to your Stream Chat app using Dialogflow and Vue. At the end of this tutorial, you will build a frequently asked questions (FAQs) <a href="https://chatbotslife.com/">bot</a>, be more familiar with Stream Chat API, and the webhook system provided by Stream.</p><p>Here is a preview of what we’ll be building:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LSyvKMabWBCo2bzb.gif" /></figure><h3>Trending Chatbot Tutorials</h3><blockquote><a href="https://chatbotslife.com/aws-setup-for-deep-learning-fda04db6df75">1. AWS setup for Deep Learning</a></blockquote><blockquote><a href="https://chatbotslife.com/how-to-integrate-api-ai-with-chatfuel-48baafd4613">2. How to Integrate API.AI with Chatfuel</a></blockquote><blockquote><a href="https://chatbotslife.com/which-are-the-best-on-site-chatbot-frameworks-3dbf5157fb57">3. Which are the best chatbot frameworks?</a></blockquote><blockquote><a href="https://chatbotslife.com/build-a-working-sms-chat-bot-in-10-minutes-b8278d80cc7a">4. Build a working SMS chat-bot in 10 minutes</a></blockquote><h3>Prerequisites</h3><p>To follow along with this tutorial comfortably, the following are expected:</p><ul><li>A basic understanding of JavaScript</li><li>A basic understanding of <a href="https://vuejs.org/">Vue.js</a></li><li>You should also have <a href="http://node.js/">Node</a> installed on your system (version 8.9 or above — preferably the latest 12.x)</li><li>You should have npm or yarn installed on your system</li><li>Have <a href="https://ngrok.com/">ngrok</a> installed on your system</li></ul><p>If you have all the above ready, then let’s get started!</p><h3>Set up the Client App — Create a New Vue App</h3><p>Vue provides a <a href="https://cli.vuejs.org/guide/creating-a-project.html#installation">CLI</a> for scaffolding a new Vue project. First, you’ll need to install the Vue CLI globally on your system (if you don’t have it installed already). After that, we’ll create a new Vue project with CLI commands.<br>Next, create a new Vue project by running the following commands in any convenient location on your system:</p><pre>$ yarn global add @vue/cli </pre><pre># Create a new Vue project (for the prompt that appears, press enter to select the default preset.) <br>$ vue create faqx </pre><pre># Change your directory to the project directory <br>$ cd faqx </pre><pre># Install Stream Chat client SDK <br>$ yarn add stream-chat </pre><pre># Install axios - a library for making request <br>$ yarn add axios </pre><pre># Run the app! <br>$ yarn serve</pre><p>Accessing the <a href="http://localhost:8080/">URL</a> displayed on your terminal will take you to a Vue default page.</p><h3>Get Your Stream Chat Keys</h3><p>To start using the Stream Chat API, you need to have an API key. <br>Create an account <a href="https://getstream.io/accounts/signup/">here</a> or <a href="https://getstream.io/accounts/login/">log in</a> if you already have an account. <br>Then, from your <a href="https://getstream.io/dashboard">dashboard</a>:</p><ul><li>Create a new app using any convenient name. I will call mine “FAQ”</li><li>Fill in the <strong>App Name</strong> as “FAQx” or any name you wish</li><li>Finally, submit the form by clicking on the <strong>Submit</strong> button to create the app</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JKMywpbcIEZoY_Aq.png" /></figure><p>Once the app is created, you will be provided with some options on your dashboard. Select <strong>Chat</strong> to go the Stream Chat dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*S8YW0xFe2ENq33j5.png" /></figure><p>Next, check <strong>Disable Permissions Checks</strong> and then click on the <strong>Save</strong> button. Then, scroll to the bottom of the page and take note of your App Access Keys — <strong>Key</strong> and <strong>Secret.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_oKSX9GyhCl7ZA95.png" /></figure><p>Next, create a `.env` file in the root directory of the project and update your Stream keys to it:</p><pre>VUE_APP_PORT=3000 <br>VUE_APP_SERVER=http://localhost:3000 <br>VUE_APP_KEY=&lt;YOUR KEY&gt; </pre><pre>APP_SECRET=&lt;YOUR SECRET&gt; <br>DIALOGFLOW_PROJECT_ID=&lt;YOUR DIALOGFLOW PROJECT ID&gt; GOOGLE_APPLICATION_CREDENTIALS=&lt;GOOGLE SERVICE FILE&gt;</pre><p>Remember to replace `&lt;YOUR KEY&gt;` and `&lt;YOUR SECRET&gt;` with the correct app keys you have noted above.</p><h3>Set up the Server</h3><p>Next, create a new directory named server in the root directory of the project. Then open up a new terminal and then change your current directory to the server directory. Then install the following dependencies that we’ll need for the server:</p><pre>$ yarn add express cors body-parser dialogflow path uuid dotenv</pre><p>The above dependencies include:</p><ul><li>`express` — A Node framework we are using to build our server</li><li>`dialogflow` — Dialogflow’s Node SDK</li><li>`dotenv` — An npm package for parsing configs from .env files</li><li>`<a href="https://www.npmjs.com/package/cors">cors</a>`, `<a href="https://www.npmjs.com/package/body-parser">body-parser</a>`, `<a href="https://www.npmjs.com/package/uuid">uuid</a>` and `<a href="https://www.npmjs.com/package/dotenv">dotenv</a>` (all excellent npm packages)</li></ul><p>Next, create an Express app by creating a new file named app.js to the server directory and then add the following code to it:</p><pre>// ./server/app.js </pre><pre>const express = require(&quot;express&quot;); <br>const cors = require(&quot;cors&quot;); <br>const bodyParser = require(&quot;body-parser&quot;); <br>const StreamChat = require(&#39;stream-chat&#39;).StreamChat; <br>const dialogflow = require(&#39;dialogflow&#39;).v2beta1; <br>const uuid = require(&#39;uuid&#39;); <br>require(&#39;dotenv&#39;).config({path: &quot;../.env&quot;}) </pre><pre>const app = express(); <br>const port = process.env.VUE_APP_PORT || 3000 app.use(cors()); </pre><pre>app.use(bodyParser.json()); <br>app.use(bodyParser.urlencoded({ extended: true })); </pre><pre>// Initialize Stream Chat SDK <br>const serverSideClient = new StreamChat( <br>   process.env.VUE_APP_KEY, <br>   process.env.APP_SECRET <br>); </pre><pre>app.get(&quot;/&quot;, async (req, res) =&gt; { <br>   res.send({ hello: &quot;World!&quot; }); <br>}); </pre><pre>app.listen(port, () =&gt; { <br>   console.log(`Node app listening on port ${port}!`) <br>});</pre><p>In the code above, after importing the packages that we have installed,</p><ul><li>We created an <a href="https://expressjs.com/">Express</a> app using const app = express();</li><li>Next, we initialize the Stream Chat SDK</li><li>Then finally, we created an endpoint — / (app.get(‘/’,…) for testing to know if the app works. So, if you visit <a href="http://localhost:3000/,">http://localhost:3000/,</a> you will get a message — { hello: ‘World!’}</li></ul><p>Next, create a new endpoint for creating a token.</p><pre>// ./server/app.js </pre><pre>app.post(&#39;/login&#39;, async (req, res) =&gt; { <br>   const userId = req.body.userId </pre><pre>   if (!userId) { <br>      return res.status(400).send({ <br>          status: &quot;error&quot;, <br>          message: &quot;username and name is required&quot; <br>      }) <br>   } </pre><pre>   return res.status(200).send({ <br>     status: &quot;success&quot;, <br>     token: serverSideClient.createToken(userId) <br>   }) </pre><pre>});</pre><p>The token is required for initializing the Stream Chat SDK. Finally, start up the server:</p><p>If it starts successfully, you will see a message printed to the terminal — “Node app listening on port 3000!”</p><h4>Set up Dialogflow</h4><p><a href="https://dialogflow.com/">Dialogflow</a> is a Google-owned developer of human-computer interaction technologies based on natural language conversations. Before you can start using the service of Dialogflow, you need to have an account with them.<br>Now head to Dialogflow’s website and create a free <a href="https://console.dialogflow.com/api-client/#/login">account</a> if you don’t have one already. You’ll need a google account to be able to create an account. Once you are on the page, click on the sign in with <strong>Google</strong> button.<br>From your dashboard,</p><ul><li>Create an agent by selecting <strong>Create Agent.</strong></li><li>Type in the Agent name as <strong>FAQX.</strong></li><li>Click the <strong>Create</strong> button to processes the form.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WXT8GGfLjhg3UM1y.png" /></figure><p>Next:</p><ol><li>Click on the gear icon, to the right of the agent name.</li><li>Enable beta features and APIs.</li><li>Copy your project ID and update the .env file with it:</li></ol><p>DIALOGFLOW_PROJECT_ID=&lt;YOUR DIALOGFLOW PROJECT ID&gt;</p><ol><li>Click the <strong>Save</strong> button to save your changes</li><li>Under the <strong>GOOGLE PROJECT</strong> section, click on the name of the <strong>Service Account</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tYEr9yB6FI7VM1FW.png" /></figure><p>This will take you to the Google Cloud Platform Service Accounts page, but you first need to update the Service Account’s role.<br>Once the page finishes loading:</p><ol><li>Click on the menu button in the upper left-hand corner and click on <strong>IAM &amp; admin</strong>.</li><li>Click on <strong>Service Accounts</strong> in the left-hand menu.</li><li>Click on the <strong>Create Service Account</strong> button at the top of the page.</li><li>In the next page, enter a name for the service account and then click on the <strong>CREATE</strong> button to submit the form.</li><li>Click on <strong>Role </strong>and select <strong>Owner</strong> as the role.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sP_JPgxn3ysjCxy9.png" /></figure><p>Then click on the <strong>CONTINUE</strong> Button.</p><p>Click on the <strong>+ CREATE KEY</strong> button. Click the <strong>CREATE</strong> to download your service key.</p><p>A download of the JSON file will start. Copy the download file to the server directory of the project. Then update the .env file to reflect the name of the JSON file you just downloaded:</p><pre>GOOGLE_APPLICATION_CREDENTIALS=&lt;GOOGLE SERVICE FILE&gt;</pre><p><strong>Prepare Your FAQ Data</strong></p><p>Here is where we prepare our frequently asked questions. Create a new file in any location on your system as faq.csv. Then, copy the below FAQ samples to it and save.</p><pre>How can I place orders?, &quot;There are two ways to place orders for our services:&quot; Which method of ordering is best for me?, &quot;In the areas of standardized text creation (with and without keywords), translations and survey tasks, it is more advantageous and favorable for you to enter the order using the Self-Service Marketplace. If you have large, individual projects from any service areas offered, please contact our sales team. They will provide personal advice and discuss the project with you.&quot; What preliminary information is needed for an offer?, &quot;Depending on the service requested we will need the following specifications:&quot; How great is the risk that the results do not meet my expectations?, &quot;We discuss the outcome requirements as accurately as possible in advance. Furthermore, when we are dealing with large orders, we agree on a test order to ensure correct and faultless processing.&quot; What does an order cost?, &quot;The costs are calculated according to the amount of time involved and the quality requirements. These vary from project to project. Therefore, per project, you will receive an individual offer on demand.&quot;</pre><p>The above is just an example for our testing. Feel free to replace with yours. The first column is the question, while the second column is the answer.</p><p>The data is comma-separated and no empty rows are expected, else, you will get an error.</p><p>Here is a simple example of the format:</p><pre>An example question 1, An answer 1 <br>An example auestion 2, An answer 2</pre><p>From the data on the faq.csv file, when a user sends in a query as — “ <strong>How can I place orders?</strong>”. The expected output from Dialogflow will be — “ <strong>here are two ways to place orders for our services:</strong>” and so on.<br>Next, go back to your Dialogflow dashboard.</p><ol><li>Click on the <strong>Knowledge</strong> tab on the left the page</li><li>Click on the <strong>CREATE KNOWLEDGE BASE</strong> button</li><li>Type in <strong>FAQ</strong> as the name of the knowledge</li><li>Click on the <strong>Create the first one </strong>link</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Edb9ghJ1efMRnZt5.png" /></figure><p>On the popup that appears,</p><ol><li>Enter the <strong>Document Name</strong> as “FAQ”</li><li>Choose “FAQ” as the <strong>knowledge type</strong></li><li>Choose txt/csv as the <strong>Mime Type</strong></li><li>Choose <strong>Upload file from your computer </strong>as the <strong>DATA SOURCE</strong></li><li>Click on the <strong>SELECT FILE</strong> button and browse through to the CSV file you created above and upload it</li><li>Then, click the <strong>CREATE</strong> button</li><li>Click on <strong>ADD RESPONSE</strong></li><li>Finally, click the <strong>SAVE</strong> button to register your changes</li></ol><h3>Building the App Interface</h3><p>Now that we have both our client and server apps running, the next thing we’ll do is to create a simple chat interface so we can integrate Dialogflow. <br>Vue enables us to build reusable components which make up our app user interface. We’ll split the app UI into smaller components so we can build them separately:<br>For brevity’s sake, we’ll divide the app into two components:</p><ul><li>`Messages.vue` — for listing messages and a form input</li><li>`Login.vue` — displays the login form</li></ul><p>Create the Messages.vue and Login.vue files inside the src/components directory.</p><p>To keep the component file as minimal as possible, I have added all the CSS of the components to a single CSS file. Create the CSS file as App.css in the src directory of the project and then add the below styles to it:</p><pre>/* ./App.css */<br><br>html,body{<br>    width: 100%;<br>    height: 99vh;<br>    overflow: hidden;<br>}<br>#app {<br>    font-family: &#39;Avenir&#39;, Helvetica, Arial, sans-serif;<br>    -webkit-font-smoothing: antialiased;<br>    -moz-osx-font-smoothing: grayscale;<br>    text-align: center;<br>    color: #2c3e50;<br>}<br>.login-container {<br>    display: grid; <br>    grid-template-rows: 4fr 1fr;<br>    max-height: 320px;<br>    min-height: 320px;<br>}<br>input[type=&quot;text&quot;] {<br>    padding: 10px 8px;<br>    margin-top: 10px;<br>    border-radius: 2px;<br>    border: 1px solid darkgray;<br>    font-size: 16px;<br>    box-sizing: border-box;<br>    display: block;<br>}<br>.inputs {<br>    text-align: center;<br>    align-self: center;<br>    justify-self: center;<br>}<br>.submit {<br>    margin-top: 9px;<br>    padding: 20px;<br>    background: rgb(99, 99, 212);<br>    color: white;<br>    font-size: 16px;<br>}<br>.chat-message {<br>    width: 70%;<br>    margin-top: 4px;<br>    padding: 4px;<br>    text-align: left;<br>    word-wrap: break-word;<br>    margin: 5px;<br>}<br>.from-admin {<br>    background: rgb(150, 178, 183);<br>    color: rgb(39, 37, 37);<br>    float: left;<br>}<br>.from-client {<br>    background: rgb(48, 13, 79);<br>    color: white;<br>    float: right;<br>}<br>.input-container {<br>    margin: 0px;<br>}<br>.chat-input {<br>    width: 99%; <br>    margin-bottom: 0px;<br>}<br>.client-messages {<br>    overflow-y: scroll; <br>    height: 320px;<br>}<br>.chat-container {<br>    position: fixed; <br>    right: 0px; <br>    bottom: 0px; <br>    width: 400px; <br>    z-index: 100000; <br>    box-sizing: border-box;<br>}<br>.head {<br>    padding: 9px; <br>    display: grid; <br>    background-color: rgb(48, 13, 79); <br>    color: white; <br>    border-top-left-radius: 5px; <br>    border-top-right-radius: 5px;<br>}<br>.chat-box {<br>    border-left: 1px solid rgb(48, 13, 79);<br>    border-right: 1px solid rgb(48, 13, 79);<br>    background: lightgray;<br>}</pre><p><strong>The Login Component</strong></p><p>We’ll be using the <a href="https://vuejs.org/v2/guide/single-file-components.html">Single File Component</a> structure for our components.</p><p>Add the mark-up for the Login component:</p><pre>&lt;!-- ./src/components/Login.vue --&gt;<br><br>&lt;template&gt;<br>    &lt;div class=&quot;login-container chat-box&quot;&gt;<br>        &lt;div class=&quot;inputs&quot;&gt;<br>            &lt;input type=&quot;text&quot; placeholder=&quot;your username&quot; v-model=&quot;username&quot;&gt;<br>        &lt;/div&gt;<br>        &lt;button type=&quot;submit&quot; class=&quot;submit&quot; v-on:click=&quot;login&quot;&gt; Submit &lt;/button&gt;<br>    &lt;/div&gt;<br>&lt;/template&gt;</pre><p>In the preceding code, we added an input form that captures the user username. Also, we added a click event that calls the login function when the form is submitted.</p><p>Next, add the script section for the Login component.</p><pre>&lt;!-- ./src/components/Login.vue --&gt; </pre><pre>&lt;script&gt; <br>export default { <br>    data: function () { <br>       return { <br>          username: &quot;&quot;, <br>       } <br>    }, <br>    methods: {  <br>      login() { <br>          this.$emit(&quot;authenticated&quot;, this.username); <br>      } <br>    } <br>} <br>&lt;/script&gt;</pre><p>Here, we defined the login function that will be called on the mark-up file. In the function, we emit a custom event named authenticated to the parent component passing the username along.</p><p><strong>The Messages Component</strong></p><p>Define the messages component that lists messages and holds the form input for adding new messages:</p><pre>&lt;!-- ./src/components/Messages.vue --&gt;<br><br>&lt;template&gt; <br>    &lt;div class=&quot;chat-box&quot;&gt;<br>        &lt;div class=&quot;client-messages &quot;&gt;<br>            &lt;div<br>                class=&quot;chat-message&quot; <br>                v-for=&quot;message in messages&quot; <br>                v-bind:key=&quot;message.id&quot;<br>                v-bind:class=&quot;[(message.user.id == userId) ? &#39;from-client&#39; : &#39;from-admin&#39;]&quot;<br>            &gt;<br>                {{ message.text }}<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>        &lt;div class=&quot;input-container&quot;&gt;<br>            &lt;input<br>                class=&quot;chat-input&quot; <br>                type=&quot;text&quot; <br>                placeholder=&quot;enter message...&quot; <br>                v-model=&quot;message&quot;<br>                v-on:keyup.enter=&quot;addMessage&quot;<br>            &gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>&lt;/template&gt;</pre><p>Then add the script section for the messages component:</p><pre>&lt;!-- ./src/components/Messages.vue --&gt; </pre><pre>&lt;script&gt; <br>export default { <br>    props: [&#39;messages&#39;, &#39;userId&#39;], <br>    data() { <br>        return { <br>            message: &quot;&quot; <br>        } <br>    }, <br>    methods: { <br>        addMessage() { <br>           this.$emit(&#39;new-message&#39;, this.message); <br>           this.message = &quot;&quot;; <br>         } <br>    } <br>} <br>&lt;/script&gt;</pre><p><strong>The App Component</strong></p><p>Now let’s bring all the other component into a single component to build up the interface. Replace the code in the src/App.vue file with the below mark-up:</p><pre>&lt;!-- ./src/App.vue --&gt; </pre><pre>&lt;template&gt; <br>    &lt;div id=&quot;app&quot;&gt; <br>        &lt;div&gt; <br>            &lt;img alt=&quot;Vue logo&quot; src=&quot;./assets/logo.png&quot;&gt; <br>        &lt;/div&gt; <br>        &lt;div class=&quot;chat-container&quot;&gt; <br>            &lt;div class=&quot;head&quot; @click=&quot;displayChatArea=!displayChatArea&quot;&gt;    <br>                &lt;div style=&quot;justify-self: center;&quot;&gt; FAQx &lt;/div&gt; <br>            &lt;/div&gt; <br>            &lt;div v-if=&quot;displayChatArea&quot;&gt; <br>                &lt;login <br>                     v-if=&quot;!authenticated&quot; <br>                     v-on:authenticated=&quot;setAuthenticated&quot; <br>                /&gt; <br>               &lt;messages <br>                    v-else <br>                    v-on:new-message=&quot;sendMessage&quot; <br>                    :messages=&quot;messages&quot; <br>                    :userId=&quot;userId&quot; <br>                /&gt; <br>            &lt;/div&gt; <br>        &lt;/div&gt; <br>    &lt;/div&gt;  <br>&lt;/template&gt;</pre><p>Then add the script section to the src/App.vue file:</p><pre>&lt;!-- ./src/App.vue --&gt; </pre><pre>&lt;script&gt; <br>import { StreamChat } from &#39;stream-chat&#39;; <br>import axios from &#39;axios&#39;; </pre><pre>import Messages from &#39;@/components/Messages.vue&#39;; <br>import Login from &#39;@/components/Login.vue&#39;; <br>import &#39;./App.css&#39;; </pre><pre>export default { <br>    name: &#39;app&#39;, <br>    components: { <br>        Messages, <br>        Login <br>    }, <br>    data: function () { <br>      return { <br>        authenticated: false, <br>        roomId: &quot;&quot;, <br>        messages: [], <br>        userId: &quot;&quot;, <br>        displayChatArea: false, <br>        channel: null, <br>        token: null, <br>        client: null <br>      } <br>    }, <br>    methods: { },<br>} <br>&lt;/script&gt;</pre><p>The Vue app should look like below at this point:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*59zOF4EzDfw5VZak.png" /></figure><h3>Making Chat Work</h3><p>So far, we have our chat interface ready but we still can’t converse because we are yet to connect the app to Stream Chat. We’ll be doing so next.</p><p>To start using the SDK, we first need to initialize it. Do so by adding the below function in the methods: {…} block in the App.vue file:</p><pre>// ./src/App.vue </pre><pre>// [...] </pre><pre>async initializeClient () { <br>    // Initialize the StreamChat SDK <br>    const client = new StreamChat(process.env.VUE_APP_KEY); </pre><pre>    await client.setUser(<br>        { <br>          id: this.userId, <br>          name: this.userId, <br>        }, <br>       this.token, <br>    ); </pre><pre>   this.client = client }, </pre><pre>// [...]</pre><p>Next, add a function for creating a new channel for the user that just logs in to the methods: {…} block of App.vue:</p><pre>// ./src/App.vue</pre><pre>// [...]</pre><pre>async initializeChannel () {</pre><pre>    const channel = <em>this</em>.client.channel(&#39;commerce&#39;, <em>this</em>.userId, {</pre><pre>        name: &#39;Customer Support&#39;,</pre><pre>    });</pre><pre><em>    this</em>.channel = channel</pre><pre><em>    // fetch the channel state, subscribe to future updates</em></pre><pre>   let state = <em>await</em> channel.watch();</pre><pre><em>   this</em>.messages = state.messages</pre><pre>   // Listen for new messages</pre><pre>   channel.on(&#39;message.new&#39;, event =&gt; {</pre><pre><em>      this</em>.messages.push(event.message) <br>   });</pre><pre>},</pre><pre>// [...]</pre><p>Here, we are creating a new channel for every user that logs in so that their messages are sperate from other users. Then we started listening for new messages on that channel using — channel.on(‘message.new…’.</p><p>Here, we are creating a new channel for every user that logs in so that their messages are sperate from other users. Then we started listening for new messages on that channel using — channel.on(‘message.new…’.</p><p>Next, add a function for logging the user into the methods: {…} block of App.vue:</p><pre>// ./src/App.vue </pre><pre>// [...] </pre><pre>async setAuthenticated(userId) { <br>   const response = await      axios.post(`${process.env.VUE_APP_SERVER}/login`, {userId}) </pre><pre>   if (response.data.status === &#39;success&#39;) { <br>       this.authenticated = true <br>       this.token = response.data.token <br>       this.userId = userId </pre><pre>       await this.initializeClient() </pre><pre>       await this.initializeChannel() <br>   } <br>}, </pre><pre>// [...]</pre><p>In the proceeding code, we make a post request to the /login endpoint on the server to generate a token for the user. The token is required for initializing the StreamChat SDK.</p><p>Finally, add a function for sending messages into the methods: {…} block of App.vue:</p><pre>// ./src/App.vue </pre><pre>// [...] </pre><pre>async sendMessage (message) { <br>   this.channel &amp;&amp; await this.channel.sendMessage({ <br>      text: message <br>    }); <br>}, </pre><pre>// [...]</pre><p>When the user submits the message form, we’ll call this function to send a message to the channel.</p><h3>Set up the Webhook</h3><p>For now, we can send a message from to channels but we don’t get a reply because there is no one on the other end to reply. We’ll now employ the service of a <a href="https://chatbotslife.com/">chatbot</a> to reply to those messages.</p><p>Next, create a function to query Dialogflow for an answer to a given input:</p><pre>// ./server/app.js </pre><pre>// [...] </pre><pre>async function getAnswer (question) { <br>   const sessionId = uuid.v4(); <br>   <br>   // Create a new session <br>   const sessionClient = new dialogflow.SessionsClient(); <br>   const sessionPath = sessionClient.sessionPath(<br>                   process.env.DIALOGFLOW_PROJECT_ID, <br>        sessionId <br>    ); </pre><pre>   // The text query request. <br>   const request = { <br>      session: sessionPath, <br>      queryInput: { <br>         text: { <br>          // The query to send to the dialogflow agent <br>          text: question, <br>          // The language used by the client (en-US) <br>          languageCode: &#39;en-US&#39;, <br>         }, <br>       }, <br>   }; </pre><pre>   // Send request and log result <br>   const responses = await sessionClient.detectIntent(request); </pre><pre>   return responses[0].queryResult.fulfillmentText; <br>} </pre><pre>// [...]</pre><p>By using <a href="https://getstream.io/chat/docs/#webhooks">webhooks</a>, you can receive all events within your application. When configured, every event happening on Stream Chat will propagate to your webhook endpoint via an HTTP POST request. For our use-case, we are most interested in the “message.new” event.</p><p>Next, create an endpoint for our <a href="https://getstream.io/chat/docs/#webhooks">webhook</a>. Stream will make a request to this endpoint for every new message sent to the channel.</p><p>Add the below code to the server/app.js file:</p><pre>// ./server/app.js </pre><pre>// [...] </pre><pre>app.post(&#39;/webhook&#39;, async (req, res) =&gt; { <br>   // extract data from the POST payload <br>   const { cid, type, message, user } = req.body </pre><pre>   // Get the organization and channel from the cid param <br>   const [org, chan] = cid.split(&#39;:&#39;) </pre><pre>   res.status(200).send({ status: &quot;success&quot; }) </pre><pre>  // Make sure the new message is not comming form the bot <br>  // We are using &#39;bandit&#39; as a username for our bot <br>  <br>  if (type === &quot;message.new&quot; &amp;&amp; user.id !== &#39;bendit&#39;) { <br>     const channel = serverSideClient.channel(org, chan); </pre><pre>     const messagePayload = { <br>        text: await getAnswer(message.text), <br>        user: {id: &#39;bendit&#39;}, <br>     } </pre><pre>    try { <br>       await channel.sendMessage(messagePayload); <br>    } catch(e) { <br>       console.log(e.message) <br>    } <br>  } </pre><pre>}); </pre><pre>// [...]</pre><p>In the proceeding code:</p><ul><li>After extracting the data from the POST request, we check the type of the event if it’s a “<strong>message.new</strong>” event. Also, we want to make sure that the message is not coming from the bot — ‘bendit’. ‘bandit’ is just a generic username we want to use as our bot. It can be any name you like.</li><li>Next, we call the getAnswer function to query Dialogflow for an answer to the new message that just came in.</li><li>Then finally, we call the channel.sendMessage(… function to send the result from Dialogflow to the channel so that the user can see the reply.</li></ul><p><strong>Enable the Webhook</strong></p><p>Although we now have our webhook ready which can be accessed from <a href="http://localhost:3000/webhook">http://localhost:3000/webhook</a>. It is only accessible from your local system. We need to expose the URL so it can be accessible by Stream which we can do using ngrok.</p><p>Open up ngrok and expose the URL:</p><pre>./ngrok http 3000</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Mgc2YPpUGve_rSE7.png" /></figure><p>Now note any of the Forwarding URLs which can now be accessed from anywhere.</p><p>Head to your Stream <a href="https://getstream.io/dashboard">Dashboard</a> and enable the webhook option:</p><ul><li>Scroll down to the <strong>Chat Event </strong>section</li><li>Enable the webhook by selecting the <strong>Active</strong> selection</li><li>Enter the ngrok generated URL in the <strong>URL</strong> input form</li><li>Click the <strong>Save</strong> button to save your changes</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T08Zs7Ez23OLi-wV.png" /></figure><h3>Testing Chat</h3><p>Good job! you have successfully built a FAQ bot. Now let’s test the app to see that it works:</p><ul><li>Restart the Node server terminal</li><li>Open the Vue app on your browser</li><li>Now, ask a user for a given question and see the response from the bot</li></ul><h3>Final Thoughts</h3><p>In this tutorial, you have successfully built a FAQ bot . We explored a way in which you can add bots to your Stream app using the webhook feature provided by the Stream Chat infrastructure.</p><p>The sky is the limit for what you can build from here. What we’ve built is just a tip of the iceberg in terms of what you can do with bots. You can extend the functionality of the bot by adding more <a href="https://dialogflow.com/docs/intents">intents</a> with <a href="https://dialogflow.com/">Dialogflow</a>.</p><p>You can find the complete code of this tutorial on <a href="https://github.com/dongido001/getstream-chat-dialogflow-faq-bot.git">GitHub</a>. For more information on Stream Chat, have a look <a href="https://getstream.io/chat/">here</a>.</p><h3>Don’t forget to give us your 👏 !</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*-a0u75kW2uWZxmib" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e59ef%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3e59ef&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e59ef%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/7078d8ad19192c4c53d3bf199468e4ab/href">https://medium.com/media/7078d8ad19192c4c53d3bf199468e4ab/href</a></iframe><figure><a href="https://chatbotslife.com/bot-communities-mastermind-group-d2dae9876709#.53x0py6ou"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*6XUspT9JOSq0w0Fi35HIaA.png" /></a></figure><figure><a href="https://m.me/ChatbotsLife"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*c1LDMH5vbnIz9rmAka8Hwg.png" /></a></figure><figure><a href="https://chatbotslife.com/chatbot-development-hire-top-ai-chatbot-developers-c8b45ef7f207"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*D0Jf3dI6ZThtqcfwDYY7mg.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51edbc6ae35b" width="1" height="1" alt=""><hr><p><a href="https://blog.chatbotslife.com/adding-chatbots-to-your-stream-chat-app-using-googles-dialogflow-the-stream-blog-51edbc6ae35b">Adding Chatbots to Your Stream Chat App Using Google’s Dialogflow</a> was originally published in <a href="https://blog.chatbotslife.com/">Chatbots Life</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I fixed PHP json_encode() returning empty result]]></title>
            <link>https://medium.com/@onwuka_gideon/how-i-fixed-php-json-encode-returning-empty-result-e4ef97638ea1?source=rss-adbc4f40f48------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4ef97638ea1</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[jsonencode]]></category>
            <dc:creator><![CDATA[Onwuka Gideon]]></dc:creator>
            <pubDate>Tue, 20 Nov 2018 15:12:03 GMT</pubDate>
            <atom:updated>2019-05-31T03:00:28.466Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are building a RESTful API in PHP, then you are most likely using the json_encode function. json_encode is a PHP function that converts an array to JSON format.</p><p>In this article, I will discuss how you can fix a `json_encode` function that returns an empty result or throws an error.</p><h3>Debugging the error</h3><p>The first step in solving a problem is to first know what the problem really is.</p><p>First, let’s see if there is any error from json_encode. Add the below code in your code after the json_encode() function that you have:</p><pre>...</pre><pre>echo json_last_error_msg(); // Print out the error if any<br>die(); // halt the script</pre><p>If what was printed out is — “No errors”, then there is nothing wrong with the data.</p><p>Here is the list of errors you might encounter:</p><p><a href="https://secure.php.net/manual/en/function.json-last-error.php#refsect1-function.json-last-error-examples">https://secure.php.net/manual/en/function.json-last-error.php#refsect1-function.json-last-error-examples</a></p><h3>Fixing “Malformed UTF-8 characters, possibly incorrectly encoded” error</h3><p>This is one of the common error you will face especially if you are fetching your data from a database.</p><p>I encountered this error personally which prompted me to write this article. I was working with a result which I fetched from the database that I converted to JSON. Below is my complete code:</p><pre>$courses = [];<br> $db = new mysqli(HOST, USERNAME, PASSWORD, DATABASE);<br> if ($db-&gt;connect_error) {<br>     echo (json_encode([<br>           &#39;status&#39; =&gt; &#39;error&#39;,<br>           &#39;message&#39; =&gt; &#39;connection to database failed.&#39;<br>     ]));<br>     die();<br> }<br> <br> if (isset($_GET[&#39;count&#39;])) {<br>      $allCoursesQuery = &quot;SELECT * FROM `courses`&quot;;<br>      $result = $db-&gt;query($allCoursesQuery);<br>      <br>      echo json_encode([&#39;count&#39; =&gt; $result-&gt;num_rows]);<br>      die();<br> }</pre><pre>$allCoursesQuery = &quot;SELECT id, title FROM `courses`&quot;;</pre><pre>$result = $db-&gt;query($allCoursesQuery);<br> <br> if ($result-&gt;num_rows &gt; 0) {<br>  while ($row = $result-&gt;fetch_assoc()) {<br>   $courses[] = [<br>                &#39;id&#39; =&gt; $row[&#39;id&#39;],<br>                &#39;title&#39; =&gt; $row[&#39;title&#39;]<br>   ];<br>  }<br> }<br> <br>echo( json_encode([<br>   &#39;status&#39; =&gt; &#39;success&#39;,<br>   &#39;data&#39; =&gt; $courses<br>]) );</pre><pre>die();</pre><p>In the code above, I’m fetching all the courses that are in the `courses` table that is about 164 records. In the last part of the code, I encode the array of courses to JSON then print out the result.</p><p>The result was empty, nothing was printed out. But if I <strong>LIMIT</strong> the result to like 100 records, I get the JSON printed out but any record I fetch above 100 shows empty.</p><p>At first, I thought it might be a memory issue (but 164 records is not that much 😕). I went ahead to increase my memory limit but that did not help. It was not memory related.</p><p>After much trial and error, I decided to see what json_encode is complaining about if any. So I placed the code after the json_encode(…) function:</p><pre>echo json_last_error_msg(); // Print out the error if any<br>die(); // halt the script</pre><p>Now, I see the error!:</p><pre>Malformed UTF-8 characters, possibly incorrectly encoded</pre><p>This error happens if the result contains mixed encoding characters.</p><p>To fix it, I introduced `JSON_UNESCAPED_UNICODE`:</p><pre>echo( json_encode([<br>   &#39;status&#39; =&gt; &#39;success&#39;,<br>   &#39;data&#39; =&gt; $courses<br>], JSON_UNESCAPED_UNICODE) );</pre><h3>Conclusion</h3><p>In this article, you have learned how to debug common json_encode() error and how to get them fixed. Although we did not discuss how to fix all of the errors independently, I strongly believe you can take it from there as you have known what the error message.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4ef97638ea1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fixing Laravel $(jQuery) is not defined]]></title>
            <link>https://medium.com/@onwuka_gideon/fixing-laravel-jquery-is-not-defined-a316fd918e0a?source=rss-adbc4f40f48------2</link>
            <guid isPermaLink="false">https://medium.com/p/a316fd918e0a</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[jquery-undefined]]></category>
            <category><![CDATA[defer]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Onwuka Gideon]]></dc:creator>
            <pubDate>Thu, 11 Oct 2018 03:22:25 GMT</pubDate>
            <atom:updated>2018-12-03T09:41:37.639Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I fixed my Laravels’ $(jQuery) is not defined error</h3><p>I was working on a particular Laravel project which relied much on jQuery with some colleagues. jQuery has been working pretty well but all of a sudden it stopped. As usual, I went deep to know what was wrong but nah! everything seems to be in order.</p><p>Here is my code giving the error:</p><pre>@section(&#39;script&#39;)</pre><pre>&lt;script&gt;</pre><pre>    alert($);</pre><pre>&lt;/script&gt;</pre><pre>@endsection</pre><p>But where should I check again (The last commit that broke the code?).</p><p>Finally, I made up mind to hit search engine with my query — maybe there is a new release of Laravel that broke it 😫. After hours of search, I found many related issues with mine. I tried all, but none worked.</p><p>Wait, did I in any way comment out the script tag that imports the js bundled file in the layout file?:</p><pre>&lt;head&gt;</pre><pre>...</pre><pre>  &lt;script src=”{{ asset(‘js/app.js’) }}” defer&gt;&lt;/script&gt;</pre><pre>...<br>&lt;/head&gt;</pre><p>No, I didn’t, it’s still intact.</p><h3>Option 1</h3><p>While checking …, I found this `defer` there on the tag. But wait what’s it doing there? who added it? But what does it mean? After this question, I removed it and just want to see if there will be any change without it. That solved!</p><p>The `defer` was the culprit. The defer attribute is a boolean attribute. When present, it specifies that the script is executed “when the page has finished parsing”. So the script I wrote that depends on jQuery was executing before the `app.js` file that contains jQuery is loaded.</p><p>So finally the tag looks like below without the `defer` boolean:</p><pre>&lt;script src=”{{ asset(‘js/app.js’) }}”&gt;&lt;/script&gt;</pre><p>And this solved my problem! 😤</p><h3>Option 2</h3><p>You can also solve this issue by executing the script after the document on the page is loaded.</p><pre>window.addEventListener(&#39;load&#39;, function() {</pre><pre>    alert($);</pre><pre>})</pre><h3>Conclusion</h3><p>“defer” is used in a script tag when you want the script to be executed after the page has been parsed. So you can only make use of the script once the page is loaded and the script is completely loaded.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a316fd918e0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>