You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
3.0 KiB

1 year ago
  1. <?php
  2. /**
  3. * This file is part of the PHP Telegram Bot example-bot package.
  4. * https://github.com/php-telegram-bot/example-bot/
  5. *
  6. * (c) PHP Telegram Bot Team
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. /**
  12. * This configuration file is used to run the bot with the webhook method.
  13. *
  14. * Please note that if you open this file with your browser you'll get the "Input is empty!" Exception.
  15. * This is perfectly normal and expected, because the hook URL has to be reached only by the Telegram servers.
  16. */
  17. // Load composer
  18. require_once __DIR__ . '/vendor/autoload.php';
  19. // Load all configuration options
  20. /** @var array $config */
  21. $config = require __DIR__ . '/config.php';
  22. try {
  23. // Create Telegram API object
  24. $telegram = new Longman\TelegramBot\Telegram($config['api_key'], $config['bot_username']);
  25. // Enable admin users
  26. $telegram->enableAdmins($config['admins']);
  27. // Add commands paths containing your custom commands
  28. $telegram->addCommandsPaths($config['commands']['paths']);
  29. // Enable MySQL if required
  30. // $telegram->enableMySql($config['mysql']);
  31. // Logging (Error, Debug and Raw Updates)
  32. // https://github.com/php-telegram-bot/core/blob/master/doc/01-utils.md#logging
  33. //
  34. // (this example requires Monolog: composer require monolog/monolog)
  35. // Longman\TelegramBot\TelegramLog::initialize(
  36. // new Monolog\Logger('telegram_bot', [
  37. // (new Monolog\Handler\StreamHandler($config['logging']['debug'], Monolog\Logger::DEBUG))->setFormatter(new Monolog\Formatter\LineFormatter(null, null, true)),
  38. // (new Monolog\Handler\StreamHandler($config['logging']['error'], Monolog\Logger::ERROR))->setFormatter(new Monolog\Formatter\LineFormatter(null, null, true)),
  39. // ]),
  40. // new Monolog\Logger('telegram_bot_updates', [
  41. // (new Monolog\Handler\StreamHandler($config['logging']['update'], Monolog\Logger::INFO))->setFormatter(new Monolog\Formatter\LineFormatter('%message%' . PHP_EOL)),
  42. // ])
  43. // );
  44. // Set custom Download and Upload paths
  45. // $telegram->setDownloadPath($config['paths']['download']);
  46. // $telegram->setUploadPath($config['paths']['upload']);
  47. // Load all command-specific configurations
  48. // foreach ($config['commands']['configs'] as $command_name => $command_config) {
  49. // $telegram->setCommandConfig($command_name, $command_config);
  50. // }
  51. // Requests Limiter (tries to prevent reaching Telegram API limits)
  52. $telegram->enableLimiter($config['limiter']);
  53. // Handle telegram webhook request
  54. $telegram->handle();
  55. } catch (Longman\TelegramBot\Exception\TelegramException $e) {
  56. // Log telegram errors
  57. Longman\TelegramBot\TelegramLog::error($e);
  58. // Uncomment this to output any errors (ONLY FOR DEVELOPMENT!)
  59. // echo $e;
  60. } catch (Longman\TelegramBot\Exception\TelegramLogException $e) {
  61. // Uncomment this to output log initialisation errors (ONLY FOR DEVELOPMENT!)
  62. // echo $e;
  63. }