Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-release-flutter-v5-stable.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

FieldValue
Package@cometchat/chat-uikit-angular
Key classCometChatUrlFormatter (extends CometChatTextFormatter)
Required setupCometChatUIKit.init(uiKitSettings) then CometChatUIKit.login("UID")
PurposeAuto-detects URLs in text messages and converts them to clickable links
RelatedCustom Text Formatter | All Guides
CometChatUrlFormatter extends CometChatTextFormatter to detect URLs in text messages and render them as clickable links.

Usage

Extend CometChatTextFormatter, set a regex pattern for URL detection, and override format() to handle formatting and click behavior.
import { CometChatTextFormatter } from "@cometchat/chat-uikit-angular";

export class CometChatUrlsFormatter extends CometChatTextFormatter {
  readonly id = "custom-url-formatter";
  override priority = 10;

  getRegex(): RegExp {
    return /(https?:\/\/[^\s]+)/g;
  }

  format(text: string): string {
    if (!text) {
      this.originalText = "";
      this.formattedText = "";
      return "";
    }

    this.originalText = text;
    this.formattedText = text.replace(
      this.getRegex(),
      '<a href="$1" class="clickable-url" target="_blank" rel="noopener noreferrer">$1</a>'
    );
    return this.formattedText;
  }
}

Customization

Apply CSS to your link class:
.clickable-url {
  color: var(--cometchat-primary-color);
  text-decoration: underline;
  cursor: pointer;
}

Handling clicks

Override onUrlClick to add tracking or custom navigation:
private onUrlClick(event: Event) {
  event.preventDefault();
  const target = event.target as HTMLAnchorElement;
  const url = target.href;
  // Add analytics tracking
  console.log("URL clicked:", url);
  window.open(url, "_blank", "noopener,noreferrer");
}
The CometChatUrlFormatter is included by default in the message list. You only need to pass it explicitly if you want to customize click behavior or combine it with other formatters.

Next Steps

Custom Text Formatter

Build custom inline text patterns.

Message List

Render real-time message threads.

All Guides

Browse all feature and formatter guides.

Mentions Formatter

Add @mentions with styled tokens.