def send_message(token, recipient, text): if text == 'Solo puedo manejar texto por ahora': print("Mensaje por defecto") bot_response = text else: req_name = requests.get( "https://graph.facebook.com/v2.6/{0}?fields=first_name&access_token={1}" .format(recipient, PAGE_ACCESS_TOKEN)) name = json.loads(req_name.text) kernel.setPredicate("name", name["first_name"], recipient) print(kernel.getPredicate("name", recipient)) bot_response = kernel.respond(text, recipient) dni = kernel.getPredicate("dni", recipient) print(dni) print(bot_response.find("Se adjuntara su pdf")) if bot_response.find("Se adjuntara su pdf") >= 0: print("entro if") page.send(recipient, bot_response) page.send( recipient, Attachment.File( "http://7223bd7f.ngrok.io/documents?dni=012345678")) else: print("entro else") page.send(recipient, bot_response)
def bot_send_attachment(self, user_model, file_url, file_type, keyboard=None): if file_type and file_type.startswith('image'): return self._service.send(user_model.conversation_id, Attachment.Image(file_url), quick_replies=keyboard) if file_type and file_type.startswith('video'): return self._service.send(user_model.conversation_id, Attachment.Video(file_url), quick_replies=keyboard) if file_type and file_type.startswith('audio'): return self._service.send(user_model.conversation_id, Attachment.Audio(file_url), quick_replies=keyboard) return self._service.send(user_model.conversation_id, Attachment.File(file_url), quick_replies=keyboard)
def send_file(recipient): #page.send(recipient, Attachment.File(CONFIG['SERVER_URL'] + "/assets/test.txt")) page.send(recipient, Attachment.File("https://www.qa.dineroexpress.com.mx/img/137435869.jpg"))
def send_file(recipient): page.send(recipient, Attachment.File(CONFIG['SERVER_URL'] + "/assets/test.txt"))
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!")