Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Setting Up Local Environment for Developing Oracle Intelligent Bots Custom Components

DZone's Guide to

Setting Up Local Environment for Developing Oracle Intelligent Bots Custom Components

Learn how to get all set to develop your customer component locally with access from your Bot running on the Oracle Mobile Cloud Enterprise instance.

· AI Zone ·
Free Resource

Start coding something amazing with the IBM library of open source AI code patterns.  Content provided by IBM.

Oh, the joy of having a local development environment is priceless. For most cloud-based solutions, the story repeats itself — it's hard to troubleshoot and make changes while developing your project.

Well, this is no different with Oracle Intelligent Bots, and for your benefit, setting up a local development environment is pretty simple to do.

Before you get started, make sure you have Node.js downloaded and installed.

There is no entry point to run this in a local environment, so here is what you have to do.

Create a file called server.js with your favorite editor in the api_implementation directory you have extracted with the ZIP file above and paste the following JavaScript code:

const express = require('express');
const bodyParser = require('body-parser');
const components = require('./mcebots');
const app = express();
app.use(bodyParser.json());
components(app);
app.listen(process.env.PORT || 3000, () => {
    console.log('Custom Components Server Ready');
}); // This is just a sample script. Paste your real code (javascript or HTML) here.

if ('this_is' == /an_example/) {
    of_beautifier();
} else {
    var a = b ? (c % d) : e[f];
}

The piece of code above will wrap the Oracle Intelligent Bots custom component SDK functionality for you.

It basically runs an Express.js server on top of Node.js in the port you want and requires the Oracle Intelligent Bots SDK by calling mcebots.js.

To run it, use the following command:

node server.js 

When you have your local server above running, try sending an HTTP GET request to http://localhost:port/mobile/custom/bots_samples/components (you can use something like curl, Postman, or simply the browser).

That call should return a list of sample components available to you and you should see something similar to the following payload:

You can start testing it or making changes to the registry and other functionality by editing the files provided in the sample package. Please refer to the Oracle Mobile Cloud Enterprise documentation if needed.

Now, the next thing you should do is to enable your local server to be accessed by your Oracle Intelligent Bot. To do that, I'd suggest that you use something like ngrok to create a public URL for exposing your local web server where the Bot Service will be able to reach your environment.

To make that happen, start a tunnel on your machine pointing to the port number you ran your local server. In my case, I started on port 3000, so I'd run ngrok like this:

./ngrok http 3000 

That would work for any free (un)registered account, but if you have an ngrok subscription, you can also set up a subdomain, which helps quite a lot, as you would not need to keep updating the server URL in the Bot Custom Component Service definition every time you restart your ngrok tunnel or it expires.

Anyway, ngrok will generate two tunnels for you (HTTP and HTTPS), so pick one to be used by your Custom Compoment definition.

Log into your OMCE (Oracle Mobile Cloud Enterprise) instance, select Bots, and choose the Bot you want to use. Go to the Components tab and click on the Add Service button.

Fill up all the required fields and remember that the Metadata URL should be your ngrok tunnel URL appended by /mobile/custom/bots_samples/components.

You should see a list of components created by expanding the recent service.

You are all set to develop your customer component locally with access from your Bot running on the Oracle Mobile Cloud Enterprise instance.

Start coding something amazing with the IBM library of open source AI code patterns.  Content provided by IBM.

Topics:
ai ,chatbot ,bot development ,oracle ,tutorial ,oracle intelligent bots ,node.js ,custom components

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}