
Once you verify that the code is working, we will proceed to read the last sent message. (If the program does not move, try playing with the confidence parameter and try it with values between 0.6 to 0.9) The way to do that would be to run the python program and quickly switch to the screen where WhatsApp web is running. Run this python code to verify that the code actually works. This code will move the mouse pointer to the smilie icon on WhatsApp. Position = pt.locateOnScreen("whatsapp/smilie.png", confidence=.6) Now that we have a smilie and unread message screenshot, save it in the project directory.Ĭreate a new file main.py in the whatsapp folder and write the following code: import pyautogui as pt To get the green circle, right-click on a contact and click mark as unread. Take a screenshot of the images marked with a red rectangle. Next, we have to take some snapshots to tell the program where it should drag the mouse to and where to click. The program will terminate when the mouse pointer touches the x-axis. The above code will print the coordinates of the mouse pointer and the color it is hovering over. Add the following code : import pyautogui as pt This program will collect information about the color and position of certain elements on the screen. Read the context of WhatsApp GUI Extract Screen InformationĬreate a folder named whatsapp and inside it create a file gui_info.py. If you are using Ubuntu (Linux), you would have to additionally install the following packages : $ sudo apt-get install scrotġ. Open your terminal and type the following commands to install the packages: $ pip install opencv-python Process the message and programmatically reply to itīefore starting, we would need to install open-cv, pyautogui, and pyperclip.



Programatically click on unread messages and extract the message.Remember in Silicon Valley, Gilfoyle created an automated reply bot for chatting with Dinesh! 😂 You can also have an AI (Artificial Intelligence) bot chatting with your friends you don’t want to be bothered by. I will be creating a python bot that will go through unread messages in WhatsApp and respond to them as per the response condition set.
