def get_statewise(p,caps):
    rhandler = dfw.response_handler()
    try:
        state = p["geo-state"]
    except:
        rhandler.simple_response("Sorry, I could not get statistics that state! Could you please repeat it?")
        return rhandler.create_final_response()
    if state == None:
        rhandler.simple_response("Sorry, I did not get that! Could you repeat it?")
    data = requests.get("http://covidstate.in/api/v1/data?state="+state+"&type=latest")
    djson = data.json()
    if data.status_code == 200:
        resdate = datetime.datetime.strptime(djson["timestamp"]["updated_time"],"%Y-%m-%d %I:%M %p").strftime("%Y-%m-%d<break time='200ms'/>%I:%M %p")
        if "actions.capability.SCREEN_OUTPUT" in caps:
            rhandler.google_assistant_response(speech="<speak>As of "+resdate+", in "+p["geo-state"]+" there are "+str(djson["data"]["active_cases"])+" active patients, "+str(djson["data"]["total"])+" infected people, "+str(djson["data"]["deaths"])+" deaths and "+str(djson["data"]["cured"])+" cured people.</speak>",displayText="Here are the statistics of "+p["geo-state"])
            rhandler.google_assistant_card(title="Statistics of "+p["geo-state"],subtitle="As Of: "+djson["timestamp"]["updated_time"],formatted_text="Active Patients: "+str(djson["data"]["active_cases"])+"  \nInfected People: "+str(djson["data"]["total"])+"  \nDeaths: "+str(djson["data"]["deaths"])+"  \nCured People: "+str(djson["data"]["cured"]))
            rhandler.google_assistant_response("What else?")
        else:
            rhandler.google_assistant_response("<speak>As of "+resdate+", in "+p["geo-state"]+str(djson["data"]["active_cases"])+" active patients, "+" there are "+str(djson["data"]["total"])+" infected people, "+str(djson["data"]["deaths"])+" deaths and "+str(djson["data"]["cured"])+" cured people. What else?</speak>")
        
        rhandler.generic_card(title="Statistics of "+p["geo-state"]+" (As of: "+djson["timestamp"]["updated_time"]+")",subtitle="Active Patients: "+str(djson["data"]["active_cases"])+"\nInfected People: "+str(djson["data"]["total"])+"\nDeaths: "+str(djson["data"]["deaths"])+"\nCured People: "+str(djson["data"]["cured"]))
        rhandler.generic_rich_text_response("What else?")
    else:
        rhandler.simple_response("Sorry, I could not get statistics that state! Could you please repeat it?")
    return rhandler.create_final_response()
Esempio n. 2
0
def main():
    intent_handler = dialogflowpy_webhook.request_handler(request.get_json())
    response_handler = dialogflowpy_webhook.response_handler()

    intent = intent_handler.get_intent_displayName()
    if intent == "gentextresponse":
        #Note: Unlike generic_response, you can have multiple generic_rich_text_response
        response_handler.generic_rich_text_response(
            "Hello! Here is a text Response")
        response_handler.generic_rich_text_response("Here is another one!")
    elif intent == "gencardresponse":
        #A Generic Card with Some text and an image
        response_handler.generic_card(
            title="Hello world!",
            subtitle="Here is a Card from Python!",
            imageURL=
            "https://storage.googleapis.com/automotive-media/album_art.jpg")
    elif intent == "gencardwbtnresponse":
        response_handler.generic_card(
            title="Hello world!",
            subtitle="Here is a Card with buttons from Python!",
            imageURL=
            "https://storage.googleapis.com/automotive-media/album_art.jpg")
        response_handler.generic_card_add_button("A link to Google",
                                                 "http://google.com")
    elif intent == "gensuggestions":
        response_handler.generic_add_suggestions(
            ["Hello world!", "Abc", "Def"], title="Here are some suggestions")
    elif intent == "genimage":
        response_handler.generic_image(
            "https://storage.googleapis.com/automotive-media/album_art.jpg",
            "An Image")

    return jsonify(response_handler.create_final_response())
def help_app(caps):
    rhandler = dfw.response_handler()
    rhandler.google_assistant_response("I can get current COVID-19 Statistics for both nationwide and statewise. Just say 'get me the statistics for Tamil Nadu' or 'get me the nationwide statistics'")
    rhandler.google_assistant_response("I can also get National and Statewise contacts as well. Just say 'get me the nationwide contacts' or 'get me the contacts for tamil nadu'")
    
    rhandler.generic_rich_text_response("I can get current COVID-19 Statistics for both nationwide and statewise")
    rhandler.generic_rich_text_response("I can also get National and Statewise contacts as well")
    rhandler.generic_rich_text_response("Try clicking on the chips below to try it out")
    rhandler.generic_add_suggestions(["get me the statistics for Tamil Nadu","get me the nationwide statistics","get me the nationwide contacts","get me the contacts for Tamil Nadu"])
    print(rhandler.create_final_response())
    return rhandler.create_final_response()
def get_nationwide_contacts(caps):
    rhandler = dfw.response_handler()
    data = requests.get("http://covidstate.in/api/v1/contacts?state=India").json()
    formattedphone = phonenumbers.format_number(phonenumbers.parse("+91"+str(data["phone"])),phonenumbers.PhoneNumberFormat.INTERNATIONAL)
    formattedwa = phonenumbers.format_number(phonenumbers.parse("+91"+str(data["whatsapp"])),phonenumbers.PhoneNumberFormat.INTERNATIONAL)
    if "actions.capability.SCREEN_OUTPUT" in caps:
        rhandler.google_assistant_response(speech="<speak>Here are the Nationwide contacts: The Helpline number is "+formattedphone+", The Email is <say-as interpret-as='characters'>"+data["email"]+"</say-as>, The website is <say-as interpret-as='characters'>"+data["website"]+"</say-as> and the Whatsapp number is "+formattedwa+" <break time='200ms'/>What else?</speak>",displayText="Here are the nationwide contacts")
        rhandler.google_assistant_card(title="Nationwide Contacts",formatted_text="📞 Phone: "+formattedphone+"  \n📬 Email: "+data["email"]+"  \n🌏 Website: "+data["website"]+"  \n📱 Whatsapp:"+formattedwa)
    else:
        rhandler.google_assistant_response("<speak>Here are the Nationwide contacts: The Helpline number is "+formattedphone+", The Email is <say-as interpret-as='characters'>"+data["email"]+"</say-as>, The website is <say-as interpret-as='characters'>"+data["website"]+"</say-as> and the Whatsapp number is "+formattedwa+" <break time='200ms'/>What else?</speak>")
    rhandler.generic_card(title="Nationwide Contacts",subtitle="📞 Phone: "+formattedphone+"\n📬 Email: "+data["email"]+"\n🌏 Website: "+data["website"]+"\n📱 Whatsapp:"+formattedwa)
    rhandler.generic_rich_text_response("What else?")
    return rhandler.create_final_response()
def get_nationwide(caps):
    data = requests.get("http://covidstate.in/api/v1/data?type=latest&state=India").json()
    rhandler = dfw.response_handler()
    resdate = datetime.datetime.strptime(data["timestamp"]["updated_time"],"%Y-%m-%d %I:%M %p").strftime("%Y-%m-%d<break time='200ms'/>%I:%M %p")
    if "actions.capability.SCREEN_OUTPUT" in caps:
        rhandler.google_assistant_response(speech="<speak>As of "+resdate+" in India, there are "+str(data["data"]["active_cases"])+" Active Patients, "+str(data["data"]["total"])+" infected people, "+str(data["data"]["deaths"])+" deaths and "+str(data["data"]["cured"])+" cured people.</speak>",displayText="Here are the Nationwide statistics")
        rhandler.google_assistant_card(title="Nationwide statistics",subtitle="As Of: "+data["timestamp"]["updated_time"],formatted_text="Active Patients: "+str(data["data"]["active_cases"])+"  \nInfected People: "+str(data["data"]["total"])+"  \nDeaths: "+str(data["data"]["deaths"])+"  \nCured People: "+str(data["data"]["cured"]))
        rhandler.google_assistant_response("What else?")
    else:
        rhandler.google_assistant_response("<speak>As of "+resdate+" in India, there are "+str(data["data"]["active_cases"])+" Active Patients, "+str(data["data"]["total"])+" infected people, "+str(data["data"]["deaths"])+" deaths and "+str(data["data"]["cured"])+" cured people. What else?</speak>")

    rhandler.generic_card(title="Nationwide statistics (As of: "+data["timestamp"]["updated_time"]+")",subtitle="Active Patients: "+str(data["data"]["active_cases"])+"\nInfected People: "+str(data["data"]["total"])+"\nDeaths: "+str(data["data"]["deaths"])+"\nCured People: "+str(data["data"]["cured"]))
    rhandler.generic_rich_text_response("What else?")
    return rhandler.create_final_response()
def main():
    request_handler = dialogflowpy_webhook.request_handler(request.get_json())
    response_handler = dialogflowpy_webhook.response_handler()
    intent = request_handler.get_intent_displayName()
    sesid = request_handler.get_session_id(
    )  #Session ID is required for saving data to a context

    if intent == "askcontext":
        response_handler.simple_response(
            "Hello. I am saving data to a contect")
        response_handler.add_context(sesid,
                                     "mycontext",
                                     lifespan=5,
                                     params={"param1": "value1"})
    elif intent == "getcontext":
        cntxt = request_handler.get_context_by_name("mycontext")
        response_handler.simple_response("Here is the data from the context " +
                                         cntxt["parameters"]["param1"])
def get_statewise_contacts(caps,params):
    rhandler = dfw.response_handler()
    req = requests.get("http://covidstate.in/api/v1/contacts?state="+params["geo-state"])
    data = req.json()
    if req.status_code == 404:
        rhandler.simple_response("Sorry, I could not get contacts for that state! Could you repeat it?")
        return rhandler.create_final_response()
    watext = ""
    emailtext = ""
    webtext = ""
    formattedphone = phonenumbers.format_number(phonenumbers.parse("+91"+str(data["phone"])),phonenumbers.PhoneNumberFormat.INTERNATIONAL)
    #Speech
    if data["whatsapp"] != None:
        watext = "The Whatsapp Number is <say-as interpret-as='characters'>"+phonenumbers.format_number(phonenumbers.parse("+91"+str(data["whatsapp"])),phonenumbers.PhoneNumberFormat.INTERNATIONAL)+"</say-as>,"
    if data["email"] != None:
        emailtext = "The Email is <say-as interpret-as='characters'>"+data["email"]+"</say-as>, "
    if data["website"] != None:
        webtext = "The Website is <say-as interpret-as='characters'>"+data["website"]+"</say-as>"
    grestext = "<speak>Here are the contacts for "+params["geo-state"]+", The Phone number is <say-as interpret-as='characters'>"+formattedphone+"</say-as>, "+watext+emailtext+webtext+" <break time='200ms'/>What else?</speak>"
    #Card
    phcard = "📞 Phone: "+formattedphone
    webcard = ""
    gwebcard = ""
    emailcard = ""
    gemailcard = ""
    wacard = ""
    gwacard = ""
    if data["website"] != None:
        webcard = "  \n🌏 Website: "+data["website"]
        gwebcard = "\n🌏 Website: "+data["website"]
    if data["email"] != None:
        emailcard = "  \n📬 Email: "+data["email"]
        gemailcard = "\n📬 Email: "+data["email"]
    if data["whatsapp"] != None:
        wacard = "  \n📱 Whatsapp:"+data["whatsapp"]
        gwacard = "\n📬 Email: "+data["email"]
    if "actions.capability.SCREEN_OUTPUT" in caps:
        rhandler.google_assistant_response(speech=grestext,displayText="Here are the nationwide contacts")
        rhandler.google_assistant_card(title=params["geo-state"]+" Contacts",formatted_text=phcard+webcard+emailcard+wacard)
    else:
        rhandler.google_assistant_response(speech=grestext)
    rhandler.generic_card(title=params["geo-state"]+" Contacts",subtitle=phcard+gwebcard+gemailcard+gwacard)
    return rhandler.create_final_response()
Esempio n. 8
0
def main():
    request_handler = dialogflowpy_webhook.request_handler(request.get_json())
    response_handler = dialogflowpy_webhook.response_handler()
    intent = request_handler.get_intent_displayName()
    capabilities = request_handler.get_capabilities()
    if intent == "googresponse":
        response_handler.google_assistant_response("Hello World!")
    elif intent == "googcardresponse":
        response_handler.google_assistant_response("Here is a Card")
        response_handler.google_assistant_card(
            title="Hello world!",
            subtitle="Here is a Card from Python!",
            imageURL=
            "https://storage.googleapis.com/automotive-media/album_art.jpg",
            imageAlt="An image")
    elif intent == "googcardwbuttonresponse":
        response_handler.google_assistant_response(
            "Here is a Card with buttons")
        response_handler.google_assistant_card(
            title="Hello world!",
            subtitle="Here is a Card from Python!",
            imageURL=
            "https://storage.googleapis.com/automotive-media/album_art.jpg",
            imageAlt="An image",
            btnName="This is a link to Google",
            btnLink="http://www.google.com")
    elif intent == "googsuggestions":
        response_handler.google_assistant_response("Here are some suggestions")
        response_handler.google_assistant_add_suggestions(
            ["Hello World!", "Abc"])
    elif intent == "googcarousel":
        if "actions.capability.WEB_BROWSER" in capabilities:  #Checks if actions.capability.WEB_BROWSER is available. If not, returns a fallback error message
            response_handler.google_assistant_response("Here is a Carousel")
            response_handler.google_assistant_new_carousel()
            response_handler.google_assistant_carousel_add_item(
                title="Item 1",
                url="http://google.com",
                imageURL=
                "https://storage.googleapis.com/automotive-media/album_art.jpg",
                imgalt="An Image")
            response_handler.google_assistant_carousel_add_item(
                title="Item 2",
                url="http://google.com",
                imageURL=
                "https://storage.googleapis.com/automotive-media/album_art.jpg",
                imgalt="An Image")
        else:
            response_handler.google_assistant_response(
                "Sorry, Carousels do not work on your device!")
    elif intent == "googtable":
        response_handler.google_assistant_response("Here is a Table")
        response_handler.google_assistant_new_table()
        response_handler.google_assistant_table_add_header_row(
            ["header1", "header2", "header3"])
        response_handler.google_assistant_table_add_row(
            ["item1", "item2", "item3"], True)
        response_handler.google_assistant_table_add_row(
            ["item1", "item2", "item3"], False)
    elif intent == "googmedia":
        response_handler.google_assistant_response("Here is a Media Response")
        response_handler.google_assistant_media_response(
            mediaURL=
            "https://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3",
            description="A Jass Song",
            displayName="A Jass in Paris")
    return jsonify(response_handler.create_final_response())
def close_app():
    rhandler = dfw.response_handler()
    rhandler.simple_response("Thank you for using Covidstate India! Hope to see you soon")
    return rhandler.create_final_response()
Esempio n. 10
0
def on_fallback():
    rhandler = dfw.response_handler()
    rhandler.simple_response("Sorry, I did not get that! Could you repeat it?")
    return rhandler.create_final_response()