Developer Integration Hub

The complete guide to connecting your WhatsApp Bot with Syntiox Session Server.
ඔබේ WhatsApp Bot එක Syntiox Server එක හරහා පහසුවෙන් සම්බන්ධ කරගන්න.

Get BizMate WhatsApp MD
100% FREE ADVANCED BOT

Perfect for users without coding experience who want to easily create an Advanced WhatsApp Bot connected with MongoDB.

කෝඩ් එකක් නැති අයට සහ MongoDB එක්ක සම්බන්ධ කරලා Advanced WhatsApp Bot කෙනෙක් පහසුවෙන් හදාගන්න අවශ්‍ය අයට මෙය භාවිතා කළ හැක.

1 How to Get Session ID (User Step / පියවර 1)

Before using the API, the user must generate a session.

  • Go to the Home Page.
  • Scan the QR Code or use Pairing Code.
  • Once connected, the user will receive a message on WhatsApp with the SESSION_ID.

WhatsApp Message Example:

⚠️ *DO NOT SHARE THIS CODE*

Your Session ID:

sz-MD_OTQ...

Use this ID in the API below.

2 API Documentation (For Developers)

POST https://syntiox-sync.vercel.app/api/get-session

Request Body (JSON)

ඔබේ බොට් කෝඩ් එකෙන් මෙම ඩේටා එවන්න.

{
  "sessionId": "sz-MD_OTQ...",
  "phoneNumber": "947XXXXXXXX"
}

Response (JSON)

ඔබට ලැබෙන සම්පූර්ණ Creds ෆයිල් එක.

{
  "noiseKey": { ... },
  "me": {
    "id": "947XXX:5@s.whatsapp.net",
    "name": "Syntiox Bot"
  },
  "platform": "smba",
  "account": { ... }
}

Example Usage (Node.js)

const axios = require('axios');

async function getSession() {
    const res = await axios.post('https://syntiox-sync.vercel.app/api/get-session', {
        sessionId: "sz-MD_...",
        phoneNumber: "947..."
    });

    // Save this data as 'creds.json'
    // මෙම data කෙලින්ම creds.json ලෙස සේව් කරන්න.
    console.log(res.data);
}

3 Critical Configuration ⚠️ (වැදගත්ම කොටස)

IMPORTANT: Your bot's socket configuration MUST match our server exactly. If these values are different, the session will logout.
ඔබේ බොට් එකේ makeWASocket සැකසුම් අපගේ සර්වර් එකට 100% සමාන විය යුතුය. නැතිනම් Session එක ක්‍රියා නොකරයි.

const sock = makeWASocket({
    version,
    auth: {
        creds: state.creds,
        // ✅ Use CacheableSignalKeyStore to prevent buffer errors
        keys: makeCacheableSignalKeyStore(state.keys, pino({ level: "fatal" }).child({ level: "fatal" })),
    },
    logger: pino({ level: 'silent' }), 

    // 🔥 DO NOT CHANGE THESE LINES (මේවා වෙනස් කරන්න එපා) 🔥
    browser: ["Ubuntu", "Chrome", "20.0.04"],
    syncFullHistory: false,
    markOnlineOnConnect: false,
    generateHighQualityLinkPreview: true,

    // Timeouts
    connectTimeoutMs: 60000, 
    keepAliveIntervalMs: 10000,
    retryRequestDelayMs: 5000,
});

🤖 Complete Bot Script Template

Copy and paste this into your index.js or bot.js.

require('dotenv').config();
const { default: makeWASocket, useMultiFileAuthState, fetchLatestBaileysVersion, makeCacheableSignalKeyStore } = require("@whiskeysockets/baileys");
const pino = require('pino');
const fs = require('fs-extra');
const axios = require('axios');
const path = require('path');

const { SESSION_ID, PHONE_NUMBER } = process.env;
const authPath = path.join(__dirname, 'auth_info');

async function startBot() {
    // 1. Download Session
    if (!fs.existsSync(path.join(authPath, 'creds.json'))) {
        try {
            console.log("⏳ Downloading Session...");
            const { data } = await axios.post('https://syntiox-sync.vercel.app/api/get-session', {
                sessionId: SESSION_ID,
                phoneNumber: PHONE_NUMBER
            });
            await fs.ensureDir(authPath);
            await fs.writeJson(path.join(authPath, 'creds.json'), data);
            console.log("✅ Session Downloaded!");
        } catch (e) {
            console.error("❌ Session Error:", e.message);
            process.exit(1);
        }
    }

    // 2. Connect
    const { state, saveCreds } = await useMultiFileAuthState(authPath);
    const { version } = await fetchLatestBaileysVersion();

    const sock = makeWASocket({
        version,
        auth: {
            creds: state.creds,
            keys: makeCacheableSignalKeyStore(state.keys, pino({ level: "fatal" }).child({ level: "fatal" })),
        },
        logger: pino({ level: 'silent' }),

        // 🔥 CRITICAL CONFIGS 🔥
        // ⚠️ DO NOT CHANGE BROWSER CONFIG BELOW ⚠️
        browser: ["Ubuntu", "Chrome", "20.0.04"],
        syncFullHistory: false,
        markOnlineOnConnect: false,
        connectTimeoutMs: 60000,
    });

    sock.ev.on('creds.update', saveCreds);

    sock.ev.on('connection.update', (update) => {
        const { connection } = update;
        if (connection === 'open') console.log("✅ Bot Connected!");
        else if (connection === 'close') setTimeout(startBot, 3000);
    });

    // 3. Msg Upsert & Auto Status Read
    sock.ev.on('messages.upsert', async ({ messages, type }) => {
        if (type !== 'notify') return;
        
        // Fixed: Handling array of messages
        const msg = messages[0]; 
        if (!msg.message) return;

        const from = msg.key.remoteJid;
        const text = msg.message.conversation || msg.message.extendedTextMessage?.text || msg.message.imageMessage?.caption || '';
        
        // 📝 Show messages in terminal
        console.log(`📩 New Msg: [${from}] -> ${text}`);

        // Auto Read Status
        if (from === 'status@broadcast') {
            await sock.readMessages([msg.key]);
            return;
        }

        // Ignore self msg
        if (msg.key.fromMe) return;

        const lowerCaseText = text.toLowerCase().trim();

        // Auto Replies
        const autoReplies = [
            { k: ['hi','hello','hey','bot'], r: "Hello! I am an automated virtual assistant. 🤖" },
            { k: ['online','alive'], r: "I am currently online and active. ⚙️" },
            { k: ['thanks','thank you'], r: "You're very welcome! ✨" },
            { k: ['help','menu'], r: "I am here to help. You can use the '.menu' command. 📋" }
        ];

        for (const item of autoReplies) {
            if (item.k.some(kw => lowerCaseText.includes(kw))) {
                await sock.sendMessage(from, { text: item.r }, { quoted: msg });
                break;
            }
        }
    });
}
startBot();