User Mentions

Overview

You can mention users in both activities and comments. When you include mentioned_user_ids, the API stores the mentions and returns enriched mentioned_users in the response. Optionally, you can create notification activities for mentioned users or send push notifications.

Adding user mentions

mentioned_user_ids can only contain existing user ids, you can use queryUsers endpoint to search for users to mention.

Please note that it's up to you to include user mentions (for example @Alice) in the activity/comment text, the Stream API won't modify these fields based on mentioned_user_ids.

Adding an activity with mentions

response = client.feeds.add_activity(
    feeds=["user:eric"],
    type="post",
    text="Hey @bob and @alice, check this out!",
    user_id="eric",
    mentioned_user_ids=["bob", "alice"],
    create_notification_activity=True,
)
# response["activity"]["mentioned_users"] contains enriched user objects

Adding a comment with mentions

response = client.feeds.add_comment(
    comment="Thanks @bob for the tip!",
    object_id="activity_123",
    object_type="activity",
    user_id="alice",
    mentioned_user_ids=["bob"],
    create_notification_activity=True,
)
# response["comment"]["mentioned_users"] contains enriched user objects

Reading mentioned users

Activities and comments returned by the API include a mentioned_users array with enriched user objects (id, name, image, etc.). Use them to render @mentions in your UI.

# From activities
response = client.feeds.get_or_create_feed("user", "eric", user_id="eric")
for activity in response["activities"]:
  mentioned = activity.get("mentioned_users") or []
  if mentioned:
    print("Mentioned:", ", ".join(u.get("name", "") for u in mentioned))
# From comments
activity_response = client.feeds.get_activity(activity_id, with_recent_replies=10)
for comment in activity_response.get("activity", {}).get("latest_replies") or []:
  mentioned = comment.get("mentioned_users") or []
  if mentioned:
    print("Comment mentioned:", ", ".join(u.get("name", "") for u in mentioned))

Mentions in notification feed

  • Activities: When create_notification_activity is true, each mentioned user receives a mention notification in their notification feed.
  • Comments: When create_notification_activity is true, each mentioned user receives a comment_mention notification (the activity author does not get an extra notification for mentions; they already get a comment notification).

For updating or deleting activities/comments and managing mention notifications (e.g. handle_mention_notifications, delete_notification_activity), see Notification feeds.

Push notifications

Use the skip_push parameter to control if push notifications are sent to mentioned users or not. For more information check the Push notification guide that contains all relevant information about setting up push notification providers, customizing notifications and user preferences.