Brazuka-Zap is an unofficial solution. We are not responsible for its use in production.
npm i brazuka-zap
or
yarn add brazuka-zap
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.
- Start Very Important
- Send message to one contact
- Send the same message to many contacts
- Send the image
- Send the link preview
- Send the location
- Creating a Bot
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');
}
import BrazukaZap from 'brazuka-zap';
const phone = '558812345678'
const message = 'I\'ll be there for you'
await brazuka.sendMessage(phone, message)
import BrazukaZap from 'brazuka-zap';
const phones = ['558812345678','556187654321']
const message = 'When the rain starts to pour'
await brazuka.sendMessage(phones, message)
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)
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)
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)
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)
}
{
"phone": "558812345678-1646089273",
"message": "Hello, welcome to my awesome company!",
"status": "OK",
"error": false
}
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
}
}
New functions will be added soon.
Contributions make the open source community an amazing place to learn, inspire and create. Any contribution you make will be much appreciated.
Distributed under license MIT. ยฉ Daniel Albuquerque