Event: "group:membership:change"

This event fires when one of the following conditions is met:

  • A group member was added to a group
  • A group member was removed from a group
  • A group member left a group
  • A user was opted into a role that is part of this group
  • A user was opted out of a role that is part of this group

Properties

PropertyTypeDescription
actorUserThe user who performed the action, or the role affected
actionstringOne of: ADD, REMOVE, JOIN, LEAVE, OPT_IN, or OPT_OUT
groupGroupThe group the operation was performed on
membersArray<User>The group members affected (added/removed)

Examples

client.on('group:membership:change', function (event) {
switch (event.action) {
case 'ADD':
case 'REMOVE':
console.log(
event.actor.displayName,
event.action === 'ADD' ? 'added' : 'removed',
event.members.map(function (m) { return m.displayName }).join(', ')
event.action === 'ADD' ? 'to' : 'from',
'the group', event.group.displayName,
'at', event.createdAt
);
break;
case 'JOIN':
case 'LEAVE':
console.log(
event.actor.displayName,
event.action === 'JOIN' ? 'joined' : 'left',
'the group', event.group.displayName,
'at', event.createdAt
);
break;
case 'OPT_IN':
case 'OPT_OUT':
console.log(
event.members[0].displayName,
event.action === 'OPT_IN'
? 'is now on duty as'
: 'is no longer on duty as',
event.actor.displayName,
'in the group', event.group.displayName,
'at', event.createdAt
);
break;
}
});