Ejemplo n.º 1
0
def webhook():
	data = request.get_json()
	log(data)
	
	
	if data['object'] == "page":
		entries = data['entry']

		for entry in entries:
			messaging = entry['messaging']

			for messaging_event in messaging:

				sender_id = messaging_event['sender']['id']
				recipient_id = messaging_event['recipient']['id']

				if messaging_event.get('message'):
					# Extracting text message
					if 'text' in messaging_event['message']:
						messaging_text = messaging_event['message']['text']
					else:
						messaging_text = 'no text'

					categories = wit_response(messaging_text)
					elements = get_news_elements(categories)
					bot.send_generic_message(sender_id, elements)

												
	return "ok", 200
Ejemplo n.º 2
0
def webhook():
    data = request.get_json()
    log(data)

    if data['object'] == 'page':
        for entry in data['entry']:
            for messaging_event in entry['messaging']:

                #IDs
                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']

                if messaging_event.get('message'):
                    if 'text' in messaging_event['message']:
                        messaging_text = messaging_event['message']['text']
                    else:
                        messaging_text = 'no text'

                    #Echo
                    # response=None

                    # entity,value=wit_response(messaging_text)
                    # if entity=='newstypes':
                    # 	response="Ok,I will send you {} news".format(str(value))
                    # elif entity=='location':
                    # 	response="Ok.So you live in {0}.I will send you top headlines from {0}".format(str(value))

                    # if response==None:
                    # 	response="Sorry,I am not getting what you want to know"

                    categories = wit_response(messaging_text)
                    elements = get_news_elements(categories)

                    bot.send_text_message(sender_id, elements)
    return "ok", 200
Ejemplo n.º 3
0
def webhook():
    data = request.get_json()
    log(data)

    #Make sure this is a page subscription
    if data['object'] == 'page':
        for entry in data['entry']:
            for messaging_event in entry['messaging']:

                # IDs
                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']

                if messaging_event.get('message'):
                    # Extracting text message
                    if 'text' in messaging_event['message']:
                        messaging_text = messaging_event['message']['text']
                    else:
                        messaging_text = 'no text'

                    # Echo
                    categories = wit_response(messaging_text)
                    elements = get_news_elements(categories)
                    bot.send_generic_message(sender_id, elements)
    """
	Assume all went well.
    
    You must send back a 200, within 20 seconds, to let us know
    you've successfully received the callback. Otherwise, the request
    will time out and we will keep trying to resend.
	"""
    return "ok", 200
Ejemplo n.º 4
0
def webhook():
    data = request.get_json()
    log(data)

    if data['object'] == 'page':
        for entry in data['entry']:
            for messaging_event in entry['messaging']:

                # IDs
                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']

                if messaging_event.get('message'):
                    # Extracting text message
                    if 'text' in messaging_event['message']:
                        messaging_text = messaging_event['message']['text']
                    else:
                        messaging_text = 'no text'

                    response = None

                    entity, value, categories = wit_response(messaging_text)
                    if entity == 'newstype':
                        if (categories):
                            elements = get_news_elements(categories)
                            bot.send_generic_message(sender_id, elements)
                            response = "here it is! what else?"
                        else:
                            response = "which news do you want?"
                        #response = "Ok, I will send you the {} news".format(str(value))
                    elif entity == 'location':
                        #categories="{}".format(str(value))
                        if (categories):
                            elements = get_news_elements(categories)
                            bot.send_generic_message(sender_id, elements)
                            response = "Ok, so you live in {0}. Here are top headlines from {0}".format(
                                str(value))
                        else:
                            response = "Ok, so you live in {0}. Here are top headlines from {0}".format(
                                str(value))

                    if response == None:
                        response = "I have no idea what you are saying!"

                    bot.send_text_message(sender_id, response)

    return "ok", 200
Ejemplo n.º 5
0
def webhook():
    elements = []
    data = request.get_json()

    if data['object'] == 'page':
        for entry in data['entry']:
            for messaging_event in entry['messaging']:
                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']
                message_text = "No text"

                if messaging_event.get('message'):

                    if 'text' in messaging_event['message']:
                        message_text = messaging_event["message"]['text']
                        if isGreeting(message_text):
                            bot.send_text_message(
                                sender_id,
                                "Hi there, I am a Newsbot , I know news :)")
                            return 'ok', 200
                    else:
                        message_text = "No text"
                    response = wit_response(message_text)

                    if response['newstype'] != None:
                        if response['location'] != None:
                            elements = get_news_elements(response)
                            pprint(
                                bot.send_generic_message(sender_id, elements))
                        else:
                            elements = get_news_elements(response)
                            pprint(
                                bot.send_generic_message(sender_id, elements))

                    else:
                        if response['location'] != None:
                            elements = get_news_elements(response)
                            pprint(
                                bot.send_generic_message(sender_id, elements))
                        else:
                            bot.send_text_message(sender_id,
                                                  "Try something else")

    return 'ok', 200
Ejemplo n.º 6
0
def webhook():
    data = request.get_json()
    log(data)

    if data['object'] == 'page':
        for entry in data['entry']:
            for messaging_event in entry['messaging']:

                # IDs
                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']

                if messaging_event.get('message'):
                    # Extracting text message
                    if 'text' in messaging_event['message']:
                        messaging_text = messaging_event['message']['text']
                    else:
                        messaging_text = 'no text'
                    categories = wit_response_main(messaging_text)
                    if (categories['NewsBot'] != None):
                        categories1 = wit_response1(messaging_text)
                        elements = get_news_elements(categories1)
                        bot.send_generic_message(sender_id, elements)

                    elif (categories['JokeBot'] != None):
                        wit_response(sender_id, messaging_text)
                        response = response_fb()
                        bot.send_text_message(sender_id, response)

                    elif (categories['FoodBot'] != None):
                        wit_response_food(sender_id, messaging_text)
                        response = response_fb()
                        bot.send_text_message(sender_id, response)
                    """else:
                                            reponse_none= "Sorry, I could not get what you said. I am a baby bot and I am still in my learning period"
                                            bot.send_text_message(sender_id,response_none)      """
                    """elif(categories['gkBot']!= None):
						response_gk = general_knowledge.main(messaging_text)
						bot.send_text_message(sender_id,response_gk)"""

    return "ok", 200
Ejemplo n.º 7
0
def webhook():
    data = request.get_json()
    log(data)

    if data['object'] == 'page':
        for entry in data['entry']:
            for messaging_event in entry['messaging']:
                
                #IDs
                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']
                
                #Check message type
                if messaging_event.get('message'):
                    if 'text' in messaging_event['message']:
                        messaging_text  = messaging_event['message']['text']
                    else:
                        messaging_text = 'no text'

                categories = wit_response(messaging_text)

                elements = get_news_elements(categories)
                bot.send_generic_message(sender_id, elements)
                    # #Echo
                    # response = None

                    # entity, value = wit_response(messaging_text)

                    # if entity == 'newstype':
                    # 	response = "Ok I will send you {} news".format(str(value))
                    # elif entity == "location":
                    # 	response = "Ok. So, you live in {0}. I will send you top headlines from {0}".format(str(value))
                    
                    # if response == None :
                    #     response = "Sorry I didn't understand!"

                    # bot.send_text_message(sender_id, response) 


    return "ok", 200
Ejemplo n.º 8
0
def webhook():
    data = request.get_json()
    log(data)

    if data['object'] == 'page':
        for entry in data['entry']:
            for messaging_event in entry['messaging']:
                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']

                if messaging_event.get('message'):
                    if 'text' in messaging_event['message']:
                        messaging_text = messaging_event['message']['text']
                    else:
                        messaging_text = 'no text'

                    categories = wit_response(messaging_text)
                    elements = get_news_elements(categories)
                    if len(elements) == 0:
                        bot.send_text_message(sender_id,
                                              'Sorry I didnt understand that')
                    bot.send_generic_message(sender_id, elements)
    return 'ok', 200
def webhook():
	data = request.get_json()
	log(data)
	if data['object']=='page':
		for entry in data['entry']:
			for messaging_event in entry['messaging']:
				#IDs
				sender_id = messaging_event['sender']['id']
				recipient_id = messaging_event['recipient']['id']
				if messaging_event.get('message'):
					if 'text' in messaging_event['message']:
						messaging_text = messaging_event['message']['text']
					else:
						messaging_text = 'no text'
					categories = wit_response(messaging_text)
					if 'greetings' in categories.keys():
						if 'name' in categories.keys():
							bot.send_text_message(sender_id,"Cheers,{}. Hope you are having a nice day.".format(str(categories['name'])))
						else:
							bot.send_text_message(sender_id,"Hi. What can I do for you?")	
					elif 'task' in categories.keys():
						req = categories['task']
						for_images = ['images']
						for_recommend = ['Recommendation','Recommend']
						if req in for_images:	
							choices = ['category','location','name','movie_name','character','adjective']
							search = " "
							for i in choices:
								if i in categories.keys():
									search+=" "+str(categories[i])
							bot.send_generic_message(sender_id,get_images(search))
						elif req in for_recommend:
							bot.send_text_message(sender_id,'\n'.join(recommend()))
						else:
							elements = get_news_elements(categories)
							bot.send_generic_message(sender_id,elements)
	return "ok",200
Ejemplo n.º 10
0
def webhook():
    data = request.get_json()
    log(data)

    if data['object'] == 'page':
        for entry in data['entry']:
            for messaging_event in entry['messaging']:

                # ID
                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']

                if messaging_event.get('message'):
                    # Text msg extraction
                    if 'text' in messaging_event['message']:
                        messaging_text = messaging_event['message']['text']
                    else:
                        messaging_text = 'no text'
                    # Wit.ai Response
                    categories = wit_response(messaging_text)
                    elements = get_news_elements(categories)
                    bot.send_generic_message(sender_id, elements)

    return "ok", 200
Ejemplo n.º 11
0
def webhook():
    data = request.get_json()
    log(data)

    if data['object'] == 'page':
        for entry in data['entry']:
            for messaging_event in entry['messaging']:

                # IDs
                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']

                if messaging_event.get('message'):
                    # Extracting text message
                    if 'text' in messaging_event['message']:
                        messaging_text = messaging_event['message']['text']
                    else:
                        messaging_text = 'no text'

                    # Echo
                    response = None
                    #categories=None
                    entity, value, categories = wit_response(messaging_text)

                    if entity == 'location':
                        response = "Welcome to {}".format(str(value))
                        categories = "{}".format(str(value))

                    if entity == 'food':
                        respo = "If you are hungry, please have a look at this"
                        bot.send_text_message(sender_id, respo)
                        response = "https://droolraftan.wordpress.com/tag/jaipur-food"

                    if entity == 'developer':
                        elements = []
                        element = {
                            'title':
                            "Vinayak Sharma",
                            'buttons': [{
                                'type':
                                'web_url',
                                'title':
                                "LinkedIn",
                                'url':
                                "https://www.linkedin.com/in/vinayak-sharma-2ab488142"
                            }, {
                                'type': 'web_url',
                                'title': "Website",
                                'url': "http://vinayaksharma.blog"
                            }, {
                                'type':
                                'web_url',
                                'title':
                                "Facebook",
                                'url':
                                "https://www.facebook.com/srma.vnyk19"
                            }],
                            'image_url':
                            "https://spiderimg.amarujala.com/assets/images/2017/12/03/500x500/udaipur_1512275413.jpeg"
                        }
                        elements.append(element)
                        bot.send_generic_message(sender_id, elements)
                        response = "Vinayak made me <3"

                    if entity == 'greetings':
                        cresponse = "Hi! I am Bhaya from Rajasthan"
                        '''Cus_response="Hi! I am Bhaya from Rajasthan"'''
                        response = "how can I help you?"
                        bot.send_text_message(sender_id, cresponse)

                    if entity == 'news':
                        if (categories):
                            elements = get_news_elements(categories)
                            bot.send_generic_message(sender_id, elements)
                            response = "here it is! what else?"
                        else:
                            response = "Where are u in Rajastan?"

                    if response == None:
                        response = "please speak clearly!"

                    bot.send_text_message(sender_id, response)

    return "ok", 200
Ejemplo n.º 12
0
def webhook():
    data = request.get_json()
    log(data)

    if data['object'] == 'page':
        for entry in data['entry']:
            for messaging_event in entry['messaging']:

                # IDs
                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']

                if messaging_event.get('message'):
                    # Extracting text message
                    if 'text' in messaging_event['message']:
                        messaging_text = messaging_event['message']['text']
                    else:
                        messaging_text = 'no text'

                    entity, value = wit_response2(messaging_text)
                    if entity == 'hello':
                        response = "你可以輸入 __(地區)密室 來找尋地方密室逃脫工作室的資訊"
                        response1 = "輸入 其它 了解其它功能或是輸入 抽正咩 來抽一張正咩圖!哈哈"
                        bot.send_text_message(sender_id, messaging_text)
                        bot.send_text_message(sender_id, response)
                        bot.send_text_message(sender_id, response1)
                    if entity == 'msaction':
                        response = "請依照格式輸入揪團內容"
                        response1 = "範例:主題,時間,人數"
                        bot.send_text_message(sender_id, response)
                        bot.send_text_message(sender_id, response1)
                    if entity == 'mstype':
                        response = "這是 {} 的資訊.".format(str(value))
                        elements2 = get_ms_elements(value)
                        bot.send_generic_message(sender_id, elements2)
                        if (value == "抽正咩"):
                            picture = [
                                "https://i.imgur.com/qKkE2bj.jpg",
                                "https://i.imgur.com/QjMLPmx.jpg",
                                "https://i.imgur.com/HefBo5o.jpg",
                                "https://i.imgur.com/AjxWcuY.jpg",
                                "https://i.imgur.com/3vDRl4r.jpg",
                                "https://i.imgur.com/3qSGcKT.jpg",
                                "https://i.imgur.com/ZbdV9Nz.jpg",
                                "https://i.imgur.com/oAkIJmH.jpg",
                                "https://i.imgur.com/MtcwDtD.jpg",
                                "https://i.imgur.com/qre60t1.jpg",
                                "https://i.imgur.com/Yrvc7LV.jpg",
                                "https://i.imgur.com/4wJXl4D.jpg",
                                "https://i.imgur.com/71suURR.jpg",
                                "https://i.imgur.com/2cdURNa.jpg",
                                "https://i.imgur.com/fHBf685.jpg"
                            ]
                            c = random.choice(picture)
                            bot.send_image_url(sender_id, c)
                    elif entity == 'newstype':
                        response = "這是 {} 新聞".format(str(value))
                        categories = wit_response(messaging_text)
                        elements = get_news_elements(categories)
                        bot.send_generic_message(sender_id, elements)
                    else:
                        print(messaging_text[0])

                elif messaging_event.get("postback"):
                    if messaging_event['postback'].get('payload'):
                        messaging_text = messaging_event['postback']['payload']
                    else:
                        messaging_text = 'no text'
                    categories = wit_response(messaging_text)
                    elements = get_news_elements(categories)
                    bot.send_generic_message(sender_id, elements)

    return "ok", 200
Ejemplo n.º 13
0
def webhook():

    page.handle_webhook(request.get_data(as_text=True) or 'UTF-8')
    print(request.get_json())
    data = request.get_json()
    #log(data)
    print(data)

    if data['object'] == 'page':
        for entry in data['entry']:
            for messaging_event in entry['messaging']:

                # IDs
                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']

                if messaging_event.get('message'):
                    # Extracting text message
                    if 'text' in messaging_event['message']:
                        messaging_text = messaging_event['message']['text']
                    else:
                        messaging_text = 'no text'
                    '''
						entity, value = wit_response(messaging_text)
						response = ''
						if entity=='newstype':
							response = "Ok I will send you {} news".format(str(value))
						if entity == None:
						 	response = "Welcome Sir, How I can help you ?"
						'''

                    categories, value = wit_response(messaging_text)
                    elements = get_news_elements(categories)
                    #weatherElements = {'temp':None,'humidity':None}

                    response = ''
                    # if value != None:
                    if (categories['newstype'] != None
                            and categories['location'] == None):
                        response = "Ok I will send you {} news".format(
                            str(value))
                        bot.send_text_message(sender_id, response)
                        bot.send_generic_message(sender_id, elements)

                    elif (categories['newstype'] != None
                          and categories['location'] != None):
                        response = "Ok I will send you {} news".format(
                            str(value))
                        bot.send_text_message(sender_id, response)
                        bot.send_generic_message(sender_id, elements)

                    elif (categories['weatherinfo'] != None
                          and categories['location'] == None):
                        response = "Current Temperature " + str(
                            weatherElements['temp'])
                        bot.send_text_message(sender_id, response)

                    elif (categories['weatherinfo'] != None
                          and categories['location'] != None):
                        print(value[:-2])
                        print(categories['location'])
                        weatherElements = data_organizer(
                            data_fetch(url_builder(str(
                                categories['location']))))
                        print(weatherElements)
                        lenWeatherElements = len(weatherElements.keys())
                        #if(weatherElements!=None and lenWeatherElements!=0):
                        response = (
                            categories['location'] + "'s Temperature is: " +
                            str(weatherElements['temp']) + "\n" +
                            "Humidity is: " +
                            str(weatherElements['humidity']) +
                            "\nWind Speed is: " +
                            str(weatherElements['wind']) + "\nPressure: " +
                            str(weatherElements['pressure']) +
                            "\nSunrise at: " +
                            str(weatherElements['sunrise']) + "\nSunset at: " +
                            str(weatherElements['sunset']))

                        bot.send_text_message(sender_id, response)
                        #else:
                        #response="Please Enter A City Name"
                        #bot.send_text_message(sender_id,response)

                    else:
                        response = "Welcome Sir, How I can help you ?"
                        bot.send_text_message(sender_id, response)

                    # # Echo
                    # response = None
                    # entity, value = wit_response(messaging_text)
                    # if entity=='newstype':
                    # 	response = "Ok I will send you {} news".format(str(value))
                    # elif entity == "location":
                    # 	response = "Ok, I will send you top headlines from {0}".format(str(value))
                    # if entity == None:
                    # 	response = "Welcome Sir, How I can help you ?"
                    # url = "https://www.youtube.com/watch?v=ru_jQk086sE"
                    #bot.send_text_message(sender_id, response)
                    #bot.send_video_url(sender_id,url)
                    #bot.send_image(sender_id,'C:\\Users\Akash\Downloads\ACI-Logo.png')

    return "ok", 200