def test_intergration(self): fb_id = "5536222" Post.objects.create(original_title="hello",url="https://bbs.uwcssa.ca/", from_location=WATERLOO,to_location=TORONTO, carpool_date=datetime(2016,12,28), phone="2261231234",scrape_date=datetime(2016,12,27)) msg = " Show me all carpools on Dec 28th from Waterloo to Toronto" show_carpool_response = (bot.get_response(msg,fb_id)) # join a list of messages print("==========",show_carpool_response) show_carpool_response="\n".join(show_carpool_response) self.assertIsNotNone(re.search("2261231234",show_carpool_response)) self.assertIsNotNone(FbUser.objects.get(fb_id=fb_id)) print(bot.get_response(" Remind me for July 29th from Toronto to Waterloo",fb_id)) cancel_response = bot.get_response("cancel reminder",fb_id) print(cancel_response) self.assertIsNotNone(re.search("Cancelled",cancel_response)) self.assertIsNotNone(re.search("No reminders",bot.get_response("cancel reminder",fb_id)))
def handle_message(request): data = json.loads(request.body) sender = data['entry'][0]['messaging'][0]['sender']['id'] message = "" try: message = data['entry'][0]['messaging'][0]['message']['text'] except KeyError: print("warn, no text found") bot_response = bot.get_response(message,sender) reply(sender, bot_response) return HttpResponse('ok')
def CustomFilter(input_message, user_data): global jokes if input_message == '': return {"text": 'None'} # msg = "Recieved: {msg}".format(msg=input_message) # tokens = re.sub(r"[^a-zA-Z0-9\s]",' ',input_message).lower().split() # joke_text = '' # for token in tokens: # if token in jokes: # joke_text = random.choice(jokes[token]) # break # if not joke_text: # joke_text = "I didn't understand! Send 'stupid', 'fat', 'dumb' for a Yo Mama joke!" Text = Bot.get_response(input_message) if input_message.lower() == 'hi': Text = "Hi " + user_data['first_name'] + " " + user_data['last_name'] messageData = {"text": Text} return messageData
def CustomFilter(input_message, user_data): global jokes if input_message == '': return {"text": 'None'} # msg = "Recieved: {msg}".format(msg=input_message) # tokens = re.sub(r"[^a-zA-Z0-9\s]",' ',input_message).lower().split() # joke_text = '' # for token in tokens: # if token in jokes: # joke_text = random.choice(jokes[token]) # break # if not joke_text: # joke_text = "I didn't understand! Send 'stupid', 'fat', 'dumb' for a Yo Mama joke!" Text= Bot.get_response(input_message) if input_message.lower() == 'hi': Text = "Hi "+user_data['first_name']+" "+user_data['last_name'] messageData = { "text": Text } return messageData
def get_bot_response(): userText = request.args.get('msg') return str(get_response(userText))
def handleMessage(self): # echo message back to client message = self.data response = get_response(message) self.sendMessage(response)
import bot bot.init_bot() print(bot.get_response('hello'))