Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Bug Fixes
- Fixed checkNumberStatus function
- Fixed Perfil not defined in WAPI
- Fixed options in send video-image status
- Fixed get profile pic for groups (close wppconnect-server
Features:
- Added support to send mentionedList in images
  • Loading branch information
3mora2 committed Jun 11, 2024
1 parent 11b9786 commit a0944f1
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 34 deletions.
13 changes: 9 additions & 4 deletions WPP_Whatsapp/api/layers/LabelsLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def addNewLabel_(self, name, options):
WPP.labels.addNewLabel(name, options);
}""", {"name": name, "options": options}, page=self.page)

async def addOrRemoveLabels_(self, chatIds, options):
async def addOrRemoveLabels_(self, chatIds: list, options: list[dict]):
"""
/**
* Add or delete label of chatId
Expand All @@ -58,7 +58,10 @@ async def addOrRemoveLabels_(self, chatIds, options):
* @example
* ```javascript
* client.addOrRemoveLabels(['[number]@c.us','[number]@c.us'],
* [{labelId:'76', type:'add'},{labelId:'75', type:'remove'}]);
* [
* { labelId:'76', type:'add' },
* { labelId:'75', type:'remove' }
* ]);
* //or
* ```
* @param chatIds ChatIds
Expand All @@ -73,10 +76,12 @@ async def getAllLabels_(self):
return await self.ThreadsafeBrowser.page_evaluate("() => WPP.labels.getAllLabels()", page=self.page)

async def getLabelById_(self, Id):
return await self.ThreadsafeBrowser.page_evaluate("""({ id }) => {WPP.labels.getLabelById(id); }""", {"id": Id}, page=self.page)
return await self.ThreadsafeBrowser.page_evaluate("""({ id }) => {WPP.labels.getLabelById(id); }""", {"id": Id},
page=self.page)

async def deleteAllLabels_(self):
return await self.ThreadsafeBrowser.page_evaluate("""() => {WPP.labels.deleteAllLabels();}""", page=self.page)

async def deleteLabel_(self, Id):
return await self.ThreadsafeBrowser.page_evaluate("""({ id }) => {WPP.labels.deleteLabel(id); }""", {"id": Id}, page=self.page)
return await self.ThreadsafeBrowser.page_evaluate("""({ id }) => {WPP.labels.deleteLabel(id); }""", {"id": Id},
page=self.page)
56 changes: 44 additions & 12 deletions WPP_Whatsapp/api/layers/RetrieverLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,28 @@ async def getAllChats_(self, withNewMessageOnly=False):
async def checkNumberStatus_(self, contactId):
# @returns contact detial as promise
contactId = self.valid_chatId(contactId)
return await self.ThreadsafeBrowser.page_evaluate("(contactId) => WAPI.checkNumberStatus(contactId)", contactId, page=self.page)
# return await self.ThreadsafeBrowser.page_evaluate("(contactId) => WAPI.checkNumberStatus(contactId)", contactId, page=self.page)
result = await self.ThreadsafeBrowser.page_evaluate(
"(contactId) => WPP.contact.queryExists(contactId)",
contactId, page=self.page)
if not result:
return {
"id": contactId,
"isBusiness": False,
"canReceiveMessage": False,
"numberExists": False,
"status": 404,
"result": result
}
else:
return {
"id": result.get("wid"),
"isBusiness": result.get("biz"),
"canReceiveMessage": True,
"numberExists": True,
"status": 200,
"result": result
}

async def getAllChatsWithMessages_(self, withNewMessageOnly=False):
# @returns array of [Chat]
Expand Down Expand Up @@ -179,15 +200,17 @@ async def getAllBroadcastList_(self):
async def getContact_(self, contactId):
# @returns contact detial as promise
contactId = self.valid_chatId(contactId)
return await self.ThreadsafeBrowser.page_evaluate("(contactId) => WAPI.getContact(contactId)", contactId, page=self.page)
return await self.ThreadsafeBrowser.page_evaluate("(contactId) => WAPI.getContact(contactId)", contactId,
page=self.page)

async def getAllContacts_(self):
# @returns array of [Contact]
return await self.ThreadsafeBrowser.page_evaluate("() => WAPI.getAllContacts()", page=self.page)

async def getChatById_(self, contactId):
contactId = self.valid_chatId(contactId)
return await self.ThreadsafeBrowser.page_evaluate("(contactId) => WAPI.getChatById(contactId)", contactId, page=self.page)
return await self.ThreadsafeBrowser.page_evaluate("(contactId) => WAPI.getChatById(contactId)", contactId,
page=self.page)

async def getChat_(self, contactId):
contactId = self.valid_chatId(contactId)
Expand All @@ -196,7 +219,8 @@ async def getChat_(self, contactId):
async def getProfilePicFromServer_(self, chatId):
# @returns url of the chat picture or unasync defined if there is no picture for the chat.
chatId = self.valid_chatId(chatId)
return await self.ThreadsafeBrowser.page_evaluate("(chatId) => WAPI._profilePicfunc(chatId)", chatId, page=self.page)
return await self.ThreadsafeBrowser.page_evaluate("(chatId) => WAPI._profilePicfunc(chatId)", chatId,
page=self.page)

async def loadEarlierMessages_(self, contactId):
contactId = self.valid_chatId(contactId)
Expand All @@ -216,13 +240,15 @@ async def getStatus_(self, contactId):

async def getNumberProfile_(self, contactId):
contactId = self.valid_chatId(contactId)
return await self.ThreadsafeBrowser.page_evaluate("(contactId) => WAPI.getNumberProfile(contactId)", contactId, page=self.page)
return await self.ThreadsafeBrowser.page_evaluate("(contactId) => WAPI.getNumberProfile(contactId)", contactId,
page=self.page)

async def getUnreadMessages_(self, includeMe, includeNotifications, useUnreadCount):
return await self.ThreadsafeBrowser.page_evaluate(
"""({ includeMe, includeNotifications, useUnreadCount }) =>
WAPI.getUnreadMessages(includeMe, includeNotifications, useUnreadCount)""",
{"includeMe": includeMe, "includeNotifications": includeNotifications, "useUnreadCount": useUnreadCount}, page=self.page)
{"includeMe": includeMe, "includeNotifications": includeNotifications, "useUnreadCount": useUnreadCount},
page=self.page)

async def getAllUnreadMessages_(self):
return await self.ThreadsafeBrowser.page_evaluate("() => WAPI.getAllUnreadMessages()", page=self.page)
Expand All @@ -240,7 +266,8 @@ async def getAllMessagesInChat_(self, chatId, includeMe=False, includeNotificati
return await self.ThreadsafeBrowser.page_evaluate("""({ chatId, includeMe, includeNotifications }) =>
WAPI.getAllMessagesInChat(chatId, includeMe, includeNotifications)""",
{"chatId": chatId, "includeMe": includeMe,
"includeNotifications": includeNotifications}, page=self.page)
"includeNotifications": includeNotifications},
page=self.page)

async def loadAndGetAllMessagesInChat_(self, chatId, includeMe=False, includeNotifications=False):
chatId = self.valid_chatId(chatId)
Expand All @@ -250,15 +277,18 @@ async def loadAndGetAllMessagesInChat_(self, chatId, includeMe=False, includeNot
return await self.ThreadsafeBrowser.page_evaluate("""({ chatId, includeMe, includeNotifications }) =>
WAPI.loadAndGetAllMessagesInChat(chatId, includeMe, includeNotifications)""",
{"chatId": chatId, "includeMe": includeMe,
"includeNotifications": includeNotifications}, page=self.page)
"includeNotifications": includeNotifications},
page=self.page)

async def getChatIsOnline_(self, chatId):
chatId = self.valid_chatId(chatId)
return await self.ThreadsafeBrowser.page_evaluate("(chatId) => WAPI.getChatIsOnline(chatId)", chatId, page=self.page)
return await self.ThreadsafeBrowser.page_evaluate("(chatId) => WAPI.getChatIsOnline(chatId)", chatId,
page=self.page)

async def getLastSeen_(self, chatId):
chatId = self.valid_chatId(chatId)
return await self.ThreadsafeBrowser.page_evaluate("(chatId) => WAPI.getLastSeen(chatId)", chatId, page=self.page)
return await self.ThreadsafeBrowser.page_evaluate("(chatId) => WAPI.getLastSeen(chatId)", chatId,
page=self.page)

async def getPlatformFromMessage_(self, msgId):
"""
Expand All @@ -269,10 +299,12 @@ async def getPlatformFromMessage_(self, msgId):
* web
* unknown
"""
return await self.ThreadsafeBrowser.page_evaluate("(msgId) => WPP.chat.getPlatformFromMessage(msgId)", msgId, page=self.page)
return await self.ThreadsafeBrowser.page_evaluate("(msgId) => WPP.chat.getPlatformFromMessage(msgId)", msgId,
page=self.page)

async def getReactions_(self, msgId):
return await self.ThreadsafeBrowser.page_evaluate("(msgId) => WPP.chat.getReactions(msgId)", msgId, page=self.page)
return await self.ThreadsafeBrowser.page_evaluate("(msgId) => WPP.chat.getReactions(msgId)", msgId,
page=self.page)

async def getVotes_(self, msgId):
return await self.ThreadsafeBrowser.page_evaluate("(msgId) => WPP.chat.getVotes(msgId)", msgId, page=self.page)
22 changes: 17 additions & 5 deletions WPP_Whatsapp/api/layers/SenderLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ async def sendImage_(self, to, filePath, filename="", caption="", quotedMessageI
else:
raise Exception("Path Not Found")

async def sendImageFromBase64_(self, to, _base64, filename, caption, quotedMessageId, isViewOnce):
async def sendImageFromBase64_(self, to, _base64, filename, caption, quotedMessageId, isViewOnce,
mentionedList=None):
mime_type = self.base64MimeType(_base64)
if not mime_type:
raise Exception("Not valid mimeType")
Expand All @@ -211,6 +212,8 @@ async def sendImageFromBase64_(self, to, _base64, filename, caption, quotedMessa
caption,
quotedMsg: quotedMessageId,
waitForAck: true,
detectMentioned: true,
mentionedList: mentionedList,
}).catch((e) => {return e});
return {
Expand All @@ -219,8 +222,15 @@ async def sendImageFromBase64_(self, to, _base64, filename, caption, quotedMessa
sendMsgResult: await result.sendMsgResult,
error: result.message,
};
}""", {"to": to, "base64": _base64, "filename": filename, "caption": caption, "quotedMessageId": quotedMessageId,
"isViewOnce": isViewOnce}, page=self.page)
}""", {
"to": to,
"base64": _base64,
"filename": filename,
"caption": caption,
"quotedMessageId": quotedMessageId,
"isViewOnce": isViewOnce,
"mentionedList": mentionedList
}, page=self.page)
return result

async def reply_(self, to, content, quotedMsg):
Expand Down Expand Up @@ -412,7 +422,8 @@ async def sendLocation_(self, to, options):

async def sendSeen_(self, chatId):
chatId = self.valid_chatId(chatId)
return await self.ThreadsafeBrowser.page_evaluate("(chatId) => WPP.chat.markIsRead(chatId)", chatId, page=self.page)
return await self.ThreadsafeBrowser.page_evaluate("(chatId) => WPP.chat.markIsRead(chatId)", chatId,
page=self.page)

async def startTyping_(self, to, duration=None):
to = self.valid_chatId(to)
Expand All @@ -425,7 +436,8 @@ async def stopTyping_(self, to):
return await self.ThreadsafeBrowser.page_evaluate("(to) => WPP.chat.markIsPaused(to)", to, page=self.page)

async def setOnlinePresence_(self, online=True):
return await self.ThreadsafeBrowser.page_evaluate("(online) => WPP.conn.markAvailable(online)", online, page=self.page)
return await self.ThreadsafeBrowser.page_evaluate("(online) => WPP.conn.markAvailable(online)", online,
page=self.page)

async def sendListMessage_(self, to, options):
to = self.valid_chatId(to)
Expand Down
31 changes: 21 additions & 10 deletions WPP_Whatsapp/api/layers/StatusLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class StatusLayer(LabelsLayer):
def sendImageStatus(self, pathOrBase64: str, timeout=60):
def sendImageStatus(self, pathOrBase64: str, options: dict = {}, timeout=60):
"""
/**
* Send a image message to status stories
Expand All @@ -17,9 +17,9 @@ def sendImageStatus(self, pathOrBase64: str, timeout=60):
*/
"""
return self.ThreadsafeBrowser.run_threadsafe(
self.sendImageStatus_, pathOrBase64, timeout_=timeout)
self.sendImageStatus_, pathOrBase64, options, timeout_=timeout)

def sendVideoStatus(self, pathOrBase64: str, timeout=60):
def sendVideoStatus(self, pathOrBase64: str, options: dict = {}, timeout=60):
"""
/**
* Send a video message to status stories
Expand All @@ -33,7 +33,7 @@ def sendVideoStatus(self, pathOrBase64: str, timeout=60):
*/
"""
return self.ThreadsafeBrowser.run_threadsafe(
self.sendVideoStatus_, pathOrBase64, timeout_=timeout)
self.sendVideoStatus_, pathOrBase64, options, timeout_=timeout)

def sendTextStatus(self, text: str, options: dict = {}, timeout=60):
"""
Expand Down Expand Up @@ -67,7 +67,7 @@ def sendReadStatus(self, chatId: str, statusId: str, timeout=60):
self.sendReadStatus_, chatId, statusId, timeout_=timeout)

##########################################################################
async def sendImageStatus_(self, pathOrBase64: str):
async def sendImageStatus_(self, pathOrBase64: str, options={}):
"""
/**
* Send a image message to status stories
Expand All @@ -77,6 +77,12 @@ async def sendImageStatus_(self, pathOrBase64: str):
* ```javascript
* client.sendImageStatus('data:image/jpeg;base64,<a long base64 file...>');
* ```
*
* @example
* ```javascript
* // Send with caption
* client.sendImageStatus('data:image/jpeg;base64,<a long base64 file...>', { caption: 'example test' } );
* ```
* @param pathOrBase64 Path or base 64 image
*/
"""
Expand Down Expand Up @@ -108,11 +114,11 @@ async def sendImageStatus_(self, pathOrBase64: str):
raise error

return await self.ThreadsafeBrowser.page_evaluate(
"""({base64}) => WPP.status.sendImageStatus(base64);""",
{"base64": base64}, page=self.page
"""({base64, options}) => WPP.status.sendImageStatus(base64, options);""",
{"base64": base64, "options": options}, page=self.page
)

async def sendVideoStatus_(self, pathOrBase64: str):
async def sendVideoStatus_(self, pathOrBase64: str, options={}):
"""
/**
* Send a video message to status stories
Expand All @@ -122,6 +128,11 @@ async def sendVideoStatus_(self, pathOrBase64: str):
* ```javascript
* client.sendVideoStatus('data:video/mp4;base64,<a long base64 file...>');
* ```
* @example
* ```javascript
* // Send with caption
* client.sendVideoStatus('data:video/mp4;base64,<a long base64 file...>', { caption: 'example test' } );
* ```
* @param pathOrBase64 Path or base 64 image
*/
"""
Expand All @@ -141,8 +152,8 @@ async def sendVideoStatus_(self, pathOrBase64: str):
raise error

return await self.ThreadsafeBrowser.page_evaluate(
"""({base64}) => WPP.status.sendVideoStatus(base64);""",
{"base64": base64}, page=self.page
"""({base64, options}) => WPP.status.sendVideoStatus(base64, options);""",
{"base64": base64, "options": options}, page=self.page
)

async def sendTextStatus_(self, text: str, options: str):
Expand Down
2 changes: 1 addition & 1 deletion WPP_Whatsapp/js_lib/wapi.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/send_text_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# example
# Simple message
result = client.sendText(phone_number, message)
# result = client.sendText(phone_number, message)
# print(result)

"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"the creation of any interaction, such as customer service, media sending, intelligence recognition "
"based on phrases artificial and many other things, use your imagination")

version = "0.2.5"
version = "0.2.8"

setup(
name="WPP_Whatsapp",
Expand Down

0 comments on commit a0944f1

Please sign in to comment.