def message(): speak("Checking for messages....") userID = "your email" psd = 'your password' useragent = "you user agent" cli = Client(userID, psd, user_agent=useragent, max_tries=1) if cli.isLoggedIn(): threads = cli.fetchUnread() if len(threads) == 1: speak(f"Sir, You have {len(threads)} message.") info = cli.fetchThreadInfo(threads[0])[threads[0]] speak("You have message from {}".format(info.name)) msg = cli.fetchThreadMessages(threads[0], 1) for message in msg: speak("Sir, the message is {}".format(message.text)) elif len(threads) >= 2: speak(f"Sir, You have {len(threads)} messages.") for thread in threads: initial_number = 0 info = cli.fetchUserInfo(thread[initial_number])[thread[initial_number]] initial_number += 1 speak("Sir, you have message from {}".format(info.name)) msg = cli.fetchThreadMessages(thread[initial_number], 1) msg.reverse() for message in msg: speak(f"The message is {message.text}.") else: speak("Sir, You have no messages.") else: print("Not logged in")
def getInfo(client: Client): #Retrieves the all the unread message Group and User conversation threads allTheUnreads = client.fetchUnread() #Goes through each one of the threads that have unread messages in it for allTheUnread in allTheUnreads: #Prints out all the Unread messages client.fetchUnreadFromThreadMessages(allTheUnread)
def main(): client = Client('*****@*****.**', '2xkzWW+%nKND', max_tries=100) #while True: unread_thread_ids = client.fetchUnread() for unread_thread in unread_thread_ids: msg = client.fetchThreadMessages(unread_thread) msg.reverse() for m in msg: if not m.is_read: print(unread_thread, m) database_holding('fb', unread_thread, m.text, 'Client') # Работа с БД send_to_operator(unread_thread, m.text) client.markAsRead(unread_thread) client.logout()
# client.send(Message(text='valo tui?'), thread_id='100007826251418', thread_type=ThreadType.USER) # users = client.searchForUsers('MD Musa Islam') # user = users[0] # print("User's ID: {}".format(user.uid)) # print("User's name: {}".format(user.name)) # print("User's profile picture url: {}".format(user.photo)) # print("User's main url: {}".format(user.url)) # client.send(Message(text='<message>'), thread_id='<group id>', thread_type=ThreadType.GROUP) # client.logout(); # Fetches a list of the 20 top threads you're currently chatting with threads = client.fetchThreadList() print("Threads: {}".format(client.fetchUnread()[0])) # client.listen() #!/usr/local/bin/python from fbchat import Client EMAIL = '*****@*****.**' PASSWORD = '******' class EchoBot(Client): def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs): self.markAsDelivered(author_id, thread_id)