add telegram bot

This commit is contained in:
xiaomlove
2024-04-01 02:35:11 +08:00
parent d1530f7611
commit dea1677522
3 changed files with 122 additions and 2 deletions

View File

@@ -5,6 +5,8 @@ namespace App\Http\Controllers;
use App\Repositories\ToolRepository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Telegram\Bot\Api;
use Telegram\Bot\Commands\HelpCommand;
class ToolController extends Controller
{
@@ -22,9 +24,42 @@ class ToolController extends Controller
return $this->success($result);
}
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';
}
public function test(Request $request)
{
dd($request->all());
$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);
}
}