How to deploy SUSI AI bots on ngrok for debugging

For production purposes, bots can be deployed in cloud services such as Heroku, Google App Engine or Amazon Web Services - or in their own data center infrastructure. However, for development purposes you can use ngrok to provide access to your bot running in your local network. Ngrok is easy to setup and use. To learn more about it, you can refer to its documentation. Ngrok is a handy tool and service that allows you tunnel requests from the wide open Internet to your local machine when it's behind a NAT or firewall. It's commonly used to develop web services and webhooks. In this blog, you’ll learn how to deploy SUSI AI bots on ngrok. We’re going to demonstrate the process for SUSI AI Kik bot. However it is the same for rest of the bots as well. First of all, you need to configure a bot on Kik. To configure a Kik bot, follow the first few steps of this blog post till you get an API key for the bot that you created using Botsworth. Now, follow these steps: In order to run SUSI AI kik bot on ngrok, you have to make some changes to the index.js file after forking susi_kikbot repository and cloning it to your local machine. Open index.js and change the information in ‘bot’ object. Write username of your kik bot in front of username and api key that you got for your bot in front of apiKey in quotations and leave the baseUrl blank for now. It will look like this: (Don’t copy the API key shown below. It’s invalid and only for demonstration purposes.) var bot = new Bot({     username: 'susi.ai',     apiKey: 'b5a5238b-b764-45fe-a4c5-629fsd1851bd',     baseUrl: '' }); Now save the file. No need to commit it. Go to https://ngrok.com/ and sign up. Next, you’ll be redirected to the setup and installation page. Follow the instructions there to setup ngrok on your local machine. Now open terminal and use ‘cd’ command to go to the susi_kikbot directory. While deploying on ngrok, we set the port for listening to http requests. Hence remove “process.env.PORT” from index.js or else this will cause an error in the next step. After removing, it should look like this: (Now save the index.js file) http.createServer(bot.incoming()).listen(8080); Also, comment out setInterval function in index.js. Now type the command ngrok http 8080 in terminal. In case ‘ngrok’ command doesn’t run, copy the ngrok file that you downloaded in step 5 and paste it in the susi_kikbot directory. Then enter ./ngrok http 8080 in terminal. When it launches, you’ll see a screen similar to the following: Copy the “forwarding” address (https://d36f0add.ngrok.io), and paste it in front of ‘baseUrl’ in the ‘bot’ object in index.js file. Add “/incoming” after it and save it. Now the ‘bot’ object should look similar to this: var bot = new Bot({     username: 'susi.ai',     apiKey: 'b5a5238b-b764-45fe-a4c5-629fsd1851bd',     baseUrl: 'https://d36f0add.ngrok.io/incoming' }); Launch another terminal window and cd into the susi_kikbot directory in your local machine. Then type node index.js command. Congratulations! You’ve successfully deployed SUSI AI Kik bot on ngrok. Now try sending a message to your SUSI AI…

Continue ReadingHow to deploy SUSI AI bots on ngrok for debugging

Running ngrok To Use Local Open Event API Server Endpoints From Public Access URL

While developing the nextgen Open Event API Server, one has to let co-developers review the changes made for each new feature added or any bug fix made. One way to do this is to fetch code from pull request head and setup a local deployment from the PR branch. This sometimes causes issues in database due to faulty migrations, if one is not careful. One other way, which is discussed in the blog post here, is using ngrok. What is ngrok? Ngrok lets you create a secure tunnel to your localhost deployment over a public URL. This particular feature comes in handy when you have changes, say along with a populated database, to demo to someone else over a public url, which can be shared between as many people. It saves you from deploying the change branch over again and saves you from hassles of database migration issues. How to setup and run ngrok? To run ngrok, you need to download it from the ngrok website. The download page can be found here. Once you have the zip installed, you’ll need to unzip it. On Linux or MacOS, run this in the terminal: $ unzip /path/to/ngrok.zip To expose the web server running on your local machine, run the following from inside the directory where you have unzipped ngrok: ./ngrok http 80 This syntax breakdowns to : ngrok :: terminal command http :: protocol of the server that is to be tunneled ( ngrok also lets you open and run TCP and TLS tunnels) 80 :: port on which the tunnel is to be run ( If you are not sure of the port on which your server is running, it might probably be 80 - the default for HTTP) The Open Event API server runs on port 5000 and it provided HTTP API, so the command we’ll use here is ./ngrok http 5000 Once you run this command, ngrok opens its UI in the terminal itself. This will contain the public url of your tunnel along with other stats related to the requests being made and traffic on localhost. Starting ngrok: Public URL updated: ngrok also offers a web interface where you can see the requests and other data which is shown in the terminal. For this go to http://localhost:4040/inspect/http. This web interface inspects and records each request made so that you can replay the requests again for debugging or cross-checking metrics. This feature can be turned off by passing an argument, so that the requests are not recorded anymore. While running a production server, it can help to both maintain security for the requests and also reduce request handling times when scaling. To read more about advanced options, please read the ngrok documentation. Running Open Event API server on the public URL: Since now we have localhost:5000 tunnelled over a public url, we’ll use that to make requests to the API server. A GET request for /v1/events : The request made to the public URL, which in this case here is: http://9a5ac170.ngrok.io is equivalent to…

Continue ReadingRunning ngrok To Use Local Open Event API Server Endpoints From Public Access URL