Skip to content

Latest commit

 

History

History
executable file
·
47 lines (44 loc) · 1.25 KB

EVENTS.md

File metadata and controls

executable file
·
47 lines (44 loc) · 1.25 KB

Available events and arguments

See events/WhatsAppEventListener.php.

How to bind a callback to an event

Create a WhatsAppEventListener class and implement the method you

would like to handle:

require 'events/WhatsAppEventListenerBase.php';

class MyEventListener extends WhatsAppEventListenerBase {
    function onGetMessage(
        $phone, // The user phone number including the country code.
        $from, // The sender JID.
        $msgid, // The message id.
        $type, // The message type.
        $time, // The unix time when send message notification.
        $name, // The sender name.
        $message // The message.
    ) {
        print( "onGetMessage(" . $phone . ", " . $from . ", " . $msgid . ", " . $type . ", " . $time . ", " . $name . ", " . $message . ")\n" );
    }
}

Require your new class;

require 'MyEventListener.php';

Create an instance of WhastProt.

$w = new WhatsProt($userPhone, $userIdentity, $userName, $debug);

Add your event listener.

w->eventManager()->addEventListener(new MyEventListener());

Connect to WhatsApp servers.

$w->connect();

Login to WhatsApp

$w->loginWithPassword($password);

[...]