Hey can i create a function which uses whatsapp web js (which under the hood opens chromium browser via pupeteer) because getting this err:-
Error: Failed to launch the browser process! spawn /usr/local/server/src/function/node_modules/puppeteer/.local-chromium/linux-982053/chrome-linux/chrome ENOENT
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
CODE:-
const qrcode = require("qrcode-terminal");
module.exports = async (context) => {
const whatsappclient = new Client({
authStrategy: new LocalAuth()
// puppeteer: { args: ['--no-sandbox', '--disable-setuid-sandbox'] }
});
whatsappclient.initialize();
whatsappclient.on("qr", (qr) => {
qrcode.generate(qr, { small: true });
context.log(qr);
});
whatsappclient.on("message", async (msg) => {
context.log("MESSAGE:- " + msg.body);
});
if (req.method === 'GET') {
if (req.path === '/message') {
const phoneNumber = req.query.phoneNumber;
const message = req.query.message;
const chatId = phoneNumber + "@c.us";
try {
// Wait for client to be ready before sending message
await new Promise((resolve) => whatsappclient.on("ready", resolve));
const response = await whatsappclient.sendMessage(chatId, message);
context.log("Message sent to:", phoneNumber, chatId);
context.log(response);
return res.send("Message sent successfully.");
} catch (err) {
context.error("Error sending message:", err);
return res.send("Error sending message.");
}
}
}
// Consider returning a placeholder response to indicate processing
// (optional, depending on your needs)
// return new Promise((resolve) => setTimeout(resolve, 1000));
};
You'll need to setup your build command to install chromium in your functions container, then set your whatsappclient/puppeteer to reference that new location of chromium.
I believe the function containers are alpine linux.
https://github.com/dishwasher-detergent/screenshot
Here is something I made that uses puppeteer, the two pages that would mean the most to you are the browser.ts file, and the appwrite.json file.
Check out https://discord.com/channels/564160730845151244/1215654642353176656, I have a working sample here, just ensure you have the correct environment variables and build settings along with the dependency declared in package.json and you should be good
Recommended threads
- Sydney Cloud Sites: App Git deployment a...
Project ID: rentwize-db The app Site fails after the build completes with a missing build archive error. Site id: app Framework: TanStack Start SSR Output dir...
- Active Running Project Deletion Alert Em...
Hi , I received an email alert from Appwrite today stating “your project will be deleted within 14 days if no action is taken,” though I have been actively usin...
- Project restoration button in console
The project restore button in console is taking no effect, i have tried several times and still nothing, it gives same popup if i reload