Arattix

A modern Node.js library for the Arattai messaging API

npm version MIT license node >= 14

Introduction

Arattix is a reverse-engineered Node.js library that lets you build bots and automation tools for the Arattai messaging platform. It handles authentication (QR code login), session management, chat/message polling, and full media support — all through a clean, promise-based API.

Note Arattix communicates with the Arattai web API. You need a valid Arattai account to authenticate.

Features

Quick Example

const { ArattixBot } = require('arattix');

async function main() {
  // Create client & authenticate via QR code
  const arattix = new ArattixBot({ isShowQr: true });
  const bot = await arattix.loginWithQr();

  // Set up CSRF token
  await bot.setupCsrf();

  // Fetch all chats
  const chats = await bot.fetchChats({ limit: 20 });

  for (const [chatId, chat] of Object.entries(chats)) {
    console.log(`${chat.title} — ${chatId}`);

    // Send a message
    await bot.sender.sendMessage('Hello from Arattix!', { chat });
  }
}

main();

Installation

$ npm install arattix

Or clone from GitHub:

git clone https://github.com/SafwanGanz/Arattix.git
cd Arattix
npm install

Docker Support:

# Run with Docker
docker build -t arattix-bot .
docker run -v $(pwd)/cookies.json:/app/cookies.json arattix-bot

# Or use Docker Compose
docker-compose up arattix-bot

Getting Started

1. Authentication

Arattix authenticates by scanning a QR code with your Arattai mobile app. The session cookies are saved to cookies.json and reused on subsequent runs.

const { ArattixBot } = require('arattix');

const arattix = new ArattixBot({ isShowQr: true });
const bot = await arattix.loginWithQr();
await bot.setupCsrf();

2. Fetching Chats

Use bot.fetchChats() to get parsed Chat objects, or bot.fetchChatsLive() to bypass server-side session caching for guaranteed fresh data.

// Parsed Chat map
const chats = await bot.fetchChats({ limit: 20 });

// Raw API response
const raw = await bot.fetchChatsRaw({ limit: 20 });

// Fresh session (bypasses cache)
const liveChats = await bot.fetchChatsLive({ limit: 20 });

3. Sending Messages

Use the bot.sender to send text or media:

// Text message
await bot.sender.sendMessage('Hello!', { chatId, dname: 'Bot' });

// Using a Chat object
await bot.sender.sendMessage('Hello!', { chat });

// Send a file from disk
await bot.sender.sendFile('/path/to/photo.jpg', 'Check this out!', { chatId });

// Send a buffer
await bot.sender.sendBuffer(buffer, 'doc.pdf', { chatId });

4. Fetching Messages

The V2 messages API returns live, uncached data — perfect for bot polling:

const messages = await bot.fetchMessages(chatId, { limit: 20 });

for (const msg of messages) {
  if (Bot.isMediaMessage(msg)) {
    const info = Bot.getMediaInfo(msg);
    console.log(`Media: ${info.fileName} (${info.mimeType})`);
  } else {
    console.log(`Text: ${msg.content?.text}`);
  }
}

5. Downloading Media

// Download to buffer
const { data, contentType } = await bot.downloadMedia(fileId, chatId);

// Download to file
await bot.downloadMediaToFile(fileId, chatId, './photo.jpg');

// Get download URL only
const url = bot.getMediaUrl(fileId, chatId);

API Reference

Explore the full class documentation:

ClassModuleDescription
ArattixBot Socket Main entry point — creates sessions & handles QR login
Bot Socket Authenticated client — chats, messages, media download
MessageSender Socket Send text messages and upload media files
Chat Types Structured chat data with participants & messages
ChatManager Types Parses raw API response into Chat objects
Message Types Message data model (v1 format)
MediaInfo Types Media metadata with type detection & helpers
Participant Types Chat participant with display name & ID
Defaults Defaults All API URLs, service names & timeouts