Messenger Client

MessengerClient handles all Messenger related actions and events. such as listening to messages, sending messages interacting with users etc.

class fbchat_muqit.MessengerClient

Bases: object

__init__(*args, **kwargs) 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.

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 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.

async change_thread_message_share(thread_id: str, enabled: bool)

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 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 fetch_all_users() Dict[str, User]

Fetch All User Threads The client is chatting with.

Returns:

Returns a dict of

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 Message object 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 Message objects.

Return type:

List[Message]

async fetch_thread_themes() List[Theme]

Fetch available themes for Threads.

Returns:

A List of Theme objects 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.

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 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 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 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.

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_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 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 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.