Class: Chat
Represents a single chat with its metadata, participants, and messages. Returned by Bot.fetchChats() and ChatManager.parseChatData().
Source: src/Types/Chat.js
Constructor
new Chat(chatId, title, owner, participants, message, lastmsguid)
- chatId
string— Chat identifier.- title
string— Chat title / name.- owner
Participant— Chat owner.- participants
Participant[]— Array of participants.- message
Message | Message[] | null— Last message(s).- lastmsguid
string | null— Last message UID.
Properties
| Property | Type | Description |
|---|---|---|
chatId | string | Chat identifier |
title | string | Chat title |
owner | Participant | Chat owner |
participants | Participant[] | All participants |
message | Message | Message[] | Last message(s) |
lastmsguid | string | null | Last message UID |
Methods
getChatId()
method
getChatId(): string
Returns the chat ID.
getTitle()
method
getTitle(): string
Returns the chat title.
getLastmsguid()
method
getLastmsguid(): string | null
Returns the last message UID.
getMessage(limit?)
method
getMessage(limit?: number): Message | Message[]
Returns messages. If
limit is provided and messages is an array,
returns the last limit messages.
addMessage(message)
method
addMessage(message: Message): void
Add a message to this chat's message list.
toJSON()
method
toJSON(): { chat_id, title, lastmsguid }
Returns a plain object representation.
toString()
method
toString(): string
Returns JSON string (pretty-printed).
const chats = await bot.fetchChats();
for (const [id, chat] of Object.entries(chats)) {
console.log(chat.getTitle());
console.log(`Owner: ${chat.getOwner().getDname()}`);
console.log(`Participants: ${chat.getParticipants().length}`);
// Use chat object to send messages
await bot.sender.sendMessage('Hello!', { chat });
}