Files
sirpremiumv2/app/Http/Controllers/TelegramWebhookController.php
T
LizandroandClaude Sonnet 4.6 f39f3d4045 Add Whisper voice transcription to Telegram bot
- handleVoice() downloads Telegram audio and transcribes via Whisper API
- transcribeAudio() calls Whisper with Basic Auth, handles json response
- TelegramWebhookController now routes message.voice and message.audio
- Whisper URL, token and toggle configurable from admin config panel
- Transcribed text echoed back to user then processed as normal text intent

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-14 19:00:57 +00:00

59 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Services\TelegramBotService;
use Illuminate\Http\Request;
class TelegramWebhookController extends Controller
{
public function handle(Request $request)
{
$update = $request->all();
$bot = new TelegramBotService();
// Inline keyboard button taps
if (isset($update['callback_query'])) {
$cq = $update['callback_query'];
$chatId = (string) $cq['message']['chat']['id'];
$bot->handleCallback($chatId, $cq['id'], $cq['data'] ?? '');
return response()->json(['ok' => true]);
}
// Photos (payment receipts)
if (isset($update['message']['photo'])) {
$chatId = (string) $update['message']['chat']['id'];
$photos = $update['message']['photo'];
$fileId = end($photos)['file_id'];
$bot->handlePhoto($chatId, $fileId);
return response()->json(['ok' => true]);
}
// Voice / audio messages
if (isset($update['message']['voice']) || isset($update['message']['audio'])) {
$chatId = (string) $update['message']['chat']['id'];
$fileId = $update['message']['voice']['file_id'] ?? $update['message']['audio']['file_id'];
$nombre = trim(
($update['message']['from']['first_name'] ?? '') . ' ' .
($update['message']['from']['last_name'] ?? '')
);
$bot->handleVoice($chatId, $fileId, $nombre);
return response()->json(['ok' => true]);
}
// Text messages
if (isset($update['message']['text'])) {
$chatId = (string) $update['message']['chat']['id'];
$text = $update['message']['text'];
$nombre = trim(
($update['message']['from']['first_name'] ?? '') . ' ' .
($update['message']['from']['last_name'] ?? '')
);
$bot->handleText($chatId, $text, $nombre);
return response()->json(['ok' => true]);
}
return response()->json(['ok' => true]);
}
}