How to create a message with message stack when user becomes a member of a group module group?
It looks like the membership relationship is stored as a GroupContent entity, so in theory you would use something like hook_ENTITY_TYPE_insert()as your event:
function MODULE_group_content_insert(\Drupal\group\Entity\GroupContentInterface $group_content) {
  // This will fire for all types of group content so make sure to filter
  if ($group_content-&gt;getContentPlugin()-&gt;getPluginId() == 'group_membership') {
    $account = $group_content-&gt;getEntity();
    $group = $group_content-&gt;getGroup();    
    // Create the message
  }
}

This is untested so may need tweaking, but it should be close enough to get going.