Skip to content

πŸ₯ƒ Javascript whatsapp library for chatbots

License

Notifications You must be signed in to change notification settings

landim/sulla

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

npm version Greenkeeper badge

sulla

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

Installation

> npm i --save sulla-hotfix

Usage

// 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!
sulla will remember the session so there is no need to authenticate everytime.

Functions list

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) βœ…

Decrypting Media

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

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

About

πŸ₯ƒ Javascript whatsapp library for chatbots

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 71.1%
  • TypeScript 28.9%