defstudio / telegraph

Telegraph is a Laravel package for fluently interacting with Telegram Bots
MIT License
697 stars 118 forks source link

How to handler parameters of action sent by buttons #448

Closed erkinov-wtf closed 10 months ago

erkinov-wtf commented 10 months ago

hello, im stuck on the step where i cant retrieve parameters form buttons here's my code:

public function groups()
    {
        $name = env('APP_NAME');
        $groupsCount = Group::all()->count();

        Telegraph::message("Groups of <b>$name</b> - total $groupsCount groups:\n\n")
            ->keyboard(Keyboard::make()->buttons([
                Button::make('Group 1')->action('group')->param('id', 35),
                Button::make('Group 2')->action('group')->param('id', 36),
                Button::make('Group 3')->action('group')->param('id', 37),
            ])->chunk(3))
            ->send();
    }

    public function group($id)
    {
        $group = Group::find($id);
        Telegraph::message($group->title)->send();
    }

so how i can get id of the group

erkinov-wtf commented 10 months ago

resolved version of code: public function groups() { $name = env('APP_NAME'); $groupsCount = Group::all()->count();

    Telegraph::message("Groups of <b>$name</b> - total $groupsCount groups:\n\n")
        ->keyboard(Keyboard::make()->buttons([
            Button::make('Group 1')->action('group')->param('id', 35),
            Button::make('Group 2')->action('group')->param('id', 36),
            Button::make('Group 3')->action('group')->param('id', 37),
        ])->chunk(3))
        ->send();
}

public function group($id)
{
     $groupId = $this->data->get('id');
    Telegraph::message($groupId->title)->send();
}