1. Go to this page and download the library: Download justify/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/ */
justify / telegram-bot-api example snippets
define('TELEGRAM_TOKEN', 'Your token');
$bot = new Justify\TelegramBotApi\Client(TELEGRAM_TOKEN);
$bot->sendMessage($chatId, 'Hello!');
$bot->sendPhoto($chatId, 'File id || URL || path to file', [
'caption' => 'My photo'
]);
$bot->handler(function ($message) use ($bot) {
// Actions ...
});
// Will react on "start" command
$bot->command('start', function ($message) use ($bot) {
// Actions ...
});
// Will react on "Some text" text
$bot->text('Some text', function ($message) use ($bot) {
// Actions ...
});
// Will react if text messages will match to regexp pattern
$bot->regexp('Password (\d+)', function ($message, $matches) use ($bot) {
// Actions ...
});
// Will react if message will have "photo" type
$bot->type('photo', function ($message) use ($bot) {
// Actions ...
});
$
$bot->sendPhoto($chatId, 'Pass file id or file url or path to file');
$photo = new Justify\TelegramBotApi\Types\InputMediaPhoto('Pass file id or file url or path to file', [
'caption' => 'My photo'
]);
$video = new Justify\TelegramBotApi\Types\InputMediaVideo('Pass file id or file url or path to file', [
'caption' => 'My video'
]);
$bot->sendMediaGroup($chatId, [$photo, $video]);