Skip to content

Commit 21c6ed9

Browse files
authored
Merge pull request #66 from nutgram/webhook-laravel
Refactor webhook setup instructions in laravel.md
2 parents 0554f07 + b87b257 commit 21c6ed9

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

docs/configuration/laravel.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -218,32 +218,28 @@ Just enable the `mixins` option in the `config/nutgram.php` file, and you will b
218218
## Webhook updates
219219

220220
For production mode, the webhook mode is recommended. Run the bot in that way is really simple, you should just create a
221-
new controller `php artisan make:controller FrontController`, and call the `run` method on the bot instance:
221+
new route and call the `run` method on the bot instance:
222222

223223
```php
224-
class FrontController extends Controller
225-
{
226-
/**
227-
* Handle the telegram webhook request.
228-
*/
229-
public function __invoke(Nutgram $bot)
230-
{
231-
$bot->run();
232-
}
233-
}
224+
// routes/api.php
225+
226+
Route::post('/webhook', fn(Nutgram $bot) => $bot->run());
234227
```
235228

236229
:::tip
237230
When calling the `run()` method on the bot instance, it automatically recognize if use the `Polling` method to retrieve updates,
238231
or `Webhook`, based on whether the current instance is running in a cli process, or is serving a web request.
239232
:::
240233

241-
and remember to register it on you http routes:
234+
:::danger
235+
Remember to add your route to the `routes/api.php` file, or make sure that the route is not protected by any authentication middleware or CSRF protection.
236+
:::
242237

243-
```php
244-
// routes/api.php
238+
### Set Webhook
239+
To set the bot webhook, you can use the `nutgram:hook:set` command:
245240

246-
Route::post('/webhook', 'FrontController');
241+
```bash
242+
php artisan nutgram:hook:set https://your-domain.com/api/webhook
247243
```
248244

249245
### Safe Mode
@@ -252,9 +248,7 @@ The safe mode is enabled by default via the `safe_mode` option in the `config/nu
252248
When enabled, the webhook mode will validate the incoming update using a secret token.
253249

254250
:::caution
255-
256-
Make sure to set the bot webhook via the `nutgram:hook:set` command!
257-
251+
Make sure to set the bot webhook via the `nutgram:hook:set` command otherwise the safe mode will reject all incoming updates.
258252
:::
259253

260254
## Facade support

0 commit comments

Comments
 (0)