---
source_url: https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/links
title: Links
updated_at: 2026-06-17T11:37:27.790Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Links

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

##### Usage in Blueprints and C++

You can use PubNub's functionality via Blueprints or directly in C++ code.

* In Blueprints, you can access PubNub from any Widget or Actor. Start by [initializing chat](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/configuration#initialize-pubnub-chat) using `InitChat` on `UPubnubChatSubsystem`. Afterwards, you can use the returned `UPubnubChat` object reference to call all Chat SDK functions.

:::warning Blueprint functions
The Blueprints provided in the documentation show how you can structure your application and may contain utility methods and elements like buttons that are not part of the Unreal Chat SDK and are meant to serve as guidance.
:::

* In C++, you can use UPubnubChatSubsystem as any other Game Instance Subsystem. #include "Kismet/GameplayStatics.h" #include "Engine/GameInstance.h" #include "PubnubChatSubsystem.h" // ACTION REQUIRED: Replace ASample_ChatSubsystem with name of your Actor class void ASample_ChatSubsystem::InitChatSample() { // Get PubnubChatSubsystem from GameInstance UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this); UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>(); // Initialize Chat - InitChat may fail under some conditions so make sure to check the Result for errors before using the Chat FPubnubChatInitChatResult InitChatResult = PubnubChatSubsystem->InitChat(TEXT("demo"), TEXT("demo"), TEXT("Player_001")); UPubnubChat* PubnubChat = InitChatResult.Chat; } Chat now allows you to call all Chat SDK functions, for example, Chat->GetChannel("my_channel").

:::tip Generic referencing
Channel references, user mentions, and links share the same `MessageElement` structure with different `MentionTarget` types.
:::

## Add links

`AddMention()` adds a link to a [draft message](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts). Use `CreateUrlMentionTarget()` to create a mention target linking to a specified URL.

### Method signature

Call `AddMention()` with `MentionTarget` of type `Url`. See [AddMention()](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts#add-message-element) for details.

Refer to the [AddMention()](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts#add-message-element) method for details.

### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with `ACTION REQUIRED` before running the code. Use it as a reference when working with other examples in this document.
:::

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

###### Actor.h

```cpp
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|ChatMessageDraft")
void AddUrlLinkSample();
```

###### Actor.cpp

```cpp
// ACTION REQUIRED: Replace ASample_ChatMessageDraft with name of your Actor class
void ASample_ChatMessageDraft::AddUrlLinkSample()
{
	// snippet.hide
	UPubnubChatChannel* Channel = nullptr;
	// snippet.show

	// Assumes Channel is a valid UPubnubChatChannel (e.g. from GetChannel)

	UPubnubChatMessageDraft* MyMessageDraft = Channel->CreateMessageDraft();

	MyMessageDraft->InsertText(0, "Hello Alex! I have sent you this link on the #offtopic channel.");

	FString Url = "https://www.example.com";
	FPubnubChatMentionTarget UrlMentionTarget = UPubnubChatMessageDraftUtilities::CreateUrlMentionTarget(Url);

	MyMessageDraft->AddMention(33, 4, UrlMentionTarget);

	MyMessageDraft->Send();
}
```

## Remove links

`RemoveMention()` removes a link from a [draft message](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts).

### Method signature

Call `RemoveMention()` at the exact offset where the link starts. See [RemoveMention()](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts#remove-message-element) for details.

Refer to the [RemoveMention()](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts#remove-message-element) method for details.

:::warning Offset value
Provide the exact position of the first character; otherwise the element is not removed.
:::

### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with `ACTION REQUIRED` before running the code. Use it as a reference when working with other examples in this document.
:::

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

###### Actor.h

```cpp
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|ChatMessageDraft")
void MessageDraftRemoveMentionSample();
```

###### Actor.cpp

```cpp
// ACTION REQUIRED: Replace ASample_ChatMessageDraft with name of your Actor class
void ASample_ChatMessageDraft::MessageDraftRemoveMentionSample()
{
	// snippet.hide
	UPubnubChatMessageDraft* MessageDraft = nullptr;
	// snippet.show

	// Assumes MessageDraft is a valid UPubnubChatMessageDraft with existing mentions
	// e.g. the message reads: "Hello Alex! I have sent you this link on the #offtopic channel."

	// Remove the link mention at position 33
	MessageDraft->RemoveMention(33);
}
```

## Get link suggestions

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

##### Details

`OnMessageDraftUpdatedWithSuggestions` delegate:

* Fires when the draft content changes
* Provides the current state of message elements (`TArray<FPubnubChatMessageElement>`)
* Offers `FPubnubChatSuggestedMention` items suggesting user mentions, links, or channel references

Unlike `OnMessageDraftUpdated`, which only delivers content changes, this delegate also includes suggestion data for dynamic draft updates.

### Method signature

Refer to the [Listen for message draft changes (with suggestions)](https://www.pubnub.com/docs/chat/unreal-chat-sdk/build/features/messages/drafts#listen-for-message-draft-changes-with-suggestions) section for details.

### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with `ACTION REQUIRED` before running the code. Use it as a reference when working with other examples in this document.
:::

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

###### Actor.h

```cpp
UFUNCTION(BlueprintCallable, Category = "PubnubChat|Samples|ChatMessageDraft")
void MessageDraftInsertSuggestedMentionSample();

void OnMessageDraftUpdateWithSuggestions_InsertSample(const TArray<FPubnubChatMessageElement>& MessageElements, const TArray<FPubnubChatSuggestedMention>& SuggestedMentions);
```

###### Actor.cpp

```cpp
// ACTION REQUIRED: Replace ASample_ChatMessageDraft with name of your Actor class
void ASample_ChatMessageDraft::MessageDraftInsertSuggestedMentionSample()
{
	// snippet.hide
	UPubnubChatChannel* Channel = nullptr;
	// snippet.show

	// Assumes Channel is a valid UPubnubChatChannel (e.g. from GetChannel)

	UPubnubChatMessageDraft* MyMessageDraft = Channel->CreateMessageDraft();

	// Bind to receive suggestions and automatically insert the first one
	MyMessageDraft->OnMessageDraftUpdatedWithSuggestionsNative.AddUObject(this, &ASample_ChatMessageDraft::OnMessageDraftUpdateWithSuggestions_InsertSample);

	// Trigger the delegate and suggestions
	MyMessageDraft->Update("Please coordinate with @Al for the meeting.");
}

// ACTION REQUIRED: Replace ASample_ChatMessageDraft with name of your Actor class
void ASample_ChatMessageDraft::OnMessageDraftUpdateWithSuggestions_InsertSample(const TArray<FPubnubChatMessageElement>& MessageElements, const TArray<FPubnubChatSuggestedMention>& SuggestedMentions)
{
	// snippet.hide
	UPubnubChatMessageDraft* MyMessageDraft = nullptr;
	// snippet.show

	if (SuggestedMentions.Num() > 0)
	{
		const FPubnubChatSuggestedMention& FirstSuggestion = SuggestedMentions[0];
		MyMessageDraft->InsertSuggestedMention(FirstSuggestion);
		UE_LOG(LogTemp, Log, TEXT("Inserted suggested mention: %s"), *FirstSuggestion.ReplaceTo);
	}
}
```

## Get text links

:::warning Removed method
`TextLinks()` and `GetTextLinks()` have been removed from the `Message` object in the latest version of the Unreal Chat SDK. Links are now managed through [MessageDraft](https://www.pubnub.com/docs/chat/unreal-chat-sdk/learn/chat-entities/message-draft) and message elements.
:::