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.

53 lines
1.5 KiB

1 year ago
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * This file is part of the PHP Telegram Bot example-bot package.
  5. * https://github.com/php-telegram-bot/example-bot/
  6. *
  7. * (c) PHP Telegram Bot Team
  8. *
  9. * For the full copyright and license information, please view the LICENSE
  10. * file that was distributed with this source code.
  11. */
  12. /**
  13. * This file is used to run the bot with the getUpdates method.
  14. */
  15. // Load composer
  16. require_once __DIR__ . '/vendor/autoload.php';
  17. // Load all configuration options
  18. /** @var array $config */
  19. $config = require __DIR__ . '/config.php';
  20. try {
  21. // Create Telegram API object
  22. $telegram = new Longman\TelegramBot\Telegram($config['api_key'], $config['bot_username']);
  23. /**
  24. * Check `hook.php` for configuration code to be added here.
  25. */
  26. // Handle telegram getUpdates request
  27. $server_response = $telegram->handleGetUpdates();
  28. if ($server_response->isOk()) {
  29. $update_count = count($server_response->getResult());
  30. echo date('Y-m-d H:i:s') . ' - Processed ' . $update_count . ' updates';
  31. } else {
  32. echo date('Y-m-d H:i:s') . ' - Failed to fetch updates' . PHP_EOL;
  33. echo $server_response->printError();
  34. }
  35. } catch (Longman\TelegramBot\Exception\TelegramException $e) {
  36. // Log telegram errors
  37. Longman\TelegramBot\TelegramLog::error($e);
  38. // Uncomment this to output any errors (ONLY FOR DEVELOPMENT!)
  39. // echo $e;
  40. } catch (Longman\TelegramBot\Exception\TelegramLogException $e) {
  41. // Uncomment this to output log initialisation errors (ONLY FOR DEVELOPMENT!)
  42. // echo $e;
  43. }