Skip to main content

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.
data
MessageResponse
Message object containing the group name change information
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.
data
MessageResponse
Message object containing the participant addition information
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.
data
MessageResponse
Message object containing the participant removal information
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.
data
MessageResponse
Message object containing the participant departure information
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.
data
MessageResponse
Message object containing the group icon change information
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.
data
MessageResponse
Message object containing the group icon removal information
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.

Build docs developers (and LLMs) love