doge 14 часов назад
Родитель
Сommit
c16017f6e6
3 измененных файлов с 18 добавлено и 10 удалено
  1. 5 10
      app/Http/Controllers/api/Home.php
  2. 5 0
      app/Http/Controllers/api/TelegramWebHook.php
  3. 8 0
      config/logging.php

+ 5 - 10
app/Http/Controllers/api/Home.php

@@ -24,7 +24,6 @@ use Telegram\Bot\Api;
 use Telegram\Bot\Exceptions\TelegramSDKException;
 use Telegram\Bot\Exceptions\TelegramSDKException;
 use Telegram\Bot\FileUpload\InputFile;
 use Telegram\Bot\FileUpload\InputFile;
 use Telegram\Bot\Objects\BotCommand;
 use Telegram\Bot\Objects\BotCommand;
-use Illuminate\Support\Facades\Log;
 
 
 class Home extends Controller
 class Home extends Controller
 {
 {
@@ -155,19 +154,15 @@ class Home extends Controller
             // 设置 Webhook
             // 设置 Webhook
             $webhookUrl = url('/api/onMessage'); // Webhook URL,指向刚才定义的路由
             $webhookUrl = url('/api/onMessage'); // Webhook URL,指向刚才定义的路由
 
 
-            $allowed_updates = [
-                'message', 'callback_query',
-//                'message_reaction', 'message_reaction_count',
-//                'removed_chat_boost', 'chat_boost',
-//                'chat_join_request', 'chat_member'
-            ];
-            $res = $telegram->setWebhook(['url' => $webhookUrl, 'allowed_updates' => $allowed_updates, 'drop_pending_updates' => true]);
+            $res = $telegram->setWebhook([
+                'url' => $webhookUrl,
+                'allowed_updates' => ['message', 'edited_message', 'channel_post', 'edited_channel_post', 'callback_query'],
+            ]);
 
 
         } catch (TelegramSDKException $e) {
         } catch (TelegramSDKException $e) {
             return $this->error($e->getCode(), $e->getMessage());
             return $this->error($e->getCode(), $e->getMessage());
         }
         }
-        Log::info('Telegram 回调数据(JSON): ' . json_encode([123454], JSON_UNESCAPED_UNICODE));
         return $this->success($res);
         return $this->success($res);
     }
     }
 
 
-}
+}

+ 5 - 0
app/Http/Controllers/api/TelegramWebHook.php

@@ -46,6 +46,11 @@ class TelegramWebHook extends BaseController
      */
      */
     public function handle(Request $request): JsonResponse
     public function handle(Request $request): JsonResponse
     {
     {
+        $payload = json_decode($request->getContent(), true);
+        if (is_int($payload['update_id'] ?? null)) {
+            rescue(fn () => Log::channel('telegram_webhook')->info('Telegram 收到更新', ['update' => $payload]));
+        }
+
         $telegram = new Api(config('services.telegram.token'));
         $telegram = new Api(config('services.telegram.token'));
 
 
         try {
         try {

+ 8 - 0
config/logging.php

@@ -150,6 +150,14 @@ return [
             'path' => storage_path('logs/wallet.log'),
             'path' => storage_path('logs/wallet.log'),
             'level' => 'info',
             'level' => 'info',
         ],
         ],
+        'telegram_webhook' => [
+            'driver' => 'daily',
+            'path' => storage_path('logs/telegram-webhook.log'),
+            'level' => 'info',
+            'days' => 14,
+            'permission' => 0600,
+            'locking' => true,
+        ],
         'issue' => [
         'issue' => [
             'driver' => 'daily',  // 改为 daily
             'driver' => 'daily',  // 改为 daily
             'path' => storage_path('logs/issue.log'),
             'path' => storage_path('logs/issue.log'),