Overview
Group events are emitted when changes occur in group chats, such as name changes, participant modifications, and group icon updates. All group events provide a MessageResponse object that contains information about the change.
Events
group-name-change
Emitted when a group chat’s name is changed.
Message object containing the group name change information Unique identifier for this system message
The new name of the group chat
Action type code indicating a name change
Whether you changed the group name
The user who changed the group name
Array containing the affected group chat
Unix timestamp when the change occurred
Basic Usage
Track Group Changes
import { SDK } from 'advanced-imessage' ;
const client = SDK ();
client . on ( 'group-name-change' , ( message ) => {
const changer = message . isFromMe ? 'You' : message . handle ?. id ;
console . log ( ` ${ changer } changed group name to: ${ message . groupTitle } ` );
});
await client . connect ();
participant-added
Emitted when a participant is added to a group chat.
Message object containing the participant addition information Unique identifier for this system message
Action type code indicating a participant was added
Whether you added the participant
The user who was added to the group
Array containing the affected group chat
Basic Usage
Welcome New Members
import { SDK } from 'advanced-imessage' ;
const client = SDK ();
client . on ( 'participant-added' , ( message ) => {
const added = message . handle ?. id || 'Unknown' ;
console . log ( ` ${ added } was added to the group` );
});
await client . connect ();
participant-removed
Emitted when a participant is removed from a group chat by another user.
Message object containing the participant removal information Unique identifier for this system message
Action type code indicating a participant was removed
The user who was removed from the group
Array containing the affected group chat
Basic Usage
Track Removals
import { SDK } from 'advanced-imessage' ;
const client = SDK ();
client . on ( 'participant-removed' , ( message ) => {
const removed = message . handle ?. id || 'Unknown' ;
console . log ( ` ${ removed } was removed from the group` );
});
await client . connect ();
participant-left
Emitted when a participant voluntarily leaves a group chat.
Message object containing the participant departure information Unique identifier for this system message
Action type code indicating a participant left
The user who left the group
Array containing the affected group chat
Basic Usage
Differentiate Leave vs Remove
import { SDK } from 'advanced-imessage' ;
const client = SDK ();
client . on ( 'participant-left' , ( message ) => {
const left = message . handle ?. id || 'Unknown' ;
console . log ( ` ${ left } left the group` );
});
await client . connect ();
group-icon-changed
Emitted when a group chat’s icon/photo is changed.
Message object containing the group icon change information Unique identifier for this system message
Action type code indicating icon was changed
Whether you changed the group icon
The user who changed the group icon
Array containing the new group icon image
Array containing the affected group chat
Basic Usage
Download New Icon
import { SDK } from 'advanced-imessage' ;
const client = SDK ();
client . on ( 'group-icon-changed' , ( message ) => {
const changer = message . isFromMe ? 'You' : message . handle ?. id ;
console . log ( ` ${ changer } changed the group icon` );
if ( message . attachments && message . attachments . length > 0 ) {
console . log ( `New icon: ${ message . attachments [ 0 ]. guid } ` );
}
});
await client . connect ();
group-icon-removed
Emitted when a group chat’s icon/photo is removed.
Message object containing the group icon removal information Unique identifier for this system message
Action type code indicating icon was removed
Whether you removed the group icon
The user who removed the group icon
Array containing the affected group chat
Basic Usage
Track Icon Changes
import { SDK } from 'advanced-imessage' ;
const client = SDK ();
client . on ( 'group-icon-removed' , ( message ) => {
const remover = message . isFromMe ? 'You' : message . handle ?. id ;
console . log ( ` ${ remover } removed the group icon` );
});
await client . connect ();
Event Methods
on()
Register a listener that will be called every time the event is emitted.
client . on ( 'group-name-change' , ( message ) => {
console . log ( message );
});
once()
Register a listener that will be called only once, then automatically removed.
client . once ( 'participant-added' , ( message ) => {
console . log ( 'First participant addition:' , message );
});
off()
Remove a specific listener from an event.
const handler = ( message ) => {
console . log ( message );
};
client . on ( 'participant-removed' , handler );
// Later, remove the listener
client . off ( 'participant-removed' , handler );
You must pass the exact same function reference to off() that was passed to on(). Anonymous functions cannot be removed.