-
Notifications
You must be signed in to change notification settings - Fork 0
FAQ
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.
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
A: No, TGbotPHP doesn't require a database. However, you can integrate one if you need to store user data.
A: Yes! Use $bot->isPrivate() to check if it's a private chat, then handle group chats differently.
A: Two ways:
Option 1 - Download:
require_once "botlib.php";Option 2 - Composer:
composer require lightyagami28/tgbotphpA: Yes, you need a web server with:
- PHP 7.0+ (8.4+ recommended)
- HTTPS support
- cURL extension
A: Not for webhooks (Telegram requires public HTTPS). Use long polling instead or deploy to a real server.
A:
- Open Telegram
- Search for @BotFather
- Send
/newbot - Follow the prompts
- Copy your 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'];A: No, only the most common methods are implemented. For others, use the $bot->send() method directly or extend the class.
A: Yes! TGbotPHP supports:
- Photos (via
photoparameter) - Custom media via
$bot->send()
A: Not yet. You can implement it using $bot->send() directly.
A: TGbotPHP is generic - use $bot->send() for any Telegram Bot API method.
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.
A:
- Open @BotFather
- Select your bot
- Use
/revokeor/newtoken - Update your bot
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;
}A:
- Use environment variables
- Add to
.gitignore - Review git history
- Use
.envfiles (never commit) - Use secret management tools
A: Depends on your server:
- Shared hosting: 1000s of users
- VPS: 10000s+ users
- Scale with load balancers
A: Yes, response time is typically <100ms. Optimize by:
- Caching database queries
- Using CDN for media
- Profiling your code
A: Yes, if you need to:
- Store user preferences
- Track conversations
- Persist data
Use MySQL with prepared statements.
A: Options:
- Shared hosting (easiest)
- VPS (more control)
- Docker (consistent)
- Serverless (if available)
See Deployment guide.
A:
curl -X POST "https://api.telegram.org/bot<TOKEN>/setWebhook" \
-d "url=https://your-domain.com/webhook.php"A: No, Telegram uses domain names.
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.
A: Enable debug mode:
$bot = new botTG(
token: $token,
updates: $updates,
debug: true,
debugFile: '/var/log/bot.log'
);A: Simulate webhooks:
$testUpdate = json_encode(['update_id' => 1, 'message' => [...]]);
$bot = new botTG(token: $token, updates: $testUpdate, debug: true);A: Yes! Modern IDEs support:
- PHP 8.4 features
- Type hints
- AutoComplete
- Debugging
Recommended: VS Code, PhpStorm, Sublime Text
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());
}
}A: Check:
- Webhook registered:
getWebhookInfo - Server responding:
curl https://your-domain.com/webhook.php - Logs: Check error logs
- HTTPS: Must be HTTPS
See Troubleshooting.
A: Common causes:
- Empty message text
- Invalid keyboard JSON
- Wrong parameter types
Check error logs and use debug mode.
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;
}A: Solutions:
- Use Let's Encrypt (free)
- Check certificate validity
- Renew before expiry
- Verify domain matches
A: Yes! See CONTRIBUTING.md
A: Use GitHub Issues with:
- Clear title
- Steps to reproduce
- Expected vs actual behavior
- Error logs
A: Create a GitHub Issue with:
- Feature description
- Use case
- Proposed implementation (optional)
A: Check CHANGELOG.md
A: Not yet - this is a bot limitation, not TGbotPHP.
A: Use Telegram payments API:
$bot->send('sendInvoice', [...]);A: Implement them:
if ($bot->update->message?->chat?->type !== 'private') {
exit; // Ignore group messages
}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;
}
}A: Yes, as long as you:
- Follow Telegram's bot policies
- Don't spam users
- Don't impersonate others
- Respect privacy
A: Yes, respect:
- User data storage regulations (GDPR, etc.)
- Permission for data collection
- Right to deletion
A: Yes, as long as you respect licenses and regulations.
- 📖 Documentation: Check the wiki
- 🐛 Bugs: GitHub Issues
- 💬 Questions: GitHub Discussions
- 🔒 Security: See SECURITY.md
Can't find an answer? Open an issue