Skip to content
maule edited this page Aug 16, 2026 · 1 revision

Frequently Asked Questions (FAQ)

General Questions

Q: What is TGbotPHP?

A: TGbotPHP is a lightweight PHP library for building Telegram bots using webhook-based updates. It provides a simple, easy-to-use API for handling messages, callbacks, and keyboards.

Q: Why use TGbotPHP instead of other libraries?

A: TGbotPHP is:

  • Lightweight - Minimal dependencies
  • Simple - Easy to learn and use
  • Modern - PHP 8.4+ with latest features
  • Flexible - Easy to extend for custom needs

Q: Do I need a database?

A: No, TGbotPHP doesn't require a database. However, you can integrate one if you need to store user data.

Q: Can I use TGbotPHP for group bots?

A: Yes! Use $bot->isPrivate() to check if it's a private chat, then handle group chats differently.

Installation & Setup

Q: How do I install TGbotPHP?

A: Two ways:

Option 1 - Download:

require_once "botlib.php";

Option 2 - Composer:

composer require lightyagami28/tgbotphp

Q: Do I need a web server?

A: Yes, you need a web server with:

  • PHP 7.0+ (8.4+ recommended)
  • HTTPS support
  • cURL extension

Q: Can I use TGbotPHP on localhost?

A: Not for webhooks (Telegram requires public HTTPS). Use long polling instead or deploy to a real server.

Q: How do I get a Telegram Bot Token?

A:

  1. Open Telegram
  2. Search for @BotFather
  3. Send /newbot
  4. Follow the prompts
  5. Copy your token

Q: Where should I store my bot token?

A: NEVER hardcode it! Use:

// Environment variable
$token = getenv('TELEGRAM_BOT_TOKEN');

// Or .env file
$env = parse_ini_file('.env');
$token = $env['TELEGRAM_BOT_TOKEN'];

Features

Q: Does TGbotPHP support all Telegram Bot API methods?

A: No, only the most common methods are implemented. For others, use the $bot->send() method directly or extend the class.

Q: Can I send files/media?

A: Yes! TGbotPHP supports:

  • Photos (via photo parameter)
  • Custom media via $bot->send()

Q: Does it support inline queries?

A: Not yet. You can implement it using $bot->send() directly.

Q: Can I use paid Telegram features?

A: TGbotPHP is generic - use $bot->send() for any Telegram Bot API method.

Security

Q: Is my bot secure?

A: TGbotPHP provides security features, but YOU must:

  • Store token securely (environment variable)
  • Enforce HTTPS
  • Validate input
  • Use secure coding practices

See Security Guide for details.

Q: My token was exposed! What should I do?

A:

  1. Open @BotFather
  2. Select your bot
  3. Use /revoke or /newtoken
  4. Update your bot

Q: Should I validate webhook requests?

A: Yes, check:

// Telegram IP
if (!botTG::checkIp($_SERVER['REMOTE_ADDR'])) {
    exit;
}

// Webhook secret
if ($secretToken !== $_SERVER['HTTP_X_TELEGRAM_BOT_API_SECRET_TOKEN']) {
    exit;
}

Q: How do I prevent token exposure?

A:

  • Use environment variables
  • Add to .gitignore
  • Review git history
  • Use .env files (never commit)
  • Use secret management tools

Performance

Q: How many users can my bot handle?

A: Depends on your server:

  • Shared hosting: 1000s of users
  • VPS: 10000s+ users
  • Scale with load balancers

Q: Is TGbotPHP fast enough?

A: Yes, response time is typically <100ms. Optimize by:

  • Caching database queries
  • Using CDN for media
  • Profiling your code

Q: Should I use a database?

A: Yes, if you need to:

  • Store user preferences
  • Track conversations
  • Persist data

Use MySQL with prepared statements.

Deployment

Q: Where should I deploy my bot?

A: Options:

  • Shared hosting (easiest)
  • VPS (more control)
  • Docker (consistent)
  • Serverless (if available)

See Deployment guide.

Q: How do I set up webhooks?

A:

curl -X POST "https://api.telegram.org/bot<TOKEN>/setWebhook" \
  -d "url=https://your-domain.com/webhook.php"

Q: Do I need a static IP?

A: No, Telegram uses domain names.

Q: How do I handle updates when offline?

A: Use Telegram's webhook storage. When you come online:

curl "https://api.telegram.org/bot<TOKEN>/getWebhookInfo"

Check pending_update_count to see pending updates.

Development

Q: How do I debug my bot?

A: Enable debug mode:

$bot = new botTG(
    token: $token,
    updates: $updates,
    debug: true,
    debugFile: '/var/log/bot.log'
);

Q: How do I test my bot locally?

A: Simulate webhooks:

$testUpdate = json_encode(['update_id' => 1, 'message' => [...]]);
$bot = new botTG(token: $token, updates: $testUpdate, debug: true);

Q: Can I use an IDE with TGbotPHP?

A: Yes! Modern IDEs support:

  • PHP 8.4 features
  • Type hints
  • AutoComplete
  • Debugging

Recommended: VS Code, PhpStorm, Sublime Text

Q: How do I write tests?

A: Use PHPUnit:

use PHPUnit\Framework\TestCase;

class BotTest extends TestCase {
    public function testEcho() {
        $update = json_encode(['message' => ['text' => 'test']]);
        $bot = new botTG(token: 'test', updates: $update);
        
        $this->assertEquals('test', $bot->getTextMessage());
    }
}

Troubleshooting

Q: Bot doesn't respond to messages

A: Check:

  1. Webhook registered: getWebhookInfo
  2. Server responding: curl https://your-domain.com/webhook.php
  3. Logs: Check error logs
  4. HTTPS: Must be HTTPS

See Troubleshooting.

Q: Getting "Bad Request" errors

A: Common causes:

  • Empty message text
  • Invalid keyboard JSON
  • Wrong parameter types

Check error logs and use debug mode.

Q: Rate limiting / "Too many requests"

A: Telegram has limits:

  • 30 msgs/sec per chat
  • Global rate limits

Implement your own rate limiting:

if (!$limiter->isAllowed($chatId)) {
    $bot->sendMessage($chatId, "Too many requests");
    exit;
}

Q: Certificate errors

A: Solutions:

  • Use Let's Encrypt (free)
  • Check certificate validity
  • Renew before expiry
  • Verify domain matches

Contributing

Q: Can I contribute?

A: Yes! See CONTRIBUTING.md

Q: How do I report bugs?

A: Use GitHub Issues with:

  • Clear title
  • Steps to reproduce
  • Expected vs actual behavior
  • Error logs

Q: How do I request features?

A: Create a GitHub Issue with:

  • Feature description
  • Use case
  • Proposed implementation (optional)

Q: Where's the roadmap?

A: Check CHANGELOG.md

Advanced

Q: Can I create groups/channels?

A: Not yet - this is a bot limitation, not TGbotPHP.

Q: How do I handle payment?

A: Use Telegram payments API:

$bot->send('sendInvoice', [...]);

Q: Can I add webhook filters?

A: Implement them:

if ($bot->update->message?->chat?->type !== 'private') {
    exit; // Ignore group messages
}

Q: How do I add middleware?

A: Create a wrapper class:

class SecureBot extends botTG {
    public function __construct(...$args) {
        parent::__construct(...$args);
        
        if (!$this->isValid()) {
            throw new Exception('Invalid request');
        }
    }
    
    private function isValid(): bool {
        // Your validation logic
        return true;
    }
}

Legal

Q: Is it legal to create a Telegram bot?

A: Yes, as long as you:

  • Follow Telegram's bot policies
  • Don't spam users
  • Don't impersonate others
  • Respect privacy

See Telegram Bot API Terms

Q: Do I need to handle user privacy?

A: Yes, respect:

  • User data storage regulations (GDPR, etc.)
  • Permission for data collection
  • Right to deletion

Q: Can I sell my bot?

A: Yes, as long as you respect licenses and regulations.

Still Have Questions?

  • 📖 Documentation: Check the wiki
  • 🐛 Bugs: GitHub Issues
  • 💬 Questions: GitHub Discussions
  • 🔒 Security: See SECURITY.md

Can't find an answer? Open an issue

Clone this wiki locally