Skip to main content

messages

---
name: messages
description: initial messages to be displayed in the chat
---
```# messages

```ts
type Message = {
id: TID;
role: "agent" | "user";
content: string;
typing?: number;
}

Controls the initial messages to be displayed in the chat. Default value: [].

Example of Setting Initial Messages

const messages = [
{ id: 1, content: "How?", role: "user" },
{ id: 2, content: "Just try", role: "agent" }
];
const chat = new ChatBot(node, { messages });

Example of Updating Messages

const updatedMessages = [
{ id: 1, content: "Hello?", role: "user" },
{ id: 2, content: "I'm here to help", role: "agent" }
];
chat.setConfig({ messages: updatedMessages });

Example of Getting Current Messages

const chat = new ChatBot(node, { 
messages: [
{ id: 1, content: "How?", role: "user" },
{ id: 2, content: "Just try", role: "agent" }
]
});

const currentMessages = chat.getConfig().messages;
console.log(currentMessages);
// Output: [
// { id: 1, content: "How?", role: "user" },
// { id: 2, content: "Just try", role: "agent" }
// ]

Message Data Format

type Message = {
id: TID;
role: "agent" | "user";
content: string;
typing?: number;
}

// Typing
// 0 - without typing animation (default)
// 1 - with typing animation, streaming mode
// -1 - with typing animation, finishing