Add authenticated Telegram ticket replies and notification tracking
This commit is contained in:
1 parent
9f8f297a5d
commit
6c9422d055
21 files changed
+439
-82
No files matched your search
@@ -56,12 +56,15 @@ class ConfigController extends Controller
|
||||
if (blank($hookUrl)) {
|
||||
return $this->fail([422, 'Telegram Webhook地址未配置']);
|
||||
}
|
||||
$hookUrl .= '?' . http_build_query([
|
||||
'access_token' => md5(admin_setting('telegram_bot_token', $request->input('telegram_bot_token')))
|
||||
]);
|
||||
$telegramService = new TelegramService($request->input('telegram_bot_token'));
|
||||
$telegramService->getMe();
|
||||
$telegramService->setWebhook(url: $hookUrl);
|
||||
$existing = $telegramService->getWebhookInfo()->result->url ?? '';
|
||||
if ($existing !== '' && (parse_url($existing, PHP_URL_HOST) !== parse_url($hookUrl, PHP_URL_HOST) || parse_url($existing, PHP_URL_PATH) !== parse_url($hookUrl, PHP_URL_PATH))) {
|
||||
return $this->fail([422, '机器人已有其他 Webhook,未覆盖。请使用独立客服机器人或先确认现有用途。']);
|
||||
}
|
||||
$secret = bin2hex(random_bytes(32));
|
||||
$telegramService->setWebhook($hookUrl, $secret);
|
||||
admin_setting(['telegram_webhook_secret' => $secret, 'telegram_bot_enable' => true]);
|
||||
$telegramService->registerBotCommands();
|
||||
return $this->success([
|
||||
'success' => true,
|
||||
|
||||
Reference in new issue
Block a user