xaamin/whatsapi

Workflow

Closed this issue · 4 comments

Hey,

It's just a question, because I get blocked many chips. I seeing the worflow in API
https://github.com/mgp25/Chat-API/wiki/WhatsAPI-Documentation#whatsapp-workflow
and not find the difference in first and others logins in your code. Other point is the [Done automatically by the API] comment in this link.

I'm doing a new script that does me online/offline and after online create a cron to getAllMessages and pollMessage or not, depends, and on offline stop that cron.
Using this client MGP (with old script) every time I doing login after minimun 10sec (sleeping the cron) and call offline on destruct. My old script run in 1:30 hour before blocking, 30min with no messages to receive/send. The log not working, the folder is empty. So, I wont see what happens. In this old script I do a sync proccess: getNewMessages(),pollMessages()[depending], sleep(min 10 sec.), do again.

You're right. This wrapper needs some mechanism to detect first and other logins. Let me get another SIMs to test. Any suggestions?

No one valid. You can done in registration after registerCode, but my code (for example) can create a number with the register process or put password manually (before registered with other application). In this case, you never known if is the first login or not, but if the number pass to your register process you known that is the first and can simulate a first login inside that process! others situation,

In others situation, user may use the gateway to make custom logics.

You can provide this methods in MGP, for personal and almost usages:

     /**
     * Never let logoff happens
     *
     * @var boolean
     */
    protected $canLogout = true;
[...]
     /**
     * Set connected property
     *
     * @param boolean $b
     * @return void
     */
    public function setConnected($b){
        $this->connected = $b;
    }

    /**
     * Set if instance can send logoutDisconnect
     *
     * @param boolean $b
     * @return void
     */
    public function setCanLogout($b){
        $this->canLogout = $b;
    }
[...]
    // change this
    public function logoutAndDisconnect()
    {
        if($this->connected && $this->canLogout)
    [...]

and In Interface:

public function setConnected($b);
public function setCanLogout($b);

With this, we can use gateway() without send connectAndLogin again. I'm triggering the login/logout in a button manually. The getNewMessages are separate, so i can end the script without send logout and just get messages in other script.

Maybe what you need is a Queue Handler to work with only one instance of whatsapi without request multiple login and logout in the process.
The __destruct method is called when the whole script ends. If the whole script ends and you start another script you'll call the connectAndLogin method again without logout from whatsapp server in the previous script.