antonosipov/telegram-common

There is no license information available for the latest version (0.1.5) of this package.

0.1.5 2023-07-24 11:05 UTC

This package is auto-updated.

Last update: 2024-04-24 12:46:33 UTC


README

How to install

   composer require antonosipov/telegram-common
 php artisan vendor:publish --provider="Antonosipov\TelegramCommon\Providers\TelegramCommonServiceProvider"

Add to .env

  TELEGRAM_TOKEN=<token_here>

or change env variable in config/telegram-common.php

Config

You can get telegram entities from Request easy, example echo-bot:

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());
        }

    }
}