PHP code example of zelenin / telegram-bot-api
1. Go to this page and download the library: Download zelenin/telegram-bot-api 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/ */
zelenin / telegram-bot-api example snippets
$api = ApiFactory::create($token);
try {
$response = $api->sendMessage([
'chat_id' => $chatId,
'text' => 'Test message'
]);
print_r($response);
$response = $api->sendPhoto([
'chat_id' => $myId,
'photo' => fopen('/home/www/photo.jpg', 'r')
]);
print_r($response);
} catch (\Zelenin\Telegram\Bot\Exception\NotOkException $e) {
echo $e->getMessage();
}
$api = ApiFactory::create($token);
$daemon = new \Zelenin\Telegram\Bot\Daemon\NaiveDaemon($api);
$daemon
->onUpdate(function (\Zelenin\Telegram\Bot\Type\Update $update) {
print_r($update);
});
$daemon->run();
php composer.phar