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

29 lines
803 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;
class TelegramController extends Controller
{
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();
return [
"start_link" => "https://t.me/$telegramBotUsername?start=$telegramBotStartParameter"
];
}
}