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
@@ -24,8 +24,11 @@ class TelegramController extends Controller
|
||||
|
||||
public function webhook(Request $request): void
|
||||
{
|
||||
$expectedToken = md5(admin_setting('telegram_bot_token'));
|
||||
if ($request->input('access_token') !== $expectedToken) {
|
||||
$botToken = (string) admin_setting('telegram_bot_token', '');
|
||||
if ($botToken === '' || !admin_setting('telegram_bot_enable', false)) { throw new ApiException('Telegram bot disabled', 401); }
|
||||
$secret = (string) admin_setting('telegram_webhook_secret', '');
|
||||
$expectedToken = md5($botToken);
|
||||
if ($secret !== '' ? !hash_equals($secret, (string) $request->header('X-Telegram-Bot-Api-Secret-Token', '')) : !hash_equals($expectedToken, (string) $request->input('access_token', ''))) {
|
||||
throw new ApiException('access_token is error', 401);
|
||||
}
|
||||
|
||||
@@ -50,8 +53,9 @@ class TelegramController extends Controller
|
||||
}
|
||||
HookManager::call('telegram.message.after', [$msg]);
|
||||
} catch (\Exception $e) {
|
||||
if (($msg->message_type ?? '') === 'reply_message') { throw new ApiException('工单回复暂时未完成,请重试', 500); }
|
||||
HookManager::call('telegram.message.error', [$msg, $e]);
|
||||
$this->telegramService->sendMessage($msg->chat_id, $e->getMessage());
|
||||
$this->telegramService->sendMessage($msg->chat_id, '暂时无法处理,请稍后重试。');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +86,8 @@ class TelegramController extends Controller
|
||||
$text = explode(' ', $message['text']);
|
||||
|
||||
$this->msg = (object) [
|
||||
'raw_message' => $message,
|
||||
'update_id' => $data['update_id'] ?? 0,
|
||||
'command' => $text[0],
|
||||
'args' => array_slice($text, 1),
|
||||
'chat_id' => $message['chat']['id'],
|
||||
|
||||
Reference in new issue
Block a user