PHP code example of m4n50n / telegram-bot-bundle

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

    

m4n50n / telegram-bot-bundle example snippets


// config/bundles.php

return [
    // ...
    M4n50n\TelegramBotBundle\TelegramBotBundle::class => ['all' => true],
];

use M4n50n\TelegramBotBundle\Factory\TelegramBotFactory;

final class TelegramBotService
{
    public function __construct(private TelegramBotFactory $botFactory)
    {
    }

    public function initialize(string $botName)
    {
        // ...
        return $this->botFactory->get($botName);        
    }
}

namespace App\Controller;

// ...

final class PHPCodeTesterBotController extends AbstractController
{
  private readonly TelegramBot $bot;

  public function __construct(private TelegramBotService $telegramBotService)
  {
    $this->bot = $telegramBotService->initialize("bot_name");
  }

  #[Route('/endpoint', name: 'app_webhook_endpoint')]
  public function webhookEndpoint(): Response
  {
    // ...
    $webhookHandler = $this->bot->webhookHandler();
    // ... or
    $setWebhook = $this->bot->setWebhook();
    // ... or
    $unsetWebhook = $this->bot->unsetWebhook();
    // ...
  }
}