Thread Actions

Classes for representing thread-related events and actions.

Overview

Thread actions represent various events that occur in conversations, such as participants joining/leaving, settings changes, admin actions, and more. These are typically received when listening to events.

from fbchat_muqit import Client, EventType
from fbchat_muqit import ParticipantsAdded, ThreadName, ThreadTheme

client = Client(cookies_file_path="cookies.json")

@client.event(EventType.PARTICIPANTS_ADDED)
async def on_participant_added(event: ParticipantsAdded):
    print(f"New members: {[p.name for p in event.added_participants]}")

@client.event(EventType.THREAD_NAME_CHANGE)
async def on_name_change(event: ThreadName):
    print(f"Group renamed to: {event.name}")

Participant Events

Participants Added

class fbchat_muqit.ParticipantsAdded

Bases: Struct

Added Participant’s information

added_participants: List[addedParticipant]

List of ‘addedParticipant’ object contains added participants data.

messageMetadata: MessageData

Extra information such as author (The one who added the Users), timestamp etc.

participants: tuple

Tuple of all participants Id in the Group.

Participant Left

class fbchat_muqit.ParticipantLeft

Bases: Struct

Left participant’s information

left_participant: str

The Id of the left participant.

messageMetadata: MessageData

Extra message information.

participants: tuple

Tuple of all participants Id in the Group.

Added Participant Info

class fbchat_muqit.addedParticipant

Bases: Struct

Adeed participant’s information.

last_unsubscribed: str | None

join timestamp

name: str

added participant’s name

user_id: str

added participant’s user id

Admin Management Events

Admin Added

class fbchat_muqit.AdminAdded

Bases: Struct

Added admin’s information.

aded_admin: str

Removed/Added admin Id

thread_type: str

Type of the thread

Admin Removed

class fbchat_muqit.AdminRemoved

Bases: Struct

Removed Admin event related data.

messageMetadata: MessageData

The message metadata information

removed_admins: List[str]

List of removed admins ids

Thread Settings Events

Thread Name

class fbchat_muqit.ThreadName

Bases: Struct

Updated Thread’s name

messageMetadata: MessageData

Metadata of the message

name: str

New name of the Thread

participants: tuple

Tuple of all participants Id in the Group.

Thread Theme

class fbchat_muqit.ThreadTheme

Bases: Struct

Updated Threaf theme information

accessibility_label: str

The keyword usee to label the theme.

gradient: str

The gradient color of the theme

theme_color: str

The color of the theme.

theme_emoji: str

The Quick Reaction Emoji for the Theme

theme_id: str

Id of the theme

theme_name: str

Name of the Theme

theme_type: str

Type of the theme

Thread Emoji

class fbchat_muqit.ThreadEmoji

Bases: Struct

Updated Threaf Emoji information

emoji: str

The new quick reaction emoji

emoji_url: str

The url of the emoji

Thread Nickname

class fbchat_muqit.ThreadNickname

Bases: Struct

Changed nickname information of a participant

nickname: str

The new nickname of the User

participant_id: str

The changed nickname User Id.

Thread Magic Word

class fbchat_muqit.ThreadMagicWord

Bases: Struct

Updated Magic word information.

emoji: str

The emoji used for the Magic word.

magic_word: str

The name of the Magic Word

new_magic_word_count: str

0 if not added any Magic Word otherwise greater than 0

removed_magic_word_count: str

0 if not removed any Magic Word otherwise greater than 0

theme_name: str

theme_name of the Magic word

Approval and Privacy Events

Approval Mode

class fbchat_muqit.ApprovalMode

Bases: Struct

Thread’s Updated Approval mode data.

messageMetadata: MessageData

Extra information about the message.

mode: str

mode wether Approval Mode is on ‘APPROVALS’(on) or OPEN’ (off)

Approval Queue

class fbchat_muqit.ApprovalQueue

Bases: Struct

A user’s join request or disapproved join request’s data exclude.

action: str

action can be either ‘REQUESTED’ or ‘REMOVED’.

inviter_id: str | None

The participant who added another User to the group.

messageMetadata: MessageData

Extra message information inluding message author, timestamp, stamp

requestSource: str

Wether joined through Link (default value) or Added by another group participant if added then value will be ‘ADD’

request_timestamp: str | None

Request timestamp

requester_id: str

Requested User’s user id

Approved User

class fbchat_muqit.ApprovedUser

Bases: Struct

Approved User event data

approved_user_id: int

The approved User Id

contact_id: int

The Admin Id who approved The User to Thread

thread_id: Value

The thread Id where the User was accepted.

Joinable Mode

class fbchat_muqit.JoinableMode

Bases: Struct

Joining through Link to a Group.

messageMetadata: MessageData

Extra message information.

mode: str

Can be joined through Link if value ‘JOINABLE’ and can’t if value is ‘PRIAVTE’

Message Actions

Thread Message Pin

class fbchat_muqit.ThreadMessagePin

Bases: Struct

Pinned Message

message_id: str

The pinned message’s id

Thread Message UnPin

class fbchat_muqit.ThreadMessageUnPin

Bases: Struct

Unpinned message

message_id: str

The Unpinned message’s id

Thread Message Sharing

class fbchat_muqit.ThreadMessageSharing

Bases: Struct

Threas Message Sharing Mode information

mode: str

Message mode is on if value is ‘enabled’ and off if value is ‘disabled’

sender_id: str

The User’s Id

sender_name: str

The User’s name who changed Message Sharing mode

Thread Management Events

Thread Action

class fbchat_muqit.ThreadAction

Bases: Struct

information of the Archived from Inbox.

action: str

The action that was done

thread_id: Value

The Thread action was done on.

Thread Folder Move

class fbchat_muqit.ThreadFolderMove

Bases: Struct

Moved Thread folder data.

folder: str

To the folder Location it was moved such as Inbox, Archive, etc.

thread_id: Value

The Thread that was moved.

user_id: str

The user who moved the Thread

Thread Delete

class fbchat_muqit.ThreadDelete

Bases: Struct

Deleted Thread information.

thread_ids: List[Value]

List of Threas Ids that were deleted.

user_id: str

The User who deleted the Thread.

Mute Settings

Mute Thread

class fbchat_muqit.MuteThread

Bases: Struct

Thread Mute information

mute_until: int

Mute duration

thread_id: Value

Muted Thread’s Id

Thread Mute Settings

class fbchat_muqit.ThreadMuteSettings

Bases: Struct

Thread mute related information.

expire_time: int

Mute expire time.

thread_id: Value

The Threas that was muted

user_id: str

The User (Client because other’s mute information is not recevied) who muted the Thread

User Status Events

Change Viewer Status

class fbchat_muqit.ChangeViwerStatus

Bases: Struct

Changed Viewer Status information

can_reply: bool

User can reply to that Thread if True else it is False

facebook_blocked_timestamp: int | None

Facebook block timestamp

is_facebook_blocked: bool | None

If the User is blocked in Facebook.

is_messenger_blocked: bool | None

If User is blocked on Messenger

messenger_blocked_timestamp: int | None

The block event timestamp

reason: int

0 if the User blocked the Thread (User Thread in that case) in Facebook and 2 if in Messenger

thread_id: Value

The Thread’s (User Thread) Id which view was changed

user_id: Value

The User (Client) who changed the View

Other Events

Forced Fetch

class fbchat_muqit.ForcedFetch

Bases: Struct

Usually recevied when messenger group cover photo changes or along with other deltas

messageId: str | None

messageId only recevied Usually when a Thread (Group) Picture is changed

threadKey: Value
type: str

Usage Examples

Handling Participant Events

from fbchat_muqit import Client, EventType
from fbchat_muqit import ParticipantsAdded, ParticipantLeft

client = Client(cookies_file_path="cookies.json")

@client.event(EventType.PARTICIPANTS_ADDED)
async def on_members_added(event: ParticipantsAdded):
    """Handle when new members are added to a group."""
    author = event.messageMetadata.actorFbId
    thread_id = event.messageMetadata.threadKey.threadFbId

    for participant in event.added_participants:
        print(f"👋 {participant.name} was added to the group")
        print(f"   Added by: {author}")

    # Welcome new members
    names = ", ".join(p.name for p in event.added_participants)
    await client.send_message(
        f"Welcome {names}! 🎉",
        thread_id=thread_id
    )

@client.event(EventType.PARTICIPANT_LEFT)
async def on_member_left(event: ParticipantLeft):
    """Handle when a member leaves the group."""
    thread_id = event.messageMetadata.threadKey.threadFbId
    left_user_id = event.left_participant

    print(f"👋 User {left_user_id} left the group")

    # Fetch remaining participants
    print(f"Remaining members: {len(event.participants)}")

Handling Thread Settings Changes

from fbchat_muqit import ThreadName, ThreadTheme, ThreadEmoji

@client.event(EventType.THREAD_NAME_CHANGE)
async def on_name_change(event: ThreadName):
    """Handle group name changes."""
    thread_id = event.messageMetadata.threadKey.threadFbId
    author = event.messageMetadata.actorFbId

    print(f"📝 Group renamed to: {event.name}")
    print(f"   Changed by: {author}")

@client.event(EventType.THREAD_THEME_CHANGE)
async def on_theme_change(event: ThreadTheme):
    """Handle theme changes."""
    print(f"🎨 New theme: {event.theme_name}")
    print(f"   Color: {event.theme_color}")
    print(f"   Emoji: {event.theme_emoji}")

@client.event(EventType.THREAD_EMOJI_CHANGE)
async def on_emoji_change(event: ThreadEmoji):
    """Handle quick reaction emoji changes."""
    print(f"😊 New quick reaction: {event.emoji}")

Handling Admin Actions

from fbchat_muqit import AdminAdded, AdminRemoved

@client.event(EventType.ADMIN_ADDED)
async def on_admin_added(event: AdminAdded):
    """Handle when someone becomes an admin."""
    print(f"👑 New admin: {event.aded_admin}")

    thread_id = event.messageMetadata.threadKey.threadFbId
    await client.send_message(
        "Congratulations on becoming an admin! 👑",
        thread_id=thread_id
    )

@client.event(EventType.ADMIN_REMOVED)
async def on_admin_removed(event: AdminRemoved):
    """Handle when admin privileges are revoked."""
    for admin_id in event.removed_admins:
        print(f"👑 Admin removed: {admin_id}")

Handling Approval Mode

from fbchat_muqit import ApprovalMode, ApprovalQueue, ApprovedUser

@client.event(EventType.APPROVAL_MODE_CHANGE)
async def on_approval_mode(event: ApprovalMode):
    """Handle approval mode toggle."""
    if event.mode == "APPROVALS":
        print("🔒 Approval mode enabled - join requests need approval")
    else:
        print("🔓 Approval mode disabled - anyone can join")

@client.event(EventType.APPROVAL_QUEUE)
async def on_join_request(event: ApprovalQueue):
    """Handle join requests."""
    if event.action == "REQUESTED":
        print(f"📥 New join request from: {event.requester_id}")

        # Auto-approve (if you're an admin)
        # Note: You'll need to implement the approval logic
    elif event.action == "REMOVED":
        print(f"❌ Join request removed: {event.requester_id}")

@client.event(EventType.USER_APPROVED)
async def on_user_approved(event: ApprovedUser):
    """Handle when a user is approved."""
    thread_id = event.thread_id.threadFbId
    approved_id = event.approved_user_id

    await client.send_message(
        f"Welcome! Your join request was approved 🎉",
        thread_id=thread_id
    )

Handling Message Actions

from fbchat_muqit import ThreadMessagePin, ThreadMessageUnPin

@client.event(EventType.MESSAGE_PINNED)
async def on_message_pinned(event: ThreadMessagePin):
    """Handle when a message is pinned."""
    print(f"📌 Message pinned: {event.message_id}")

    # Fetch the pinned message details
    thread_id = event.messageMetadata.threadKey.threadFbId
    message = await client.fetch_message_info(
        event.message_id,
        thread_id
    )
    print(f"   Content: {message.text}")

@client.event(EventType.MESSAGE_UNPINNED)
async def on_message_unpinned(event: ThreadMessageUnPin):
    """Handle when a message is unpinned."""
    print(f"📍 Message unpinned: {event.message_id}")

Handling Mute Events

from fbchat_muqit import MuteThread, ThreadMuteSettings

@client.event(EventType.THREAD_MUTED)
async def on_thread_muted(event: MuteThread):
    """Handle when a thread is muted."""
    thread_id = event.thread_id.threadFbId

    if event.mute_until == -1:
        print(f"🔇 Thread {thread_id} muted forever")
    else:
        print(f"🔇 Thread {thread_id} muted until {event.mute_until}")

@client.event(EventType.MUTE_SETTINGS_CHANGE)
async def on_mute_settings(event: ThreadMuteSettings):
    """Handle mute settings changes."""
    thread_id = event.thread_id.threadFbId
    user_id = event.user_id

    print(f"🔕 User {user_id} changed mute settings")
    print(f"   Expires: {event.expire_time}")

See Also