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

Error in download document #984

Closed g4w4 closed 3 years ago

g4w4 commented 3 years ago

When a file arrived either txt or pdf I would get the error of:

AttributeError: 'Message' object has no attribute 'save_media

I noticed that when the "type" of the message comes as "document" the "isMedia" field comes as false so in the "factory_message" function I changed it to include the document as media.


    """Factory function for creating appropriate object given selenium JS object"""
    #print("ok",js_obj)
    #print("dir",dir(js_obj))
    if js_obj is None:
        return

    if "lat" in js_obj and "lng" in js_obj and js_obj["lat"] and js_obj["lng"]:
        return GeoMessage(js_obj, driver)

    if js_obj["isMedia"] or js_obj["type"] == 'document':
        return MediaMessage(js_obj, driver)

    if js_obj["isNotification"]:
        return NotificationMessage(js_obj, driver)

    if 'isMMS' in js_obj and js_obj["isMMS"]:
        return MMSMessage(js_obj, driver)

    if js_obj["type"] in ["vcard", "multi_vcard"]:
        return VCardMessage(js_obj, driver)

    return Message(js_obj, driver)```
erm3nda commented 3 years ago

This is already in another issue, don't forget to include type ptt.

if js_obj["isMedia"] or js_obj["type"] == 'document' or js_ob["type"] == 'ptt': return MediaMessage(js_obj, driver)