Build beautiful and interactive API documentation for ORDS

Image
In this blog post, I will show you how to quickly build beautiful and interactive API documentation for your Oracle APEX REST data sources using  swagger hub . Using APEX v23.1. I downloaded the  titanic data set  and loaded them into tables in my APEX instance, created some authorized restful services and published them using swagger hub. You can create a free account on swagger hub.   Check out my titanic swagger hub here ; Press Authorize. Username REST, password Glasgow123! I won't go through creating RESTful services and just show you the four I created that sit on top of the titanic data set; The GET is a very simple SQL query;      select * from TITANIC_DATA_SET_NEW A handy tip is to add comments, as there will appear on swagger hub, making your API self documenting; Once you have created your modules, press the Generate Swagger Doc button; This will generate an open API for you.  Copy the API and paste it into swagger hub This will generate the documentation; As mentioned b

Add a chatbot to your APEX app using DialogFlow

This post will show you how you can add a free chatbot to your APEX app using the always free Oracle Autonomous database and Google’s natural language processing (NLP) Dialogflow ES.

This Oracle APEX NSS web site allows users to ask the chatbot for the percentage of students who overall, were satisfied with the quality of the courses at the University of Glasgow.  It allows users to query over 1,200 courses.  Give it a try by clicking NSS→Russell Group NSS Course Search


Here is some info about how DialogFlow works on another project I built.

How I built it.

Loaded data into autonomous database

I loaded the National Student Survey CSV data into autonomous database using database actions data load;


Created a REST API for the data

Using the REST action above I created a REST API for the data, it takes a course and aim and retrieves it from the Database


Try it out;

https://kjwvivmv0n5reuj-apexkqor.adb.uk-london-1.oraclecloudapps.com/ords/admin/nss/q27/Mathematics/BSc

This returns the following JSON which has selected the question Q27 overall percentage satisfied with Mathematics BSC course. It also returns the course ID and overall rank for UK universities for that course

"items":[{"q27":77,"kiscourseid":"G100-2208","rank":11}]

Create the chatbot

I used DialogFlow ES to create the chatbot.

Call the REST API from DialogFlow

In webhook fulfilment, I added this function that takes a course and aim and calls the REST API. As it is calling a REST API, I used a promise to make the call and return the result to DialogFlow;

function aim(agent) {
   
    console.log('in AIM intent');    
    var course = agent.contexts[0].parameters.course;
    var aim = agent.contexts[1].parameters.aim;
       
    const promise1 =  new Promise(function (resolve, reject) {
       
    axios.get('https://kjwvivmv0n5reuj-apexkqor.adb.uk-london-1.oraclecloudapps.com/ords/admin/nss/q27/'+course+ '/'+ aim)
        .then(res => {
        resolve(res);
        })
        .catch(error => {
        console.log('Error in fetch ', error);
        });
   });
 
   promise1.then(function (result) {
      console.log("Result is " + JSON.stringify(result.data));
      if (result.data.items && result.data.items[0])
      {
       console.log('Percentage is ', result.data.items[0].q27 );
       console.log('Rank is ', result.data.items[0].rank );
       
        var rank = '';
        if (result.data.items[0].rank == 1)
        {
          rank = 'Good news, the University of Glasgow is the number 1 ranked University in the Russell Group :-).';
        }
        else if (result.data.items[0].rank)
        {
          rank = 'The University of Glasgow is ranked ' + result.data.items[0].rank + ' in the Russell Group.';
        }
       agent.add(course + ' ' + aim + ' overall satisfaction is ' + result.data.items[0].q27 + '%.' + rank + ' Say another course to start again');          
      }
      else
      {
       agent.add(course+ ' does not have an aim of ' + aim + '. Say another course to start again');
      }
    }, function (error) {
                console.log("Error in then ", error);
    });  
    return promise1;  
  }

The DialogFlow aim intent calls the webhook, which passes in the course and aim;


To get the chatbot HTML to add to your APEX app, select DialogFlow Messenger in Integrations;


this created the code to add to our APEX page;

<script src="https://www.gstatic.com/dialogflow-console/fast/messenger/bootstrap.js?v=1"></script>
<df-messenger
  intent="WELCOME"
  chat-title="UofG Overall satisfaction"
  agent-id="XXXXXX"
  language-code="en"
></df-messenger>

we now have the chatbot on our APEX app;




Comments

Popular posts from this blog

Oracle APEX Interactive Grid colour cells based on a condition using JavaScript and CSS

Oracle APEX pretty checkbox item plugin

Build beautiful and interactive API documentation for ORDS