Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/Covid19-chatbot.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 11 additions & 13 deletions DataRequests/MakeApiRequests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import requests
import json


class Api:
def __init__(self):
pass
Expand All @@ -9,7 +11,7 @@ def makeApiRequestForCounrty(self, country_name):
querystring = {"country": country_name}
headers = {
'x-rapidapi-host': "covid-193.p.rapidapi.com",
'x-rapidapi-key': "482a8f8516msh16204eb9d1f4f68p1a9146jsnf33914c7300e"
'x-rapidapi-key': "36626c56f2msh8580d29c47aca59p12a368jsnc74c1cdf1888"
}
response = requests.request("GET", url, headers=headers, params=querystring)
# print(response.text)
Expand All @@ -18,34 +20,30 @@ def makeApiRequestForCounrty(self, country_name):
result = js.get('response')[0]
print(result.get('cases'))
print("*" * 20)
return result.get('cases') , result.get('deaths'),result.get('tests')

return result.get('cases'), result.get('deaths'), result.get('tests')

def makeApiRequestForIndianStates(self):
url = "https://covid19-data.p.rapidapi.com/india"
url = "https://covid-193.p.rapidapi.com/history?country=india&day=2022-04-17"
headers = {
'x-rapidapi-host': "covid19-data.p.rapidapi.com",
'x-rapidapi-key': "482a8f8516msh16204eb9d1f4f68p1a9146jsnf33914c7300e"
'x-rapidapi-host': "covid-193.p.rapidapi.com",
'x-rapidapi-key': "36626c56f2msh8580d29c47aca59p12a368jsnc74c1cdf1888"
}
response = requests.request("GET", url, headers=headers)
# print(response.text)
js = json.loads(response.text)
print("******", js)
#result = js.get('list')
# result = js.get('list')
return js


def makeApiWorldwide(self):
url = "https://covid-19-statistics.p.rapidapi.com/reports/total"
url = "https://covid-193.p.rapidapi.com/countries"
headers = {
"x-rapidapi-host": "covid-19-statistics.p.rapidapi.com",
"x-rapidapi-key": "482a8f8516msh16204eb9d1f4f68p1a9146jsnf33914c7300e"
"x-rapidapi-host": "covid-193.p.rapidapi.com",
"x-rapidapi-key": "36626c56f2msh8580d29c47aca59p12a368jsnc74c1cdf1888"
}
response = requests.request("GET", url, headers=headers)
# print(response.text)
js = json.loads(response.text)
print("******", js)
result = js.get('data')

return result

Binary file not shown.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# As requested by many people over mail or linkedin.I am making stepwise Implementation playist on youtube.

Here is the link of stepwise implementation Youtube- https://bit.ly/3c0n0ss

# End-to-End Covid-19 chatbot using DialogFlow,Python/Flask,MongoDb Atlas and deployed on Pivotal Cloud foundary and Telegram
# End-to-End Covid-19 chatbot using DialogFlow,Python/Flask,MongoDb Atlas and deployed on Heroku and Telegram
This chatbot developed using Dialoglow,python,flask,MongoDB and deployed on Telegram. search @bestcovid19_bot on telegram app
BestCovid-19 Bot can give answers of all of your queries related to covid-19 also it can -

Expand All @@ -27,7 +23,7 @@ If you like my work kindly hit 🌟🌟🌟


How to Setup the whole system ?
1. Setup Pivotal Cloud foundary account and install foundary CLI to your system
1. Setup Heroku account


2. Setup MongoDB Atlas account
Expand All @@ -42,5 +38,5 @@ How to Setup the whole system ?
5. use PostMan to test this code locally. localhost:5000/webhook , give header and body as Raw json. (Everything mentioned inside document.)


feel free to contact me in case of any problem reachout to me @ 'dineshraturi22@gmail.com' and Add subject-BestCovid Github Query
feel free to contact me in case of any problem reachout to 'navneetguptaend@gmail .com' and Add subject-BestCovid Github Query

69 changes: 35 additions & 34 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# doing necessary imports
from flask import Flask, render_template, request, jsonify, make_response
from flask_cors import CORS, cross_origin
import requests
import pymongo
import json
import os
from saveConversation import Conversations
import pymongo
import requests

from flask import Flask, render_template, request, jsonify, make_response
from flask_cors import cross_origin
from pymongo import MongoClient

from DataRequests import MakeApiRequests
from saveConversation import Conversations
from sendEmail import EMailClient
from pymongo import MongoClient

import os

app = Flask(__name__) # initialising the flask app with the name 'app'


# geting and sending response to dialogflow
# getting and sending response to dialogflow
@app.route('/webhook', methods=['POST'])
@cross_origin()
def webhook():
Expand All @@ -29,7 +32,7 @@ def webhook():
# processing the request from dialogflow
def processRequest(req):
# dbConn = pymongo.MongoClient("mongodb://localhost:27017/") # opening a connection to Mongo
log = Conversations.Log()
# log = Conversations.Log()
sessionID = req.get('responseId')
result = req.get("queryResult")
intent = result.get("intent").get('displayName')
Expand All @@ -38,11 +41,11 @@ def processRequest(req):
cust_name = parameters.get("cust_name")
cust_contact = parameters.get("cust_contact")
cust_email = parameters.get("cust_email")
db = configureDataBase()
# db = configureDataBase()

if intent == 'covid_searchcountry':
cust_country = parameters.get("geo-country")
if(cust_country=="United States"):
if cust_country == "United States":
cust_country = "USA"

fulfillmentText, deaths_data, testsdone_data = makeAPIRequest(cust_country)
Expand All @@ -55,8 +58,8 @@ def processRequest(req):
deaths_data.get('new')) + \
"\n" + " Total Test Done : " + str(deaths_data.get('total')) + "\n\n*******END********* \n "
print(webhookresponse)
log.saveConversations(sessionID, cust_country, webhookresponse, intent, db)
log.saveCases( "country", fulfillmentText, db)
# log.saveConversations(sessionID, cust_country, webhookresponse, intent, db)
# log.saveCases("country", fulfillmentText, db)

return {

Expand All @@ -82,13 +85,13 @@ def processRequest(req):
}
elif intent == "Welcome" or intent == "continue_conversation" or intent == "not_send_email" or intent == "endConversation" or intent == "Fallback" or intent == "covid_faq" or intent == "select_country_option":
fulfillmentText = result.get("fulfillmentText")
log.saveConversations(sessionID, query_text, fulfillmentText, intent, db)
# log.saveConversations(sessionID, query_text, fulfillmentText, intent, db)
elif intent == "send_report_to_email":
fulfillmentText = result.get("fulfillmentText")
log.saveConversations(sessionID, "Sure send email", fulfillmentText, intent, db)
val = log.getcasesForEmail("country", "", db)
print("===>",val)
prepareEmail([cust_name, cust_contact, cust_email,val])
# log.saveConversations(sessionID, "Sure send email", fulfillmentText, intent, db)
# val = log.getcasesForEmail("country", "", db)
# print("===>", val)
# prepareEmail([cust_name, cust_contact, cust_email, val])
elif intent == "totalnumber_cases":
fulfillmentText = makeAPIRequest("world")

Expand All @@ -102,8 +105,8 @@ def processRequest(req):
"\n" + " Last updated : " + str(
fulfillmentText.get('last_update')) + "\n\n*******END********* \n "
print(webhookresponse)
log.saveConversations(sessionID, "Cases worldwide", webhookresponse, intent, db)
#log.saveCases("world", fulfillmentText, db)
# log.saveConversations(sessionID, "Cases worldwide", webhookresponse, intent, db)
# log.saveCases("world", fulfillmentText, db)

return {

Expand Down Expand Up @@ -136,7 +139,7 @@ def processRequest(req):
webhookresponse1 = ''
webhookresponse2 = ''
webhookresponse3 = ''
for i in range(0,11):
for i in range(0, 11):
webhookresponse = fulfillmentText[i]
# print(webhookresponse['state'])
# js = json.loads(webhookresponse.text)
Expand Down Expand Up @@ -173,12 +176,10 @@ def processRequest(req):
webhookresponse['active']) + "\n" + " Recovered cases : " + str(
webhookresponse['recovered']) + "\n*********"
print("***World wide Report*** \n\n" + webhookresponse1 + "\n\n*******END********* \n")
print("***World wide Report*** \n\n" + webhookresponse2 + "\n\n*******END********* \n")
print("***World wide Report*** \n\n" + webhookresponse3 + "\n\n*******END********* \n")

print("***Country wide Report*** \n\n" + webhookresponse2 + "\n\n*******END********* \n")
print("***State wide Report*** \n\n" + webhookresponse3 + "\n\n*******END********* \n")


log.saveConversations(sessionID, "Indian State Cases", webhookresponse1, intent, db)
# log.saveConversations(sessionID, "Indian State Cases", webhookresponse1, intent, db)
return {

"fulfillmentMessages": [
Expand Down Expand Up @@ -218,15 +219,15 @@ def processRequest(req):
]
}


else:
return {
"fulfillmentText": "something went wrong,Lets start from the begning, Say Hi",
}


def configureDataBase():
client = MongoClient("mongodb+srv://username:passwrod@cluster0-replace with you URL.mongodb.net/test?retryWrites=true&w=majority")
client = MongoClient(
"mongodb+srv://Covid_19-Bot:Project_1@[email protected]/myFirstDatabase?retryWrites=true&w=majority")
return client.get_database('covid19DB')


Expand All @@ -242,14 +243,14 @@ def makeAPIRequest(query):
return api.makeApiRequestForCounrty(query)


def prepareEmail(contact_list):
mailclient = EMailClient.GMailClient()
mailclient.sendEmail(contact_list)
# def prepareEmail(contact_list):
# mailclient = EMailClient.GMailClient()
# mailclient.sendEmail(contact_list)


if __name__ == '__main__':
port = int(os.getenv('PORT'))
print("Starting app on port %d" % port)
app.run(debug=False, port=port, host='0.0.0.0')
'''if __name__ == "__main__":
app.run(port=5000, debug=True)''' # running the app on the local machine on port 8000
app.run(debug=True, port=5000, host='0.0.0.0')
# if __name__ == "__main__":
# app.run(port=5000, debug=True) # running the app on the local machine on port 8000
2 changes: 1 addition & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

---
applications:
- name: covid_19_bot
- name: MionrCovid_19Bot
memory: 2.0GB
disk_quota: 2.0GB
random-route: true
Expand Down
Binary file added requirement.txt
Binary file not shown.
36 changes: 0 additions & 36 deletions requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.7.6
python-3.10.4
28 changes: 15 additions & 13 deletions saveConversation/Conversations.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
from datetime import datetime


class Log:
def __init__(self):
pass

def saveConversations(self, sessionID, usermessage,botmessage,intent,dbConn):
self.current_time = None
self.date = None
self.now = None

def saveConversations(self, sessionID, usermessage, botmessage, intent, dbConn):
self.now = datetime.now()
self.date = self.now.date()
self.current_time = self.now.strftime("%H:%M:%S")

#db = dbConn['Covid-19DB'] # connecting to the database called crawlerD
mydict = {"sessionID":sessionID,"User Intent" : intent ,"User": usermessage, "Bot": botmessage, "Date": str(self.date) + "/" + str(self.current_time)}
# db = dbConn['Covid-19DB'] # connecting to the database called crawlerD
mydict = {"sessionID": sessionID, "User Intent": intent, "User": usermessage, "Bot": botmessage,
"Date": str(self.date) + "/" + str(self.current_time)}

#table = db[sessionID]
# table = db[sessionID]
records = dbConn.chat_records
records.insert_one(mydict)

#table.insert_one(mydict)
# table.insert_one(mydict)


def saveCases(self, search,botmessage,dbConn):
def saveCases(self, search, botmessage, dbConn):
myquery = {"search": search}

cases_dict = {"search":search,"cases": botmessage}
cases_dict = {"search": search, "cases": botmessage}
newvalues = {"$set": cases_dict}

records = dbConn.cases_records
records.update_one(myquery, newvalues)
#records.insert_one(cases_dict)
# records.insert_one(cases_dict)

def getcasesForEmail(self, search,botmessage,dbConn):
def getcasesForEmail(self, search, botmessage, dbConn):
records = dbConn.cases_records
return records.find_one({'search': search})

Binary file not shown.
Loading