mukulhase / WebWhatsapp-Wrapper

An API for sending and receiving messages over web.whatsapp [Working as of 18th May 2018]
https://webwhatsapi.readthedocs.io/en/latest/
MIT License
2.03k stars 795 forks source link

Create New Group with contact with emojis in group name #983

Open wholesomegarden opened 3 years ago

wholesomegarden commented 3 years ago

Hi There for the past few hours I've been trying to add a new group with a user AND HAVING EMOJI IN THE GROUP NAME

I've finally found a working workaround :smiley:

I'm posting the entire function so maybe you could add a proper new_group(number,groupName) and may incorperate the emoji workaround somehow check the @@@@@ just for the emoji workaround :)

### in __init__.py

def tryOut(self, target, args, timeout = 3, click = False):
    res = None
    t = time.time()
    while(res is None and time.time() - t < timeout):
        try:
            res = target(args)
        except Exception as e:
            print("EEEEEEEEEEEEE",args,"---",e)
            # print(e)
            # print()
            time.sleep(1)
    if click and res is not None:
        again = True
        t2 = time.time()
        while(again and time.time() - t2 < timeout):
            try:
                res.click()
                again = False
            except Exception as e:
                again = True
                print("EEEEEEEEEEEEE","click","---",e)
            # print()
    return res

def dictDiff(self,newDict,oldDict):
    newList = list(newDict.keys())
    oldList = list(oldDict.keys())
    if len(newList) == len(oldList):
        return None

    diffList = list(set(x) - set(y))
    diff = {}
    for k in diffList:
        diff[k] = newList[k]
    return diff

def listDiff(self,newList,oldList):
    if len(newList) == len(oldList):
        return None

    diffList = list(set(newList) - set(oldList))
    print(len(diffList),"--------------",diffList)
    return diffList

def newGroup(self,
newGroupName = 'New Group Name',
number = "+972XXXXXXXXX",
):
    oldChats = self.get_all_chats()

    dots = self.tryOut(self.driver.find_element_by_xpath,"//span[@data-testid='menu']",click=True)
    newgroup = self.tryOut(self.driver.find_element_by_tag_name,'li', click=True)
    input = self.tryOut(self.driver.find_element_by_tag_name,'input',click=True)
    input.send_keys(number+Keys.ENTER+Keys.ENTER)
    # txt = self.tryOut(input.send_keys,"+972512170493")
    # txt = self.tryOut(input.send_keys,Keys.ENTER)
    # contact = self.tryOut(driver1.find_element_by_class_name,'q2PP6',click=True)
    # next = self.tryOut(driver1.find_element_by_class_name,'_2_g1_',click=True)
    nameInput = self.tryOut(self.driver.find_element_by_class_name,'_1awRl',click=True)
    # self.driver.execute_script(JS_ADD_TEXT_TO_INPUT,nameInput,newGroupName)

    print("WORKING EMOJI WORKAROUND! ",newGroupName)
    print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
    print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
    print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
    self.driver.execute_script("arguments[0].innerHTML = '{}'".format(newGroupName),nameInput)
    nameInput.send_keys('.')
    nameInput.send_keys(Keys.BACKSPACE)
    nameInput.send_keys(Keys.ENTER)
    print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
    print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
    print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")

    newChats = self.get_all_chats()
    res = None
    t = time.time()
    timeout = 10
    while(len(newChats) == len(oldChats) and time.time() - t < timeout):
        try:
            newChats = self.get_all_chats()
            print(len(newChats),len(oldChats))

        except Exception as e:
            print("EEEEEEEEEEEEE: ",e)
            time.sleep(.5)

    diff =  self.listDiff(newChats,oldChats)
    # print("DIFF",diff)
    if len(diff) == 1:
        return diff[0]
    return diff

HOPE THIS HELPS 💚 would love to see more group functions such as: newGroup, ExitAndDeleteGroup, removeUserFromGroup, changeGroupName, changeGroupImage(from file or url), changeGroupDescription Thank You