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:
StructAdded 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:
StructLeft 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¶
Admin Management Events¶
Admin Added¶
Admin Removed¶
- class fbchat_muqit.AdminRemoved¶
Bases:
StructRemoved 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:
StructUpdated 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:
StructUpdated 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¶
Thread Nickname¶
Thread Magic Word¶
- class fbchat_muqit.ThreadMagicWord¶
Bases:
StructUpdated 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:
StructThread’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:
StructA 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¶
Joinable Mode¶
- class fbchat_muqit.JoinableMode¶
Bases:
StructJoining 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¶
Thread Message UnPin¶
Thread Message Sharing¶
Thread Management Events¶
Thread Action¶
Thread Folder Move¶
Thread Delete¶
Mute Settings¶
Mute Thread¶
Thread Mute Settings¶
User Status Events¶
Change Viewer Status¶
- class fbchat_muqit.ChangeViwerStatus¶
Bases:
StructChanged 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¶
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¶
Thread Models - Thread models
Message Models - Message models
Client - Client methods for thread management
/guides/event-handling - Guide on handling events