allerta-vvf/backend/app/Http/Controllers/TelegramController.php

35 lines
980 B
PHP
Raw Normal View History

2023-08-29 16:18:26 +02:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\TelegramBotLogins;
use DefStudio\Telegraph\Models\TelegraphBot;
use Illuminate\Support\Str;
2023-09-01 14:24:10 +02:00
use App\Utils\Logger;
2023-08-29 16:18:26 +02:00
class TelegramController extends Controller
{
2024-02-24 00:52:25 +01:00
/**
* Returns a link that the user can use to start the login process
*/
2023-08-29 16:18:26 +02:00
public function loginToken(Request $request)
{
//Get telegramBotUsername from the name of the first bot (first row)
$telegramBotUsername = TelegraphBot::first()->name;
$telegramBotStartParameter = (string) Str::uuid();
$row = new TelegramBotLogins();
$row->chat_id = null;
$row->tmp_login_code = $telegramBotStartParameter;
$row->user = $request->user()->id;
$row->save();
2023-09-01 14:24:10 +02:00
Logger::log("Inizio procedura collegamento bot Telegram");
2023-08-29 16:18:26 +02:00
return [
"start_link" => "https://t.me/$telegramBotUsername?start=$telegramBotStartParameter"
];
}
}