Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] qrcode not printing because 405 error #912

Open
darkshadowside1 opened this issue Jul 7, 2024 · 6 comments
Open

[BUG] qrcode not printing because 405 error #912

darkshadowside1 opened this issue Jul 7, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@darkshadowside1
Copy link

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 [email protected] 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
@darkshadowside1 darkshadowside1 added the bug Something isn't working label Jul 7, 2024
@Laminhdatau
Copy link

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 [email protected] 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
Copy link

Laminhdatau commented Jul 11, 2024

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
Copy link
Author

Still same....

@Laminhdatau
Copy link

Laminhdatau commented Jul 15, 2024 via email

@darkshadowside1
Copy link
Author

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
Copy link

hacxk commented Jul 29, 2024

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
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants