PHP code example of phenogram / framework

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

    

phenogram / framework example snippets


// bot.php


amework\TelegramBot;
use Phenogram\Bindings\Types\Interfaces\UpdateInterface;

$token = getenv('TELEGRAM_BOT_TOKEN'); // Ваш токен, полученный у @BotFather например 7245389610:AAFHBDYMKpWxYu5JrSnTlQRD9bvPz0OgHkLf

$bot = new TelegramBot($token);
$bot->addHandler(fn (UpdateInterface $update, TelegramBot $bot) => $bot->api->sendMessage(
        chatId: $update->message->chat->id,
        text: $update->message->text
    ))
    ->supports(fn (UpdateInterface $update) => $update->message?->text !== null);

$bot->run();

// bot.php


amework\TelegramBot;
use Phenogram\Framework\Type\LocalFile;
use Phenogram\Framework\Type\ReadableStreamFile;
use Phenogram\Framework\Type\BufferedFile;

$token = getenv('TELEGRAM_BOT_TOKEN');
$bot = new TelegramBot($token);

$chatId = 123456789; // ID чата, куда отправляем файл

// 1. Отправка файла по локальному пути
$bot->api->sendDocument(
    chatId: $chatId,
    document: new LocalFile(
        filepath: '../../README.md'
//        // Необязательный параметр с именем файла. Если отсутствует, будет использовано имя файла из пути
//        filename: 'документация.md',
    ),
);

// 2. Отправка файла через поток
$bot->api->sendDocument(
    chatId: $chatId,
    document: new ReadableStreamFile(
        stream: \Amp\File\openFile('../../README.md', 'r'),
        filename: 'README.md', // Имя файла обязательно
    ),
);

// 3. Отправка файла через строку
$bot->api->sendDocument(
    chatId: $chatId,
    document: new BufferedFile(
        content: 'Здесь может быть ваша реклама',
        filename: 'README.md', // Имя файла обязательно
    ),
);