Webwhatsapp-wrapper: [Discussion] New feature help: validate functions with ChatID, ContactID and GroupID as argument

Created on 31 May 2018  路  11Comments  路  Source: mukulhase/WebWhatsapp-Wrapper

Hi! I'm working on new feature that validates Whatsapp IDs (inpirated from this https://github.com/mukulhase/WebWhatsapp-Wrapper/issues/247#issuecomment-393541798), but i'm not sure if my validation is the best to work fine for everyone that uses this library... I'm from Brazil and in here the ChatId is like: [email protected], my guess is that the 'c.us' at the end is the same for everyone and every place right?

What you guys think about these three functions to validate this IDs?

import re

# validate ContactID: [email protected] (or any end, I'm not sure about 'c.us' is always the end of ContactID)
# or GroupID: [email protected]
def is_valid_chat_id(chat_id):
    return bool(re.match(r'^[0-9\-]+@[a-zA-Z].[a-zA-Z]+?$', chat_id))


# validate ContactID: [email protected]. 
# I guess that the contact id always has '@c.[any string]' at the end, but not sure.
def is_valid_contact_id(contact_id):
    return bool(re.match(r'^[0-9]+@c.[a-zA-Z]+?$', contact_id))

# validate GroupID: [email protected]. 
# I guess that the group id always has '@g.[any string]' at the end, but not sure.
def is_valid_group_id(group_id):
    return bool(re.match(r'^[0-9]+-[0-9]+@g.[a-zA-Z]+?$', group_id))

discussion

All 11 comments

@alan-albuquerque
no no no no :-)
It would be better to question Whatsapp about the number - whether it is registered
I think this is the way to go.

@oltanalkan How do you intend to do that? And what will be the cost of doing this in every request of each function that needs such validation? o.O

I do not think that asking whatsapp if the number is valid will work, since this function won't be provided by the API itself. Furterhmore would this enable spamming or broadcasting to many people, which is not the intention of this project.
Furthermore, will this increase the traffic really hard. I made the mistake of sending to some unregistered number / wrong parameter, what happens is that the contact gets automatically shown in your contact list (on phone) but the whatsapp app crashes directly. This means, that "you will not get banned" but more like Whatsapp itself find that you have done something that they do not want you to do and will throw an exception on their server side - which will lead to the ban.

@alan-albuquerque I can confirm your assomption with "@.g.us" and "@c.us" however I am not quite sure if regular expression are necessary since they may slow don the process. If it is possible we could try to make the contact index into a tulple or work directly on the list, such as that the end always has to be "us" or that an "@" has to be in the string

@kevinkit the function to ask whatsapp if a number is valid or not is Store.Wap.queryExist
and it can be used like this:
xyzh = await Store.Wap.queryExist(fullnumber+"@c.us");

Oh I did not see that function, thank you for your insight.

However, I still think that implementing this functionality directly into the framework would advert the possibilty to spam others which could backfire. Since it is directly available as mentioned by @dubriel one could use it easily and implement the functionality by himself.
Thus, in my opinion it still would be the best if we just make sure that the number is in the given format and not to check wether it is it registered or not.

At the end of the day the owner of the repositry should give its insights, thoughts and decision @mukulhase

we can subscribe presence on whatsapp web by few methods.
Store.Wap.subscribePresence("XXXXXXXX")
if we execute this command websocket sending message to server.
also when we use Store.Presence.find("XXXXXXXXXX") it will automatically subscribe for presence update.
you can confirm it through network tab on chrome developer tools.

But the problem is server no longer responding for subscribing presence via whatsapp web.
subscribe presence will get responce code 200. but no any message from server when presence available/unavailable.

have found one interesting code which can help us for subscribe presence.
clearAllPresence: function() { this.forEach(function(e) { e.reset(), e.set({ stale: !0, isSubscribed: !1 }) }) },
Let me know if we can modify and use it for subscribe presence.
Thanks

@dubriel My goal is to keep this validation in the python layer, because with this approach (JS) we will wait for the promise response/resolve to be able to continue with the script, and doing this in every function that demands this verification would be very costly and I think it would call the whatsapp attention

@kevinkit you're right, giving the client the power to check if there is a real contact ID (and not just validate to prevent things like the whatsapp application crashes when passing an invalid ID) is dangerous and open the door to spammers.

@kevinkit agreed

@alan-albuquerque should only be called before trying to add a new chat just as the original app does

@dubriel
xyzh = await Store.Wap.queryExist(fullnumber+"@c.us");
What can I do to recognize the registered and unregistered ones?

@oltanalkan I have tested this function, if you get an object.status = 200 means that the phone is valid and registered in wp, otherwise the number is invalid or is not registered. Unfortunately, this function is not present anymore in the actual Store.Wap object, you need to get another object from webpack that have this function, I don鈥檛 know now what webpack id is because I鈥檓 not in a computer, but you can find it on app.js or app2.js or you can use an extension of the autodiscovery approach in the #242 to find the object with this function.

Best

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NolanWang picture NolanWang  路  5Comments

rzlnhd picture rzlnhd  路  3Comments

erickythierry picture erickythierry  路  5Comments

d2hf picture d2hf  路  6Comments

dafner picture dafner  路  6Comments