PHP code example of bagart / telegram-bot-lib

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

    

bagart / telegram-bot-lib example snippets


$registry = new TgUpdateProcessorRegistry();
$registry->register(MessageTypeDTO::class, MessageEchoProcessor::class);
$registry->register(MessageTypeDTO::class, UpdateLoggerProcessor::class);

$processor = new TgUpdateProcessor($registry);
$processor->process($update,  $serviceConfig);
bash
export TELEGRAM_BOT_TOKEN=xxx:xxx           # Default Telegram Token

php commands/tg_daemons-daemon.php                     # receive updates
php commands/tg_daemons-daemon.php --help              # show help
php commands/tg_daemons-daemon.php                     # receive updates with DTOProcessor
  --echo                                    # echo reply to messages
  --store                                   # store messages to database
  --log                                     # log messages to stderr
  --show                                    # dump update objects
  --token=xxx:xxx                           # use custom token
bash
export TELEGRAM_BOT_TOKEN=xxx:xxx           # Default Telegram Token

php commands/pollers/tg_daemons-raw.php --help          # show help
php commands/pollers/tg_daemons-raw.php                 # receive updates in raw mode
  --echo                                    # echo reply to messages
  --show                                    # dump update objects
  --token=xxx:xxx                           # use custom token
bash
php commands/mapper.php
bash
export TELEGRAM_BOT_TOKEN=xxx:xxx

php commands/tg_webhook-processing.php --help
php commands/tg_webhook-processing.php                                     # show current tg_webhook + auto-secret
php commands/tg_webhook-processing.php --token=xxx:xxx                     # use token. default: export TELEGRAM_BOT_TOKEN=xxx:xxx
php commands/tg_webhook-processing.php --url=https://example.com/tg        # set tg_webhook (secret auto-generated)
php commands/tg_webhook-processing.php --url=... --secret=custom-secret    # set url with custom secret
php commands/tg_webhook-processing.php --url=... --secret                  # set url with empty secret
php commands/tg_webhook-processing.php --delete                            # delete tg_webhook