Ejemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $username = getenv('USERNAME');
     $nickname = getenv('NICKNAME');
     $password = getenv('PASSWORD');
     $debug = false;
     // Create a instance of WhastPort.
     $w = new \WhatsProt($username, $nickname, $debug);
     $w->connect();
     // Connect to WhatsApp network
     $w->loginWithPassword($password);
     $events = new CustomEvent($w, $output);
     $events->setEventsToListenFor(['onGetMessage']);
     $w->pollMessage();
     $helper = $this->getHelper('question');
     $question = new Question('..', false);
     $destination = $helper->ask($input, $output, $question);
 }
Ejemplo n.º 2
0
 /** IMPLEMENTS SEND MESSAGES **/
 protected function sendFiles($to, $files)
 {
     set_time_limit(600);
     $explode = explode('.', $files['image']['name']);
     $extensao = end($explode);
     $extensao = strtolower($extensao);
     define('CAMINHO_MIDIA', 'c:/xampp5-6/htdocs/whatsApi/public/img/send-messages/');
     if (in_array($extensao, array('3gp', 'mp4', 'mov', 'avi'))) {
         $newName = md5($files['image']['name'] . date('Ymdhis')) . "." . $extensao;
         $pathImage = CAMINHO_MIDIA . $newName;
         $urlMain = $_SERVER['HTTP_ORIGIN'] . '/img/send-messages/' . $newName;
         if (move_uploaded_file($files['image']['tmp_name'], $pathImage)) {
             $this->managerWhats->sendMessageVideo($to, $urlMain);
             $this->managerWhats->pollMessage();
         } else {
             $this->setLogTalk("Enviar image:" . $to, "Não foi possível enviar a mídia");
         }
     }
     if (in_array($extensao, array('jpg', 'jpeg', 'gif', 'png'))) {
         $newName = md5($files['image']['name'] . date('Ymdhis')) . "." . $extensao;
         $pathImage = CAMINHO_MIDIA . $newName;
         $urlMain = $_SERVER['HTTP_ORIGIN'] . '/img/send-messages/' . $newName;
         if (move_uploaded_file($files['image']['tmp_name'], $pathImage)) {
             $this->managerWhats->sendMessageImage($to, $urlMain);
             $this->managerWhats->pollMessage();
         } else {
             $this->setLogTalk("Enviar image:" . $to, "Não foi possível enviar a mídia");
         }
     }
     if (in_array($extensao, array('3gp', 'caf', 'wav', 'mp3', 'wma', 'ogg', 'aif', 'aac', 'm4a'))) {
         $newName = md5($_FILES['image']['name'] . date('Ymdhis')) . "." . $extensao;
         $pathImage = CAMINHO_MIDIA . $newName;
         $urlMain = $_SERVER['HTTP_ORIGIN'] . '/img/send-messages/' . $newName;
         if (move_uploaded_file($files['image']['tmp_name'], $pathImage)) {
             $this->managerWhats->sendMessageAudio($to, $urlMain);
             $this->managerWhats->pollMessage();
         } else {
             $this->setLogTalk("Enviar image:" . $to, "Não foi possível enviar a mídia");
         }
     }
     return true;
 }
Ejemplo n.º 3
0
$w = new WhatsProt($username, $nickname, $debug);
$w->eventManager()->bind('onPresenceAvailable', 'onPresenceAvailable');
$w->eventManager()->bind('onPresenceUnavailable', 'onPresenceUnavailable');
$w->connect();
// Nos conectamos a la red de WhatsApp
$w->loginWithPassword($password);
// Iniciamos sesion con nuestra contraseña
echo "[*]Conectado a WhatsApp\n\n";
$w->sendGetServerProperties();
// Obtenemos las propiedades del servidor
$w->sendClientConfig();
// Enviamos nuestra configuración al servidor
$sync = [$target];
$w->sendSync($sync);
// Sincronizamos el contacto
$w->pollMessage();
// Volvemos a poner en cola mensajes
$w->sendPresenceSubscription($target);
// Nos suscribimos a la presencia del usuario
$pn = new ProcessNode($w, $target);
$w->setNewMessageBind($pn);
while (1) {
    $w->pollMessage();
    $msgs = $w->getMessages();
    foreach ($msgs as $m) {
        // process inbound messages
        //print($m->NodeString("") . "\n");
    }
    $line = fgets_u(STDIN);
    if ($line != '') {
        if (strrchr($line, ' ')) {
Ejemplo n.º 4
0
$w->eventManager()->bind('onPresenceUnavailable', 'onPresenceUnavailable');
echo "[*] Connected to WhatsApp\n\n";
//update your profile picture
$w->sendSetProfilePicture('demo/venom.jpg');
//send picture
$w->sendMessageImage($target, 'demo/x3.jpg');
//send video
//$w->sendMessageVideo($target, 'http://techslides.com/demos/sample-videos/small.mp4');
//send Audio
//$w->sendMessageAudio($target, 'http://www.kozco.com/tech/piano2.wav');
//send Location
//$w->sendMessageLocation($target, '4.948568', '52.352957');
// Implemented out queue messages and auto msgid
$w->sendMessage($target, 'Guess the number :)');
$w->sendMessage($target, 'Sent from WhatsApi at ' . date('H:i'));
while ($w->pollMessage()) {
}
/*
 * You can create a ProcessNode class (or whatever name you want) that has a process($node) function
 * and pass it through setNewMessageBind, that way everytime the class receives a text message it will run
 * the process function to it.
 */
$pn = new ProcessNode($w, $target);
$w->setNewMessageBind($pn);
echo "\n\nYou can also write and send messages to {$target} (interactive conversation)\n\n> ";
while (1) {
    $w->pollMessage();
    $msgs = $w->getMessages();
    foreach ($msgs as $m) {
        // process inbound messages
        //print($m->NodeString("") . "\n");
Ejemplo n.º 5
0
    exit(0);
}
echo "[*] Logging in as WhatsApp Tracker ({$sender})\n";
$wa = new WhatsProt($sender, 'WhatsApp Tracker', FALSE);
$wa->connect();
try {
    $wa->loginWithPassword($password);
} catch (Exception $e) {
    echo "Bad authentication: Bad password or blocked account";
}
$events = new MyEvents($wa);
$wa->eventManager()->bind("onPresenceAvailable", "onPresenceAvailable");
$wa->eventManager()->bind("onPresenceUnavailable", "onPresenceUnavailable");
echo "\n[-] Tracker mode (ON): Waiting the user to get online...\n";
$wa->SendPresenceSubscription($target);
$wa->pollMessage();
if ($presence == "available") {
    echo "- The user is now online\n\n";
} else {
    echo "- The user is offline\n\n";
}
$lastpresence = "";
while (true) {
    $wa->pollMessage();
    if ($lastpresence == "available" && $presence == "unavailable") {
        $timeOffline = date("Y-m-d H:i:s");
        while ($presence == "unavailable") {
            $timeDiff = round(strtotime(date("Y-m-d H:i:s")) - strtotime($timeOffline));
            echo secondsToTime($timeDiff) . "\n";
            if ($notify != "") {
                $wa->sendMessage($notify, "({$target}) " . secondsToTime($timeDiff));
Ejemplo n.º 6
0
    if ($poll == 5) {
        echo "\n[{$ke}][" . date('H:i:s') . "] ----------------------------------------------------\n";
        echo "[{$ke}][" . date('H:i:s') . "] --- BOT SIAP!\n";
        echo "[{$ke}][" . date('H:i:s') . "] --- \n";
        echo "[{$ke}][" . date('H:i:s') . "] --- Sekarang coba kirim pesan ke bot ini,\n";
        echo "[{$ke}][" . date('H:i:s') . "] --- seharusnya bot akan mengirim balik teks yang\n";
        echo "[{$ke}][" . date('H:i:s') . "] --- dikirimkan ke dia.\n";
        echo "[{$ke}][" . date('H:i:s') . "] --- \n";
        echo "[{$ke}][" . date('H:i:s') . "] --- Ubah perilaku bot dengan mengedit function\n";
        echo "[{$ke}][" . date('H:i:s') . "] --- onGetMessage() dan onGetGroupMessage()\n";
        echo "[{$ke}][" . date('H:i:s') . "] --- di baris 126 dan baris 182.\n";
        echo "[{$ke}][" . date('H:i:s') . "] --- \n";
        echo "[{$ke}][" . date('H:i:s') . "] --- Semoga sukses!\n";
        echo "[{$ke}][" . date('H:i:s') . "] ----------------------------------------------------\n";
    }
    $w->pollMessage(true);
    // markAsRead
    // cek konek
    if ($poll % 100 == 0 && $poll != 0) {
        cek_konek();
    }
    $poll++;
    // poll control
}
// ------------------------------------------------------------------------------------------------------------------
// FUNCTIONS
// ------------------------------------------------------------------------------------------------------------------
// ketika dapat pesan pm
function onGetMessage($mynumber, $from, $id, $type, $time, $name, $body)
{
    global $ke, $w, $poll;
Ejemplo n.º 7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     if (!$this->argument('number')) {
         return $this->error('No number specified.');
     }
     $number = Number::where('number', $this->argument('number'))->first();
     if (is_null($number) || is_null($number->wa_password) || is_null($number->wa_expiration)) {
         return $this->error('Whatsapp not registered. Run php artisan whatsapp:register');
     }
     $contacts = $number->contacts->map(function ($contact) {
         return $contact->number;
     });
     $wa = new WhatsProt($number->number, $number->number, true);
     $wa->connect();
     // Connects to WhatsApp
     $wa->loginWithPassword($number->wa_password);
     // Login
     $wa->pollMessage();
     $wa->sendGetPrivacyBlockedList();
     // Get our privacy list
     $wa->sendGetClientConfig();
     // Get client config
     $wa->sendGetServerProperties();
     // Get server properties
     if (!$contacts->isEmpty()) {
         $wa->sendGetHasVoipEnabled($contacts);
     }
     // Get which users have voip enabled
     $wa->sendGetGroups();
     // Get groups (participating)
     $wa->sendGetBroadcastLists();
     // Get broadcasts lists
     // $wa->sendGetProfilePicture(self); // self preview profile picture [OPTIONAL]
     if (!$contacts->isEmpty()) {
         $wa->sendSync($contacts);
     }
     // Sync all contacts
     // $wa->sendGetStatuses(All contacts); // Get contacts status [OPTIONAL]
     /*
     for (All contacts) [OPTIONAL]
     {
       			$wa->sendGetProfilePicture(contact); // preview profile picture of every contact
     }
     */
     // $wa->sendPing(); // Keep alive
     $wa->eventManager()->bind("onGetMessage", function ($mynumber, $from, $id, $type, $time, $name, $body) {
         // todo // save message id and compare to avoid duplicate
         $inbound = new Inbound();
         $inbound->from = $this->getFrom($from);
         $inbound->to = $mynumber;
         $inbound->text = $body;
         $inbound->type = 'whatsapp';
         $inbound->save();
     });
     $wa->eventManager()->bind("onPresenceAvailable", function ($mynumber, $from) {
         $from = $this->getFrom($from);
         // todo // add or update wa-contact
     });
     $wa->eventManager()->bind("onPresenceUnavailable", function ($mynumber, $from, $last) {
         $from = $this->getFrom($from);
         // todo // add or update wa-contact
     });
     $wa->eventManager()->bind("onMessageReceivedClient", function ($mynumber, $from, $id) {
         $outbound_chunk = OutboundChunk::where('message_id', $id)->first();
         if (!$outbound_chunk) {
             return;
         }
         $outbound_chunk->dn_error_code = 0;
         $outbound_chunk->dn_status = 'delivered';
         $outbound_chunk->save();
     });
     $time = time();
     while (true) {
         sleep(1);
         $wa->pollMessage();
         $this->processMessages($wa);
         if (time() - $time >= 8) {
             $wa->sendActiveStatus();
             $time = time();
             // whatsapp command action
             $whatsAppAction = Cache::get('whatsAppAction_' . $number->number, false);
             if ($whatsAppAction) {
                 $whatsAppActionInput = Cache::get('whatsAppActionInput_' . $number->number, false);
                 Cache::forget('whatsAppAction_' . $number->number);
                 Cache::forget('whatsAppActionInput_' . $number->number);
                 switch (strtolower($whatsAppAction)) {
                     case 'updatestatus':
                         $wa->sendStatusUpdate($whatsAppActionInput);
                         break;
                     case 'setprofilepicture':
                         try {
                             $wa->sendSetProfilePicture($whatsAppActionInput);
                         } catch (Exception $e) {
                         }
                         break;
                     case 'stop':
                         $wa->disconnect();
                         exit('whatsapp is stopped');
                 }
             }
             // end whatsapp command action
         }
     }
 }