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.02k stars 797 forks source link

How can I send an image? #23

Closed gwilches closed 6 years ago

gwilches commented 6 years ago

Hey , How can I send an Image, I was trying to found the correct function but it is really hard to find.

mhndm commented 6 years ago

Is there any update on this case?

vikaspwr commented 6 years ago

any update on sending images or video?

iciani commented 6 years ago

I need to send an image too. Did anyone discover how to do it?

mhndm commented 6 years ago

is this hard or impossible ?

kevinkit commented 6 years ago

Hello,

I have made an attempt to send images. Basically what one has to do is enable the clicking by css element.

Which should break down to something like this:

# Click on the append button driver.driver.find_element_by_css_selector('span[data-icon="clip"]').click()

Then one has to append open the "append" button, which should work like this:

driver.driver.find_element_by_css_selector('span[data-icon="image"]').click()

However this results in an exception. Basically what it does is to mimic a mouse click by searching for css elements. Maybe someone can work from here to imrpove this feauture?

Another option would be to mimic a draggable element

alpires commented 6 years ago

This software send images and videos: https://www.youtube.com/watch?v=x014GN_9k_0&t=6s Please guys, take a look on this software to develope some solution to send image.

malufett commented 6 years ago

any news?

Ch-Sh commented 6 years ago

Only found chat.send_message command for sending. have tried to echo MediaMessage back. With .mime, .content, .repr only can send back type, binary data, sender information. badly need help for sending image and some other media file.

bansal95 commented 6 years ago

Hi guys, I found a solution but may be it not a good solution. You can automate the whole. For this you can do like... 1) Go to the screen of whom you want to send images: (Note : I'm using this according my req. you can use another approach to go there.
ph = '919874563210' strs = 'https://api.whatsapp.com/send?phone=' + ph search_xpath = '//*[@id="input-chatlist-search"]' driver.driver.find_element_by_xpath(search_xpath).send_keys(phone + Keys.ENTER)

2) Click on attachment on whatsapp using : driver.driver.find_element_by_xpath('//*[@id="main"]/header/div[3]/div/div[2]/div/span').click()

3) Search the upload button like..(Note: Please change XPATH accordingly) element = driver.driver.find_element_by_xpath('//*[@id="main"]/header/div[3]/div/div[2]/span/div/div/ul/li[1]/input')

4) Use the function to send images (Note : file_path -> '/home/Desktop/image.jpg') element.send_keys(file_path) time.sleep(1)

If you have image URL in that case you can download image first using and then use above help.

folder_path = '/home/Desktop/' URL = ['image1_url', 'image2_url'] (Please put your URL here) def download_images_with_url(URL): for index, url in enumerate(URL): file_object = str(index) + '.jpg' file_path = os.path.join(folder_path, file_object) try: urllib.urlretrieve(url, file_path) except Exception as e: print(e)

Surely it will help to send an image.

mmoreirasouza commented 6 years ago

any news about this?

gwilches commented 6 years ago

Hey guys, I am sendind images now.

There are too many things to do to send images using JS:

  1. Upload the file to Whatsapp Server
  2. Receive the URL with whatsapp Server Validation
  3. Send the image to the group using the validation URL plus other params.

So I Gave up.

And I decided to take a different route, actually it is the same @bansal95 was explaining. I create a full script to send the images in selenium.

  1. Fill the search text with the group or contact I want to send the image
  2. Click on the Clip icon.
  3. Fill the File Input with the location of the image
  4. Click on the send button.

I hope it helps,

kevinkit commented 6 years ago

Would you kindly share or implement the Implementation? It would be a great Feature for this API

Btw, in this way it would also be possible to Senf any Kind of different Attachment (just Change the click on attach file). That'd be nice to have, maybe we can Work Something Out

Greetings

Am 21.02.2018 12:44 vorm. schrieb "gwilches" notifications@github.com:

Hey guys, I am sendind images now.

There are too many things to do to send images using JS:

  1. Upload the file to Whatsapp Server
  2. Receive the URL with whatsapp Server Validation
  3. Send the image to the group using the validation URL plus other params.

So I Gave up.

And I decided to take a different route, actually it is the same @bansal95 https://github.com/bansal95 was explaining. I create a full script to send the images in selenium.

  1. Fill the search text with the group or contact I want to send the image
  2. Click on the Clip icon.
  3. Fill the File Input with the location of the image
  4. Click on the send button.

I hope it helps,

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mukulhase/WebWhatsAPI/issues/23#issuecomment-367161443, or mute the thread https://github.com/notifications/unsubscribe-auth/AGhecaYIdfW1gF_GU0eoi53_2Xk0VJKmks5tW1jngaJpZM4P_sKr .

m2datacenter commented 6 years ago

@gwilches Thanks for feedback! I'm sending image too like you. The problem is sometimes Whatsapp change some properties on html like class names or path. so it's hard to keep de code up to date. Can you describe how do you send file to whatsapp server? You did this?

olofmeister442 commented 6 years ago

@m2datacenter @gwilches If you can send the script that'd be awesome.

victorriba commented 6 years ago

@gwilches can get a email to contact please? @gwilches

dmreinoso commented 6 years ago

@gwilches could you please share your solution?

wallysonn commented 6 years ago

I can send image in a simple way. Just send the image to the clipboard and with the chat open, paste. Then click on the submit button

victorriba commented 6 years ago

@wallysonn can explain more this solution?

dmreinoso commented 6 years ago

@wallysonn could you please explain your solution?

parthibd commented 6 years ago

@gwilches : Can you please share the code ?

parthibd commented 6 years ago

Here is the code in puppeteer

Link to code

parthibd commented 6 years ago

Someone please port it to selenium.

parthibd commented 6 years ago

@kevinkit @mukulhase Please look at the code

kevinkit commented 6 years ago

Actually, I just looked a little bit at the WAP given from Whatsapp and found that there is a"sendMedia" function in Javascript implemented.

It can be found with:

window.Store.Wap.sendMedia

I think this is they way to go, since it will automatically be updated and not depend on css or html paths and names.

However, I was not able to reverse engineer this function or its parameters, since I am far far away from the javascript world.

UmairAnjum commented 6 years ago

Hello, Is there any built in functionality for sending any image or file to any contact, I have tried above methods but it throws an exception "Element could not be scrolled into view" Thanks in advance

BrendoBomfim commented 6 years ago

Hi guys, I did like @bansal95 suggested, I know this isn't the best way to do it but at least it works just fine although, I'm having a little problem with large files (+20 megas), getting the error of maximum Heap size of Java. Here is how I did it:

phone = 'XXXXXXXXX'
#This is the Header of the input where you look for the contact, its in portuguese
search_xpath = '//*[@title="Procurar ou começar uma nova conversa"]'

driver.driver.find_element_by_xpath(search_xpath).send_keys(phone + Keyss.ENTER)
#This part clicks on the attachment button
driver.driver.find_element_by_xpath('//*[@title="Anexar"]').click()
time.sleep(1)

#Gets the photo/video input, you can alter the last li[1] for other type of input
element = driver.driver.find_element_by_xpath('//*[@id="main"]/header/div[3]/div/div[2]/span/div/div/ul/li[1]/input')

#Make the input visible
driver.driver.execute_script("arguments[0].setAttribute('style', 'block')",element)

url = "http://pm1.narvii.com/6448/92e4dd26d8b6bf69e23c4eb9b417b9ea53bc25a1_00.jpg"
file_path = "/app"
filename = "galocego.jpg"
fullfilename = os.path.join(file_path, filename)
urllib.urlretrieve(url, fullfilename)
element. send_keys("/app/galocego.jpg")
time.sleep(2)

#Clicks on the send button
driver.driver.find_element_by_xpath('//*[@id="app"]/div/div/div[1]/div[2]/span/div/span/div/div/div[2]/span[2]/div/div').click()
WilliamCampolina commented 6 years ago

I placed a text next to the image, but I'm not able to break the line, the \ n 'does not work, could someone help me?

kevinkit commented 6 years ago

Removed comments due to language violation.

Also see #279 for further insturctions on how to send media

WilliamCampolina commented 6 years ago

@wallysonn

elem = driver.driver.find_element_by_class_name ('_ 2S1VP')
time.sleep (2)
elem.send_keys (caption)

I am sending this way, if I put the <br> it interprets as "hello '< br >' world"

kevinkit commented 6 years ago

@WilliamCampolina please format your code in the future

wallysonn commented 6 years ago

@kevinkit stop fresh

kevinkit commented 6 years ago

@wallysonn Excuse me, I do not know what that statement is supposed to mean. Please elaborate

WilliamCampolina commented 6 years ago

@wallysonn Do you send images?

wallysonn commented 6 years ago

@WilliamCampolina yes.

WilliamCampolina commented 6 years ago

Do you send caption with image?

wallysonn commented 6 years ago

@WilliamCampolina yes. Submission with the function available right here in the API. I just made some adjustments.

wallysonn commented 6 years ago

@WilliamCampolina use this function: window.WAPI.sendImageFromDatabasePicBot

WilliamCampolina commented 6 years ago

@wallysonn I'll take a look and try to use ... do you have a telegram?

wallysonn commented 6 years ago

A brief explanation to use this function window.WAPI.sendImageFromDatabasePicBot

wallysonn commented 6 years ago

There is a server in Discord where we talk about WhatsApp WEB API.

wallysonn commented 6 years ago

https://discord.gg/vwrKec6

bobaoapae commented 6 years ago

@wallysonn new function -> https://github.com/mukulhase/WebWhatsapp-Wrapper/pull/300

phpRajat commented 5 years ago

Hey, Here is the code for send media file(like image) just by convert file to base64 ( here is url for convert image to base64 https://www.base64-image.de/ ) and use this function

window.send_media("919999999999@c.us", "file base64 string", "test messsage", null, null);

And here is full code https://gist.github.com/phpRajat/a6422922efae32914f4dbd1082f3f412

ShyHeidy commented 1 year ago

https://github.com/mukulhase/WebWhatsapp-Wrapper/issues/23#issuecomment-355776501