1

According to this FAQ page of Whatsapp on How to link to WhatsApp from a different app

Using the URL

whatsapp://send?phone=XXXXXXXXXXXXX&text=Hello

can be used to open the Whatsapp app on a Windows PC and perform a custom action.

It does work when it is opened in a browser. The URL opens Whatsapp installed and composes the message(parameter:text) for the given contact(parameter:phone)

I want to open the Whatsapp application directly using python script without the intervention of browser in between

I have tried using request and urlib, but they don't consider it as a valid schema for URL as it does not have a http:// or https:// instead it has whatsapp://.

requests.exceptions.InvalidSchema: No connection adapters were found for 'whatsapp://send'

Is there a library in python that would open the associated applications directly based on the URL.

P.S. I know the page is for Iphone but the link works perfectly on windows browser. Just need to know if that can be used.

Working with Python 3.7.9 on Windows 10

Sangeet Menon
  • 9,555
  • 8
  • 40
  • 58

2 Answers2

3

You can use cmd exe to do such a job. Just try

import subprocess

subprocess.Popen(["cmd", "/C", "start whatsapp://send?phone=XXXXXXXXXXXXX&text=Hello"], shell=True)

edit: if you want to pass '&'(ampersand) in cmd shell you need to use escape char '^' for it.

please try that one

subprocess.Popen(["cmd", "/C", "start whatsapp://send?phone=XXXXXXXXXXXXX^&text=Hello"], shell=True)
Gurhan Polat
  • 696
  • 5
  • 12
  • This does open the Whatsapp PC application. But the command seems to discard the `&text` part as the chat window opened does not have the text pre-filled. While I could do that explicitly after the application window opens but would like to know if it can be done directly – Sangeet Menon Aug 28 '20 at 15:36
  • You may try https://stackoverflow.com/a/49754020/2016727 . But it’s out of the scope of this question. You may accept that one as answered and create a new question about whatsapp application parameters. – Gurhan Polat Aug 28 '20 at 21:35
  • That answer, as you said, does not fit in the scope of the question. But this solution also only solves half the purpose of the question. – Sangeet Menon Aug 29 '20 at 16:57
  • I have edited my answer to solve the remaining half of your problem. I have also tested and it should be working as expected now. – Gurhan Polat Aug 31 '20 at 13:16
-2

Using this command

start whatsapp://send?phone=XXXXXXXXXXXXX^&text=Hello

not working after updated to new WhatsApp Desktop App (UWP) for windows.

you have other idea for send text message to destination user.

Luca
  • 11
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 16 '22 at 13:54
  • this document https://faq.whatsapp.com/563219570998715/?cms_platform=iphone&locale=us_us no work with last versione of WhatsApp Desktop – Luca Nov 17 '22 at 14:08