Client¶
The main client class for interacting with Facebook and Messenger.
- class fbchat_muqit.Client¶
Bases:
EventDispatcher,FacebookClient,MessengerClient- __init__(cookies_file_path: str, userAgent: str | None = None, proxy: str | None = None, log_level='INFO', disable_logs=False, online=True, initial_state: State | None = None)¶
- async accept_friend_request(user_id: int)¶
Accept a friend request using the requester User Id.
- Parameters:
user_id (int) – The User friend request to accept.
- add_listener(event_type: EventType, callback: Callable[[...], Awaitable[None]]) None¶
Add an event listener for a specific event.
- Parameters:
event_type (EventType) – The type of the event you want to add listener for.
callback (EventCallback) – The listener function you want to add. Note, that the function must be
async.
- async add_participants(thread_id: str, user_ids: List[int])¶
Add users to a messenger group. Only Group admin can perform this action.
- Parameters:
thread_id (str) – The Thread Id to add participants.
user_ids (List[str]) – A list of User Ids to add the users to the Group.
- async cancel_friend_request(user_id: str)¶
Cancel a friend request that you sent using the requested to user Id.
- Parameters:
user_id (str) – The Id of the User you sent friend request to.
- async change_nickname(thread_id: str, user_id: str, nickname: str)¶
Set or update nickname of a participant in a thread.
- Parameters:
thread_id (str) – The Thread wheere to perform the action.
user_id (str) – The user’s Id to change thd name.
nickname (str) – Ths nickname you want to give.
- async change_read_receipts(thread_id: str, enabled: bool)¶
Enable or disable read receipts for a group thread.
- Parameters:
thread_id (str) – The Id of the Thread to perform the action.
enabled (bool) – Enables if value is True else disables read receipts.
- async change_thread_approval(thread_id: str, enabled: bool)¶
Toggle (on/off) group join approval mode.
- Parameters:
thread_id (str) – The Thread to perform the action.
enabled (bool) – Enables join approval mode if True else disables.
- async change_thread_emoji(thread_id: str, emoji: str)¶
Set a Thread’s quick reaction emoji.
- Parameters:
thread_id (str) – The Thread which quick reaction to change.
emoji (str) – The emoji to set to.
- async change_thread_image(thread_id: str, image_id: int | None = None, image_path: str | None = None, image_url: str | None = None)¶
Change a Group’s group photo.
- Parameters:
thread_id (str) – The Thread’s Which group photo will be changed.
image_id (str) – If a uploaded image’s Id is available you can use that.
image_path (str) – change group photo from your local image file.
image_url (str) – Use remote photo url to change group photo.
Toggle (on/off) message sharing persmission of a Thread.
- Parameters:
thread_id (str) – The Id of the Thread to perform the action.
enabled (bool) – Enables message sharing persmission of a Thread if Value is True else disables if the value is False.
- async change_thread_name(thread_id: str, name: str)¶
Rename a group chat.
- Parameters:
thread_id (str) – The Thread to perform the action.
name (str) – The name to change to.
- async change_thread_theme(thread_id: str, theme_id: int)¶
Update a Thread’s theme using theme Id. You can get available themeids using the
fetch_thread_themes()method.- Parameters:
thread_id (str) – The Id of the Thread to update its theme.
theme_id (str) – The Id of the theme to change to.
- async close()¶
Closes and clears all connections of Client
- async create_group_thread(participant_ids: List[str], emoji_sticker: str = '369239263222822') str | None¶
Creates a mssengsr Group Chat.
- Parameters:
participant_ids (List[str]) – A list of User Ids to create the group with them.
emoji (str) – Any emoji is sent to finalise the group creation.
- Returns:
If the group creation is succesfull then it returns the new created Thread’s Id.
- Return type:
Optional[str]
- async dispatch(event_name: EventType, *args, **kwargs) None¶
Dispatch to
ClientManagerlisteners (if any) then normal client handlers.
- async download(url: str, filename: str)¶
Download a image, video sent from messenger.
- Parameters:
url – Url of the image, video.
filename – name of the file.
- event(event_type: EventType | None = None)¶
Register an event handler.
Supports
@client.eventand@client.event(EventType.X).
- async fetch_all_users() Dict[str, User]¶
Fetch All User Threads The client is chatting with.
- Returns:
Returns a
dictof- Return type:
Dict[str, User]
- async fetch_message_info(message_id: str, thread_id: str) Message | None¶
Fetch a specific message’s information using the message’s ids
- Parameters:
message_id (str) – Id of The message you want to fetch.
thread_id (str) – The Thread Id where the message was sent.
- Returns:
Returns a
Messageobject if succesfully fetches else returns None.- Return type:
Optional[Message]
- async fetch_thread_info(thread_ids: List[str]) Tuple[Thread, ...]¶
Fetches multiple thread information by their thread Ids.
- Parameters:
thread_ids (List[str]) – List of thread Id to fetch threads info.
- Returns:
Returns A Tuple of Thread objects containing thread info.
- Return type:
Tuple[Thread]
- async fetch_thread_list(limit: int = 5, thread_folder: ThreadFolder = ThreadFolder.INBOX, before: int | None = None) Tuple[Thread, ...]¶
Fetch all threads from INBOX, ARCHIVE etc.
- Parameters:
limit (int) – The amount of Threads to fetch from the thread folder.
thread_folder (str) – The location of the threads such as INBOX, ARCHIVE, PENDING etc.
before – A timstamp to fetch threads from.
- Returns:
A Tuple of Thread objects is returned cointaining fetched thread information.
- Return type:
Tuple[Thread, …]
- async fetch_thread_messages(thread_id: str, message_limit: int = 5, before: int | None = None) List[Message] | None¶
Fetch messages from a Thread using The Thread’s Id.
- Parameters:
thread_id (str) – The Thread Id of the Thread to fetch messages from.
message_limit (int) – The amout of messages to fetch. (message_limit=10 by default)
before (int) – Fetch messages before a specific timestamp (Time in miliseceonds).
- Returns:
If succesfull returns a list of
Messageobjects.- Return type:
List[Message]
- async fetch_thread_themes() List[Theme]¶
Fetch available themes for Threads.
- Returns:
A List of
Themeobjects with Theme data is returned.- Return type:
List[Theme]
- async fetch_user_info(*user_ids) Dict[str, User]¶
Fetches Users info using their user Id.
- Parameters:
user_ids (str) – Pass Any amout of user Ids to fetch their information.
- Returns:
Returns a dict cointaining User objects as value and their User Id as key.
- Return type:
Dict[str, User]
- async forward_message(message_id: str, forward_thread_id: str)¶
Forwards a message by Its Id.
- Parameters:
message_id (str) – The Id of the message you want to forward.
forward_thread_id (str) – The Thread you want to forward the message to.
- get_mutation_id() str¶
- async listen()¶
Starts listening to events Blockingly
- async manage_friend_request(user_id: str, accept_request: bool = True)¶
Manage friend requests accept or reject a friend requests
- Parameters:
user_id (str) – The user’s id you want to accept or reject the friend requests.
accept_request (bool) – Accepts the friend request if true else rejects it.
- async mark_as_read(thread_id: str)¶
Mark a Thread As Read.
- Parameters:
thread_id (str) – The Thread Id of Thread to mark as read.
- async mark_as_unread(thread_id: str)¶
Mark a Thread As Unread.
- Parameters:
thread_id (str) – The Thread Id of Thread to mark as unread.
- async mute_thread(thread_id: str, mute_forever: bool = False, duration_ms: int = -1)¶
Mute both messages and calls in a thread.
- Parameters:
thread_id (str) – The Thread to mute.
mute_forever (bool) – If mute_forever=True, sets mute_expire_time_ms = -1 (permanent mute) and mutes the Thread for infinite time. If mute_forever=False, provide a duration in ms.
duration_ms (int) – For the time to mute a Thread.
- async on_admin_added(event_data: AdminAdded, message: MessageData)¶
Called when an admin is added to a messenger group.
- Parameters:
event_data (AdminsAdded) – Receives a
AdminsAddedobject contains added admin id.message (MessageData) – A MessageData object contains the message information meta data.
- async on_admin_removed(event_data: AdminRemoved)¶
Called when an admin is removed from admin role.
- Parameters:
event_data (AdminRemoved) – Receives a
AdminRemovedobject.
- async on_approval_mode_change(event_data: ApprovalMode)¶
Called when Approval mode is changed in a group.
- Parameters:
event_data (ApprovalMode) – Receives a
ApprovalModeobject.
- async on_approval_queue(event_data: ApprovalQueue)¶
Called when an user requests to join a group or invited by another participant of the group or disapproved a User’s join request but approved join request information is not received.
- Parameters:
event_data (ApprovalQueue) – Receives a
ApprovalQueueobject.
- async on_emoji_change(event_data: ThreadEmoji, message: MessageData)¶
Called when a thread’s quick reaction emoji is changed.
- Parameters:
event_data (UpdatedThreadEmoji) – Receives a
UpdatedThreadEmojiobject.
- async on_friend_request_change(event_data: FriendRequestState)¶
Called when a friend request is confirmed/rejected or a friend request is sent by the Client.
- Parameters:
event_data (FriendRequestState) – Receives a
FriendRequestStateobject.
- async on_listening()¶
Called when the client starts listening to events
- async on_magic_words_change(event_data: ThreadMagicWord, message: MessageData)¶
Called when Magic words are added or removed in a group
- Parameters:
event_data (UpdatedMagicWords) – Receives a
UpdatedMagicWordsobject.message (MessageData) – A
MessageDataobject with message data.
- async on_mark_read(event_data: MarkRead)¶
Called when client marks a thread as read
- Parameters:
event_data (MarkRead) – Receives a
MarkReadobject with read information.
- async on_mark_unread(event_data: MarkUnread)¶
Called when client marks a thread as unread
- Parameters:
event_data (MarkUnread) – Receives a
MarkUnreadobject with read information.
- async on_message(event_data: Message)¶
Called when a message received in messenger
- Parameters:
event_data (Message) – A
Messageobject contains the message information.
- async on_message_delivered(event_data: DeliveryReceipt)¶
Called when a message is successfully delivered to a thread.
- Parameters:
event_data (DeliveryReceipt) – Receives a
DeliveryReceiptobject with delivery information.
- async on_message_pinned(event_data: ThreadMessagePin, message: MessageData)¶
Called when a message gets pinned in a thread
- Parameters:
event_data (ThreadMessagePin) – Receives a
ThreadMessagePinobject.message (MessageData) – A
MessageDataobject with message data.
- async on_message_reaction(event_data: MessageReaction)¶
Called when an user reacts to a message
- Parameters:
event_data (MessageReaction) – Receives a
MessageReactionobject.
- async on_message_removed(event_data: MessageRemove)¶
Called when the client removes a message for only itself :param event_data: A
MessageRemovewith additional information. :type event_data: MessageRemove
- async on_message_seen(event_data: ReadReceipt)¶
Called when message is seen by an User.
- Parameters:
event_data (ReadReceipt) – Receives a
ReadReceiptobject.
- async on_message_sharing_change(event_data: ThreadMessageSharing, message: MessageData)¶
Called when message sharing permission is changed in a thread.
- Parameters:
event_data (ThreadMessageSharing) – Receives a
ThreadMessageSharingobject.message (MessageData) – Receives a
MessageDataobject with extra message info.
- async on_message_unpinned(event_data: ThreadMessageUnPin, message: MessageData)¶
Called when a message gets unpinned in a thread
- Parameters:
event_data (ThreadMessagePin) – Receives a
ThreadMessagePinobject.message (MessageData) – A ``MessageData` object with message data.
- async on_message_unsent(event_data: MessageUnsend)¶
Called when a message is unsent by a User.
- Parameters:
event_data (MessageUnsend) – A
MessageUnsendobject with the unsent message information.
- async on_nickname_change(event_data: ThreadNickname, message: MessageData)¶
Called when a User’s nickname is changed in a thread.
- Parameters:
event_data (ThreadNickname) – Receives a
ThreadNicknameobject with user nickname change info.
- async on_page_notification(event_data: PageNotification)¶
Called when a message is sent to a page that Client created.
- Parameters:
event_data (PageNotification) – Receives a
PageNotificationobject.
- async on_participant_joined(event_data: ParticipantsAdded)¶
Called when an user joins a messenger group/community
- Parameters:
event_data (ParticipantsAdded) – Receives a
ParticipantsAddedobject.
- async on_participant_left(event_data: ParticipantLeft)¶
Called when an user leaves or removed from a messenger group/community
- Parameters:
event_data (ParticipantLeft) – Receives a
ParticipantLeftobject.
- async on_poke_nofification(event_data: PokeNotification)¶
Called when a user pokes the Client.
- Parameters:
event_data (PokeNotification) – Receives a
PokeNotificationobject.
- async on_theme_change(event_data: ThreadTheme, message: MessageData)¶
Called when a thread’s theme is changed.
- Parameters:
event_data (ThreadTheme) – Receives a
ThreadThemeobject.message (MessageData) – A
MessageDataobject with message information.
- async on_thread_action(event_data: ThreadAction)¶
Called when client moves a Thread to archive/inbox.
- Parameters:
event_data (ThreadAction) – Receives a
ThreadActionobject.
- async on_thread_delete(event_data: ThreadDelete)¶
Called when client deletes a Thread.
- Parameters:
event_data (ThreadDelete) – Receives a
ThreadDeleteobject.
- async on_thread_mute(event_data: MuteThread)¶
Called when the client mutes a thread community/group.
- Parameters:
event_data (MuteThread) – Receives a
MuteThreadobject.
- async on_thread_mute_settings(event_data: ThreadMuteSettings)¶
Called when the client mutes a Thread.
- Parameters:
event_data (ThreadMuteSettings) – Receives a
ThreadMuteSettingsobject.
- async on_thread_name_change(event_data: ThreadName)¶
Called when a thread’s name is changed
- Parameters:
event_data (UpdatedThreadName) – Receives a
UpdatedThreadNameobject.
- async on_typing(event_data: Typing)¶
Called When someone starts/stops typing
- Parameters:
event_data (Typing) – Receives a
Typingobject.
- async on_viewer_status_change(event_data: ChangeViwerStatus)¶
Called when a Thread gets blocked on Facebook/Messenger
- Parameters:
event_data (ChangeViwerStatus) – Receives a
ChangeViwerStatusobject.
- async pin_message(thread_id: str, message_id: str, pin: bool = True)¶
Pin or unpin a message in a thread.
- Parameters:
thread_id (str) – The Thread where to pin the message.
message_id (str) – The Id of the message you want to pin. The message must be in the same Thread as The passed Thread Id.
pin (bool) – Pins the message the if True and unpins if the value is False.
- async publish_post(text: str, image_paths: List[str] | None = None, video_paths: List[str] | None = None, tag_users: List[str] | None = None, specific_users: List[str] | None = None, except_users: List[str] | None = None, audience: Audience = Audience.PUBLIC, mentions: List[Mention] | None = None) str¶
Publish a post in facebook.
- Parameters:
text (str) – The text message you want to add in the post.
image_paths (Optional[str]) – The Images you want to attach to the post.
video_paths (Optional[List[str]]) – The video to attach to the post.
tag_users (Optional[str]) – Tag users to the postu using their uid.
specific_users (Optional[str]) – only show the post to specific users.
except_users (Optional[str]) – Show the post except some users using their uid.
audience (Audience) – The audience of the post can be FRIENDS, EVERYONE, ONLYME.
mentions (Optional[List[Mention]]) – The users you want to mention in the post.
- Returns:
If successfully published the post returns post’s feedback Id (base64 encoded post id) or post Id.
- Return type:
str
- async react(reaction: str, message_id: str, thread_id: str)¶
React to message using The message’s id
- Parameters:
reaction (str) – The reaction you want to react with. Any available emoji.
message_id (str) – Id of the message to react.
thread_id (str) – Thread Id of the message.
- async react_to_post(feedback_id: str | None = None, post_id: int | None = None, reaction: FBReaction = FBReaction.LOVE)¶
React to a post using post’s feedback Id or Post Id
- Parameters:
feedback_id (Optional[str]) – The feedback Id of the post to react.
post_id (Optional[int]) – The Id of post to react. (feedback_id or post_id one of them must be provided)
reaction (FBReaction) – The reaction to react with (LOVE, HAHA, SAD e.g.)
- remove_listener(event_type: EventType, callback: Callable[[...], Awaitable[None]]) bool¶
Remove an event listener for a specific event.
- Parameters:
event_type (EventType) – The type of the event you want to remove listener for.
callback (EventCallback) – The listener function you want to remove.
- async remove_participant(thread_id: str, user_id: str)¶
Remove a participant from a group. Only Group admin can perform this action.
- Parameters:
thread_id (str) – From the Thread to remove a participant.
user_id (str) – The participant’s User Id.
- async restrict_user(user_id: str, restrict: bool = True)¶
Restrict or unrestrict a user (hide active status and filter messages without blocking other user).
- Parameters:
user_id (str) – The User you want to restrict.
restrict (bool) – Restricts The User if True else if restrict value is False unrestricts The User.
- run()¶
Blocking Call listens to incoming events
- async search_message(text: str, thread_id: str, thread_type: ThreadType = ThreadType.GROUP) Dict¶
Search for a specific text message in a Thread
- Parameters:
text (str) – The text message to search.
thread_id (str) – The Thread where you want to search the text.
thread_type (ThreadType) – The type of the Thread.
- Returns:
A Dict containing The text message matched search results.
- Return type:
Dict
- async send_files(thread_id: str, file_ids: List[int])¶
Send already-uploaded files (images, videos, attachments) by Id to a thread.
- Parameters:
thread_id (str) – The Id of the Thread to send message.
files_ids (List[int]) – A list of file Ids.
- async send_files_from_path(thread_id: str, file_paths: List[str])¶
Send local files to Thread.
- Parameters:
thread_id (str) – The Thread’s Id to send files.
file_paths (List[str]) – A list of local file paths.
- async send_files_from_url(thread_id: str, file_urls: List[str])¶
Send remote files to a Thread using url of the file.
- Parameters:
thread_id (str) – The Thread Id to send the files to.
file_urls (List[str]) – A List of file urls.
- async send_friend_request(user_ids: List[str])¶
Send friend request to one or multiple users using their Id.
- Parameters:
user_ids (List[str]) – A list of user ids to send friend request.
- async send_message(text: str | None, thread_id: str, file_path: List[str] | None = None, file_url: List[str] | None = None, sticker: str | None = None, reply_to_message: str | None = None, files_ids: str | None = None, mentions: List[Mention] | None = None) str | None¶
Sends message to a messenger thread (User, Group etc.)
- Parameters:
text (str) – The text message you want to send.
thread_id (str) – The thread id of the Thread you want to send message.
file_path (Optional[List[str]]) – A list of local file paths such as Download/image.jpg, fav/music.mp3, video.mkv etc.
file_url (Optional[List[str]]) – A list of file Urls if you want to send remote files.
sticker (str) – The id of the sticker you want to send.
reply_to_message (str) – The message ID you want to reply.
mentions (Optional[List[Mention]]) – pass a list of Mention objects including offset (start index of the name in the text), length (length of the user’s name) and the user’s Id if you want to mention a user.
- Returns:
The Id of the sent message.
- Return type:
message_id (str | None)
- async send_quick_reaction(thread_id: str, emoji: str, emojj_size: int = 3)¶
Send a quick reaction emoji to a Thread. :param emoji: The emoji you want to send. :type emoji: str :param emojj_size: The size of the emoji (range: 1-3) by default it is 3. :type emojj_size: int
- async set_thread_admin(thread_id: str, user_id: str, is_admin: bool)¶
Grant or revoke admin privilege in a group. Only Group admin can perform this action.
- Parameters:
thread_id (str) – Thread where the action will be performed.
user_id (str) – The user’s Id to Grant/revoke the user ‘s admin privilege.
is_admin (bool) – Grants The User admin privilege if True else revokes The User’s admin privilege.
- async start()¶
Initiates Client class and logins to account. But doesn’t listens to event. To listen to events call listen() method.
- async start_listening()¶
Start listening from an external event loop.
- Raises:
FBchatException – If request failed
- async stop_listening()¶
Stop the listening mqtt and realtime loop.
- async typing(thread_id: str, is_typing: bool, thread_type: ThreadType = ThreadType.GROUP)¶
Starts/Stops typing indicator.
- Parameters:
thread_id (str) – The Thread to show typing indicator.
is_typing (bool) – Shows Client Typing if value is True else stops showing typing indicator.
thread_type (ThreadType) – Type of the Thread.
- async unfriend(user_id: str)¶
Unfriend a friend using their Id.
- Parameters:
user_id (str) – Id of the User to unfriend.
- async unsend(message_id: str, thread_id: str)¶
Unsent a message for everyone which is sent by the Client by its message id.
- Parameters:
message_id (str) – Id of the message you want to unsend.
thread_id (str) – The Id of the Thread where message was sent.
- async upload_photo(image_path: str) str¶
Upload a photo to Facebook and return the photo ID.
- Parameters:
image_path (str) – Path to the image file to upload
- Returns:
Upload response containing photoID
- Return type:
str
- async upload_photos(image_paths: List[str], max_concurrent: int = 5) List[str]¶
Upload multiple photos concurrently and return list of photo IDs.
- Parameters:
image_paths (List[str]) – List of image file paths to upload
max_concurrent (int) – Maximum number of concurrent uploads (default: 5)
- Returns:
List of successfully uploaded photo IDs (preserves order)
- Return type:
List[str]
- property name¶
The Facebook name of the client.
- property uid¶
The Facebook user ID of the client.
Overview¶
The Client class is the main entry point for fbchat-muqit. It combines Facebook operations,
Messenger operations, and event handling into a single interface.
import asyncio
from fbchat_muqit import Client, Message
# Enter correct cookie file path
client = Client(cookies_file_path="cookies.json")
@client.event
async def on_message(message: Message):
# To avoid spam check if sender_id is client's id or not
if message.sender_id != client.uid:
# show typing indicator
await client.typing(message.thread_id, True, message.thread_type)
# typing for 0.5s
await asyncio.sleep(0.5)
# stop typing indicator
await client.typing(message.thread_id, False, message.thread_type)
# send a message
await client.send_message("Hello!", thread_id=message.thread_id)
client.run()
Initialization¶
- Client.__init__(cookies_file_path: str, userAgent: str | None = None, proxy: str | None = None, log_level='INFO', disable_logs=False, online=True, initial_state: State | None = None)¶
Session Management¶
- async Client.start()¶
Initiates Client class and logins to account. But doesn’t listens to event. To listen to events call listen() method.
- async Client.close()¶
Closes and clears all connections of Client
- Client.run()¶
Blocking Call listens to incoming events
Event Listening¶
- async Client.listen()¶
Starts listening to events Blockingly
- async Client.start_listening()¶
Start listening from an external event loop.
- Raises:
FBchatException – If request failed
- async Client.stop_listening()¶
Stop the listening mqtt and realtime loop.
Messenger Operations¶
Sending Messages¶
- async MessengerClient.send_message(text: str | None, thread_id: str, file_path: List[str] | None = None, file_url: List[str] | None = None, sticker: str | None = None, reply_to_message: str | None = None, files_ids: str | None = None, mentions: List[Mention] | None = None) str | None¶
Sends message to a messenger thread (User, Group etc.)
- Parameters:
text (str) – The text message you want to send.
thread_id (str) – The thread id of the Thread you want to send message.
file_path (Optional[List[str]]) – A list of local file paths such as Download/image.jpg, fav/music.mp3, video.mkv etc.
file_url (Optional[List[str]]) – A list of file Urls if you want to send remote files.
sticker (str) – The id of the sticker you want to send.
reply_to_message (str) – The message ID you want to reply.
mentions (Optional[List[Mention]]) – pass a list of Mention objects including offset (start index of the name in the text), length (length of the user’s name) and the user’s Id if you want to mention a user.
- Returns:
The Id of the sent message.
- Return type:
message_id (str | None)
- async MessengerClient.send_quick_reaction(thread_id: str, emoji: str, emojj_size: int = 3)¶
Send a quick reaction emoji to a Thread. :param emoji: The emoji you want to send. :type emoji: str :param emojj_size: The size of the emoji (range: 1-3) by default it is 3. :type emojj_size: int
- async MessengerClient.send_files(thread_id: str, file_ids: List[int])¶
Send already-uploaded files (images, videos, attachments) by Id to a thread.
- Parameters:
thread_id (str) – The Id of the Thread to send message.
files_ids (List[int]) – A list of file Ids.
- async MessengerClient.send_files_from_path(thread_id: str, file_paths: List[str])¶
Send local files to Thread.
- Parameters:
thread_id (str) – The Thread’s Id to send files.
file_paths (List[str]) – A list of local file paths.
- async MessengerClient.send_files_from_url(thread_id: str, file_urls: List[str])¶
Send remote files to a Thread using url of the file.
- Parameters:
thread_id (str) – The Thread Id to send the files to.
file_urls (List[str]) – A List of file urls.
- async MessengerClient.forward_message(message_id: str, forward_thread_id: str)¶
Forwards a message by Its Id.
- Parameters:
message_id (str) – The Id of the message you want to forward.
forward_thread_id (str) – The Thread you want to forward the message to.
Message Interactions¶
- async MessengerClient.react(reaction: str, message_id: str, thread_id: str)¶
React to message using The message’s id
- Parameters:
reaction (str) – The reaction you want to react with. Any available emoji.
message_id (str) – Id of the message to react.
thread_id (str) – Thread Id of the message.
- async MessengerClient.unsend(message_id: str, thread_id: str)¶
Unsent a message for everyone which is sent by the Client by its message id.
- Parameters:
message_id (str) – Id of the message you want to unsend.
thread_id (str) – The Id of the Thread where message was sent.
- async MessengerClient.pin_message(thread_id: str, message_id: str, pin: bool = True)¶
Pin or unpin a message in a thread.
- Parameters:
thread_id (str) – The Thread where to pin the message.
message_id (str) – The Id of the message you want to pin. The message must be in the same Thread as The passed Thread Id.
pin (bool) – Pins the message the if True and unpins if the value is False.
Fetching Data¶
- async MessengerClient.fetch_thread_list(limit: int = 5, thread_folder: ThreadFolder = ThreadFolder.INBOX, before: int | None = None) Tuple[Thread, ...]¶
Fetch all threads from INBOX, ARCHIVE etc.
- Parameters:
limit (int) – The amount of Threads to fetch from the thread folder.
thread_folder (str) – The location of the threads such as INBOX, ARCHIVE, PENDING etc.
before – A timstamp to fetch threads from.
- Returns:
A Tuple of Thread objects is returned cointaining fetched thread information.
- Return type:
Tuple[Thread, …]
- async MessengerClient.fetch_thread_info(thread_ids: List[str]) Tuple[Thread, ...]¶
Fetches multiple thread information by their thread Ids.
- Parameters:
thread_ids (List[str]) – List of thread Id to fetch threads info.
- Returns:
Returns A Tuple of Thread objects containing thread info.
- Return type:
Tuple[Thread]
- async MessengerClient.fetch_thread_messages(thread_id: str, message_limit: int = 5, before: int | None = None) List[Message] | None¶
Fetch messages from a Thread using The Thread’s Id.
- Parameters:
thread_id (str) – The Thread Id of the Thread to fetch messages from.
message_limit (int) – The amout of messages to fetch. (message_limit=10 by default)
before (int) – Fetch messages before a specific timestamp (Time in miliseceonds).
- Returns:
If succesfull returns a list of
Messageobjects.- Return type:
List[Message]
- async MessengerClient.fetch_message_info(message_id: str, thread_id: str) Message | None¶
Fetch a specific message’s information using the message’s ids
- Parameters:
message_id (str) – Id of The message you want to fetch.
thread_id (str) – The Thread Id where the message was sent.
- Returns:
Returns a
Messageobject if succesfully fetches else returns None.- Return type:
Optional[Message]
- async MessengerClient.fetch_user_info(*user_ids) Dict[str, User]¶
Fetches Users info using their user Id.
- Parameters:
user_ids (str) – Pass Any amout of user Ids to fetch their information.
- Returns:
Returns a dict cointaining User objects as value and their User Id as key.
- Return type:
Dict[str, User]
Thread Management¶
- async MessengerClient.create_group_thread(participant_ids: List[str], emoji_sticker: str = '369239263222822') str | None¶
Creates a mssengsr Group Chat.
- Parameters:
participant_ids (List[str]) – A list of User Ids to create the group with them.
emoji (str) – Any emoji is sent to finalise the group creation.
- Returns:
If the group creation is succesfull then it returns the new created Thread’s Id.
- Return type:
Optional[str]
- async MessengerClient.change_thread_name(thread_id: str, name: str)¶
Rename a group chat.
- Parameters:
thread_id (str) – The Thread to perform the action.
name (str) – The name to change to.
- async MessengerClient.change_thread_image(thread_id: str, image_id: int | None = None, image_path: str | None = None, image_url: str | None = None)¶
Change a Group’s group photo.
- Parameters:
thread_id (str) – The Thread’s Which group photo will be changed.
image_id (str) – If a uploaded image’s Id is available you can use that.
image_path (str) – change group photo from your local image file.
image_url (str) – Use remote photo url to change group photo.
- async MessengerClient.change_thread_theme(thread_id: str, theme_id: int)¶
Update a Thread’s theme using theme Id. You can get available themeids using the
fetch_thread_themes()method.- Parameters:
thread_id (str) – The Id of the Thread to update its theme.
theme_id (str) – The Id of the theme to change to.
- async MessengerClient.change_thread_emoji(thread_id: str, emoji: str)¶
Set a Thread’s quick reaction emoji.
- Parameters:
thread_id (str) – The Thread which quick reaction to change.
emoji (str) – The emoji to set to.
- async MessengerClient.change_nickname(thread_id: str, user_id: str, nickname: str)¶
Set or update nickname of a participant in a thread.
- Parameters:
thread_id (str) – The Thread wheere to perform the action.
user_id (str) – The user’s Id to change thd name.
nickname (str) – Ths nickname you want to give.
Thread Settings¶
- async MessengerClient.change_thread_approval(thread_id: str, enabled: bool)¶
Toggle (on/off) group join approval mode.
- Parameters:
thread_id (str) – The Thread to perform the action.
enabled (bool) – Enables join approval mode if True else disables.
Toggle (on/off) message sharing persmission of a Thread.
- Parameters:
thread_id (str) – The Id of the Thread to perform the action.
enabled (bool) – Enables message sharing persmission of a Thread if Value is True else disables if the value is False.
- async MessengerClient.change_read_receipts(thread_id: str, enabled: bool)¶
Enable or disable read receipts for a group thread.
- Parameters:
thread_id (str) – The Id of the Thread to perform the action.
enabled (bool) – Enables if value is True else disables read receipts.
- async MessengerClient.mute_thread(thread_id: str, mute_forever: bool = False, duration_ms: int = -1)¶
Mute both messages and calls in a thread.
- Parameters:
thread_id (str) – The Thread to mute.
mute_forever (bool) – If mute_forever=True, sets mute_expire_time_ms = -1 (permanent mute) and mutes the Thread for infinite time. If mute_forever=False, provide a duration in ms.
duration_ms (int) – For the time to mute a Thread.
Participant Management¶
- async MessengerClient.add_participants(thread_id: str, user_ids: List[int])¶
Add users to a messenger group. Only Group admin can perform this action.
- Parameters:
thread_id (str) – The Thread Id to add participants.
user_ids (List[str]) – A list of User Ids to add the users to the Group.
- async MessengerClient.remove_participant(thread_id: str, user_id: str)¶
Remove a participant from a group. Only Group admin can perform this action.
- Parameters:
thread_id (str) – From the Thread to remove a participant.
user_id (str) – The participant’s User Id.
- async MessengerClient.set_thread_admin(thread_id: str, user_id: str, is_admin: bool)¶
Grant or revoke admin privilege in a group. Only Group admin can perform this action.
- Parameters:
thread_id (str) – Thread where the action will be performed.
user_id (str) – The user’s Id to Grant/revoke the user ‘s admin privilege.
is_admin (bool) – Grants The User admin privilege if True else revokes The User’s admin privilege.
Thread Actions¶
- async MessengerClient.mark_as_read(thread_id: str)¶
Mark a Thread As Read.
- Parameters:
thread_id (str) – The Thread Id of Thread to mark as read.
- async MessengerClient.mark_as_unread(thread_id: str)¶
Mark a Thread As Unread.
- Parameters:
thread_id (str) – The Thread Id of Thread to mark as unread.
- async MessengerClient.typing(thread_id: str, is_typing: bool, thread_type: ThreadType = ThreadType.GROUP)¶
Starts/Stops typing indicator.
- Parameters:
thread_id (str) – The Thread to show typing indicator.
is_typing (bool) – Shows Client Typing if value is True else stops showing typing indicator.
thread_type (ThreadType) – Type of the Thread.
- async MessengerClient.search_message(text: str, thread_id: str, thread_type: ThreadType = ThreadType.GROUP) Dict¶
Search for a specific text message in a Thread
- Parameters:
text (str) – The text message to search.
thread_id (str) – The Thread where you want to search the text.
thread_type (ThreadType) – The type of the Thread.
- Returns:
A Dict containing The text message matched search results.
- Return type:
Dict
File Handling¶
- async MessengerClient.uploadFiles(**kwargs)¶
User Management¶
- async MessengerClient.restrict_user(user_id: str, restrict: bool = True)¶
Restrict or unrestrict a user (hide active status and filter messages without blocking other user).
- Parameters:
user_id (str) – The User you want to restrict.
restrict (bool) – Restricts The User if True else if restrict value is False unrestricts The User.
- async MessengerClient.accept_friend_request(user_id: int)¶
Accept a friend request using the requester User Id.
- Parameters:
user_id (int) – The User friend request to accept.
Facebook Operations¶
Posts¶
- async FacebookClient.publish_post(text: str, image_paths: List[str] | None = None, video_paths: List[str] | None = None, tag_users: List[str] | None = None, specific_users: List[str] | None = None, except_users: List[str] | None = None, audience: Audience = Audience.PUBLIC, mentions: List[Mention] | None = None) str¶
Publish a post in facebook.
- Parameters:
text (str) – The text message you want to add in the post.
image_paths (Optional[str]) – The Images you want to attach to the post.
video_paths (Optional[List[str]]) – The video to attach to the post.
tag_users (Optional[str]) – Tag users to the postu using their uid.
specific_users (Optional[str]) – only show the post to specific users.
except_users (Optional[str]) – Show the post except some users using their uid.
audience (Audience) – The audience of the post can be FRIENDS, EVERYONE, ONLYME.
mentions (Optional[List[Mention]]) – The users you want to mention in the post.
- Returns:
If successfully published the post returns post’s feedback Id (base64 encoded post id) or post Id.
- Return type:
str
- async FacebookClient.react_to_post(feedback_id: str | None = None, post_id: int | None = None, reaction: FBReaction = FBReaction.LOVE)¶
React to a post using post’s feedback Id or Post Id
- Parameters:
feedback_id (Optional[str]) – The feedback Id of the post to react.
post_id (Optional[int]) – The Id of post to react. (feedback_id or post_id one of them must be provided)
reaction (FBReaction) – The reaction to react with (LOVE, HAHA, SAD e.g.)
Media Upload¶
- async FacebookClient.upload_photo(image_path: str) str¶
Upload a photo to Facebook and return the photo ID.
- Parameters:
image_path (str) – Path to the image file to upload
- Returns:
Upload response containing photoID
- Return type:
str
- async FacebookClient.upload_photos(image_paths: List[str], max_concurrent: int = 5) List[str]¶
Upload multiple photos concurrently and return list of photo IDs.
- Parameters:
image_paths (List[str]) – List of image file paths to upload
max_concurrent (int) – Maximum number of concurrent uploads (default: 5)
- Returns:
List of successfully uploaded photo IDs (preserves order)
- Return type:
List[str]
Friend Management¶
- async FacebookClient.send_friend_request(user_ids: List[str])¶
Send friend request to one or multiple users using their Id.
- Parameters:
user_ids (List[str]) – A list of user ids to send friend request.
- async FacebookClient.manage_friend_request(user_id: str, accept_request: bool = True)¶
Manage friend requests accept or reject a friend requests
- Parameters:
user_id (str) – The user’s id you want to accept or reject the friend requests.
accept_request (bool) – Accepts the friend request if true else rejects it.
- async FacebookClient.cancel_friend_request(user_id: str)¶
Cancel a friend request that you sent using the requested to user Id.
- Parameters:
user_id (str) – The Id of the User you sent friend request to.
- async FacebookClient.unfriend(user_id: str)¶
Unfriend a friend using their Id.
- Parameters:
user_id (str) – Id of the User to unfriend.
Properties¶
- property Client.uid¶
The Facebook user ID of the client.
- property Client.name¶
The Facebook name of the client.
See Also¶
/guides/sending-messages - Guide on sending different types of messages
/guides/event-handling - Guide on handling events
Models - Data models used throughout the library