PHP code example of botasis / telegram-client

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

    

botasis / telegram-client example snippets


   $streamFactory = new \HttpSoft\Message\StreamFactory();
   $client = new \Botasis\Client\Telegram\Client\ClientPsr(
   getenv('BOT_TOKEN'),
   new \Http\Client\Socket\Client(),
   new \HttpSoft\Message\RequestFactory(),
   $streamFactory,
   new \Http\Message\MultipartStream\MultipartStreamBuilder($streamFactory),
   );
   

   $response = $client->send(new \Botasis\Client\Telegram\Request\TelegramRequest(
       'sendMessage', // any telegram bot api method you like
       // data to send
       [
           'text' => 'Hello Botasis!',
           'chat_id' => $chatId,
       ]
   ));
   

$requestTyped = new \Botasis\Client\Telegram\Request\Message\Message(
    'Hello *Botasis*\!', // be sure you correctly escape special characters when use Markdown message format
    \Botasis\Client\Telegram\Request\Message\MessageFormat::MARKDOWN,
    $chatId,
);

// This is equal, but not strictly typed request:
$requestGeneric = new \Botasis\Client\Telegram\Request\TelegramRequest(
        'sendMessage',
        [
            'text' => 'Hello *Botasis*\!',
            'chat_id' => $chatId,
            'parse_mode' => 'MarkdownV2',
        ]
    )