Skip to content

PrivateChat

PrivateChat represents a one-to-one direct message conversation between the bot and a user. By Telegram convention, the chat ID equals the user ID.

ts
const user = chats.newUser();
// user.privateChat is auto-created — same as:
const dm = chats.newPrivateChat(user);

Properties

PropertyTypeDescription
idnumberChat ID (equals user.id)
type'private'Chat type discriminant
userUser<TContext>The user this chat belongs to
messagesMessagesLog<TContext>All bot sends to this chat

PrivateChat.messages vs user.replies

These two look similar but track different things:

user.replies (RepliesInbox)privateChat.messages (MessagesLog)
What it tracksBot replies to that user (via ctx.reply or sendMessage with the user's chat ID)All bot sends to the private chat, including proactive messages
SourceDerived from onCapture matching the user IDSame — both are routed by Chats.deriveFromCapture
In practiceVirtually identical for PrivateChatVirtually identical for PrivateChat

For group chats, user.replies tracks per-user replies while group.messages tracks all messages in the group. In private chats both refer to the same conversation.

Usage

ts
const { chats } = await prepareBot(bot);
const user = chats.newUser();

// Bot proactively sends a message (not a reply)
await chats.outgoing.respondNext('sendMessage', { message_id: 99 });
await bot.api.sendMessage(user.id, 'Proactive message!');

// Check via messages log
expect(user.privateChat.messages.last?.text).toBe('Proactive message!');

Most of the time you'll use user.repliesprivateChat.messages is mainly useful when you need to inspect messages sent outside of a handler context (e.g. scheduled messages, broadcast calls, or bot-initiated conversations).

Released under the MIT License.