New to Telerik UI for ASP.NET Core? Start a free 30-day trial

Kendo UI Chat TagHelper

Definition

Namespace:Kendo.Mvc.TagHelpers

Assembly:Kendo.Mvc.dll

Syntax:

C#
[HtmlTargetElement("kendo-chat")]
[RestrictChildren("messages", new string[] { "user", "toolbar", "author-message-settings", "receiver-message-settings", "file-actions", "suggestions", "datasource", "message-toolbar-actions", "message-actions", "message-status-settings", "header-items", "files-template", "message-group-template", "message-reference-template", "message-template", "suggested-actions-template", "suggestions-template", "timestamp-template", "action-button", "message-box", "speech-to-text", "file-attachment", "pinned-messages" })]
[OutputElementHint("div")]
public class ChatTagHelper : TagHelperBase, ITagHelper, ITagHelperComponent, IDataBoundWidget<DataSourceTagHelper>, ITemplateComponent

Inheritance: objectTagHelperTagHelperBaseChatTagHelper

Implements: IDataBoundWidget<DataSourceTagHelper>ITagHelperITagHelperComponentITemplateComponent

Inherited Members TagHelperBase.MinimumValidatorTagHelperBase.MaximumValidatorTagHelperBase.Init(TagHelperContext)TagHelperBase.Process(TagHelperContext, TagHelperOutput)TagHelperBase.GetInitializator()TagHelperBase.VerifySettings()TagHelperBase.GenerateId(TagHelperOutput)TagHelperBase.CreateHandler(string)TagHelperBase.GetRangeValidationParameter<TValue>(ModelExplorer, string)TagHelperBase.ExtractEditFormat(string)TagHelperBase.ToDictionaryHandler(IDictionary<string, string>)TagHelperBase.AddSelfToTemplate(TagHelperContext)TagHelperBase.ViewContextTagHelperBase.GeneratorTagHelperBase.InitializerTagHelperBase.WriterTagHelperBase.ScriptAttributesTagHelperBase.NameTagHelperBase.IdTagHelperBase.SelectorTagHelperBase.IdPrefixTagHelperBase.IsInClientTemplateTagHelperBase.DeferredTagHelperBase.AsModuleTagHelper.Orderobject.GetType()object.MemberwiseClone()object.ToString()object.Equals(object)object.Equals(object, object)object.ReferenceEquals(object, object)object.GetHashCode()...

Example:

csharp
@addTagHelper *, Kendo.Mvc

<kendo-chat name="chat">
    <header-items>
        <header-item type="AppBarItemType.ContentItem" template="<strong>Customer Support Chat</strong>"/>
        <header-item type="AppBarItemType.Spacer"/>
        <header-item type="AppBarItemType.ContentItem" template="<button>Export</button>"/>
    </header-items>
    <file-actions>
        <file-action name="download" text="Download" icon="download" />
    </file-actions>
    <message-toolbar-actions>
        <message-toolbar-action name="settings" icon="gear" />
        <message-toolbar-action name="share" icon="share" />
    </message-toolbar-actions>
    <message-actions>
        <message-action name="copy" text="Copy" icon="copy" />
        <message-action name="pin" text="Pin" icon="pin" />
        <message-action name="delete" text="Delete" icon="trash" />
    </message-actions>
    <suggestions>
        <suggestion text="Analyse a file" />
        <suggestion text="Generate a cover letter" />
    </suggestions>
</kendo-chat>

Constructors

Initializes a new instance of the ChatTagHelper class.

C#
public ChatTagHelper(IKendoHtmlGenerator generator)
Parameters:generatorIKendoHtmlGenerator

Properties

Enables or disables message collapsing functionality for expandable messages. When enabled, long messages can be collapsed to save screen space.

C#
public bool? AllowMessageCollapse { get; set; }

Sets the default layout mode for rich attachments.

C#
public ChatAttachmentLayout? AttachmentLayout { get; set; }

The field of the message data item that provides the attachment layout mode for that specific message. Allows per-message override of the global attachmentLayout setting.

C#
public string AttachmentLayoutField { get; set; }

The field of the message data item that provides the rich attachments array. Each attachment object can contain contentType, title, subtitle, thumbnailUrl, and actions properties.

C#
public string AttachmentsField { get; set; }

The template used to render individual attachments within messages. Receives the attachment data object and should return an HTML string. When not set, the default attachment rendering is used.The function receives the attachment object with properties such as title, subtitle, image, contentType, and content. This option expects the name of a JavaScript function that will be called to return the template.

C#
public string AttachmentTemplateHandler { get; set; }

Specifies the unique identifier of the current user. If not set, a GUID will be generated automatically. This determines which messages are displayed as "own messages" (right-aligned) versus "other messages" (left-aligned).

C#
public string AuthorId { get; set; }

Specifies the field name in the data source from which the message author's unique identifier will be read.

C#
public string AuthorIdField { get; set; }

Specifies the field name in the data source from which the alt text for the author's avatar image will be read.

C#
public string AuthorImageAltTextField { get; set; }

Specifies the field name in the data source from which the URL for the author's avatar image will be read.

C#
public string AuthorImageUrlField { get; set; }

Specifies the field name in the data source from which the author's display name will be read.

C#
public string AuthorNameField { get; set; }

Enables or disables automatic assignment of a unique ID to each message posted in the chat. When enabled, messages without an explicit ID will be assigned a generated unique identifier.This option should be set to false if the chat is configured to work with a remote data source and the messages are created on the server. In that case, the id should be assigned on the server itself.

C#
public bool? AutoAssignId { get; set; }

Controls whether the Chat will automatically fetch data from the data source when initialized.When scrollMode is set to "endless" and the dataSource uses serverPaging, autoBind: false is not supported. Remote endless mode always starts with a Chat-managed latest-window request, and manual dataSource.read() and dataSource.fetch() calls are not supported for that mode.

C#
public bool? AutoBind { get; set; }

Defines the amount of space that is preserved above a newly auto-scrolled incoming message when the user is already near the bottom of the message list. Accepts either a pixel value or a percentage of the visible message list area.

C#
public double? AutoScrollThreshold { get; set; }

The collection of data items which the data source contains.

C#
public IEnumerable<ChatMessage> BindTo { get; set; }

The data source id

C#
public string DatasourceId { get; set; }

Specifies the text direction of the Chat.

C#
public TextDirection? Dir { get; set; }

Specifies the delay in milliseconds before the Chat loads older or newer messages after the user reaches an endless-scroll edge. The delay applies only to endless edge-trigger loading and does not affect the scroll-to-bottom button behavior or separator updates.

C#
public double? EndlessScrollDebounceDelay { get; set; }

The field of the message data item that provides the failed flag. When true, the message is rendered with a failed state indicator and a retry button.

C#
public string FailedField { get; set; }

Specifies the field name in the data source from which the array of files attached to a message will be read.

C#
public string FilesField { get; set; }

Controls the layout mode for file attachments within messages.

C#
public ChatFilesLayout? FilesLayoutMode { get; set; }

The template used to render file attachments in messages. This option expects the name of a JavaScript function that will be called to return the template.

C#
public string FilesTemplateHandler { get; set; }

The template used to render file attachments in messages. This option expects the ID of the script element that contains the template.

C#
[Obsolete("FilesTemplateId is obsolete. Please use FilesTemplateHandler or FilesTemplate instead.")]
public string FilesTemplateId { get; set; }

A custom template function for rendering the chat header. When set, this overrides the headerItems configuration and provides full control over the header content. The function should return an HTML string. This option expects the name of a JavaScript function that will be called to return the template.

C#
public string HeaderTemplateHandler { get; set; }

Sets the height of the Chat component.

C#
public string Height { get; set; }

Specifies the field name in the data source from which the unique identifier for each message will be read.

C#
public string IdField { get; set; }

Specifies the field name in the data source that indicates whether a message has been deleted.

C#
public string IsDeletedField { get; set; }

Specifies the field name in the data source that indicates whether a message is pinned.

C#
public string IsPinnedField { get; set; }

Specifies the field name in the data source that indicates whether a message is currently being typed.

C#
public string IsTypingField { get; set; }

Sets the initial loading state of the Chat component. When true, the send button displays a loading/stop indicator instead of the send icon. This is useful for AI chat applications where generating responses takes time. See also the loading method for toggling this state at runtime.

C#
public bool? Loading { get; set; }

The template used to render the message input area at the bottom of the Chat. The function receives no arguments and should return an HTML string for the custom message box markup.When using a custom template, the first textarea or supported text input inside the template is used as the message input. To enable send button behavior, add an element with the ref-chat-message-box-send-button attribute. If the template contains input[type='file'] elements, they participate in the file selection flow. This option expects the name of a JavaScript function that will be called to return the template.

C#
public string MessageBoxTemplateHandler { get; set; }

A custom template function for rendering the content area inside message bubbles. This template controls only the text/content portion of messages, not the entire message group structure. When set, it is used for both author and receiver messages unless overridden by authorMessageSettings.messageContentTemplate or receiverMessageSettings.messageContentTemplate. This option expects the name of a JavaScript function that will be called to return the template.

C#
public string MessageContentTemplateHandler { get; set; }

The template used to render message groups. This option expects the name of a JavaScript function that will be called to return the template.

C#
public string MessageGroupTemplateHandler { get; set; }

The template used to render message groups. This option expects the ID of the script element that contains the template.

C#
[Obsolete("MessageGroupTemplateId is obsolete. Please use MessageGroupTemplateHandler or MessageGroupTemplate instead.")]
public string MessageGroupTemplateId { get; set; }

The template used to render message references (replies and pinned messages). This option expects the name of a JavaScript function that will be called to return the template.

C#
public string MessageReferenceTemplateHandler { get; set; }

The template used to render message references (replies and pinned messages). This option expects the ID of the script element that contains the template.

C#
[Obsolete("MessageReferenceTemplateId is obsolete. Please use MessageReferenceTemplateHandler or MessageReferenceTemplate instead.")]
public string MessageReferenceTemplateId { get; set; }

A custom template function for rendering message status indicators. Receives a context object with status (the status string) and message (the message object). When set, this overrides the default status rendering and messageStatusSettings. This option expects the name of a JavaScript function that will be called to return the template.

C#
public string MessageStatusTemplateHandler { get; set; }

The template used to render individual messages. This option expects the name of a JavaScript function that will be called to return the template.

C#
public string MessageTemplateHandler { get; set; }

The template used to render individual messages. This option expects the ID of the script element that contains the template.

C#
[Obsolete("MessageTemplateId is obsolete. Please use MessageTemplateHandler or MessageTemplate instead.")]
public string MessageTemplateId { get; set; }

The format string used to display message timestamps.

C#
public string MessageTimeFormat { get; set; }

Sets the message width mode.

C#
public ChatMessageWidth? MessageWidthMode { get; set; }

A custom template function for rendering an empty state when the chat has no messages. When set, the template output is displayed in place of the empty message list area, providing a visual cue that the conversation has not started yet. This option expects the name of a JavaScript function that will be called to return the template.

C#
public string NoDataTemplateHandler { get; set; }

The name of the JavaScript function that will handle the contextMenuAction event. Fired when a message context menu action is executed. This event allows you to handle custom message actions and respond to user interactions with message context menus.

C#
public string OnContextMenuAction { get; set; }

The name of the JavaScript function that will handle the download event. Fired when a download action is triggered, either from the "Download All" button or from a file menu download action.

C#
public string OnDownload { get; set; }

The name of the JavaScript function that will handle the executeAction event. Fired when the user clicks an action button in an attachment card. Use this event to handle custom actions defined in attachment data.

C#
public string OnExecuteAction { get; set; }

The name of the JavaScript function that will handle the fileMenuAction event. Fired when a file context menu action is executed. This event allows you to handle custom file actions and respond to user interactions with file attachments.

C#
public string OnFileMenuAction { get; set; }

The name of the JavaScript function that will handle the fileRemove event. Fired when the user removes a file attachment.

C#
public string OnFileRemove { get; set; }

The name of the JavaScript function that will handle the fileSelect event. Fired when the user selects files using the file attachment button.

C#
public string OnFileSelect { get; set; }

The name of the JavaScript function that will handle the input event. Fired when the user types in the message input field.

C#
public string OnInput { get; set; }

The name of the JavaScript function that will handle the referencedMessageClick event. Fired when the user clicks a pinned message banner or a reply reference.The event payload contains only { id } for both pinned-banner clicks and reply-reference clicks.In endless scrolling mode, the event fires before the Chat attempts to render and scroll to a referenced message that is outside the current batch.The event handler function context (available via the this keyword) will be set to the widget instance.

C#
public string OnReferencedMessageClick { get; set; }

The name of the JavaScript function that will handle the resendMessage event. Fired when the user clicks the retry button on a failed message. Use this event to re-attempt message delivery.

C#
public string OnResendMessage { get; set; }

The name of the JavaScript function that will handle the sendMessage event. Fired when the user clicks the action button (send or stop). This is the primary event for handling message submission and stop generation requests.The postMessage method do not trigger this event.

C#
public string OnSendMessage { get; set; }

The name of the JavaScript function that will handle the suggestionClick event. Fired when a user clicks a suggestion in the Chat. Global suggestions always trigger this event. Per-message suggestedActions trigger this event when suggestionsBehavior is set to "insert"; otherwise they flow through sendMessage.

C#
public string OnSuggestionClick { get; set; }

The name of the JavaScript function that will handle the toolbarAction event. Fired when a toolbar action is executed on a message. This event allows you to handle custom toolbar actions and respond to user interactions with message controls.

C#
public string OnToolbarAction { get; set; }

The name of the JavaScript function that will handle the unpin event. Fired when a pinned message is unpinned. This event is triggered when a user clicks the close (X) button on a pinned message.

C#
public string OnUnpin { get; set; }

Documents the default endless batch size.When scrollMode is set to "endless", the effective batch size comes from dataSource.pageSize() for the initial latest window, older/newer adjacent loads, and jump requests. Configure the bound DataSource page size for endless mode instead of relying on a separate Chat range contract, because a root Chat pageSize value does not override the bound DataSource page size.If the bound DataSource does not declare a valid page size, the Chat seeds the DataSource with the default endless batch size of 20 before the first endless load.

C#
public double? PageSize { get; set; }

Specifies the field name in the data source that contains the ID of the message being replied to.

C#
public string ReplyToIdField { get; set; }

The scroll mode for the scrollable behavior.

C#
public ChatScrollMode? ScrollMode { get; set; }

Shows or hides the floating scroll-to-bottom button that appears when the user moves away from the latest messages. In endless scrolling mode, the button is also used to return to the latest rendered batch before scrolling to its bottom.

C#
public bool? ScrollToBottomButton { get; set; }

Controls whether avatars are displayed next to messages. This is a global setting that can be overridden per-user via authorMessageSettings and receiverMessageSettings.

C#
public bool? ShowAvatar { get; set; }

Controls whether usernames are displayed above messages. This is a global setting that can be overridden per-user via authorMessageSettings and receiverMessageSettings.

C#
public bool? ShowUsername { get; set; }

Controls whether HTML sanitization is skipped when rendering message content. When set to true, the Chat component will not automatically encode HTML entities in message text, allowing for rich HTML content to be displayed. This is useful when integrating with markdown parsers or when you need to display pre-formatted HTML content.Warning: Setting this to true can introduce security vulnerabilities if user input is not properly sanitized elsewhere in your application. Only use this option when you trust the content source or have implemented your own sanitization logic.

C#
public bool? SkipSanitization { get; set; }

Specifies the field name in the data source from which the message status will be read. The status describes the delivery state of the message (e.g. "Sending", "Sent", "Delivered", "Seen", "Failed"). See also messageStatusSettings.

C#
public string StatusField { get; set; }

Layout mode for suggested actions.

C#
public SuggestionsLayoutMode? SuggestedActionsLayoutMode { get; set; }

Deprecated: Use suggestedActionsLayoutMode instead.Enables or disables scrollable behavior for suggested actions.

C#
[Obsolete]
public bool? SuggestedActionsScrollable { get; set; }

The template used to render suggested actions. This option expects the name of a JavaScript function that will be called to return the template.

C#
public string SuggestedActionsTemplateHandler { get; set; }

The template used to render suggested actions. This option expects the ID of the script element that contains the template.

C#
[Obsolete("SuggestedActionsTemplateId is obsolete. Please use SuggestedActionsTemplateHandler or SuggestedActionsTemplate instead.")]
public string SuggestedActionsTemplateId { get; set; }

Controls what happens when a user selects a suggestion.

C#
public ChatSuggestionsBehavior? SuggestionsBehavior { get; set; }

The layout mode for the message box suggestions.

C#
public SuggestionsLayoutMode? SuggestionsLayoutMode { get; set; }

Deprecated: Use suggestionsLayoutMode instead.Enables or disables scrollable behavior for message suggestions.

C#
[Obsolete]
public bool? SuggestionsScrollable { get; set; }

The template used to render message suggestions. This option expects the name of a JavaScript function that will be called to return the template.

C#
public string SuggestionsTemplateHandler { get; set; }

The template used to render message suggestions. This option expects the ID of the script element that contains the template.

C#
[Obsolete("SuggestionsTemplateId is obsolete. Please use SuggestionsTemplateHandler or SuggestionsTemplate instead.")]
public string SuggestionsTemplateId { get; set; }

Configures the templates for the Chat.

C#
[HtmlAttributeNotBound]
public IDictionary<string, string> Templates { get; }

Implements: ITemplateComponent.Templates

Specifies the field name in the data source from which the message text content will be read.

C#
public string TextField { get; set; }

Specifies the field name in the data source from which the message timestamp will be read.

C#
public string TimestampField { get; set; }

The template used to render timestamp elements that separate message groups by date. When set to null, the default timestamp logic is used which displays relative dates like "Today", "Yesterday", "Last Wednesday", or absolute dates for older messages.The template function receives an object with date (parsed Date object) and message (current message object) properties and should return the complete HTML structure for the timestamp element.Returning null or an empty string will hide the time breaks from the chat. This option expects the name of a JavaScript function that will be called to return the template.

C#
public string TimestampTemplateHandler { get; set; }

The template used to render timestamp elements that separate message groups by date. When set to null, the default timestamp logic is used which displays relative dates like "Today", "Yesterday", "Last Wednesday", or absolute dates for older messages.The template function receives an object with date (parsed Date object) and message (current message object) properties and should return the complete HTML structure for the timestamp element.Returning null or an empty string will hide the time breaks from the chat. This option expects the ID of the script element that contains the template.

C#
[Obsolete("TimestampTemplateId is obsolete. Please use TimestampTemplateHandler or TimestampTemplate instead.")]
public string TimestampTemplateId { get; set; }

Controls the visibility of message timestamps.

C#
public ChatTimestampVisibility? TimestampVisibility { get; set; }

The template used to render the user status content shown next to the latest message in a receiver group. The function receives a context object with a message field, where message.author contains the normalized author data, and should return an HTML string. This option expects the name of a JavaScript function that will be called to return the template.

C#
public string UserStatusTemplateHandler { get; set; }

Sets the width of the Chat component.

C#
public string Width { get; set; }

Methods

Gets the initialization script.

C#
protected override string GetInitializationScript()
Returns:

string

The initialization script.

Overrides: TagHelperBase.GetInitializationScript()

C#
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
Parameters:contextTagHelperContextoutputTagHelperOutputReturns:

Task

Overrides: TagHelper.ProcessAsync(TagHelperContext, TagHelperOutput)

Serializes the defined settings.

C#
public override IDictionary<string, object> Serialize()
Returns:

IDictionary<string, object>

Overrides: TagHelperBase.Serialize()

SerializeEvents method.

C#
protected override Dictionary<string, object> SerializeEvents()
Returns:

Dictionary<string, object>

Overrides: TagHelperBase.SerializeEvents()

SerializeSettings method.

C#
protected override Dictionary<string, object> SerializeSettings()
Returns:

Dictionary<string, object>

Overrides: TagHelperBase.SerializeSettings()

Serializes the defined templates.

C#
protected override Dictionary<string, object> SerializeTemplates()
Returns:

Dictionary<string, object>

Overrides: TagHelperBase.SerializeTemplates()

Writes the HTML output.

C#
protected override void WriteHtml(TagHelperOutput output)
Parameters:outputTagHelperOutput

The TagHelper output.

Overrides: TagHelperBase.WriteHtml(TagHelperOutput)