1. Go to this page and download the library: Download tarik02/laravel-telegram 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/ */
tarik02 / laravel-telegram example snippets
namespace App\Telegram;
use Illuminate\Contracts\Container\Container;
use Tarik02\Telegram\Methods\SendMessage;
use Tarik02\LaravelTelegram\{
Contracts\Dispatcher as TelegramDispatcher,
Request,
Response
};
/**
* Class Dispatcher
* @package App\Telegram
*/
class Dispatcher implements TelegramDispatcher
{
/**
* @var Container
*/
protected Container $container;
/**
* @param Container $container
* @return void
*/
public function __construct(Container $container)
{
$this->container = $container;
}
/**
* @param Request $request
* @return Response|null
*/
public function dispatch(Request $request): ?Response
{
$update = $request->update();
if (null !== $message = $update->message()) {
$text = \sprintf(
"Hello, %s. I received your message with text:\n%s",
$message->from()->firstName(),
$message->text() ?? ''
);
return Response::reply(
SendMessage::make()
->withChatId($message->chat()->id())
->withText($text)
);
}
return null;
}
}
namespace App\Telegram;
use Tarik02\LaravelTelegram\Kernel as TelegramKernel;
/**
* Class Kernel
* @package App\Telegram
*/
class Kernel extends TelegramKernel
{
/**
* @var string[]
*/
protected array $middleware = [
];
}