8000 Routing · wekser/laragram Wiki · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Routing

Sergey Lapin edited this page Feb 10, 2019 · 4 revisions

The Default Route File

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.

Registering A Routes

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');

Available Router Bindings

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');

Catching of incoming data

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');

Default Route Bind Listeners

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

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.

Prologue

Getting Started

The Basics

Security

Clone this wiki locally
0