antonosipov/telegram-common

该包最新版本(0.1.5)没有提供许可证信息。

0.1.5 2023-07-24 11:05 UTC

This package is auto-updated.

Last update: 2024-09-24 13:51:49 UTC


README

如何安装

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

添加到 .env

  TELEGRAM_TOKEN=<token_here>

或在 config/telegram-common.php 中更改环境变量

配置

您可以轻松地从请求中获取Telegram实体,例如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());
        }

    }
}