Covid Center Bot

Covid Center Bot

  • Docs
  • Help

โ€บPart Contents

Single Page

  • Covid Center Bot Tutorial

Part Contents

  • Introduction
  • Design User Interaction
  • Learn Terms in Wit.AI
  • Create and Train wit.AI Application to do Natural Language Processing (NLP)
  • Integrate Wit.AI with your Messenger Bot
  • Train Covid Intent with Wit.AI API
  • Enhance bot parser for Covid Intent
  • Improvement

Enhance bot parser for Covid Intent

Enhance bot parser for Covid Intent

The first thing that you have to do is listing your bot behaviours and responses that come from entities that you have.

We have covid_intents which have two entities.

  1. Covid entities
  2. Location entities

In order to give covid result based on area, the intent should fulfill both entities. If one of them is not exist, we must asking user for the missing items.

But, in order to make this bot simpler, we avoid Finite State Machine. So we give response how user should send text to bot.

Therefore, this is code you must add to bot/index.js in your branch covid template.

bot/index.js


// default response
const DEFAULT_RESPONSE = 'Sorry, cocid doesnt understand :(. If you want to know the latest covid info, please type "total covid in your city". Example: total covid in Jakarta'

function getMessageFromNlp(nlp) {
  // intents checker
  if (nlp.intents.length == 0) {
    return DEFAULT_RESPONSE
  }

  // switch case the intent.
  switch (nlp.intents[0].name) {
    case 'covid_intents':
      return getCovidResponse(nlp.entities)
    case 'sentiment_intent':
      return getSentimentResponse(nlp.traits.sentiment)
    default:
      return DEFAULT_RESPONSE
  }
}

function getCovidResponse(entities) {
  console.log(entities["covid:covid"]);
  var city = ''
  var isCovid = false

  // null checker
  if (entities['wit$location:location'] == null || entities['covid:covid'] == null) {
    return DEFAULT_RESPONSE;
  }

  // iterate to find covid entities and location entities.
  entities['wit$location:location'].forEach(function (c) {
    city = c.body
  })
  entities['covid:covid'].forEach(function (c) {
    if (c.value == "covid") {
      isCovid = true
    }
  })


  if (isCovid && city != '') {
    // covid response when covid and city is available.
    var totalCase = getRandomNumber(1,100)
    var confirmCase = getRandomNumber(1, totalCase)
    return `total covid in ${city} is ${totalCase} cases, ${confirmCase} confirmed, ${totalCase - confirmCase} deaths.\n
    if you experience the following symptoms, your sense of taste disappears, difficulty breathing, high fever, dry cough, fatigue, immediately do further checks at the referral hospital and after doing the test, if positive it is recommended to do self-quarantine for 14 days at your home. \n\n the following article on how to self quarantine
    good and true according to WHO (World Heart Organization) : https://www.who.int/indonesia/news/novel-coronavirus/new-infographics/self-quarantine
    This is referral hospitals in ${city}:\n
1. rumah sakit Umum Fatmawati (https://goo.gl/maps/GV6fZRxhEgg2PPjK7)\n
2. rumah sakit Jakarta Medical Centre (https://goo.gl/maps/oPnpyw2edFJcg3ha7)\n
3. rumah sakit Umum Andhika (https://g.page/rsuandhika?share)`
  } else if (isCovid) {
    // response when location is not provided (ask the location and give how they should give message)
    return 'Sorry, Cocid wants to know what area is Covid? for example, you can retype the number of covid in your city'
  }

  return DEFAULT_RESPONSE;
}

// random the total case 
function getRandomNumber(start, end) {
  return Math.floor(Math.random() * end-start) + start
}

and change the function getSentimentResponse to getMessageFromNlp on post webhook.

- text: getSentimentResponse(message.nlp.traits.sentiment),
+ text: getMessageFromNlp(message.nlp),

Now you can try your bot on facebook messenger, repeat step Deploy your webhook from start to finish your setup messenger.

Enjoy, and hack your bot !!! ๐Ÿค– ๐Ÿ“ฑ

๐Ÿ†๐Ÿ†๐Ÿ†

โ† Train Covid Intent with Wit.AI APIImprovement โ†’
  • Enhance bot parser for Covid Intent
Covid Center Bot
Docs
Covid Center Bot TutorialCovid Center Bot Tutorial - Github
More
GitHubStar
Follow @sukangwurr
Facebook Open Source
Copyright ยฉ 2020 Covid Center Bot