jeast-whatsapp-api
Advanced tools
Comparing version 1.0.6 to 1.1.0
@@ -24,3 +24,3 @@ const { Jeast } = require("./main"); | ||
if (connection.isConnected) { | ||
console.log("connected!"); | ||
await client.sendOfflineStatus(); | ||
} | ||
@@ -31,6 +31,4 @@ }); | ||
if (message.body == "Hello") { | ||
await client.createNewGroup("Test", [ | ||
await client.getContactById(message.id.remote), | ||
]); | ||
await client.sendOnlineStatus(); | ||
} | ||
}); |
{ | ||
"name": "jeast-whatsapp-api", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"description": "Useful tools for whatsapp", | ||
@@ -5,0 +5,0 @@ "main": "./main.js", |
@@ -11,5 +11,7 @@ <h1 align="center"> | ||
# Jeast Whatsapp API | ||
A Simple whatsapp api that connects through the whatsapp web, that is used for all needs such as sending messages, and authenticating on whatsapp via qr code. | ||
## 🚀 Installation | ||
Type the npm command below to install the package | ||
@@ -67,12 +69,16 @@ | ||
```js | ||
const { Jeast } = require("jeast-whatsapp-api"); | ||
const { Jeast } = require("jeast-whatsapp-api"); | ||
const client = new Jeast(); | ||
const client = new Jeast(); | ||
client.ev.qr(callback); //Event listener to get or print qr code | ||
client.ev.connection(callback); //Event listener that which will be called when connected or authenticated | ||
client.ev.message(callback); //Event listener that which will be called when some peoples send message | ||
client.ev.revokeMe(callback); //Event listener that which will be called when some peoples revoke to you | ||
client.ev.revokeAll(callback); //Event listener that which will be called when revoke all related to you | ||
client.ev.uploadMedia(callback); //Event listener that will be called if you are sending a message | ||
client.ev.qr(callback); //Event listener to get or print qr code | ||
client.ev.connection(callback); //Event listener that which will be called when connected or authenticated | ||
client.ev.message(callback); //Event listener that which will be called when some peoples send message | ||
client.ev.revokeMe(callback); //Event listener that which will be called when some peoples revoke to you | ||
client.ev.revokeAll(callback); //Event listener that which will be called when revoke all related to you | ||
client.ev.uploadMedia(callback); //Event listener that will be called if you are sending a message | ||
client.ev.incomingCall(callback); //Event listener will be called when someone calls you with whatsapp | ||
client.ev.group.join(callback); //Event listener will be called when someone invite you on group | ||
client.ev.group.leave(callback); //Event listener will be called when someone remove you from group | ||
client.ev.group.update(callback); //Event listener will be called when someone update same group as you | ||
``` | ||
@@ -85,10 +91,10 @@ | ||
```js | ||
const options = { | ||
sendAudioAsVoice: Boolean, // make it true if you use this options | ||
sendVideoAsGif: Boolean, // make it true if you use this options | ||
sendAsSticker: Boolean, // make it true if you use this options | ||
sendAsDocument: Boolean, // make it true if you use this options | ||
} | ||
const options = { | ||
sendAudioAsVoice: Boolean, // make it true if you use this options | ||
sendVideoAsGif: Boolean, // make it true if you use this options | ||
sendAsSticker: Boolean, // make it true if you use this options | ||
sendAsDocument: Boolean, // make it true if you use this options | ||
}; | ||
sendMessage('receiver-number@.c.us', 'message', options); // asynchronous function | ||
sendMessage("receiver-number@.c.us", "message", options); // asynchronous function | ||
``` | ||
@@ -101,4 +107,5 @@ | ||
```js | ||
getChats(); // asynchronous function | ||
getChats(); // asynchronous function | ||
``` | ||
**Logout** | ||
@@ -109,3 +116,3 @@ | ||
```js | ||
logout(); // asynchronous function | ||
logout(); // asynchronous function | ||
``` | ||
@@ -132,3 +139,3 @@ | ||
```js | ||
sendMessageSeen('receiver-number@c.us') // asynchronous function | ||
sendMessageSeen("receiver-number@c.us"); // asynchronous function | ||
``` | ||
@@ -141,3 +148,3 @@ | ||
```js | ||
getChatById('receiver-number@c.us') // asynchronous function | ||
getChatById("receiver-number@c.us"); // asynchronous function | ||
``` | ||
@@ -150,3 +157,3 @@ | ||
```js | ||
getPhoneCountry('phone-number') // asynchronous function | ||
getPhoneCountry("phone-number"); // asynchronous function | ||
``` | ||
@@ -159,3 +166,3 @@ | ||
```js | ||
createNewGroup("Test", ["List of participant number id"]); // asynchronous function | ||
createNewGroup("Test", ["List of participant number id"]); // asynchronous function | ||
``` | ||
@@ -168,3 +175,3 @@ | ||
```js | ||
getWAVersion() // asynchronous function | ||
getWAVersion(); // asynchronous function | ||
``` | ||
@@ -177,3 +184,3 @@ | ||
```js | ||
getContacts() // asynchronous function | ||
getContacts(); // asynchronous function | ||
``` | ||
@@ -207,6 +214,4 @@ | ||
if (connection.isConnected) { | ||
const sticker = MsgMedia.fromFilePath( | ||
__dirname + "/path/to/file" | ||
); | ||
await client.sendMessage('receiver-number@c.us', sticker, { | ||
const sticker = MsgMedia.fromFilePath(__dirname + "/path/to/file"); | ||
await client.sendMessage("receiver-number@c.us", sticker, { | ||
sendAsSticker: true, | ||
@@ -244,6 +249,4 @@ }); | ||
if (connection.isConnected) { | ||
const document = MsgMedia.fromFilePath( | ||
__dirname + "/path/to/file" | ||
); | ||
await client.sendMessage('receiver-number@c.us', document, { | ||
const document = MsgMedia.fromFilePath(__dirname + "/path/to/file"); | ||
await client.sendMessage("receiver-number@c.us", document, { | ||
sendAsDocument: true, | ||
@@ -282,6 +285,4 @@ }); | ||
if (connection.isConnected) { | ||
const video = MsgMedia.fromFilePath( | ||
__dirname + "/path/to/file" | ||
); | ||
await client.sendMessage('receiver-number@c.us', video, { | ||
const video = MsgMedia.fromFilePath(__dirname + "/path/to/file"); | ||
await client.sendMessage("receiver-number@c.us", video, { | ||
sendVideoAsGif: true, | ||
@@ -288,0 +289,0 @@ }); |
@@ -16,2 +16,4 @@ module.exports = { | ||
Chat: require("./chat.jeast"), | ||
Call: require("./call.jeast"), | ||
GroupNotification: require("./group-notification.jeast"), | ||
}; |
@@ -19,5 +19,7 @@ exports.whatsappURL = "https://web.whatsapp.com/"; | ||
QR_RECEIVED: "qr_code", | ||
GROUP_LEAVE: "grp_leave", | ||
GROUP_INVITATION_JOIN: "grp_join", | ||
GROUP_UPDATE: "grp_update", | ||
DISCONNECTED: "disconnected", | ||
STATE_CHANGED: "change_state", | ||
BATTERY_CHANGED: "change_battery", | ||
INCOMING_CALL: "incoming_call", | ||
@@ -24,0 +26,0 @@ }; |
@@ -61,3 +61,3 @@ exports.ExposeStore = (moduleRaidStr) => { | ||
window.Store.ProfilePic = window.mR.findModule("profilePicResync")[0]; | ||
window.Store.PresenceUtils = window.mR.findModule("sendPresenceAvailable")[0]; | ||
window.Store.PresenceStatus = window.mR.findModule("sendPresenceAvailable")[0]; | ||
window.Store.ChatState = window.mR.findModule("sendChatStateComposing")[0]; | ||
@@ -64,0 +64,0 @@ window.Store.GroupParticipants = window.mR.findModule( |
172
src/jeast.js
@@ -16,4 +16,6 @@ const EventEmitter = require("events"); | ||
List, | ||
GroupNotification, | ||
Contact, | ||
Chat, | ||
Call, | ||
} = require("./jeast-models"); | ||
@@ -106,2 +108,59 @@ const { QR_CANVAS, QR_RETRY_BUTTON, QR_CONTAINER, MAIN_SELECTOR } = selectors; | ||
}, | ||
/** | ||
* Events Emitter | ||
* @param {Function} callback Incoming call event will passed with callbacck events | ||
* @returns {EventEmitter} Incoming call return the events that has been assigned with parameter | ||
*/ | ||
incomingCall: (callback) => { | ||
this.on(Events.INCOMING_CALL, async (call) => { | ||
callback(call); | ||
}); | ||
}, | ||
/** | ||
* Events Emitter | ||
* @param {Function} callback Message Ack message will passed with callbacck events | ||
* @returns {EventEmitter} Message will return the events that has been assigned with parameter | ||
*/ | ||
ackMessage: (callback) => { | ||
this.on(Events.MESSAGE_ACK, async (ack) => { | ||
callback(ack); | ||
}); | ||
}, | ||
group: { | ||
/** | ||
* Events Emitter | ||
* @param {Function} callback Group join action will passed with callbacck events | ||
* @returns {EventEmitter} Group join action return the events that has been assigned with parameter | ||
*/ | ||
join: (callback) => { | ||
this.on(Events.GROUP_JOIN, async (join) => { | ||
callback(join); | ||
}); | ||
}, | ||
/** | ||
* Events Emitter | ||
* @param {Function} callback Group leave action will passed with callbacck events | ||
* @returns {EventEmitter} Group leave action return the events that has been assigned with parameter | ||
*/ | ||
leave: (callback) => { | ||
this.on(Events.GROUP_LEAVE, async (leave) => { | ||
callback(leave); | ||
}); | ||
}, | ||
/** | ||
* Events Emitter | ||
* @param {Function} callback Group update action will passed with callbacck events | ||
* @returns {EventEmitter} Group update action return the events that has been assigned with parameter | ||
*/ | ||
update: (callback) => { | ||
this.on(Events.GROUP_UPDATE, async (update) => { | ||
callback(update); | ||
}); | ||
}, | ||
}, | ||
}; | ||
@@ -314,3 +373,3 @@ } | ||
*/ | ||
this.emit(Events.GROUP_JOIN, notification); | ||
this.emit(Events.GROUP_INVITATION_JOIN, notification); | ||
} else if (msg.subtype === "remove" || msg.subtype === "leave") { | ||
@@ -416,2 +475,20 @@ /** | ||
await page.exposeFunction("onIncomingCall", (call) => { | ||
/** | ||
* Emitted when a call is received | ||
* @event Client#incoming_call | ||
* @param {object} call | ||
* @param {number} call.id - Call id | ||
* @param {string} call.peerJid - Who called | ||
* @param {boolean} call.isVideo - if is video | ||
* @param {boolean} call.isGroup - if is group | ||
* @param {boolean} call.canHandleLocally - if we can handle in waweb | ||
* @param {boolean} call.outgoing - if is outgoing | ||
* @param {boolean} call.webClientShouldHandle - If Waweb should handle | ||
* @param {object} call.participants - Participants | ||
*/ | ||
const callPayload = new Call(this, call); | ||
this.emit(Events.INCOMING_CALL, callPayload); | ||
}); | ||
await page.evaluate(() => { | ||
@@ -435,2 +512,5 @@ window.Store.Msg.on("change", (msg) => { | ||
}); | ||
window.Store.Call.on("add", (call) => { | ||
window.onIncomingCall(call); | ||
}); | ||
window.Store.Msg.on("add", (msg) => { | ||
@@ -782,4 +862,94 @@ if (msg.isNewMsg) { | ||
} | ||
/** | ||
* Returns an object with information about the invite code's group | ||
* @param {string} invitationCode | ||
* @returns {Promise<object>} Invite information | ||
*/ | ||
async invitationInfo(invitationCode) { | ||
return await this.clientPage.evaluate((invitationCode) => { | ||
return window.Store.InviteInfo.sendQueryGroupInvite(invitationCode); | ||
}, invitationCode); | ||
} | ||
/** | ||
* Accepts an invitation to join a group | ||
* @param {string} invitationCode Invitation code | ||
* @returns {Promise<string>} Id of the joined Chat | ||
*/ | ||
async acceptInvite(invitationCode) { | ||
const chatId = await this.clientPage.evaluate(async (invitationCode) => { | ||
return await window.Store.Invite.sendJoinGroupViaInvite(invitationCode); | ||
}, invitationCode); | ||
return chatId._serialized; | ||
} | ||
/** | ||
* Accepts a private invitation to join a group | ||
* @param {object} inviteInfo Invite V4 Info | ||
* @returns {Promise<Object>} | ||
*/ | ||
async acceptGroupInvitationV4(inviteInfo) { | ||
if (!inviteInfo.invitationCode) throw "Invalid invite code!!"; | ||
if (inviteInfo.invitationCodeExp == 0) throw "Invitation code expired!!"; | ||
return this.clientPage.evaluate(async (inviteInfo) => { | ||
let { groupId, fromId, invitationCode, invitationCodeExp } = inviteInfo; | ||
return await window.Store.JoinInviteV4.sendJoinGroupViaInviteV4( | ||
invitationCode, | ||
String(invitationCodeExp), | ||
groupId, | ||
fromId | ||
); | ||
}, inviteInfo); | ||
} | ||
/** | ||
* Sets the current user's status info | ||
* @param {string} status New status info | ||
*/ | ||
async setStatusInfo(status) { | ||
await this.clientPage.evaluate(async (status) => { | ||
return await window.Store.StatusUtils.setMyStatus(status); | ||
}, status); | ||
} | ||
/** | ||
* Marks the client as online | ||
*/ | ||
async sendOnlineStatus() { | ||
return await this.clientPage.evaluate(() => { | ||
return window.Store.PresenceStatus.sendPresenceAvailable(); | ||
}); | ||
} | ||
/** | ||
* Marks the client as unavailable | ||
*/ | ||
async sendOfflineStatus() { | ||
return await this.clientPage.evaluate(() => { | ||
return window.Store.PresenceStatus.sendPresenceUnavailable(); | ||
}); | ||
} | ||
/** | ||
* Returns the contact ID's | ||
* @param {string} contactId user's ID | ||
* @returns {Promise<string>} | ||
*/ | ||
async getPictUrl(contactId) { | ||
const profilePic = await this.clientPage.evaluate(async (contactId) => { | ||
try { | ||
const chatWid = window.Store.WidFactory.createWid(contactId); | ||
return await window.Store.ProfilePic.profilePicFind(chatWid); | ||
} catch (err) { | ||
if (err.name === "ServerStatusCodeError") return undefined; | ||
throw err; | ||
} | ||
}, contactId); | ||
return profilePic ? profilePic.eurl : undefined; | ||
} | ||
} | ||
module.exports = Jeast; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
223255
35
3692
295