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",
    active=True,
    id=None,
    properties=None,
    class_name=None,
    hover_text=None,
) -> None

Create a new chat element.

Parameters:

Name Type Description Default

messages

list[str]
dynamic

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

list[Union[str,Icon]]
dynamic

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

bool
dynamic

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

active

bool
dynamic

Indicates if this component is active.
An inactive component allows no user interaction.

True

id

str

The identifier that is assigned to the rendered HTML component.

None

properties

dict[str, Any]

Bound to a dictionary that contains additional properties for this element.

None

class_name

str
dynamic

The list of CSS class names that are associated with the generated HTML Element.
These class names are added to the default taipy-chat class name.

None

hover_text

str
dynamic

The information that is displayed when the user hovers over this element.

None