2021-05-02 17:24:05 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Repositories\ToolRepository;
|
|
|
|
|
use Illuminate\Http\Request;
|
2022-03-31 16:28:08 +08:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2024-04-01 02:35:11 +08:00
|
|
|
use Telegram\Bot\Api;
|
|
|
|
|
use Telegram\Bot\Commands\HelpCommand;
|
2021-05-02 17:24:05 +08:00
|
|
|
|
|
|
|
|
class ToolController extends Controller
|
|
|
|
|
{
|
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
|
|
public function __construct(ToolRepository $repository)
|
|
|
|
|
{
|
|
|
|
|
$this->repository = $repository;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-31 16:28:08 +08:00
|
|
|
public function notifications(): array
|
|
|
|
|
{
|
|
|
|
|
$user = Auth::user();
|
|
|
|
|
$result = $this->repository->getNotificationCount($user);
|
|
|
|
|
return $this->success($result);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-01 02:35:11 +08:00
|
|
|
public function tgBot(): string
|
|
|
|
|
{
|
|
|
|
|
$token = "xxxxxx";
|
|
|
|
|
$telegram = new Api($token);
|
|
|
|
|
$commandHelp = new HelpCommand();
|
|
|
|
|
$commandBind = new TgCommandBind();
|
|
|
|
|
$telegram->addCommand($commandHelp);
|
|
|
|
|
$telegram->addCommand($commandBind);
|
|
|
|
|
$update = $telegram->commandsHandler(true);
|
|
|
|
|
return 'OK';
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-08 03:35:41 +08:00
|
|
|
public function test(Request $request)
|
|
|
|
|
{
|
2024-04-01 02:35:11 +08:00
|
|
|
$token = "xxxxxx";
|
|
|
|
|
$telegram = new Api($token);
|
|
|
|
|
// $response = $telegram->getMe();
|
|
|
|
|
// $response = $telegram->sendMessage([
|
|
|
|
|
// "chat_id" => "-4170177008",
|
|
|
|
|
// "text" => "Comes from xiaomlove!",
|
|
|
|
|
// ]);
|
|
|
|
|
|
|
|
|
|
$commandHelp = new HelpCommand();
|
|
|
|
|
$commandBind = new TgCommandBind();
|
|
|
|
|
|
|
|
|
|
$commands = [
|
|
|
|
|
['command' => $commandHelp->getName(), 'description' => $commandHelp->getDescription()],
|
|
|
|
|
['command' => $commandBind->getName(), 'description' => $commandBind->getDescription()],
|
|
|
|
|
];
|
|
|
|
|
$response = $telegram->setMyCommands([
|
|
|
|
|
"commands" => json_encode($commands)
|
|
|
|
|
]);
|
|
|
|
|
// $response = $telegram->setWebhook(['url' => 'https://dev.nexusphp.org/nexusphp-tgbot/webhook']);
|
|
|
|
|
|
|
|
|
|
// $response = $telegram->getWebhookUpdate();
|
|
|
|
|
dd($response);
|
2024-03-08 03:35:41 +08:00
|
|
|
}
|
|
|
|
|
|
2021-05-02 17:24:05 +08:00
|
|
|
}
|