Skip to Content
Technical Articles

SAP Conversational AI (WhatsApp Bot) Integration with Coronavirus (Covid-19) Live GIS System

 

Introduction

Welcome to my another blog, I hope blog title is self explanatory, Even if its not, after end of the blog you will get everything, Its quite sensitive topics almost everyone aware but there is some cool learning stuff also you will get in this blog. So let me tell you how its started, i was just exploring the live GIS for Coronavirus (Covid-19) update. Then started doing little reverse engineering to find an API to get all the data, it was Little  tricky because i don’t wanted to integrate with Static Github based csv. Finally ended up with creating an express js based application and integrated with WhatsApp through SAP Conversational AI.

 

For those who is not aware what is GIS (Geographic Information System), let me explain you bit.

A geographic information system (GIS) is a framework for gathering, managing, and analyzing data. Rooted in the science of geography, GIS integrates many types of data. It analyzes spatial location and organizes layers of information into visualizations using maps and 3D scenes. ​With this unique capability, GIS reveals deeper insights into data, such as patterns, relationships, and situations—helping users make smarter decisions

Best Example – > Live Geographic Information System for Covid-19 (nCoronavirus)

 

So, What you are going to see in this Blog?

In this Blog i will show you how i did reverse engineer on Covid-19 Live Geographic Information System, then finally built rest API for finding the confirmed cases country wise and then made a Integration with SAP Conversational AI and Finally Integrating with WhatsApp. Pretty Simple isn’t it.

** Earlier in my blogs i have discussed how to Integrate WhatsApp with SAP Conversational AI. So that part i am not going to cover, rather i am going to share the link of those blogs.  Please refer to below blog, if you are not aware how to Integrate WhatsApp with SAP Conversational AI.

WhatsApp Integration with SAP Conversational AI.

Lets get into action and our first action would be looking at the Technical Architecture.

Technical Architecture

 

By looking at Architecture many of you already must have drawn a picture in your mind, how this whole Integration will work, pretty straight forward, trick is to build a rest API which will accept input as a country and and give you the data you want.

Let’s Break this whole Integration into smaller piece for better understanding.

 

Step 1: How i did Reverse Engineering the GIS System of Coronavirus (Covid-19) and Find the Correct API from GIS Server

Answer is pretty simple, the way we debug any UI Application by pressing F12 and see the Network log what APIs are getting called.

Actually it calls Multiple APIs to fetch different types of Data and I was looking for something where i can Pass Country as Input and get the confirmed cases.

The URL Was encoded and Pretty Complex, So i used Online URL Decoder to Decode it which i will understand

Much Clear, Lastly Postman did actual job to find the filter

Just to Play around with it, i tried with India and Japan, and voila it gives me the expected result

That’s it, our main hurdle is done, we got our filter name “Country_Region”

Below is API URL to Find Confirm Cases of Coronavirus based on Country

https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Confirmed > 0) AND (Deaths>0) AND (Country_Region='Mainland China')&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Deaths desc,Country_Region asc,Province_State asc&outSR=102100&resultOffset=0&resultRecordCount=250&cacheHint=true

 

Step 2: Build a simple (Node.Js based) API to integrate with SAP Conversational AI As WebHook

const express = require('express')
const bodyParser = require('body-parser')
const  nodefetch =  require('node-fetch')
const app = express() 
const port =  process.env.PORT || 3000
app.use(bodyParser.json())
app.post('/countrywise', async(req,res)=>{
    var country = req.body.country;
    const confirmcases = async function (country){
        var url = 'https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Confirmed > 0) AND (Country_Region=\''+country+'\')&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&outStatistics=[{"statisticType":"sum","onStatisticField":"Confirmed","outStatisticFieldName":"value"}]&outSR=102100&cacheHint=true';
        const result = await nodefetch (url,{
            method: 'GET',
            headers: { 'Content-Type': 'application/json',
            Accept : 'application/json' }
    
      });
      const output = await result.json();
      return output.features[0].attributes.value;
    }
    res.send({
        replies: [{
          type: 'text',
          content: 'Total Confirmed cases in '+country+ ' is '+await confirmcases(country) 
        }], 
        conversation: {
          memory: { key: 'value' }
        }
      })
 
})

app.listen(port, () => { 
    console.log('Server is running on port '+port) 
  })

Now Deploy the App into SAP Cloud Platform Cloud Foundry 🙂

 

Step 3: Design the bot in SAP Conversational AI

Below is the how my intent looks like for this Scenario

Let’s build skill for this, Below is How the skill triggers looks like

This Skill have requirement as Country is needed, as it will be used as parameter for our  API

And Finally Configure the deployed Node.JS Based API as WebHook in Skill’s Action

Step 4: Integrate this bot with WhatsApp

In-Order to Integrate this bot with WhatsApp follow this blog (Step 8.9.10.11)

 

Demo : I have recorded short Video to show you how it looks like. Watch and Enjoy.

**I hope everyone enjoyed this Blog, Please share your thought, questions as comment.  I wish everyone’s safety. Will see you in next Blog.

 

**N.B: You can use this for Integrating with any other Social Messenger Like Telegram, Facebook. In that cases Last step you don’t have to  perform just use standard connector of SAP Conversational AI. You can also have a look at other API  if you want to build cool UI/Mobile based App.

 

Regards,

Sudip

 

 

 

17 Comments
You must be Logged on to comment or reply to a post.