WhiskeySockets / Baileys

Lightweight full-featured typescript/javascript WhatsApp Web API
https://baileys.whiskeysockets.io/
MIT License
3.95k stars 1.34k forks source link

[BUG] qrcode not printing because 405 error #912

Open darkshadowside1 opened 4 months ago

darkshadowside1 commented 4 months ago

I am just running the sample code given in the main page

import makeWASocket, {
  useMultiFileAuthState,
  makeInMemoryStore,
  Browsers,
  DisconnectReason,
  delay,
  fetchLatestBaileysVersion,
} from "@whiskeysockets/baileys";
async function connectToWhatsApp() {
  const { state, saveCreds } = await useMultiFileAuthState("auth_info_baileys");

  const waConfig = {
    auth: state,
    printQRInTerminal: true,
  };
  const sock = makeWASocket.default(waConfig);
  sock.ev.on("connection.update", async (update) => {
    const { connection, lastDisconnect } = update;
    if (connection === "close") {
      const shouldReconnect =
        lastDisconnect.error?.output?.statusCode !== DisconnectReason.loggedOut;
      console.log(
        "connection closed due to ",
        lastDisconnect.error,
        ", reconnecting ",
        shouldReconnect
      );
      if (shouldReconnect) {
        // connectToWhatsApp();
      }
    } else if (connection === "open") {
      console.log("opened connection");
    }
    // if (update.qr) {
    //   console.log(update.qr);
    //   const phoneNumber = process.env.WA_NUMBER;
    //   const code = await sock.requestPairingCode(phoneNumber);
    //   console.log(`Pairing code: ${code}`);
    // }
  });

  sock.ev.on("creds.update", saveCreds);
  sock.ev.on("messages.upsert", async (m) => {
    if (m.messages[0].key.fromMe) return;
    console.log(JSON.stringify(m, undefined, 2));

    console.log("replying to", m.messages[0].key.remoteJid);
    await sock.sendMessage(m.messages[0].key.remoteJid, {
      text: "Hello there!",
    });
  });
}
// run in main file
connectToWhatsApp();

Steps to reproduce the behavior:

  1. Copy the code and run it

Expected behavior QR or pairing code should be printed out

Environment (please complete the following information): I am running it on windows 11

Additional context I have tried using different methods, I have tried changing version: [2, 2413, 51], and i have tried using baileys@6.6.0 but still the issues is same. I have also noticed that location in data changes everytime i runt the application, i don't know if it is supposed to run that way

data: { reason: '405', location: 'nao' },
  isBoom: true,
  isServer: false,
  output: {
    statusCode: 405,
    payload: {
      statusCode: 405,
      error: 'Method Not Allowed',
      message: 'Connection Failure'
    },
    headers: {}
  }
  data: { reason: '405', location: 'rva' },
  isBoom: true,
  isServer: false,
  output: {
    statusCode: 405,
    payload: {
      statusCode: 405,
      error: 'Method Not Allowed',
      message: 'Connection Failure'
    },
    headers: {}
  }
} , reconnecting  true
data: { reason: '405', location: 'vll' },
  isBoom: true,
  isServer: false,
  output: {
    statusCode: 405,
    payload: {
      statusCode: 405,
      error: 'Method Not Allowed',
      message: 'Connection Failure'
    },
    headers: {}
  }
} , reconnecting  true
Laminhdatau commented 3 months ago

Saya hanya menjalankan kode contoh yang diberikan di halaman utama

import makeWASocket, {
  useMultiFileAuthState,
  makeInMemoryStore,
  Browsers,
  DisconnectReason,
  delay,
  fetchLatestBaileysVersion,
} from "@whiskeysockets/baileys";
async function connectToWhatsApp() {
  const { state, saveCreds } = await useMultiFileAuthState("auth_info_baileys");

  const waConfig = {
    auth: state,
    printQRInTerminal: true,
  };
  const sock = makeWASocket.default(waConfig);
  sock.ev.on("connection.update", async (update) => {
    const { connection, lastDisconnect } = update;
    if (connection === "close") {
      const shouldReconnect =
        lastDisconnect.error?.output?.statusCode !== DisconnectReason.loggedOut;
      console.log(
        "connection closed due to ",
        lastDisconnect.error,
        ", reconnecting ",
        shouldReconnect
      );
      if (shouldReconnect) {
        // connectToWhatsApp();
      }
    } else if (connection === "open") {
      console.log("opened connection");
    }
    // if (update.qr) {
    //   console.log(update.qr);
    //   const phoneNumber = process.env.WA_NUMBER;
    //   const code = await sock.requestPairingCode(phoneNumber);
    //   console.log(`Pairing code: ${code}`);
    // }
  });

  sock.ev.on("creds.update", saveCreds);
  sock.ev.on("messages.upsert", async (m) => {
    if (m.messages[0].key.fromMe) return;
    console.log(JSON.stringify(m, undefined, 2));

    console.log("replying to", m.messages[0].key.remoteJid);
    await sock.sendMessage(m.messages[0].key.remoteJid, {
      text: "Hello there!",
    });
  });
}
// run in main file
connectToWhatsApp();

Langkah-langkah untuk mereproduksi perilaku:

  1. Salin kode dan jalankan

Perilaku yang diharapkan QR atau kode pasangan harus dicetak

Lingkungan (harap lengkapi informasi berikut): Saya menjalankannya di windows 11

Konteks tambahan Saya telah mencoba menggunakan metode yang berbeda, saya telah mencoba mengubah versi: [2, 2413, 51], dan saya telah mencoba menggunakan baileys@6.6.0 tetapi masalahnya tetap sama. Saya juga memperhatikan bahwa lokasi dalam data berubah setiap kali saya menjalankan aplikasi, saya tidak tahu apakah itu seharusnya berjalan seperti itu

data: { reason: '405', location: 'nao' },
isBoom: true,
isServer: false,
output: {
  statusCode: 405,
  payload: {
    statusCode: 405,
    error: 'Method Not Allowed',
    message: 'Connection Failure'
  },
  headers: {}
}
data: { reason: '405', location: 'rva' },
isBoom: true,
isServer: false,
output: {
  statusCode: 405,
  payload: {
    statusCode: 405,
    error: 'Method Not Allowed',
    message: 'Connection Failure'
  },
  headers: {}
}
} , reconnecting  true
data: { reason: '405', location: 'vll' },
isBoom: true,
isServer: false,
output: {
  statusCode: 405,
  payload: {
    statusCode: 405,
    error: 'Method Not Allowed',
    message: 'Connection Failure'
  },
  headers: {}
}
} , reconnecting  true

Sorry, try doing it like this.

import makeWASocket, { useMultiFileAuthState, makeInMemoryStore, Browsers, DisconnectReason, delay, fetchLatestBaileysVersion, } from "@whiskeysockets/baileys"; async function connectToWhatsApp() { const { state, saveCreds } = await useMultiFileAuthState("auth_info_baileys");

const sock = makeWASocket({ auth: state, //dont't forget install library qr-terminal printQRInTerminal: true, auth: state, // delay request qrcode qrTimeout: 20000, }); sock.ev.on("connection.update", async (update) => { const { connection, lastDisconnect,qr } = update; if (connection === "close") { const shouldReconnect = lastDisconnect.error?.output?.statusCode !== DisconnectReason.loggedOut; console.log( "connection closed due to ", lastDisconnect.error, ", reconnecting ", shouldReconnect ); if (shouldReconnect) { // connectToWhatsApp(); } } else if (connection === "open") { console.log("opened connection"); } // if (qr) { // console.log(update.qr); // const phoneNumber = process.env.WA_NUMBER; // const code = await sock.requestPairingCode(phoneNumber); // console.log(Pairing code: ${code}); // } });

sock.ev.on("creds.update", saveCreds); sock.ev.on("messages.upsert", async (m) => { if (m.messages[0].key.fromMe) return; console.log(JSON.stringify(m, undefined, 2));

console.log("replying to", m.messages[0].key.remoteJid);
await sock.sendMessage(m.messages[0].key.remoteJid, {
  text: "Hello there!",
});

}); } // run in main file connectToWhatsApp();

Laminhdatau commented 3 months ago

Sorry, try doing it like this.

import makeWASocket, { useMultiFileAuthState, makeInMemoryStore, Browsers, DisconnectReason, delay, fetchLatestBaileysVersion, } from "@whiskeysockets/baileys"; async function connectToWhatsApp() { const { state, saveCreds } = await useMultiFileAuthState("auth_info_baileys");

const sock = makeWASocket({ auth: state, //dont't forget install library qr-terminal printQRInTerminal: true, auth: state, // delay request qrcode qrTimeout: 20000, }); sock.ev.on("connection.update", async (update) => { const { connection, lastDisconnect,qr } = update; if (connection === "close") { const shouldReconnect = lastDisconnect.error?.output?.statusCode !== DisconnectReason.loggedOut; console.log( "connection closed due to ", lastDisconnect.error, ", reconnecting ", shouldReconnect ); if (shouldReconnect) { // connectToWhatsApp(); } } else if (connection === "open") { console.log("opened connection"); } // if (qr) { // console.log(update.qr); // const phoneNumber = process.env.WA_NUMBER; // const code = await sock.requestPairingCode(phoneNumber); // console.log(Pairing code: ${code}); // } });

sock.ev.on("creds.update", saveCreds); sock.ev.on("messages.upsert", async (m) => { if (m.messages[0].key.fromMe) return; console.log(JSON.stringify(m, undefined, 2));

console.log("replying to", m.messages[0].key.remoteJid);
await sock.sendMessage(m.messages[0].key.remoteJid, {
  text: "Hello there!",
});

}); } // run in main file connectToWhatsApp();

darkshadowside1 commented 3 months ago

Still same....

Laminhdatau commented 3 months ago

Retry to running in linux

Pada Sen, 15 Jul 2024 19.14, darkshadowside1 @.***> menulis:

Still same....

— Reply to this email directly, view it on GitHub https://github.com/WhiskeySockets/Baileys/issues/912#issuecomment-2228254838, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3BQIJRLQVLGVQKXEE65V6DZMOVKHAVCNFSM6AAAAABKPI3MJCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRYGI2TIOBTHA . You are receiving this because you commented.Message ID: @.***>

darkshadowside1 commented 3 months ago

I think this may be a problem from the build from TS to JS, when I run the same code with in this project (Baileys-master) it runs as expected but when i run the same with the baileys as a dependency it does not work.

hacxk commented 3 months ago

I THINK THAT'S BECAUSE YOUR IP BLOCKED BY WHATSAPP USE A PROXY TRY. STILL THE SAME ERROR TRY ADDING A VERSION TO makeWASocket EXAMPLE:

 const sock = await makeWASocket({
            version: [2, 3000, 1014080102], // add latest version this is example version
            printQRInTerminal: true,
            auth: state
})