Links

Unreal Chat SDK lets you encode URLs that begin with www, http, or https (plain links) so that they can be rendered as links.

Generic referencing

Channel references, user mentions, and links are instances of MessageElement with different MentionTarget types.

icon

Usage in Blueprints and C++

AddMention() lets you replace a plain link on the draft message to display a meaningful text in the published message.

You can use the static CreateUrlMentionTarget() method to create a mention target that links to a specified Url and reference it in the method.

Method signature

You can add a link suggestion by calling the AddMention() method with the MentionTarget of type Url.

Refer to the AddMention() method for details.

Basic usage

Create the Hello Alex! I have sent you this link on the #offtopic channel. message where link is a URL.

// Create a message draft
UPubnubMessageDraft* MyMessageDraft = Channel->CreateMessageDraft();

// Insert the whole text to the message draft
MyMessageDraft->InsertText(0, "Hello Alex! I have sent you this link on the #offtopic channel.");

// Specify the URL to be included in the mention
FString Url = "https://www.example.com";
UPubnubMentionTarget* UrlMentionTarget = UPubnubMentionTarget::CreateUrlMentionTarget(Url);

// Add the mention for the URL starting from where "link" is inserted
MyMessageDraft->AddMention(33, 4, UrlMentionTarget); // 'link' is 4 characters long

// Send the message draft with the mentions
MyMessageDraft->Send();

RemoveMention() lets you remove a previously added link from a draft message.

Method signature

You can remove a link from a draft message by calling the RemoveMention() method at the exact position where the link starts.

Refer to the RemoveMention() method for details.

Position value

If you don't provide the position of the first character of the message element to remove, it isn't removed.

Basic usage

Remove the link from the Hello Alex! I have sent you this link on the #offtopic channel. message where link is a URL.

// Assume the message reads
// Hello Alex! I have sent you this link on the #offtopic channel.`
// Remove the link mention
MessageDraft->RemoveMention(33)

Add a callback to listen for changes to the message draft along with receiving suggestions for user mentions, links, and channel references.

AddChangeListenerWithSuggestions() returns all links referenced in the draft message that match the provided 3-letter string from your app's keyset.

icon

Single listener


For example, if you type #Sup, you will get the list of channels starting with Sup like Support or Support-Agents. The default number of returned suggested channel names is 10, configurable to a maximum value of 100.

Method signature

Refer to the Add a message draft listener section for details.

Basic usage

Insert the first suggested link whenever the draft is updated and links are detected.

// Assuming you have a UPubnubMessageDraft pointer named MyMessageDraft

// Define your callback function to handle updates with suggestions
void AMyActor::OnMessageDraftUpdateWithSuggestions(const TArray<UPubnubMessageElement*>& MessageElements, const TArray<FPubnubSuggestedMention>& SuggestedMentions)
{
// Check if there are any suggested mentions
if (SuggestedMentions.Num() == 0)
{
return;
}

// Insert the first suggested mention into the draft
const FPubnubSuggestedMention& FirstMention = SuggestedMentions[0];
MyMessageDraft->InsertSuggestedMention(FirstMention, FirstMention.ReplaceTo);
}
show all 25 lines

TextLinks() is a getter method that returns all text links in a given message.

Method signature

Output

TypeDescription
TArray<FPubnubTextLink>Array of text links included in the message.

Basic usage

Get all text links included in the message with the 16200000000000000 timetoken.

#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");

FString Timetoken = "16200000000000001";

// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken);

show all 16 lines
Last updated on