On this page

Links

Encode URLs (www, http, https) as clickable links or create hyperlinks with custom text.

icon

Usage in Blueprints and C++

Generic referencing

Channel references, user mentions, and links share the same MessageElement structure with different MentionTarget types.

AddMention() adds a link to a draft message. Use CreateUrlMentionTarget() to create a mention target linking to a specified URL.

Method signature

Call AddMention() with MentionTarget of type Url. See AddMention() for details.

Refer to the AddMention() method for details.

Sample code

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() removes a link from a draft message.

Method signature

Call RemoveMention() at the exact offset where the link starts. See RemoveMention() for details.

Refer to the RemoveMention() method for details.

Offset value

Provide the exact position of the first character; otherwise the element is not removed.

Sample code

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

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

The message elements listener returns link suggestions along with user mentions and channel references.

icon

Single listener


Method signature

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

Sample code

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

1// Assuming you have a UPubnubMessageDraft pointer named MyMessageDraft
2
3// Define your callback function to handle updates with suggestions
4void AMyActor::OnMessageDraftUpdateWithSuggestions(const TArray<UPubnubMessageElement*>& MessageElements, const TArray<FPubnubSuggestedMention>& SuggestedMentions)
5{
6 // Check if there are any suggested mentions
7 if (SuggestedMentions.Num() == 0)
8 {
9 return;
10 }
11
12 // Insert the first suggested mention into the draft
13 const FPubnubSuggestedMention& FirstMention = SuggestedMentions[0];
14 MyMessageDraft->InsertSuggestedMention(FirstMention, FirstMention.ReplaceTo);
15}
show all 25 lines

TextLinks() returns all text links in a message.

Method signature

Output

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

Sample code

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

1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15
show all 16 lines
Last updated on