PHP code example of segakgd / telegram_client

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

    

segakgd / telegram_client example snippets


    $telegramManager = new TelegramManager();

    $telegramToken = '0000000:0000000000000000000000000';

    $message = $telegramMessageBuilder
        ->addText("Привет, мир!")
        ->newLine()
        ->addIndent()
        ->bold("Это жирный текст")
        ->newLine(2)
        ->italic("Курсивный текст")
        ->newLine()
        ->monospace("Моноширинный текст")
        ->newLine()
        ->addLink("Нажми сюда", "https://example.com")
        ->getMessage();

    $chatId = '0000000';
    $messageDto = $telegramManager->createMessage($chatId, $message);
    
    $response = $telegramManager->sendMessage(
        message: $messageDto,
        token: $telegramToken,
    );

    $telegramManager = new TelegramManager();

    $telegramToken = '0000000:0000000000000000000000000';

    $exception1 = new Exception('1');
    $exception2 = new Exception(message: '2', previous: $exception1);
    $exception3 = new Exception(message: '3', previous: $exception2);
    $exception4 = new Exception(message: '4', previous: $exception3);
    $exception5 = new Exception(message: '5', previous: $exception4);
    $exception6 = new Exception(message: '6', previous: $exception5);
    
    $message = (new TelegramExceptionManager())->makeReport($exception6);

    $chatId = '0000000';
    $messageDto = $telegramManager->createMessage($chatId, $message);
    
    $response = $telegramManager->sendMessage(
        message: $messageDto,
        token: $telegramToken,
    );