def handle_dinowrong(sender_psid, received_message, me): print('The dino menu is wrong, should be', received_message) meal = functions.getCurrentDino() meal.description = received_message['text'] meal.save() response = Response(sender_psid) response.text = handle_dino_message(sender_psid, response, 'dino') response.send() return 'Fixed!'
def handlePostback(sender_psid, received_postback, msg): """ Handles a postback request to the webhook and determines what functionality / response to call """ payload = received_postback["payload"] print("RECEIVED POSTBACK: ", received_postback) response = Response(sender_psid) if payload == "goodvote": response.text = "Sounds like a nice meal!" functions.makeDinoVote("goodvote") elif payload == "badvote": response.text = "Too bad it was gross :(" functions.makeDinoVote("badvote") elif payload == "ADDCRUSH": start_conversation(sender_psid, "ADDCRUSH") response.text = "Enter your crush name:" elif payload == "REMOVECRUSH": start_conversation(sender_psid, "REMOVECRUSH") response.text = "Enter the crush name to remove:" elif payload == "DINOIMAGE": start_conversation(sender_psid, "DINOIMAGE") response.text = "Send me a photo of dino!" elif payload == 'DINOWRONG': start_conversation(sender_psid, 'DINOWRONG') response.text = 'What is the dino meal actually?' else: # response.text = "[DEBUG] Received postback for some reason..." handleMessage(sender_psid, msg) return "OK" response.send() return "OK"
def handleMessage(sender_psid, received_message): """ Handles a plain message request and determines what to do with it By word matching the content and sender_psid """ received_message = received_message.lower() response = Response(sender_psid) print(sender_psid) if "psid" in received_message: Response(sender_psid, text=str(sender_psid)).send() elif ( "dinopoll" in received_message or "dino like" in received_message or "dino good" in received_message ): response.text = handle_dinopoll_message(response) elif ( "what's on" in received_message or "what’s on" in received_message or "what is on" in received_message or "event" in received_message or "calendar" in received_message ): response.text = handle_calendar_message(sender_psid) elif 'dino is wrong' in received_message: response.text = handle_dinowrong_message(sender_psid, response) elif "nudes" in received_message or "noods" in received_message: # response.asset = "270145943837548" url = 'https://indomie.com.au/wp-content/uploads/2020/03/migorengjumbo-new.png' Response(sender_psid, image=url).send() elif ( "dino is shit" in received_message or "dino is bad" in received_message or "dino is good" in received_message or "dinovote" in received_message or "vote" in received_message ): response.text = handle_dinovote_message(response) elif is_dino_message(received_message): response.text = handle_dino_message( sender_psid, response, received_message) # Response(sender_psid, text='Arc Board elections are currently underway. If you want someone to vote for, Nick Patrikeos who helps maintain me is running. Type "arc board" for more info!').send() elif "snazzy pic" in received_message: meal = functions.getCurrentDino() if meal is not None and meal.images: image = random.choice(list(meal.images)) Response(sender_psid, image=image.url).send() Response(sender_psid, f"Photo by: {image.sender.full_name}").send() else: Response(sender_psid, "No snazzy pics :(").send() elif 'am i a ressiexd' in received_message: pass elif 'order me a late meal' in received_message: response.text = handle_latemeal_message(sender_psid, received_message) elif "room is" in received_message: response.text = handle_getroom_message(sender_psid, received_message) elif "crush list" in received_message: response.text = handle_crushlist_message(sender_psid, response) else: reply = bot.reply(str(sender_psid), received_message) response.text = str(reply) if sender_psid == "cmd": return response.payload print("sent back:") pprint(response.payload) response.send() return "OK"