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.04k stars 794 forks source link

Whatsapp Changes broke things #733

Open eq0rip opened 5 years ago

eq0rip commented 5 years ago

I always thought WA would change UI components, classes and html, so I researched and tapped into their functions to get the QRcode and studied WA QR structure and needed modules for WAPI and used to extract raw QRCode like below

QR includes 3 parts, 1st is ref, 2nd part is generatedCode and 3rd one is id.

qr = "{},{},{}".format(g.driver.getConn()["ref"],g.driver.getOrGenerateQrMiddle(),g.driver.getQrLastPart())

Needed fuctions were assigned as below

window.WAPI.getConn = function (done) {
    const output = Object.assign({ refExpiry: window.Store.Conn.refExpiry}, window.Store.Conn.attributes);
    if (done !== undefined) {
        done(output);
    }
    return output;
}

window.WAPI.getOrGenerateQrMiddle = function (done) {
    output = window.Store.getOrGenerate();
    if (done !== undefined) {
        done(output);
    }
    return output;
}

window.WAPI.getQrLastPart = function (done) {
    output = window.ExtraUtils.id();
    if (done !== undefined) {
        done(output);
    }
    return output;
}

window.ExtraUtils was assigned like below

if(module.id && module.hardRefresh) {
    window.ExtraUtils  = module;
}

The performance was also good compared to previous methods and I was happy with the result. But... Now since last update we are loading WAPI only after user is logged in, I am scratching my head how can I achieve something like this.

I also customized my code to refresh the QR through WA functions instead of UI through hardRefresh and minimized most of the things relying on UI and button clicks like logout and all. But I think I wasted my time and it would be better if I relied on button clicks and just changed classnames whenever WA brought new updates.

Any suggestion/solution from you guys ?

eq0rip commented 5 years ago

Moreover I am also relying on wapi.js to know the status and details about WA client because I run multiple clients and control them through my dashboard

    if client_id not in drivers:
        return None
    report = {
        # "is_timer": bool(timers[client_id]) and timers[client_id].is_running,
        "conn": drivers[client_id].getConn(),
        "state": drivers[client_id].getState(),
        "streamMode": drivers[client_id].getStreamMode(),
    }

    needed_only = {
            "ref": report["conn"]["ref"],
            "refExpiry": report["conn"]["refExpiry"],
            "refTTL": report["conn"]["refTTL"],
            "state": report["state"]["state"],
            "stream": report["state"]["stream"],
            "canSend": report["state"]["canSend"],
            "mode": report["streamMode"]["mode"],
            "info": report["streamMode"]["info"],
            "phoneAuthed": report["streamMode"]["phoneAuthed"],
        }
    report['needed_only'] = needed_only

    if needed_only['mode'] == 'QR' and needed_only['state'] == 'UNPAIRED':
        needed_only['status'] = 'QR_UNPAIRED'

    elif needed_only['mode'] == 'QR' and needed_only['state'] == 'UNPAIRED_IDLE':
        needed_only['status'] = 'QR_UNPAIRED_IDLE'

    elif needed_only['mode'] == 'SYNCING' or needed_only['mode'] == 'OFFLINE' or needed_only["info"] == "TIMEOUT" or needed_only["info"] == "PAIRING" or needed_only["info"] == "RESUMING":
        needed_only['status'] = 'LOGGED_IN_DISCONNECTED'

    elif needed_only['mode'] == 'CONFLICT':
        needed_only['status'] = 'LOGGED_IN_CONFLICT'

    elif needed_only['mode'] == 'MAIN' and needed_only['state'] == 'CONNECTED':
        needed_only['status'] = 'LOGGED_IN_NORMAL'

    else:
        needed_only['status'] = 'UNKNOWN'

    return report

Loading wapi.js only after logging in breaks everything for me