PHP code example of whitebock / telegramapi

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

    

whitebock / telegramapi example snippets


use Whitebock\TelegramApi\Bot;
use Whitebock\TelegramApi\Photo;

$bot = new Bot('');

$me = $bot->getMe();
echo $me->getUsername().PHP_EOL;

$updates = $bot->getUpdates();
foreach ($updates as $update) {
    $chat = $update->getMessage()->getChat();
    echo $chat->getUsername().': '.$update->getMessage()->getText().PHP_EOL;
    $bot->sendMessage($chat, 'Hello World');
    $bot->sendChatAction($chat, 'upload_photo');
    $bot->sendMedia($chat, Photo::fromFile('test/bird.jpg'));
    $bot->sendLocation($chat, 52.520038, 13.404799);
    $bot->sendContact($chat,'+49123456789', 'John');
    $bot->sendVenue($chat, 51.496797, 7.455505, 'Westfalenhallen', 'Rheinlanddamm 200, 44139 Dortmund');
}