PHP code example of he110 / communication-tools

1. Go to this page and download the library: Download he110/communication-tools 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/ */

    

he110 / communication-tools example snippets




// Telegram client's taken as an example. You can use other
use He110\CommunicationTools\Telegram\Messenger;
use He110\CommunicationTools\MessengerScreen;

$messenger = new Messenger();
$messenger->setAccessToken(YOUR_TOKEN_HERE);

// If you want, to send simple text message
$messenger->sendMessage("Your message text here");

// To send image use method sendImage
$messenger->sendImage("path/to/file", "(Optional) Your text description");
// or, to send document...
$messenger->sendDocument("path/to/file", "(Optional) Your text description");
// you can also send voice files
$messenger->sendVoice("path/to/file");

// If you wanna use buttons, it's better way to use MessengerScreen
$screen = new MessengerScreen();
$screen->addMessage("Your message text here");
$screen->addButtonText("Text button");
$screen->addButtonLink("URL button", "https://google.com");
$messenger->sendScreen($screen);




// Telegram client's taken as an example. You can use other
use He110\CommunicationTools\MessengerPool;
use He110\CommunicationTools\Telegram\Messenger;
use He110\CommunicationTools\MessengerScreen;

$messenger = new Messenger();
$messenger->setAccessToken(YOUR_TOKEN_HERE);

// Pool allows you to use multiple messengers as one
$pool = new MessengerPool();
$pool->add($messenger);

$pool->sendMessage("Your message text here");

// If you wanna use buttons, it's better way to use MessengerScreen
$screen = new MessengerScreen();
$screen->addMessage("Your message text here");
$screen->addButtonText("Text button");
$screen->addButtonLink("URL button", "https://google.com");
$pool->sendScreen($screen);




// Telegram client's taken as an example. You can use other
use He110\CommunicationTools\Telegram\Messenger;
use He110\CommunicationTools\Request;
use He110\CommunicationTools\MessengerUser;

$messenger = new Messenger();
$messenger->setAccessToken(YOUR_TOKEN_HERE);

// Action for simple incoming messages
$messenger->onMessage(function(Request $request) use ($messenger) {
    // Your code here...
    $text = $request->getMessage();
    /** @var MessengerUser $user $user */
    $user = $request->getUser();
    $messenger->setTargetUser($user->getUserId());
    $messenger->sendMessage("We've got your message: '$text'");
});

// Action for buttons click
$messenger->onButtonClick(function(Request $request) use ($messenger) {
     // Your code here...
     $payload = $request->getPayload();
});

// Required!!! Run this method to check if events are triggered
$messenger->checkEvents();