
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
- No access control allow origin -blocked ...
im not sure what exaclty im doing wrong - its my first time using appwrite - and im watching a tutorial about how to create a movie app and followed everything ...
- Number of Database Reads Bugged
My Appwrite project is generating a huge amount of database reads even when all my apps are closed and no one is using it. The reads counter keeps going up. (it...
- [SOLVED] Appwriteexception: invalid redi...
I've been following this documentation on my app: https://appwrite.io/docs/tutorials/nextjs-ssr-auth/step-7 On Localhost and local development, it's working fi...
