'irazasyed/telegram-bot-sdk get update object on commands

I was using irazasyed/telegram-bot-sdk for a Telegram bot in Laravel. I just wanted to access the update object on my StartCommand class and send a welcome message to a user with his name. The StartCommand class looks like this:

<?php

namespace App\TelegramCommands;

use Telegram\Bot\Commands\Command;

class StartCommand extends Command
{
    protected $name = "start";

    protected $description = "Lets you get started";

    public function handle()
    {
        $this->replyWithMessage(['text' => 'Welcome ']);
    }
}

And the route (which is inside api.php) is:

Route::post('/'.env('TELEGRAM_BOT_TOKEN').'/webhook', function (Request $request) {
    $update = Telegram::commandsHandler(true);
    return 'ok';
});

I just wanted to access users data when he sends /start command and replay with a message like, "Welcome [his name]". Thank you in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source