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

Switched To ChromeDriver because of Heroku #981

Open wholesomegarden opened 3 years ago

wholesomegarden commented 3 years ago

Hi there, first of all thank you so much for this repo. Really amazing :)

i've read that it's better to user gecko firefox instead of chrome because of async problems.

Q1: is this a problem with the driver or with this repo? will an update to the driver in the future change this?

Q2: Can someone please make a tutorial on how to run this well on Heroku ?!

I've been running this quite well from docker and also from source Wanna move this to Heroku for 24/7 uptime :D

For the life of me I couldnt get my head around how to do these in heroku (a guide will be great!)

docker network create selenium
docker run -d -p 4444:4444 -p 5900:5900 --name firefox --network selenium -v /dev/shm:/dev/shm selenium/standalone-firefox-debug:3.14.0-curium
docker build -t webwhatsapi .
docker run --network selenium -it -e SELENIUM='http://firefox:4444/wd/hub' -v $(pwd):/app  webwhatsapi /bin/bash -c "pip install ./;pip list;python sample/remote.py"

I've tried adding various buildpacks for firefox and gecko and pushing mirror of source to heroku but couldnt do it either

Finally I've been able to follow... Running ChromeDriver with Python Selenium on Heroku (adding buildpacks and env variables)

Then changed updated my code to include...

from selenium import webdriver
import os
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--no-sandbox")

driver = WhatsAPIDriver(client='chrome', chrome_options=chrome_options,username="wholesomegarden")

And changed '_init.py'

        if chrome_options is not None:
                self._profile = chrome_options
                ## for option in chrome_options:
                ##     self._profile.add_argument(option)
        self.logger.info("Starting webdriver")
        self.driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"),chrome_options=self._profile, **extra_params)

And this works :D

the last thing was to also setup a flask server to display the qr :) and bam! serverless whatsapp api :star: you can check it all out at in app.py WhatsappReminder and please let me know if I can do any of this better :+1: THANK YOU AND HAPPY NEW YEAR 2021 :love_you_gesture:

erm3nda commented 3 years ago

Isn't Heroku a server itself? :-P