PHP code example of junisan / php-google-chat

1. Go to this page and download the library: Download junisan/php-google-chat 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/ */

    

junisan / php-google-chat example snippets




le = new \GuzzleHttp\Client();
$webhooks = [
    'default' => 'https://chat.googleapis.com/v1/spaces/AAAAK4AL5Bg/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=3PPfdSFIA_p3ColcvumRTiRnbMftokJhDjz0RJI3sa8%3D'
];
$sender = new \Junisan\GoogleChat\GoogleChatSender($guzzle, $webhooks);


$message = \Junisan\GoogleChat\SimpleMessage::create()->addText('Hello');
$sender->send($message, 'default');


//... Create sender

$message = new \Junisan\GoogleChat\SimpleMessage();
$message
    ->addText('Hola')
    ->addLine()
    ->addBoldText('Como estás')
    ->addLine()
    ->addLink('https://www.juannicolas.eu');
$sender->send($message, 'default');

$link = \Junisan\GoogleChat\UIElements\TextButton::create('http://google.es', 'Follow');
$link2 = \Junisan\GoogleChat\UIElements\TextButton::create('http://google.es', 'Unfollow');
$link3 = \Junisan\GoogleChat\UIElements\ImageButton::create('http://google.es', 'https://goo.gl/aeDtrS');

$order = \Junisan\GoogleChat\UIElements\KeyValue::create('Order No.', '12345');
$status = \Junisan\GoogleChat\UIElements\KeyValue::create('Status', '12345');
$textParagraph = \Junisan\GoogleChat\UIElements\TextParagraph::create('Hola');

$sectionA = \Junisan\GoogleChat\Elements\Section::create()
    ->addWidgets($order, $status, $textParagraph, $link3);



$sectionB = \Junisan\GoogleChat\Elements\Section::create()
    ->addWidgets($link, $link2);

$card = \Junisan\GoogleChat\Elements\Card::create('Pizza __Bot__', '[email protected]', 'https://goo.gl/aeDtrS')
    ->addSections($sectionA, $sectionB);

$cardB = \Junisan\GoogleChat\Elements\Card::create('Hola');
$message = \Junisan\GoogleChat\Message::create()
    ->addCard($card);

$sender->send($message, 'default');

$webhooks = [
    'default' => 'https://chat.googleapis.com/v1/.....',
    'another_channel' => 'https://chat.googleapis.com/v1/.....'
];

$sender = new \Junisan\GoogleChat\GoogleChatSender($guzzle, $webhooks);

$sender->send($message, 'another_channel');