PHP code example of federicoq / zulip-php

1. Go to this page and download the library: Download federicoq/zulip-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

federicoq / zulip-php example snippets




$client = new \ZulipPhp\Client('https://chat.mndrn.cloud/', 'bot-email', 'bot-api-key');

$client->sendMessage([ 'to' => 'email-utente', 'type' => 'private', 'content' => "Messaggio!" ]);

$client->sendMessage([ 'to' => 'Canale', 'subject' => 'nome-dello-stream', 'type' => 'stream', 'content' => "Messaggio!" ]);

$client = new \ZulipPhp\…

$queue_id = false;
$last_id = -1; // Di default, -1 ti risponde con tutti gli eventi dalla creazione della queue.
// il last_id non è il vero identificativo dell'evento, è un indice parziale a partire dalla nascita della query (-1, 0, 1, 2, 3, …)

// Registriamo la queue:
$queue_id = $zulip->registerQueue()['queue_id'];

while(true) {

	try {

		$events = $client->getEvents([ 'queue_id' => $queue_id, 'last_event_id' => $last_id, 'dont_block' => 'false']);

		if(count($events) > 0) {
			$last_id += count($events);
			print_r($events);
		} else {
			echo "No new messages. Last event id: ".$msg.".\n";
		}

		sleep(2);

	} catch (Exception $e) {
		echo "Error in fetching Events. Try again in 1 sec.\n";
		sleep(1);
	}

}

$client = new \ZulipPhp\…

$messages = $client->getMessages([ 'narrow' => json_encode([ [ 'stream', 'NomeStream' ] ]), 'had_error_retry' => 'false', 'anchor' => 0, 'num_before' => 1, 'num_after' => 5]);
// Fare riferimento alla loro documentazione, per l'endpoint GET /messages