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' response = None entity, value = wit_response(messaging_text) if entity == 'topico': response = "Qual tópico em {} gostaria de ver?".format( str(value)) if entity == 'greeting': response = "Oi, tudo bem? Qual tópico em Revisão Sistemática gostaria de ver?" if response == None: response = "Desculpe, poderia repetir?" bot.send_text_message(sender_id, response) return "ok", 200
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
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 = wit_response(messaging_text) if entity == "number": response = "3la wad3ak" elif entity == "location": response = "l2" else: response = "Sorry, I don't get it" bot.send_text_message(sender_id, response) print(response) return "ok", 200
def webhook(): data = request.get_json() #debug: print out JSON from FB webhook 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 = wit_response(messaging_text) bot.send_text_message(sender_id, response) return "Process completed.", 200
def bot(): replyStack = list() msg_in_json = request.get_json() replyToken = msg_in_json["events"][0]['replyToken'] userID = msg_in_json["events"][0]["source"]["userId"] msgType = msg_in_json["events"][0]["message"]["type"] if msgType != 'text': return 'OK', 200 text = msg_in_json["events"][0]["message"]["text"].strip() user_detail = {} user_detail["id"] = userID rsp1, rsp2 = wit_response(text) #rsp = wit_response(text) """if(rsp1 == "age_of_person"): user_detail["age"] = rsp2 rsp = insertUser(user_detail)""" replyStack.append(rsp1) replyStack.append(rsp2) reply(replyToken, replyStack[:5]) return 'OK', 200
def webhook(): #print("HI****************************") data = request.get_json() print("data") 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' response = None entity, value = wit_response(messaging_text) if entity == 'books': response = "Ok. I will show you {} books.".format( str(value)) elif entity == "greetings": response = "Hello, how can I help you?" elif entity == "intent": response = "Which subject books do you want?" else: response = "Sorry, I din't get you." bot.send_text_message(sender_id, response) 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'): # Extracting text message if 'text' in messaging_event['message']: messaging_text = messaging_event['message']['text'] else: messaging_text = 'no text' # Echo # response = messaging_text # bot.send_text_message(sender_id, response) response = None entity, value = wit_response(messaging_text) if entity == "location": response = "Intersting, so what city in {} you come from? ".format(str(value)) if response == None: respones = "Sorry I don't understand" bot.send_text_message(sender_id,response) 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']: # ID 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' # Response response = None entity, value = wit_response(messaging_text) if entity == 'newstype': response = "好的,我會回傳{}新聞".format(str(value)) elif entity == "location": response = "好的,你來自{0}. 我會回傳{0}的頭條新聞".format(str(value)) if response == None: response = "抱歉,我不知道你在說什麼" # Echo #response = messaging_text bot.send_text_message(sender_id, response) 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'): # Extracting text message if 'text' in messaging_event['message']: messaging_text = messaging_event['message']['text'] else: messaging_text = 'no text' response = None answer = wit_response(messaging_text) response = answer bot.send_text_message(sender_id, response) 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"]: #ID sender_id = messaging_event["sender"]["id"] recipient_id = messaging_event["recipient"]["id"] if messaging_event.get("message"): #extract 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 == "quadros": response = "Nossos modelos são esses:" if response == None: response = "Desculpe, não entendi :/" bot.send_text_message(sender_id, response) 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'): # Extracting text message if 'text' in messaging_event['message']: messaging_text = messaging_event['message']['text'] else: messaging_text = 'no text' response = None entity, value = wit_response(messaging_text) if entity == 'newstype': response = "ok. i will send u {} news".format( str(value)) elif entity == 'location': response = "ok so u live in {0}. i will send u news from {0} area".format( str(value)) if response == None: response = "Sorry, i didn't understand" bot.send_text_message(sender_id, response) return "ok", 200
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
def webhook(): 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'] log(messaging_event) if messaging_event.get('message'): if 'text' in messaging_event['message']: messaging_text = messaging_event['message']['text'] else: messaging_text = 'no text' response = None entity, value = wit_response(messaging_text) if entity == 'metal_bands': response = "Ok. I will give you {} metal bands!".format(str(value)) elif entity == 'command': try: subscribe_to_band(value) except: traceback.print_exc() response = "You have subscribed to {}".format(str(value)) elif entity == 'add_location': try: add_a_city(value) response = "The city of {} has been added as a possible location.".format(str(value)) except: traceback.print_exc() else: print('Me no geti') bot.send_text_message(sender_id, response) 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']: #ID's 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' #witbot response = None entity, value = wit_response(messaging_text) if entity == "languageName": response = "Ok, I will teach you {0}".format(str(value)) elif entity == "location": response = "Ok, you live in {0}. I will send you top headlines from your location".format(str(value)) elif entity == "greetings": response = "Hello, I am Ayush's page" if response == None: response = "Sorry, I didn't understand" bot.send_text_message(sender_id, response) return "ok", 200
def webhook(): data = request.get_json() log(data) if data['object'] == 'page': for entry in data['entry']: for msg_event in entry['messaging']: sender_id = msg_event['sender']['id'] recipient_id = msg_event['recipient']['id'] if msg_event.get('message'): if 'text' in msg_event['message']: msg_text = msg_event['message']['text'] else: msg_text = 'no text' response = None entity, value = wit_response(msg_text) print(entity) if entity == "infotype": response = "Collaboo is an application that helps contribute to opensource projects. It helps in managing project. Our recommendation engine helps YOU to choose project that fits you based on your skillset. For more information visit: https://github.com/AxolotlOfConflagration/Collaboo" elif entity == "welcome": response = "Welcome to our project aggregating open-source projects and gathering programmers for a noble purpose. Ask me about project info for more! Learn more about open-source!" elif entity == "opensource": response = "Open-source software (OSS) is a type of computer software in which source code is released under a license in which the copyright holder grants users the rights to study, change, and distribute the software to anyone and for any purpose. Open-source software may be developed in a collaborative public manner. According to scientists who have studied it, open-source software is a prominent example of open collaboration. The term is often written without a hyphen as \"open source software\"." elif response == None: response = "Sorry I don't understand" bot.send_text_message(sender_id, response) 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' #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
def webhook(): data = request.get_json() log(data) #To print all message that has been received.. if data["object"] == "page": #Contains all the dictionaries and lists.. for entry in data["entry"]: for things in entry["messaging"]: if things.get("message"): s_id = things["sender"]["id"] #Sender id r_id = things["recipient"]["id"] #recepient id log("Sender id:" + s_id) log("Receiver id: " + r_id) try: messaging_text = things["message"]["text"] #message entity, value = wit_response(str(messaging_text)) response = None if entity == 'foodcourt': response = "I got ya.. Will be right there at {} ".format( str(value)) #send_message(s_id, "I got ya.. Will be right there at {} ".format(str(value))) elif entity == 'food_item': response = "You want to have {0}... I'll get you".format( str(value)) #send_message(s_id, "You want to have {0}... I'll get you".format(str(value))) except: response = "Sorry!! Couldn't understand that.." #send_message(s_id, "Sorry!! Couldn't understand that..") bot.send_text_message(s_id, response) else: log("->Check your code... no POST handle functioned.") return 'ok', 200 #ok 200 response for successful feedback..
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 = wit_response(messaging_text) if entity == 'newstype': response = "Ok, I will send you the {} news".format( str(value)) elif entity == 'location': 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
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' 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)) elif entity == 'greetings': response = "Hej!".format(str(value)) if response == None: response = "Sorry, I didn't understand." bot.send_text_message(sender_id, response) return "ok", 200
def webhook(): data = request.get_json() 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'] messaging_text = None if messaging_event.get('message'): if 'text' in messaging_event['message']: messaging_text = messaging_event['message']['text'] else: messaging_text = 'no text' #Echo #response = messaging_text response = None entity, value = wit_response(messaging_text) print(entity) print(value) #DM for healthbot if entity == 'intent_greeting': response = "반갑습니다. 저는 피트니스 프로그램과 헬스 악세사리를 선택하는데 도움을 드릴 수 있습니다." if entity == 'intent_recommend' and value == 'fit_program': response = "당신의 헬스앱 사용 패턴을 분석하여 최적의 피트니스 프로그램을 준비하였습니다. 보시겠습니까?" if entity == 'intent_recommend' and value == 'health_acc': response = "추천하는 헬스 악세사리 입니다. \n 1.삼성 기어 S3 \n 2. 삼성 기어핏 \n 3. Mi Smart Scales" if entity == 'intent_positive': type = random.randrange(1, 3) if type == 1: response = "달리기를 자주하셨군요. 10 킬로미터 달리기 프로그램을 바로 시작하세요" elif type == 2: response = "다이어트에 관심이 많으시군요. 체중 감량 프로그램 중 기초부터 시작하는 적응 훈련을 해보세요." elif type == 3: response = "당신에게 필요한 근지구력 강화하기 프로그램을 준비하였습니다." if entity == 'intent_negative': response = "네 알겠습니다." if response == None: response = "죄송합니다. 제가 이해할수 없는 말입니다." bot.send_text_message(sender_id, response) return "ok", 200
def test_wit_response(self): user_input = "i am going from singapore to france next week for 3 days with 2 adults and 2 children" wit_res = wit_response(user_input) expected_output = [[ 'i am going from singapore to france next week for 3 days with 2 adults and 2 children' ], ['who', 'i'], ['origin', 'singapore'], ['destination', 'france'], ['datetime', '2017-07-03T00:00:00.000+08:00'], ['duration', 3], ['number', 2], ['adults', 'adults'], ['children', 'children']] self.assertEqual(wit_res, expected_output)
def handle_messages(): print "Handling Messages" payload = request.get_data() print payload for sender, message in messaging_events(payload): print "Incoming from %s: %s" % (sender, message) # Handle logic of responses response = "Sorry, I could not understand \U0001f61e" # base case entities, values = wit_response(message) print "entities: %s " % entities #DEBUG print "values: %s " % values #DEBUG if 'permission' in entities and 'object' in entities: # Rice cooker query if 'rice cooker' in values: response = "Sure " + getName(PAT, sender) + ", go ahead" send_message( PAT, BrandonID, "I let " + getName(PAT, sender) + " use the rice cooker.") if 'thanks' in entities and 'true' in values: # case thanks response = "You're welcome" if 'greetings' in entities and 'true' in values: # case greeting response = "Hi " + getName(PAT, sender) + "!" if 'command' in entities and 'user' in entities and 'message_body' in entities: # case command tell with user command = values[entities.index('command')] message = values[entities.index( 'message_body')] # gathering message_body with minimal error user = values[entities.index('user')] # getting user value recipientID = None if user == 'Elaine': recipientID = ElaineID elif user == 'Bryan': recipientID = BryanID elif user == 'CJ': recipientID = CjID elif user == 'Brandon': recipientID = BrandonID else: print 'this error needs be handled!' send_message(PAT, sender, "Sorry, I cannot do that yet!") break if command == 'notify': response = getName(PAT, recipientID) + ", " + message send_message(PAT, recipientID, response) else: #tell response = getName(PAT, recipientID) + ", " + getName( PAT, sender) + " says " + message send_message(PAT, recipientID, response) response = "Okay!" send_message(PAT, sender, response) return "ok"
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' response = None entity, value = wit_response(messaging_text) if entity == 'intent': if value == 'getPreRequisites': response = "intent = getPreRequisites" # some elif value == 'getCoRequisites': response = "intent = getCoRequisites" # some elif value == 'getCourses': response = "intent = getCourses" # some elif value == 'getMajors': response = "intent = getMajors" # some elif value == 'getPapers': response = "intent = getPapers" # some code else: response = "Unknown intent" elif entity == 'autPaper': response = "paper {}".format(str(value)) elif entity == 'autMajor': response = "Major {}".format(str(value)) elif entity == 'autCourse': response = 'Course {}'.format(str(value)) if response is None: response = "Sorry, I didn't understand that.enter some course number" bot.send_text_message(sender_id, response) 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']: ### ID sender_ID = messaging_event['sender']['id'] recipient_ID = messaging_event['recipient']['id'] ### "message" type received from user if messaging_event.get('message'): ### text message if 'text' in messaging_event['message']: messaging_text = messaging_event['message']['text'] messaging_text = messaging_text.lower() ### other types of message else: messaging_text = 'no text' info = user_info(sender_ID) log(info) ### responses to user intputs bot_typing_on_off(sender_ID, "typing_on") msg_list = wit_response(messaging_text) text_message_handling(sender_ID, recipient_ID, msg_list) ### "postback" type received from user elif messaging_event.get('postback'): ### button's payload messaging_text = messaging_event['postback']['payload'] #messaging_text = messaging_text.lower() log("Inside postback") log(messaging_text) info = user_info(sender_ID) log(info) ### handles the payload bot_typing_on_off(sender_ID, "typing_on") payload_handler(sender_ID, messaging_text) return "ok", 200
def db_response(input): user_request = input intent, confidence, entities = wit_response(user_request) if (intent == None or confidence <= 0.65): return "Non ho capito" else: if (intent == "get_aula"): return intent_get_aula(entities) elif (intent == "get_corso"): return intent_get_corso(entities) elif (intent == "get_orario"): return intent_get_orario(entities) elif (intent == "get_quante_ore"): return intent_get_quante_ore(entities)
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 = wit_response(messaging_text) if entity == 'newstype': response = "Ok, I will send you the {} news".format( str(value)) elif entity == 'location': response = "Ok, so you live in {0}. I'll send you top headlines from {0}".format( str(value)) t = translator.translate(response) detect = translator.detect(messaging_text) if detect.lang == 'en': t = translator.translate(response, dest='en') response = t.text if detect.lang == 'it': t = translator.translate(response, dest='it') response = t.text if detect.lang == 'es': t = translator.translate(response, dest='es') response = t.text if detect.lang == 'fr': t = translator.translate(response, dest='es') response = t.text else: response = "Sorry I didn't understand your laguage" if response == None: response = "I have no idea what you are saying!" bot.send_text_message(sender_id, response) return "ok", 200
def get_message(input_text): entity, value = wit_response(input_text) #value is the value WIT.AI returns if input_text == 'bird meme': return 'Here is bird meme! https://www.facebook.com/331078540726047/photos/a.331493887351179.1073741827.331078540726047/331643797336188/?type=3&theater' elif (entity == 'greetings') and (value == 'true'): return 'Hello! I am your friendly neighborhood MemeBot! Ask for memes or just chat for compliments :)' elif (entity == 'sendmemes') and (value == 'memes'): memes = meme_getter(5) meme = random.choice(memes) return 'Here is a nice meme! {}'.format(meme) else: sample_responses = ["You are stunning!", "We're proud of you.", "Keep on being you!", "We're grateful to know you :)", "Your smile is contagious.", "You're a smart cookie.", "Is that your picture next to 'charming' in the dictionary?"] # return selected item to the user return random.choice(sample_responses)
def chatbot(txt): ##ECHO ##response = messaging_text #count = 0 #my_ques_series = pd.Series(['What is your age?','What is your gender? 1 : Male 0 : Transgender -1 : Female','Do you have a family history of mental illness? 1 : yes 0 : no','If you have a mental health condition, do you feel that it interferes with your work? 0 : never 1 : rarely 2 : sometimes 3 : often','How many employees does your company or organization have? 1 : 1-5 2 : 6-25 3 : 26-100 4 : 100-500 5 : 500-1000 6: More than 1000','Do you work remotely (outside of an office) at least 50% of the time? 1 : yes 0 : no','Is your employer primarily a tech company/organization? 1 : yes 0 : no','Does your employer provide mental health benefits? 1 : yes 0 : don\'t know -1 : no','Do you know the options for mental health care your employer provides? 1 : yes 0 : not sure -1 : no','Has your employer ever discussed mental health as part of an employee wellness program? 1 : yes 0 : don\'t know -1 : no','Does your employer provide resources to learn more about mental health issues and how to seek help? 1 : yes 0 : don\'t know -1 : no','Is your anonymity protected if you choose to take advantage of mental health or substance abuse treatment resources? 1 : yes 0 : don\'t know -1 : no','How easy is it for you to take medical leave for a mental health condition? 0 : very easy 1 : somewhat easy 2 : don\'t know 3 : somewhat difficult 4 : very difficult','Do you think that discussing a mental health issue with your employer would have negative consequences? 1 : yes 0 : maybe -1 : no','Do you think that discussing a physical health issue with your employer would have negative consequences? 1 : yes 0 : maybe -1 : no','Would you be willing to discuss a mental health issue with your coworkers? 1 : yes 0 : some of them -1 : no','Would you be willing to discuss a mental health issue with your direct supervisor(s)? 1 : yes 0 : some of them -1 : no','Would you bring up a mental health issue with a potential employer in an interview?1 : yes 0 : maybe -1 : no','Would you bring up a physical health issue with a potential employer in an interview? 1 : yes 0 : maybe -1 : no','Do you feel that your employer takes mental health as seriously as physical health? 1 : yes 0 : don\'t know -1 : no','Have you heard of or observed negative consequences for coworkers with mental health conditions in your workplace? 1 : yes 0 : no','Thanks! Calculating...']) #allval = [] global allval, od, x response = None entity, value = wit_response(txt) print(entity, value) allval[x] = value x = x + 1 tup = () #if len(allval) < 24: if entity == 'greetings': response = "Hi, Welcome to Knowmad! We will do a small survey to predict how work related stress could be affecting your mental health. Shall we begin?" #global count #print(count, allval[count]) elif entity == 'yes_no': #or entity == 'number': if value == 'yes': #or value != '': #global my_ques_series print(0, "First in Question list") response = od[0] else: response = "Okay maybe next time." elif entity == 'number' and len(allval) < 24: #value > -1 and value < 100: global count print(count, " in Question list") response = od[count] count = count + 1 print(allval) elif len(allval) == 24: print("reached the end!") allval.pop(0) allval.pop(1) for key, value in allval.items(): tup = tup + (value,) outcome = predict(tup) response = "The outcome is {}".format(str(outcome)) return response
def hello(): if request.method == 'GET': # At your webhook URL, add code for verification. # Your code should look for the Verify Token and respond with the challenge sent in the verification request. # Click Verify and Save in the New Page Subscription to call your webhook with a GET request. if request.args.get("hub.mode") == "subscribe" and request.args.get("hub.challenge"): if not request.args.get("hub.verify_token") == VERIFY_TOKEN: return "Verification token mismatch", 403 return request.args["hub.challenge"], 200 return "Hello world", 200 if request.method == 'POST': output = request.get_json() for event in output['entry']: messaging = event['messaging'] for x in messaging: if x.get('message'): recipient_id = x['sender']['id'] if x['message'].get('text'): message = x['message']['text'] categories = wit_response(message) if categories.get('confidence') and categories['confidence'] > 0.75: rp_message = '' if categories['intent_v'] == 'major': rp_message = "My major is Computer Science" elif categories['intent_v'] == 'name': rp_message = "My name is Min" elif categories['intent_v'] == 'college': rp_message = "I graduated from ######## University" elif categories['intent_v'] == 'fav_class': rp_message = "My favorite classes include Machine Learning, Algorithm, and Statistics." elif categories['intent_v'] == 'greeting': rp_message = "Hello, my name is Min. How can I help you?" elif categories['intent_v'] == 'fav_program_lan': rp_message = "If I do have to pick a favorite one, it would either be C/C++, python, or C# depending on the kind of project, as I have used these the most. But I won't hesitate to use other languages if those will do a better job. I like C++, because it is fast, precise, and reasonably close to machine language as far as high level languages go. I also like Python because it is very easy to use." elif categories['intent_v'] == 'best_at_program_lan': rp_message = "I am good at more than one language. If I do have to pick one, it would either be C/C++, python, or C# depending on the kind of project, as I have used these the most." else: rp_message = 'I am sorry, I could not understand what you are asking.' bot.send_text_message(recipient_id, rp_message) else: message = 'I am sorry, I could not understand what you are asking.' bot.send_text_message(recipient_id, message) else: pass return "Success"
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 #simply get response from wit.ai entity, value = wit_response(messaging_text) #Define your entities in your wit.ai application if entity == 'User-defined entity': response = "(Note: this is sample response)Ok, I we will send you the {} What ever you demanded for".format( str(value)) elif entity == 'Another wit.ai entity': response = "(Note: this is sample response)Ok, I we will send you the {} What ever you demanded for".format( str(value)) # Simply detect your response and translate into any language (Read doc of googletrans for language support) sentence = translator.translate(response) detect = translator.detect(messaging_text) if detect.lang == 'en': sentence = translator.translate(response, dest='en') response = sentence.text # If got nothing if response == None: response = "Sorry didn't got your language" bot.send_text_message(sender_id, response) return "ok", 200