PHP code example of chatflowphp / telegram

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

    

chatflowphp / telegram example snippets


use ChatFlow\Core\Context;
use ChatFlow\Telegram\Bot;
use ChatFlow\View\Action;
use ChatFlow\View\View;

$bot = new Bot($_ENV['TELEGRAM_BOT_TOKEN'], __DIR__);

$bot->command('start', static function (Context $ctx): void {
    $ctx->reply(
        View::text('Hello from ChatFlow Telegram')
            ->addActionRow(new Action('menu:open', 'Open menu'))
    );
});

$bot->prefix('menu:', static function (Context $ctx): void {
    $ctx->ack();
    $ctx->render(View::text('Menu opened'));
});

$bot->runWebhook();

use ChatFlow\Telegram\TelegramContext;

$bot->command('ask', static function (TelegramContext $telegram): void {
    $telegram->forceReply('Send the updated post text');
});

$bot->onTelegramEvent('my_chat_member', static function (TelegramContext $telegram, array $update): void {
    $telegram->reply('Membership changed');
});

use ChatFlow\Telegram\TelegramView;

$ctx->reply(TelegramView::forceReply('Reply with details'));
sh
php examples/StarterBot/mock.php
php examples/MiniShop/mock.php
sh
TELEGRAM_BOT_TOKEN=... php examples/MiniShop/run.php
tail -f storage/minishop/runtime.jsonl