Skip to content

chat class

A control that provides the user interface for chatting.

Methods

__init__()

__init__(
    messages=None,
    users=None,
    sender_id="taipy",
    with_input=True,
    on_action=None,
    page_size=50,
    height=None,
    show_sender=False,
    mode="markdown",
    max_file_size=0.8 * 1024 * 1024,
    allow_send_images=False,
    active=True,
    id=None,
    properties=None,
    class_name=None,
    hover_text=None,
) -> None

Create a new chat element.

Parameters:

Name Type Description Default
messages dynamic(list[str])

The list of messages. Each item of this list must consist of a list of three strings: a message identifier, a message content, and a user identifier.

None
users dynamic(list[Union[str, Icon]])

The list of users. See the section on List of Values for more details.

None
sender_id str

The user identifier, as indicated in the users list, associated with all messages sent from the input.

taipy
with_input dynamic(bool)

If False, the input field is not rendered.

True
on_action Union[str, Callable]

A function or the name of a function that is triggered when the user enters a new message.
This function is invoked with the following parameters:

  • state (State): the state instance.
  • var_name (str): the name of the variable bound to the messages property.
  • payload (dict): the details on this callback's invocation.
    This dictionary has the following keys:
    • action: the name of the action that triggered this callback.
    • args (list): a list composed of a reason ("click" or "Enter"), the variable name, the message, and the user identifier of the sender.

None
page_size int

The number of messages retrieved from the application and sent to the frontend. Larger values imply more potential latency.

50
height Union[str, int, float]

The maximum height of the chat control, in CSS units.

None
show_sender bool

If True, the sender avatar and name are displayed.

False
mode str

Define the way the messages are processed when they are displayed:

  • "raw" no processing
  • "pre": keeps spaces and new lines
  • "markdown" or "md": basic support for Markdown.

markdown
max_file_size int

The maximum allowable file size, in bytes, for files uploaded to a chat message.
The default is 0.8 MB.

0.8 * 1024 * 1024
allow_send_images bool

If True, the "Upload image" button is visible.

False
active dynamic(bool)

Indicates if this element is active.
If False, the element is disabled, and user interaction is not allowed.

True
id str

The identifier assigned to the rendered HTML component.
This can be used in callbacks or to target the element for styling.

None
properties dict[str, Any]

A dictionary of additional properties that can be set to the element.

None
class_name dynamic(str)

A space-separated list of CSS class names to be applied to the generated HTML element.
These classes are added to the default taipy-chat class.

None
hover_text dynamic(str)

The text that is displayed when the user hovers over the element.

None