Class: ArattixBot

Main entry point for the Arattix library. Creates an authenticated HTTP session, handles QR code login, and returns a Bot instance ready to use.

Source: src/Socket/index.js

Constructor

new ArattixBot(options?)
constructor({ isShowQr?, proxy? })
Creates a new ArattixBot client with an axios session and cookie jar.
options.isShowQr
boolean — Display QR code in the terminal. Default: true
options.proxy
string | null — HTTP proxy URL (e.g. "http://127.0.0.1:8080"). Default: null
const { ArattixBot } = require('arattix');

// Default — show QR in terminal
const arattix = new ArattixBot();

// With options
const arattix = new ArattixBot({
  isShowQr: true,
  proxy: 'http://127.0.0.1:8080'
});

Properties

session property
AxiosInstance
The underlying axios instance with cookie jar support. Created during construction.
isShowQr property
boolean
Whether to render the QR code in the terminal during login.
token property
string | null
Auth token (populated after login). Initially null.

Methods

loginWithQr() async
loginWithQr(): Promise<Bot>
Authenticate using QR code login. If a saved session (cookies.json) is valid, it will be reused without showing the QR code. Otherwise, a new QR code is displayed for scanning.
Returns
Promise<Bot> — An authenticated Bot instance.
Throws
Error — If QR login fails.
const arattix = new ArattixBot({ isShowQr: true });

try {
  const bot = await arattix.loginWithQr();
  await bot.setupCsrf();
  console.log('Logged in!');
} catch (err) {
  console.error('Login failed:', err.message);
}

Full Example

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

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

  // Fetch chats
  const chats = await bot.fetchChats({ limit: 10 });
  console.log(`Found ${Object.keys(chats).length} chats`);

  // Send a message to the first chat
  const firstChat = Object.values(chats)[0];
  if (firstChat) {
    await bot.sender.sendMessage('Hello from Arattix!', { chat: firstChat });
  }
}

main();