Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add router #488

sadegh19b started this conversation in Ideas
Sep 1, 2023 · 3 comments · 2 replies
Discussion options

Hi, I have a suggestion for this great package. It would be great if a router could be added.

I will give some examples:

TelegraphRouter::command('start', [\App\Telegraph\Controllers\BotMenuController::class, 'start']);
TelegraphRouter::callback('cancel', function (\DefStudio\Telegraph\Models\TelegraphChat $chat, \DefStudio\Telegraph\DTO\CallbackQuery $callbackQuery, \Illuminate\Support\Collection $data) {
 // do something
});
TelegraphRouter::message('❌ Cancel', \App\Telegraph\Controllers\BotMenuController::class)->middleware(\App\Telegraph\Middleware\CheckCancel::class);

A router is similar to the Laravel router, which can be used for commands, callback queries, and messages. action it can be called by closure, an invokable controller, or as an array whose first index is the controller and the second index is the method. It can also have middleware like Laravel for more flexibility.

A file called telegraph.php can be created in the routes folder to define the routes there.

If it's implementing these things, it will be great and this package will be more useful.

You must be logged in to vote

Replies: 3 comments 2 replies

Comment options

Hi!

like this idea, will further explore it in v2 which we'll start developing in the next months

You must be logged in to vote
0 replies
Comment options

Hi.

Is there an approximate release time for version 2 with routing functionality?

You must be logged in to vote
2 replies
Comment options

@fabio-ivona Hi. Any news about the next version?

Comment options

Hi, we are fixing the payment feature and will be out with v2 a couple of months after, no need for now

Comment options

hi! what about routing for several handlers?

i do this updates, migration:

 if (!Schema::hasColumn('telegraph_bots', 'handler_class_name')) {
 Schema::table('telegraph_bots', function (Blueprint $table) {
 $table->string('handler_class_name')->nullable()->after('name');
 });
 }

config:
'handler' => \App\Http\Telegram\RouteWebhookHandler::class,

handler:

class RouteWebhookHandler extends WebhookHandler
{
 public function handle(Request $request, TelegraphBot $bot): void
 {
 if (empty($bot->handler_class_name))
 return;
 $handlerClassName = '\App\Http\Telegram\\'.$bot->handler_class_name;
 if (!class_exists($handlerClassName)) 
 return;
 /** @var WebhookHandler $handler */
 $handler = app($handlerClassName);
 $handler->handle($request, $bot);
 }
}
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Converted from issue

This discussion was converted from issue #406 on January 26, 2024 07:54.

AltStyle によって変換されたページ (->オリジナル) /