Mention users

The Mentions feature lets users tag specific individuals within a chat or conversation.

icon

Usage in Blueprints and C++


Unreal Chat SDK lets one user tag another user by adding @ and typing at least three first letters of the username they want to mention. As a result, they get a list of suggested usernames when typing such a suggestion, like @Mar.

The list of returned users depends on your app configuration - these can be either all members in the channel where you write a message or all users of your app (user data taken from the Admin Portal keyset for your app). The number of returned suggested users for the mention also depends on your app configuration and can show up to 100 suggestions. The names of the suggested users can consist of multiple words and contain up to 200 characters.

You can configure your app to let users mention up to 100 users in a single message (default value is 10) and configure mentions to be shown as links or display user details when highlighted (for example, by hovering over them).

For @ to be treated as a mention in the message, you must first map a given @ character to a specific user. Without it, @ will be treated as a regular string and will be shown as plain text.

You can implement mentions in your app in a similar way you would implement channel referencing.

Requires App Context

To mention users from a keyset, you must enable App Context for your app's keyset in the Admin Portal.

Get user suggestions

GetUserSuggestions() returns all suggested users that match the provided 3-letter string from a selected data source (channel members or global users on your app's keyset).

For example, if you type Sam, you will get the list of users starting with Sam like Samantha or Samir. The default number of returned suggested usernames is 10 which is configurable to a maximum value of 100.

Method signature

Output

TypeReturned on Channel objectReturned on Chat objectDescription
TArray<UPubnubMembership*>YesNoReturned array of Membership objects.
TArray<UPubnubUser*>NoYesReturned array of User objects.

Basic usage

Return five channel users whose names start with Mar.

#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();

UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");

FString Text = "Mar";

Chat->GetUserSuggestions(Text);

Send message with mentions

SendText() publishes the text message with mentioned users and emits events of type mention.

Use the SendText() method with an additional MentionedUsers param to send a message with user mentions.

Method signature

Basic usage

Mention the users @James, Sarah and @Twain, Mark in a message.

#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();

UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");

UPubnubChannel* Channel = Chat->GetChannel("support");
FSendTextParams SendTextParams;

FSendTextParams SendTextParams;
FPubnubMentionedUser MentionedUser({"twain_mark", "Twain, Mark"});
FPubnubMentionedUser MentionedUser2({"james_sarah", "James, Sarah"});
TMap<int, FPubnubMentionedUser> MentionedUsers;
show all 20 lines

Get mentioned users

Use the MentionedUsers() method to return all users mentioned in a message.

Method signature

Output

TypeDescription
TArray<FPubnubMentionedUser>Array with specific mentioned users.
FPubnubMentionedUser

PropertyTypeDescription
IdFStringUnique identifier of the mentioned user.
NameFStringName of the mentioned user.

Basic usage

Check if the last message on the support channel contains any mentions.

#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();

UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");

UPubnubChannel* Channel = Chat->GetChannel("support");

// Fetch historical messages
TArray<UPubnubMessage*> Messages = Channel->GetHistory();

UPubnubMessage* Message = Messages.Messages[0];

show all 16 lines

The GetCurrentUserMentions() method lets you collect in one place all instances when a specific user was mentioned by someone — either in channels or threads. You can use this info to create a channel with all user-related mentions.

Method signature

Output

This method returns a FPubnubUserMentionDataList object containing two fields: UserMentions and IsMore.

ParameterTypeDescription
UserMentionsTArray<FPubnubUserMentionData>Array listing the requested number of historical mention events with a set of information that differ slightly depending on whether you were mentioned in the main (parent) channel or in a thread.

For mentions in the parent channel, the returned information includes these fields: ChannelID where you were mentioned, UserID that mentioned you, Event (of type mention), and Message that included the mention.

For mentions in threads, the returned information includes similar fields, the only difference is that you'll get ParentChannelID and ThreadChannelID fields instead of just ChannelId to clearly differentiate the thread that included the mention from the parent channel in which this thread was created.
isMoreboolInfo whether there are more historical events to pull.

Basic usage

List the last ten mentions for the current chat user.

#include "PubnubChatSubsystem.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(ContextObject);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();

UPubnubChat* Chat = PubnubChatSubsystem->InitChat("demo", "demo", "my_user");

// Define the conversation/channel ID
FString ChannelID = "ask-support";

// Define the channel data
FPubnubChatChannelData ChannelData;
ChannelData.ChannelName = "ask-support";
ChannelData.Description = "Space dedicated to answering all support-related questions";

show all 31 lines

Show notifications for mentions

You can monitor all events emitted when you are mentioned in a parent or thread channel you are a member of using the ListenForEvents() method. You can use this method to create pop-up notifications for the users.

Events documentation

To read more about the events of type mention, refer to the Chat events documentation.

Method signature

icon

Handle the response

Output
TypeDescription
UPubnubCallbackStop*Object on which you can call Stop() to stop receiving updates.

Basic usage

Print a notification for a mention of the administrator chat user on the support channel.

#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"

UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();

UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");

UPubnubChannel* Channel = Chat->GetChannel("support");

FSendTextParams SendTextParams;
FPubnubMentionedUser MentionedUser({"admin_george", "Administrator"});
TMap<int, FPubnubMentionedUser> MentionedUsers;
MentionedUsers.Add(1, MentionedUser);
SendTextParams.MentionedUsers = MentionedUsers;
show all 28 lines
Last updated on