---
source_url: https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/links
title: Links
updated_at: 2026-06-25T11:25:19.293Z
---

> 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.

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

## Send message with links

`AddMention()` lets you replace a plain link on the [draft message](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/drafts) to display a meaningful text in the published message.

### Method signature

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

Refer to the [addMention()](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/drafts#add-message-element) 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.

```csharp
using System.Linq;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var channelResult = await chat.GetChannel("offtopic");
if (channelResult.Error) return;
var testChannel = channelResult.Result;
        
// Create a message draft
var messageDraft = testChannel.CreateMessageDraft();

// Update the message with the initial text
messageDraft.Update("Hello Alex! I have sent you this link on the #offtopic channel.");

// Add a URL to the word "link"
messageDraft.AddMention(33, 4, new MentionTarget
{
    Target = "https://example.com",
    Type = MentionType.Url
});
```

## Remove links

`RemoveMention()` lets you remove a previously added link from a [draft message](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/drafts).

### Method signature

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

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

:::warning Offset value
If you don't provide the position of the first character of the message element to remove, it isn't 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.

```csharp
using System.Linq;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
// assume the message reads
// Hello Alex! I have sent you this link on the #offtopic channel.`

// remove the link mention
messageDraft.RemoveMention(33);
```

## Get link suggestions

The event handler you attached to the `OnDraftUpdated` event returns all links referenced in the [draft message](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/message-draft) that match the provided 3-letter string from your app's keyset.

##### Single listener

The event handler returns suggestions for channel references, user mentions, and links using `<List<MessageElement>` and `<List<SuggestedMention>`.

* `<List<MessageElement>` represent the draft's current state and can include plain text or links, such as user mentions, channel references, or URLs. These elements are organized to reflect their order in the draft.
* `<List<SuggestedMention>` provides potential mentions when available.

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

You must handle the event to update to the contents of a message draft, as well as retrieve the current message elements suggestions for user mentions, channel reference, and links. For example, when the message draft contains `... @name ...` or `... #chann ...`.

:::warning Enable receiving suggested mentions
You must enable receiving suggested mentions by setting `messageDraft.ShouldSearchForSuggestions = true;` before introducing your event handler.
:::

Refer to the [Add a message draft listener](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/drafts#add-message-draft-change-listener) section for details.

### Sample code

Insert the first suggested mention whenever the draft is updated and mentions are detected.

```csharp
using System.Linq;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var channelResult = await chat.GetChannel("support");
if (channelResult.Error) return;
var channel = channelResult.Result;
        
var messageDraft = channel.CreateMessageDraft();

messageDraft.ShouldSearchForSuggestions = true;

messageDraft.OnDraftUpdated += (elements, mentions) =>
{
    if (!mentions.Any())
    {
        return;
    }
    messageDraft.InsertSuggestedMention(mentions[0], mentions[0].ReplaceTo);
};

messageDraft.Update("Alex, update the link to https://www.pubnub.com ");
```

## Get text links

You can access the `TextLinks` property of the [Message object](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/message) to return all text links in a given message.

### Method signature

This is how you can access the property:

```csharp
message.TextLinks
```

#### Properties

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| TextLinks | List<TextLink> | Optional |  | List of all links included in a message. |

### Sample code

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

```csharp
using System.Linq;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;

// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
// reference the "support" channel
var channelResult = await chat.GetChannel("support");
if (!channelResult.Error)
{
    var channel = channelResult.Result;
    // get the message with the specific timetoken
    var messageResult = await channel.GetMessage("16200000000000000");
    if (!messageResult.Error)
    {
        var message = messageResult.Result;
        // check if the message contains any text links
        if (message.TextLinks != null && message.TextLinks.Count > 0)
        {
            Debug.Log("The message contains the following text links:");
            foreach (var textLink in message.TextLinks)
            {
                Debug.Log($"Text Link: {textLink.Link}");
            }
        }
        else
        {
            Debug.Log("The message does not contain any text links.");
        }
    }
    else
    {
        Debug.Log("Message with specified timetoken not found.");
    }
}
else
{
    Debug.Log("Channel 'support' not found.");
}
```