Class: MessageSender
Sends text messages and files to Arattai chats. Access it via
bot.sender (see Bot.sender).
Source: src/Socket/messages.js
Constructor
new MessageSender(session)
constructor(session: AxiosInstance)
Creates a MessageSender with the authenticated session. You typically don't construct this
directly — use
bot.sender instead.
Text Messaging
sendMessage(message, options)
async
sendMessage(message: string, { chatId?, dname?, chat? }): Promise<object>
- message
string— The message text.- options.chatId
string— Target chat ID.- options.dname
string— Display name for the sender.- options.chat
Chat— A Chat object (overrides chatId/dname).- Returns
Promise<object>— API response data.- Throws
Error— If neither chatId nor chat is provided.
// Using chatId
await bot.sender.sendMessage('Hello!', {
chatId: '12345',
dname: 'My Bot'
});
// Using Chat object
const chats = await bot.fetchChats();
const chat = Object.values(chats)[0];
await bot.sender.sendMessage('Hello!', { chat });
File Sending
sendFile(filePath, caption, options)
async
sendFile(filePath: string, caption?: string, { chatId?, dname?, chat? }): Promise<object>
Upload and send a file from the local filesystem. The MIME type is automatically detected
from the file extension.
- filePath
string— Absolute or relative path to the file.- caption
string— Optional caption. Default:""
sendBuffer(buffer, fileName, options)
async
sendBuffer(buffer: Buffer, fileName: string, { chatId?, chat?, mimeType?, caption? }): Promise<object>
Send a Buffer as a file. Perfect for forwarding downloaded media or sending generated content.
- buffer
Buffer— The file data.- fileName
string— Display name (e.g."photo.jpg").- options.mimeType
string— MIME type override. Auto-detected from fileName if omitted.- options.caption
string— Caption. Default:""
// Send file from disk
await bot.sender.sendFile('/path/to/photo.jpg', 'Nice photo!', { chatId });
// Send buffer
const data = fs.readFileSync('report.pdf');
await bot.sender.sendBuffer(data, 'report.pdf', { chatId, caption: 'Monthly report' });
Convenience Methods
These are aliases for sendFile() that improve code readability:
sendImage(filePath, caption, opts)
async
sendImage(filePath: string, caption?: string, opts?): Promise<object>
Send an image file. Alias for
sendFile().
sendAudio(filePath, caption, opts)
async
sendAudio(filePath: string, caption?: string, opts?): Promise<object>
Send an audio file. Alias for
sendFile().
sendVideo(filePath, caption, opts)
async
sendVideo(filePath: string, caption?: string, opts?): Promise<object>
Send a video file. Alias for
sendFile().
sendDocument(filePath, caption, opts)
async
sendDocument(filePath: string, caption?: string, opts?): Promise<object>
Send a document. Alias for
sendFile().await bot.sender.sendImage('./photo.jpg', 'Check this!', { chatId });
await bot.sender.sendAudio('./song.mp3', '', { chatId });
await bot.sender.sendVideo('./clip.mp4', 'Funny video', { chatId });
await bot.sender.sendDocument('./report.pdf', 'Q4 Report', { chatId });