PHP code example of antonosipov / telegram-common

1. Go to this page and download the library: Download antonosipov/telegram-common library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

antonosipov / telegram-common example snippets

 

namespace App\Http\Controllers;

use Antonosipov\TelegramCommon\Message;
use Antonosipov\TelegramCommon\TelegramService;
use Illuminate\Http\Request;

class TelegramHookController extends Controller
{


    public function __construct(protected TelegramService $telegramService)
    {
    }

    public function hook(Request $request)
    {
        $message = Message::fromRequest($request);
        if($message){
            $this->telegramService->sendMessage($message->getChat()->getId(), $message->getText());
        }

    }
}



 php artisan vendor:publish --provider="Antonosipov\TelegramCommon\Providers\TelegramCommonServiceProvider"
config/telegram-common.php