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

PropertyTypeDescription
chatIdstringChat identifier
titlestringChat title
ownerParticipantChat owner
participantsParticipant[]All participants
messageMessage | Message[]Last message(s)
lastmsguidstring | nullLast message UID

Methods

getChatId() method
getChatId(): string
Returns the chat ID.
getTitle() method
getTitle(): string
Returns the chat title.
getOwner() method
getOwner(): Participant
Returns the chat owner.
getParticipants() method
getParticipants(): Participant[]
Returns the list of participants.
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 });
}