Skip to Content
Technical Articles
Author's profile photo Sudip Ghosh

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

 

 

 

Assigned Tags

      19 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Syed Abdul Imran
      Syed Abdul Imran

      Another informative blog. Good one Sudip

      Author's profile photo Sudip Ghosh
      Sudip Ghosh
      Blog Post Author

      Thank you so much imran bhai 🙂

      Author's profile photo Raffael Herrmann
      Raffael Herrmann

      Hi Sudip,

      thanks for the great article. Now I definitely want to dive into the GIS topic. I tried to find a list of other GIS dashboards, but couldn't find. Is there something like a repository/list of all public dashboards create on arcgis.com? (Googling for "inurl:www.arcgis.com/apps/" works somehow, but I think it doesn't find all dashboards hosted...)

      Best regards

      Author's profile photo Sudip Ghosh
      Sudip Ghosh

      Hello Raffael,

      No, I couldn't find any straight forward way but I did little reverse engineering and tried google dork also like you. What I found is https://services1.arcgis.com/0MSEUqKaxRlEPj5g/ArcGIS/rest/services which might excite you. Let me know your thought on this.

      Regards,

      Sudip

      Author's profile photo Raffael Herrmann
      Raffael Herrmann

      Not exactly what I searched for, but still a pretty interesting link. Thanks! 🙂

      Author's profile photo Arun Chembra
      Arun Chembra

      Hello Sudip,

      Again wonderful one...

      Good, keep writing.

      Thanks & Regards,

      Arun

      Author's profile photo Sudip Ghosh
      Sudip Ghosh
      Blog Post Author

      Thank you so much

      Author's profile photo Liviu Malaescu
      Liviu Malaescu

      Great showcase of an integration scenario!

      Author's profile photo Sudip Ghosh
      Sudip Ghosh
      Blog Post Author

      Thank you so much for your comment

      Author's profile photo Juan Jose Rueda
      Juan Jose Rueda

      Thanks. for this content! really great job.

      That's a very nice application case,

       

      Regards

      Author's profile photo Sudip Ghosh
      Sudip Ghosh
      Blog Post Author

      Thank you so much, yes ut can be good use case

      Author's profile photo kratika varshney
      kratika varshney

      Hi Sudip Ghosh,

      Very nice Blog. Actually i am implementing this scenario but i am getting error on running node.js application on localhost. I am getting the following

      Cannot GET /

      Can you help in this?

       

      Author's profile photo Sudip Ghosh
      Sudip Ghosh
      Blog Post Author

      Hello Please look at the express path, you have to mention proper path also. And i belive its a post call. you have to pass the payload also in this format {"country":"india"}

      Author's profile photo Ahmed Ayad
      Ahmed Ayad

      Hi Sudip

      Iam facing the below issue during call Webhook API, Even all steps working fine and i created app with index.js with your sample code and deployed it to trial SCP.

       {
              "level": "warning",
              "code": "W_API_ERROR",
              "data": {
                "uuid": "3be02c4d-3a82-4a07-8c6e-df744873cb22",
                "error_code": "BusinessConnector(RT) - 1020",
                "skill_id": "bfd9b0bc-51bf-440a-9eb8-7e85a247e696",
                "action_id": "a51209db-08e4-49ca-bdaa-6238d688ad2e",
                "error": "Error while calling API"
              },
              "timestamp": "2020-06-10T10:40:40.763Z"
            }
      Author's profile photo Pedro Bigoli
      Pedro Bigoli

      The skill is probably configured as "API Service Configuration" instead of "Webhook Configuration", please check it.

      Author's profile photo Moaen Mustafa
      Moaen Mustafa

      Dear Ahmed,

      Would you advise how to came over this issue please

      can you share your chatbot to explore and learn from it .

      also, you can drop me an email or call me on moaen.mustafa@gmail.com if you can spare a minute pls

      Author's profile photo Dutta Somojothi
      Dutta Somojothi

      It is becoming almost a practice to look through if you have any new blogs posted . Again a very wonderful informative blog on chatbot. Thanks Sudip.

      Stay safe!!

      Author's profile photo Sudip Ghosh
      Sudip Ghosh
      Blog Post Author

      Thank you for your words, very soon i ll be posting new blog.

      Author's profile photo Moaen Mustafa
      Moaen Mustafa

      Hi,

      I am trying to consume api directly from arcgis server using the json .but I am facing some issue.

       

      can you share the chatbot for covid19 so I can fork it to explore .

       

      Also, can you advise how to use arcgis Server rest element.,I need to update the intent with the name of the publish feature dataset e.g. pipeline , and then ask the user select which feature insdie the feature dataset and then select /or set the critical .like water pipeline or gas pipeline

       

      can you help . thanks