provideMessages
chat.provideMessages({
id,
data
} as ProvideMessagesData);
Provides updated messages to the chat widget.
ProvideMessagesData Properties
id
(TID
): The chat identifier.data
(Message[]
): Array of message objects to be displayed in the chat.
Message Properties
id
(TID
): The message identifier.role
("agent" | "user"
): Specifies the sender of the message, either an agent or a user.content
(string
): The actual content of the message.typing?
(number
): Controls the typing animation. Defaults to0
if not specified.0
: Without typing animation (default).1
: With typing animation, streaming mode.-1
: With typing animation, finishing.
Use-Cases
Updating Chat with New Messages
chat.provideMessages({
id: 'chat1234',
data: [
{ id: 'msg1', role: 'user', content: 'Hello!' },
{ id: 'msg2', role: 'agent', content: 'Hi, how can I assist you today?' }
]
} as ProvideMessagesData);
This use-case updates the chat with an initial user message followed by an agent's response.
Streaming Mode for Typing Animation
chat.provideMessages({
id: 'chat1234',
data: [
{ id: 'msg3', role: 'agent', content: 'Hold on, I am checking...', typing: 1 }
]
} as ProvideMessagesData);
This use-case updates the chat with an agent message that includes a typing animation in streaming mode.
Finishing Typing Animation
chat.provideMessages({
id: 'chat1234',
data: [
{ id: 'msg4', role: 'agent', content: 'The issue has been resolved.', typing: -1 }
]
} as ProvideMessagesData);
This use-case updates the chat with an agent message that includes a finishing typing animation.