How to insert the title of the group in a message?
For this, you need to know that a node can be in multiple groups and there is also a midlevel entity between a node an a Group called a GroupContent entity.

To retrieve the Groups for a given node you can use this code:

 $plugin_id = 'group_node:' . $node-&gt;bundle();

 // Only act if there are group content types for this node type.
 $group_content_types = GroupContentType::loadByContentPluginId($plugin_id);

  // Load all the group content for this node.
  $group_contents = \Drupal::entityTypeManager()
        -&gt;getStorage('group_content')
        -&gt;loadByProperties([
        'type' =&gt; array_keys($group_content_types),
        'entity_id' =&gt; $node-&gt;id(),
  ]);

  /** @var \Drupal\group\Entity\GroupInterface[] $groups */
  $groups = [];
  foreach ($group_contents as $group_content) {
    /** @var \Drupal\group\Entity\GroupContentInterface $group_content */
    $group = $group_content-&gt;getGroup();
    $groups[$group-&gt;id()] = $group;
  }


You can see this code in action in gnode_node_access() which works out access permissions for a node by checking the Groups it is attached to.

Now you have a list of groups, you can load the first one from the list and use its title.

  $group = reset($groups);
  $title = empty($group) ? '' : $group-&gt;label();