Skip to content

Latest commit

 

History

History
335 lines (274 loc) · 7.61 KB

README.md

File metadata and controls

335 lines (274 loc) · 7.61 KB

Send messages for free via WhatsApp

Note

Brazuka-Zap is an unofficial solution. We are not responsible for its use in production.


Installation

npm i brazuka-zap

or

yarn add brazuka-zap

Usage

At the beginning it will display a QR Code on Terminal, just scan it using WhatsApp app. Your session will be remembered, there is no need to authenticate everytime.


Table of Contents

  1. Start Very Important
  2. Send message to one contact
  3. Send the same message to many contacts
  4. Send the image
  5. Send the link preview
  6. Send the location
  7. Creating a Bot

Very Important

With the start function, you can define a name for the session (passed as a string parameter), so you can have multiple WhatsApp sessions at the same time.

For the library to work correctly it is necessary to run the functions using async and await.

import BrazukaZap from 'brazuka-zap';

test()

async function test(){
	var brazuka = new BrazukaZap();
	await brazuka.start(); // or await brazuka.start('session_name');
}

Send message to one contact

import BrazukaZap from 'brazuka-zap';


const phone = '558812345678'
const message = 'I\'ll be there for you'

await brazuka.sendMessage(phone, message)

Send the same message to many contacts

import BrazukaZap from 'brazuka-zap';

const phones  = ['558812345678','556187654321']
const message = 'When the rain starts to pour'

await brazuka.sendMessage(phones, message)

Send the Image

import BrazukaZap from 'brazuka-zap';

const phone  = '558812345678'
const path   = 'path/to/image.jpg'
const imageName = 'my-image-name'
const caption = 'my-caption'

await brazuka.sendImage(phone, path, imageName, caption)

Send the link preview

import BrazukaZap from 'brazuka-zap';

const phone  = '558812345678'
const link   = 'https://youtu.be/RIjTq_OdFvo'
const message = 'You\'re still in bed at ten\nAnd work began at eight'

await brazuka.sendLinkPreview(phone, message)

Send the Location

import BrazukaZap from 'brazuka-zap';

const phone  = '558812345678'
const latitude = '-3.7594297599906294'
const longitude = '-40.81624143391349'
const local = 'Brasil'

await brazuka.sendLocation(phone, latitude, longitude, local)

Creating a Bot

The Bot will be listening to WhatsApp connected, and when it receives a new message, the Bot will respond according to what was previously registered. You can use Artificial Intelligence to improve your Bot if you wish.


try {
  var zap = new BrazukaZap();
	await zap.start();

	zap.onMessage((msg: any) => {
	switch (msg.body.toLowerCase()) {
		case 'hi': {
			zap.sendMessage(msg.from, `Hello ${msg.sender.pushname}, welcome to my awesome company!`)
			break
		}
		case 'catalog': {
			zap.sendMessage(msg.from, 'Alright, I\'ll be sending you our product catalog!')
			break
		}
		case 'address': {
			zap.sendMessage(msg.from, 'Our address is: 666 Park Avenue')
			break
		}
		default: {
			zap.sendMessage(msg.from, 'Sorry, I couldn\'t understand, I\'m still learning about your world! 🤖')
			break
		}
	}
	})
	} catch (err) {
		console.log(err)
	}

Example Response

{
  "phone": "558812345678-1646089273",
  "message": "Hello, welcome to my awesome company!",
  "status": "OK",
  "error": false
}

Customizing the message

To customize the message, you will have the following properties to use, via the msg variable passed in the onMessage function

{
  "id":"[email protected]_1BG7C215D2D4F156AE84E0862DD58880",
  "body":"Hi",
  "type":"chat",
  "t":1636110320,
  "notifyName":"",
  "from":"[email protected]",
  "to":"[email protected]",
  "author":"[email protected]",
  "self":"in",
  "ack":0,
  "invis":false,
  "isNewMsg":true,
  "star":false,
  "recvFresh":true,
  "isFromTemplate":false,
  "broadcast":false,
  "mentionedJidList":[
    
  ],
  "isVcardOverMmsDocument":false,
  "isForwarded":false,
  "labels":[
    
  ],
  "ephemeralOutOfSync":false,
  "productHeaderImageRejected":false,
  "isDynamicReplyButtonsMsg":false,
  "isMdHistoryMsg":false,
  "chatId":"[email protected]",
  "fromMe":false,
  "sender":{
    "id":"[email protected]",
    "name":"Daniel",
    "shortName":"Daniel",
    "pushname":"Daniel Albuquerque",
    "type":"in",
    "isBusiness":false,
    "isEnterprise":false,
    "statusMute":false,
    "labels":[
      
    ],
    "formattedName":"Daniel",
    "isMe":false,
    "isMyContact":true,
    "isPSA":false,
    "isUser":true,
    "isWAContact":true,
    "profilePicThumbObj":{
      "eurl":"https://pps.whatsapp.net/v/t61.24694-24/155555555_000000000000000_777441025896523658_n.jpg?ccb=11-4&oh=a5024da3cd299dbaf16b1da1a4a98ee6&oe=60F16F53",
      "id":"[email protected]",
      "img":"https://web.whatsapp.com/pp?e=https%3A%2F%2Fpps.whatsapp.net%2Fv%2Ft61.24694-24%2F153312958_000000000000000_777441025896523658_n.jpg%3Fccb%3D11-4%26oh%3Da5024da3cd299dbaf16b1da1a4a98ee6%26oe%3D60F16F53&t=s&u=558812345678%40c.us&i=1613954550&n=q417zd84AaHW0He4pHzwT3lADc7RH%2BDbvUuDBwScb%2F4%3D",
      "imgFull":"https://web.whatsapp.com/pp?e=https%3A%2F%2Fpps.whatsapp.net%2Fv%2Ft61.24694-24%2F153312958_000000000000000_777441025896523658_n.jpg%3Fccb%3D11-4%26oh%3Da5024da3cd299dbaf16b1da1a4a98ee6%26oe%3D60F16F53&t=l&u=558812345678%40c.us&i=1613954550&n=q417zd84AaHW0He4pHzwT3lADc7RH%2BDbvUuDBwScb%2F4%3D",
      "raw":null,
      "tag":"1613454350"
    },
    "msgs":null
  },
  "timestamp":1836010520,
  "content":"Hi",
  "isGroupMsg":true,
  "isMedia":false,
  "isNotification":false,
  "isPSA":false,
  "chat":{
    "id":"[email protected]",
    "pendingMsgs":false,
    "lastReceivedKey":{
      "fromMe":true,
      "remote":"[email protected]",
      "id":"1IBRGOQDW44CNCDN9TFQ",
      "_serialized":"[email protected]_1IBRGOQDW44CNCDN9TFQ"
    },
    "t":1626118707,
    "unreadCount":0,
    "archive":false,
    "isReadOnly":false,
    "isAnnounceGrpRestrict":false,
    "muteExpiration":0,
    "name":"HL",
    "notSpam":true,
    "pin":0,
    "msgs":null,
    "kind":"group",
    "isGroup":true,
    "contact":{
      "id":"[email protected]",
      "name":"HL",
      "type":"in",
      "isBusiness":false,
      "isEnterprise":false,
      "statusMute":false,
      "labels":[
        
      ],
      "formattedName":"HL",
      "isMe":false,
      "isMyContact":false,
      "isPSA":false,
      "isUser":false,
      "isWAContact":false,
      "profilePicThumbObj":[
        "Object"
      ],
      "msgs":null
    },
    "groupMetadata":{
      "id":"[email protected]",
      "creation":1646200718,
      "owner":"[email protected]",
      "restrict":false,
      "announce":false,
      "noFrequentlyForwarded":false,
      "ephemeralDuration":0,
      "support":false,
      "uniqueShortNameMap":{
        
      },
      "participants":[
        "Array"
      ],
      "pendingParticipants":[
        
      ]
    },
    "presence":{
      "id":"[email protected]",
      "chatstates":[
        "Array"
      ]
    },
    "isOnline":true,
    "lastSeen":null
  }
}

🛠️ Coming soon 🛠️

New functions will be added soon.

🚀 Contribution

Contributions make the open source community an amazing place to learn, inspire and create. Any contribution you make will be much appreciated.

✔️ License

Distributed under license MIT. © Daniel Albuquerque