it works perfectly fine in my local functions emulator `const admin = require("firebase-admin");
const { Client, LocalAuth } = require("whatsapp-web.js");
const { onCall } = require("firebase-functions/v2/https");
admin.initializeApp();
const initializeAndSendMessage = async (userId) => {
return new Promise( async (resolve, reject) => {
console.log("Initializing WhatsApp client for user:", userId);
const client = new Client({
authStrategy: new LocalAuth({
clientId: userId,
}),
puppeteer: {
headless: true,
args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-gpu"],
},
webVersionCache: {
type: "remote",
remotePath: "https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2412.54.html",
},
});
client.on("ready", async () => {
console.log("Client is ready for user:", userId);
resolve(client);
});
client.on("qr", async (qr) => {
console.log("Storing QR-Code for user:", userId);
// You can add your code to store the QR code here
});
client.on("authenticated", async () => {
console.log("Authenticated for user:", userId);
});
client.on("auth_failure", async () => {
console.log("Auth failure for user:", userId);
reject(new Error("Authentication failed"));
});
client.on("disconnected", async () => {
console.log("Client disconnected for user:", userId);
// Handle disconnection if necessary
});
console.log("client.initialize:", userId);
await client.initialize();
});
};
`