Webwhatsapp-wrapper: send mutimedia file example

Created on 18 Aug 2018  路  2Comments  路  Source: mukulhase/WebWhatsapp-Wrapper

is there an example to send multimedia files, images, sound etc?

Most helpful comment

Hey @mikhakhaldea,
There is no example yet but the function send_media is coded as you can see on __init__.py (L:550) or wapi.js.

I've made a very quick and simple example, hope it helps you:

from webwhatsapi import WhatsAPIDriver
from webwhatsapi.objects.message import Message

driver = WhatsAPIDriver(loadstyles=False)
print("Waiting for QR")
driver.wait_for_login()

print("Bot started")

try:
    phone_safe = "1122333333333" # Phone number with country code
    phone_whatsapp = "{}@c.us".format(phone_safe) # WhatsApp Chat ID
    image_path = "image.png" # Local path file
    caption = "Testing a media sender!" # The caption sent under the image, optional
    driver.send_media(image_path, phone_whatsapp, caption) # Expected send_media(self, path, chatid, caption)
    print("Media file was successfully sent to {}".format(phone_safe))
except:
    print("Error while trying to send the midia file.")

This function expects the chat ID, a local media path and _optionally_ a caption.
You can get the media from a URL using some libraries like requests, urllib, etc. but that depends a lot on which Python version you are using.

All 2 comments

Hey @mikhakhaldea,
There is no example yet but the function send_media is coded as you can see on __init__.py (L:550) or wapi.js.

I've made a very quick and simple example, hope it helps you:

from webwhatsapi import WhatsAPIDriver
from webwhatsapi.objects.message import Message

driver = WhatsAPIDriver(loadstyles=False)
print("Waiting for QR")
driver.wait_for_login()

print("Bot started")

try:
    phone_safe = "1122333333333" # Phone number with country code
    phone_whatsapp = "{}@c.us".format(phone_safe) # WhatsApp Chat ID
    image_path = "image.png" # Local path file
    caption = "Testing a media sender!" # The caption sent under the image, optional
    driver.send_media(image_path, phone_whatsapp, caption) # Expected send_media(self, path, chatid, caption)
    print("Media file was successfully sent to {}".format(phone_safe))
except:
    print("Error while trying to send the midia file.")

This function expects the chat ID, a local media path and _optionally_ a caption.
You can get the media from a URL using some libraries like requests, urllib, etc. but that depends a lot on which Python version you are using.

thank you very much @lfdelphino.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

desstannoz picture desstannoz  路  4Comments

d2hf picture d2hf  路  6Comments

kashif-raza picture kashif-raza  路  5Comments

drsoporte picture drsoporte  路  5Comments

dmreinoso picture dmreinoso  路  3Comments