PHP code example of arodu / tebo

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

    

arodu / tebo example snippets


public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
{
    $csrf = new CsrfProtectionMiddleware(['httponly' => true]);

    $csrf->skipCheckCallback(function ($request) {
        // Exclude requests from the TeBo plugin from CSRF protection
        if ($request->getParam('plugin') === 'TeBo') {
            return true;
        }
    });

    $middlewareQueue->add($csrf);

    return $middlewareQueue;
}


return [
    'tebo' => [
        'webhookUrl' => [ // Specifies the webhook route, useful for custom development.
            'plugin' => 'TeBo', 
            'controller' => 'Bot',
            'action' => 'webhook',
        ],
        'obfuscation' => env('WEBHOOK_OBFUSCATION', null), // Sets the webhook URL obfuscation.
        'actions' => [
            'command' => [ // Command mapping, allowing for custom actions.
                'start' => \TeBo\Action\Command\StartAction::class, // Action for the '/start' command.
                'about' => \TeBo\Action\Command\AboutAction::class, // Action for the '/about' command.
                'help' => \TeBo\Action\Command\HelpAction::class, // Action for the '/help' command.
                'default' => \TeBo\Action\Command\NotFoundAction::class, // Action for the default command, executed when no command is found.
            ],
            'default' => \TeBo\Action\DefaultAction::class,  // Default action if no match is found.
        ],
    ],
];


namespace App\Actions;

class Prices extends \TeBo\Action\Action
{
    public static function description(): ?string
    {
        return 'Get the current prices.';
    }

    public function execute(): void
    {
        $message = new \TeBo\Response\TextMessage('The current price is $100');
        $this->getChat()->send($message);
    }
}

'actions' => [
    'command' => [
        'prices' => \App\Actions\Prices::class,
    ],
],

$message = new \TeBo\Response\HtmlMessage([
    '<b>HTML Message</b>',
    '',
    'This is an example of an HTML message.',
    'You can use basic HTML tags to format the text.',
    'Example: <b>bold</b>, <i>italic</i>, <a href="https://example.com">link</a>',
    'Refer to Telegram API documentation for more info.',
]);

$this->getChat()->send($message);

$file = fopen(TEBO_CORE_PATH . DS . '/resources/tebo.jpg', 'rb');
$photo = new \TeBo\Response\Photo($file, 'This is a placeholder image.');
$update->reply($photo);

$photo = new \TeBo\Response\Photo('https://placehold.it/300x200');
$update->reply($photo);

$chatId = '12345678'; // The Telegram chat ID to send the message to
$chat = new \TeBo\Telegram\Chat(['id' => $chatId]); // Creates a Chat instance with the specified ID
$message = new \TeBo\Response\TextMessage('Hello!'); // Creates the text message to send
$chat->send($message); // Sends the message to the specified chat
bash
export WEBHOOK_OBFUSCATION="your_obfuscation_key_here"
export WEBHOOK_BASE="your_base_url_here"