-
Notifications
You must be signed in to change notification settings - Fork 0
Routing
All Laragram routes are defined in your route file, which are located in the routes
directory. These file are automatically loaded by the framework. The routes/laragram.php
file defines routes that are for your Telegram bot interface.
Any new route must always be tied to the type of the object received via Telegram bot updates. For organize your request handling logic used Controller classes.
$bot->bind('message')->call('ExampleController@index');
The router allows you to register routes that respond to any user request with bot (channels are not supported):
$bot->bind('message')->call('BotController@message');
$bot->bind('edited_message')->call('BotController@editedMessage');
$bot->bind('inline_query')->call('BotController@inlineQuery');
$bot->bind('chosen_inline_result')->call('BotController@chosenInlineResult');
$bot->bind('callback_query')->call('BotController@callbackQuery');
$bot->bind('shipping_query')->call('BotController@shippingQuery');
$bot->bind('pre_checkout_query')->call('BotController@preCheckoutQuery');
For example, you need to catch an incoming request with information that the user sent a specific command to your bot. It is very easy to do!
$bot->bind('message')->catch('/start')->call('BotController@start');
We can also specify a binding listener to expect data from a specific "location" (field in update object).
$bot->bind('message', 'text')->catch('/start')->call('BotController@start');
$bot->bind('callback_query', 'data')->catch('deposit')->call('AccountController@deposit');
$bot->bind('callback_query', 'game_short_name')->catch('tetris')->call('TetrisController@play');
Event | Listener |
---|---|
message | text |
edited_message | text |
inline_query | query |
chosen_inline_result | result_id |
callback_query | data |
shipping_query | invoice_payload |
pre_checkout_query | invoice_payload |
Default listeners don't need be specify to bind.
Named routes allow the convenient implement of user location in bot and redirect her for specific routes. You may specify a name for a route by changing the alias
method onto the route definition:
$bot->bind('message')->alias('home')->call('BotController@home');
Once you have assigned a name to a given route, you may use the route's name when redirects via the BotResponse.