Sulla is a javascript library which provides a high-level API control to Whatsapp so it can be configured to automatize resposes or any data that goes trough Whatsapp effortlessly.
It is built using puppeteer and based on this python wrapper
> npm i --save sulla-hotfix
// import { create, Whatsapp } from 'sulla';
const sulla = require('sulla-hotfix');
sulla.create().then(client => start(client));
function start(client) {
client.onMessage(message => {
if (message.body === 'Hi') {
client.sendText(message.from, 'π Hello from sulla!');
}
});
}
After executing create()
function, sulla will create an instance of whatsapp web. If you are not logged in, it will print a QR code in the terminal. Scan it with your phone and you are ready to go!
Function | Description | Implemented |
---|---|---|
Receive message | β | |
Send text | β | |
Get contacts | β | |
Get chats | β | |
Get groups | β | |
Get group members | β | |
Send contact | β | |
Get contact detail | β | |
Send Images (image) | β | |
Send media (audio, doc, video) | ||
Send stickers | ||
Decrypt media (image, audio, doc) | β |
Here is a sample of how to decrypt media. This has been tested on images, videos, documents, audio. It does not work for voice notes right now, or I don't have the right codecs to play them.
import { create, Whatsapp, decryptMedia} from 'sulla-hotfix';
const mime = require('mime-types')
const fs = require('fs');
function start(client: Whatsapp) {
client.onMessage(async message => {
if (message.mimetype) {
const filename = `${message.t}.${mime.extension(message.mimetype)}`;
const mediaData = await decryptMedia(message);
const imageBase64 = `data:${message.mimetype};base64,${mediaData.toString('base64')}`;
await client.sendImage(message.from,imageBase64,filename, `You just sent me this ${message.type}`);
fs.writeFile(
filename,
mediaData,
function(err) {
if (err) {
return console.log(err);
}
console.log('The file was saved!');
}
);
}
});
}
create().then(client => start(client));
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.