def bot_log_participant(fb_id): participant = Participant.get_participant(fb_id) if participant is None: profile = page.get_user_profile(fb_id) name = "{} {}".format(profile['first_name'], profile['last_name']) participant = Participant.create_participant(name, fb_id) return participant
def send_welcome_messege(recipient, event): user_profile = page.get_user_profile(event.sender_id) # return dict print(user_profile) text1 = "Hello " + user_profile['first_name'] + "!" text2 = "Welcome to the Hotel Test Bot. We have a list of hotel branches below. Please choose one. 🙂" page.send(recipient, text1, metadata="DEVELOPER_DEFINED_METADATA") page.send(recipient, text2, metadata="DEVELOPER_DEFINED_METADATA")
def select_room_message(recipient, event): user_profile = page.get_user_profile(event.sender_id) # return dict print(user_profile) text1 = "Good Choice " + user_profile['first_name'] text2 = "Please select your preferred room." page.send(recipient, text1, metadata="DEVELOPER_DEFINED_METADATA") page.send(recipient, text2, metadata="DEVELOPER_DEFINED_METADATA")
def view_more(recipient, event): user_profile = page.get_user_profile(event.sender_id) # return dict print(user_profile) page.send(recipient, quick_replies=[ QuickReply(title=("Sneakers 👟"), payload="BUY_SNEAKERS"), QuickReply(title=("Jeans 👖"), payload="BUY_JEANS"), ], metadata="DEVELOPER_DEFINED_METADATA")
def received_postback(event): sender_id = event.sender_id recipient_id = event.recipient_id time_of_postback = event.timestamp payload = event.postback_payload delete_persistent_menu() print("Received postback for user %s and page %s with payload '%s' at %s" % (sender_id, recipient_id, payload, time_of_postback)) manejar_saludo(sender_id, page.get_user_profile(event.sender_id)['first_name'])
def send_welcome_message(recipient, event): user_profile = page.get_user_profile(event.sender_id) # return dict print(user_profile) text1 = "Hello " + user_profile['first_name'] + "!" text2 = "Welcome to your personal Shopping Example Bot. We have the following items for sale. Please choose one. 🙂" page.send(recipient, text1, metadata="DEVELOPER_DEFINED_METADATA") page.send(recipient, text2, quick_replies=[ QuickReply(title=("Sneakers 👟"), payload="BUY_SNEAKERS"), QuickReply(title=("Jeans 👖"), payload="BUY_JEANS"), ], metadata="DEVELOPER_DEFINED_METADATA")
def message_handler(event): """:type event: fbmq.Event""" sender_id = event.sender_id message = event.message_text # try Menu buttons = [ Template.ButtonWeb("Open Web URL", "https://www.codeforces.com"), Template.ButtonPostBack("Subscribe", "www.nytimes.com"), Template.ButtonPhoneNumber("Call Phone Number", "+91") ] user_profile = page.get_user_profile(sender_id) page.typing_on(sender_id) page.typing_off(sender_id) #print(user_profile) if bot(message,sender_id): print("Bot results") else: page.send(sender_id,"Didn't get you ")
def message_handler(event): """:type event: fbmq.Event""" sender_id = event.sender_id message = event.message_text # try Menu buttons = [ Template.ButtonWeb("Open Web URL", "https://www.codeforces.com"), Template.ButtonPostBack("Subscribe", "www.nytimes.com"), Template.ButtonPhoneNumber("Call Phone Number", "+91") ] user_profile = page.get_user_profile(sender_id) page.typing_on(sender_id) page.typing_off(sender_id) print("=" * 100) if "username" in message.lower(): hostname, username, password = message.split("\n") hostname = hostname[9:] password = password[9:] username = username[9:] print(hostname, username, password, sender_id) current_path = str( shell_commands(hostname, username, password, "pwd").decode("utf-8"))[:-1] addUser(sender_id, hostname, username, password, current_path) page.send(sender_id, "Go Ahead! Have Fun! ") elif "help" in message: page.send(sender_id, "Just 3 easy steps to follow 🚶") page.send( sender_id, Template.Generic([ Template.GenericElement( "Connect 🤝", subtitle="", item_url="", image_url="https://i.imgur.com/xXy4kib.png", buttons=[ Template.ButtonWeb( "Step 1", "https://www.oculus.com/en-us/rift/") ]), Template.GenericElement( "Add ➕", subtitle="", item_url="", image_url="https://i.imgur.com/RzjPKZM.png", buttons=[ Template.ButtonWeb( "Step 2", "https://www.oculus.com/en-us/rift/") ]), Template.GenericElement( "Go ✅", subtitle="", item_url="", image_url="https://i.imgur.com/NmNXnc7.png", buttons=[ Template.ButtonWeb( "Step 3", "https://www.oculus.com/en-us/rift/") ]) ])) else: response = getUser(sender_id) if not response: quick_replies = [ QuickReply(title="Yeah !", payload="PICK_SSH"), QuickReply(title="Nah ", payload="PICK_NSSH") ] page.send(sender_id, "Would you like to configure your ssh ", quick_replies=quick_replies, metadata="DEVELOPER_DEFINED_METADATA") else: # print(hostname,username,password,message) hostname, username, password, current_path = response if message[:2] == "cd": # add cd need_path = message[3:] current_path = os.path.join(current_path, need_path) try: new_path = str( shell_commands(hostname, username, password, "cd " + current_path + "; pwd").decode("utf-8"))[:-1] updatePath(sender_id, new_path) page.send(sender_id, "Your Current Directory:\n" + new_path) except: page.send(sender_id, "Path doesn't exist") elif "send" in message: file_name = message.split()[-1] if send_commands(current_path + "/" + file_name, file_name, hostname, username, password): debug(659) print(CONFIG['SERVER_URL'] + "/" + file_name) os.rename("./" + file_name, "./static/" + file_name) page.send(sender_id, "Here You Go!") page.send( sender_id, Attachment.File(CONFIG['SERVER_URL'] + "/static/" + file_name)) else: page.send(sender_id, "Error Accessing the file !!") elif message != "Nah ": try: result = str( shell_commands(hostname, username, password, "cd " + current_path + "; " + message).decode("utf-8")) result = result[:min(150, len(result))] page.send(sender_id, result) except: page.send(sender_id, "Unknown Output!") print("Bot results!")
def received_message(event): sender_id = event.sender_id recipient_id = event.recipient_id time_of_message = event.timestamp message = event.message # print("Received message for user %s and page %s at %s with message:" # % (sender_id, recipient_id, time_of_message)) pprint(message) seq = message.get("seq", 0) message_id = message.get("mid") app_id = message.get("app_id") metadata = message.get("metadata") message_text = message.get("text") message_attachments = message.get("attachments") quick_reply = message.get("quick_reply") # nlp = message['nlp']['entities'] nlp = message.get("nlp") seq_id = sender_id + ':' + recipient_id if USER_SEQ.get(seq_id, -1) >= seq: print("Ignore duplicated request") return None else: USER_SEQ[seq_id] = seq if quick_reply: quick_reply_payload = quick_reply.get('payload') if quick_reply_payload == 'VIEW_MORE': view_more(sender_id) # print("quick reply for message %s with payload %s" % (message_id, quick_reply_payload)) elif quick_reply_payload == 'BUY_SNEAKERS': show_shoes(sender_id) start_again(sender_id) elif quick_reply_payload == 'BUY_JEANS': show_jeans(sender_id) start_again(sender_id) else: print("quick reply for message %s with payload %s" % (message_id, quick_reply_payload)) # Check for user sent greetings elif nlp: nlp_payload = nlp.get('entities') if 'greetings' in nlp_payload: nlp_greet = nlp_payload.get('greetings') hello(sender_id) pprint(nlp_greet) # Check for different entities # print("Exists") # elif message_text: # # send_message(sender_id, message_text) # echo_messege(sender_id) elif message_attachments: page.send(sender_id, "Message with attachment received") else: # Create get started button # page.show_starting_button("START_PAYLOAD") user_profile = page.get_user_profile(event.sender_id) # return dict print(user_profile) print("Nothing")