You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For enhanced security, you can set a secret token when you [set your webhook](https://core.telegram.org/bots/api#setwebhook). Telegram will then send this token in the `X-Telegram-Bot-Api-Secret-Token` header with every update. This library can automatically validate this token for you.
122
+
123
+
### 1. Set the Webhook with a Secret Token
124
+
125
+
When setting your webhook, provide a `secret_token`:
In your webhook handler (e.g., `hook.php`), set the same secret token on your `Telegram` object. The library will then automatically check the header on incoming requests and throw an exception if the token is missing or invalid.
136
+
137
+
```php
138
+
<?php
139
+
140
+
require_once __DIR__ . '/vendor/autoload.php';
141
+
142
+
$bot_api_key = 'YOUR_BOT_API_KEY';
143
+
$bot_username = 'YOUR_BOT_USERNAME';
144
+
$bot_secret = 'YOUR_SECRET_TOKEN';
145
+
146
+
try {
147
+
$telegram = new Longman\TelegramBot\Telegram($bot_api_key, $bot_username);
148
+
149
+
// Set the secret token for incoming webhook requests
0 commit comments